-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Implement builtin # syntax and use it for offset_of!(...) #110694
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+333
−136
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
struct Foo { | ||
v: u8, | ||
w: u8, | ||
} | ||
fn main() { | ||
builtin # offset_of(Foo, v); //~ ERROR `builtin #` syntax is unstable | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
error[E0658]: `builtin #` syntax is unstable | ||
--> $DIR/feature-gate-builtin_syntax.rs:6:15 | ||
| | ||
LL | builtin # offset_of(Foo, v); | ||
| ^^^^^^^^^ | ||
| | ||
= note: see issue #110680 <https://github.com/rust-lang/rust/issues/110680> for more information | ||
= help: add `#![feature(builtin_syntax)]` to the crate attributes to enable | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0658`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,59 @@ | ||
error: expected one of `!`, `(`, `+`, `,`, `::`, or `<`, found `<eof>` | ||
--> $DIR/offset-of-arg-count.rs:6:16 | ||
error: unexpected end of macro invocation | ||
--> $DIR/offset-of-arg-count.rs:6:34 | ||
| | ||
LL | offset_of!(NotEnoughArguments); | ||
| ^^^^^^^^^^^^^^^^^^ expected one of `!`, `(`, `+`, `,`, `::`, or `<` | ||
| ^ missing tokens in macro arguments | ||
| | ||
note: while trying to match `,` | ||
--> $SRC_DIR/core/src/mem/mod.rs:LL:COL | ||
|
||
error: expected 2 arguments | ||
--> $DIR/offset-of-arg-count.rs:7:5 | ||
error: unexpected end of macro invocation | ||
--> $DIR/offset-of-arg-count.rs:7:45 | ||
| | ||
LL | offset_of!(NotEnoughArgumentsWithAComma, ); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| ^ missing tokens in macro arguments | ||
| | ||
note: while trying to match meta-variable `$fields:tt` | ||
--> $SRC_DIR/core/src/mem/mod.rs:LL:COL | ||
|
||
error: expected 2 arguments | ||
--> $DIR/offset-of-arg-count.rs:8:5 | ||
error: no rules expected the token `too` | ||
--> $DIR/offset-of-arg-count.rs:8:34 | ||
| | ||
LL | offset_of!(Container, field, too many arguments); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| ^^^ no rules expected this token in macro call | ||
| | ||
= note: while trying to match sequence end | ||
|
||
error: unexpected end of macro invocation | ||
--> $DIR/offset-of-arg-count.rs:11:21 | ||
| | ||
LL | offset_of!(S, f.); | ||
| ^ missing tokens in macro arguments | ||
| | ||
note: while trying to match meta-variable `$fields:tt` | ||
--> $SRC_DIR/core/src/mem/mod.rs:LL:COL | ||
|
||
error: expected identifier, found `,` | ||
--> $DIR/offset-of-arg-count.rs:12:21 | ||
| | ||
LL | offset_of!(S, f.,); | ||
| ^ expected identifier | ||
|
||
error: no rules expected the token `..` | ||
--> $DIR/offset-of-arg-count.rs:13:20 | ||
| | ||
LL | offset_of!(S, f..); | ||
| ^^ no rules expected this token in macro call | ||
| | ||
= note: while trying to match sequence start | ||
|
||
error: no rules expected the token `..` | ||
--> $DIR/offset-of-arg-count.rs:14:20 | ||
| | ||
LL | offset_of!(S, f..,); | ||
| ^^ no rules expected this token in macro call | ||
| | ||
= note: while trying to match sequence start | ||
|
||
error: aborting due to 3 previous errors | ||
error: aborting due to 7 previous errors | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#![feature(builtin_syntax)] | ||
|
||
// For the exposed macro we already test these errors in the other files, | ||
// but this test helps to make sure the builtin construct also errors. | ||
// This has the same examples as offset-of-arg-count.rs | ||
|
||
fn main() { | ||
builtin # offset_of(NotEnoughArguments); //~ ERROR expected one of | ||
} | ||
fn t1() { | ||
// Already errored upon at the macro level. Yielding an error would require | ||
// extra effort. | ||
builtin # offset_of(NotEnoughArgumentsWithAComma, ); | ||
} | ||
fn t2() { | ||
builtin # offset_of(Container, field, too many arguments); //~ ERROR expected identifier, found | ||
//~| ERROR found `,` | ||
//~| ERROR found `many` | ||
//~| ERROR found `arguments` | ||
} | ||
fn t3() { | ||
builtin # offset_of(S, f); // compiles fine | ||
} | ||
fn t4() { | ||
// Already errored upon at the macro level. Yielding an error would require | ||
// extra effort. | ||
builtin # offset_of(S, f); | ||
} | ||
fn t5() { | ||
builtin # offset_of(S, f.); //~ ERROR expected identifier | ||
} | ||
fn t6() { | ||
builtin # offset_of(S, f.,); //~ ERROR expected identifier | ||
} | ||
fn t7() { | ||
builtin # offset_of(S, f..); //~ ERROR expected one of | ||
} | ||
fn t8() { | ||
// Already errored upon at the macro level. Yielding an error would require | ||
// extra effort. | ||
builtin # offset_of(S, f..,); | ||
} | ||
|
||
struct S { f: u8, } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
error: expected one of `!`, `(`, `+`, `,`, `::`, or `<`, found `)` | ||
--> $DIR/offset-of-builtin.rs:8:43 | ||
| | ||
LL | builtin # offset_of(NotEnoughArguments); | ||
| ^ expected one of `!`, `(`, `+`, `,`, `::`, or `<` | ||
|
||
error: expected identifier, found `,` | ||
--> $DIR/offset-of-builtin.rs:16:41 | ||
| | ||
LL | builtin # offset_of(Container, field, too many arguments); | ||
| ^ | ||
| | | ||
| expected identifier | ||
| help: remove this comma | ||
|
||
error: expected one of `)` or `.`, found `,` | ||
--> $DIR/offset-of-builtin.rs:16:41 | ||
| | ||
LL | builtin # offset_of(Container, field, too many arguments); | ||
| ^ | ||
| | | ||
| expected one of `)` or `.` | ||
| help: missing `.` | ||
|
||
error: expected one of `)` or `.`, found `many` | ||
--> $DIR/offset-of-builtin.rs:16:47 | ||
| | ||
LL | builtin # offset_of(Container, field, too many arguments); | ||
| -^^^^ expected one of `)` or `.` | ||
| | | ||
| help: missing `.` | ||
|
||
error: expected one of `)` or `.`, found `arguments` | ||
--> $DIR/offset-of-builtin.rs:16:52 | ||
| | ||
LL | builtin # offset_of(Container, field, too many arguments); | ||
| -^^^^^^^^^ expected one of `)` or `.` | ||
| | | ||
| help: missing `.` | ||
|
||
error: expected identifier, found `)` | ||
--> $DIR/offset-of-builtin.rs:30:30 | ||
| | ||
LL | builtin # offset_of(S, f.); | ||
| ^ expected identifier | ||
|
||
error: expected identifier, found `,` | ||
--> $DIR/offset-of-builtin.rs:33:30 | ||
| | ||
LL | builtin # offset_of(S, f.,); | ||
| ^ expected identifier | ||
|
||
error: expected one of `)` or `.`, found `..` | ||
--> $DIR/offset-of-builtin.rs:36:29 | ||
| | ||
LL | builtin # offset_of(S, f..); | ||
| ^^ expected one of `)` or `.` | ||
| | ||
help: if you meant to bind the contents of the rest of the array pattern into `f`, use `@` | ||
| | ||
LL | builtin # offset_of(S, f @ ..); | ||
| + | ||
|
||
error: aborting due to 8 previous errors | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#![feature(builtin_syntax)] | ||
|
||
fn main() { | ||
builtin # foobar(); //~ ERROR unknown `builtin #` construct | ||
} | ||
|
||
fn not_identifier() { | ||
builtin # {}(); //~ ERROR expected identifier after | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
error: unknown `builtin #` construct `foobar` | ||
--> $DIR/builtin-syntax.rs:4:5 | ||
| | ||
LL | builtin # foobar(); | ||
| ^^^^^^^^^^^^^^^^ | ||
|
||
error: expected identifier after `builtin #` | ||
--> $DIR/builtin-syntax.rs:8:15 | ||
| | ||
LL | builtin # {}(); | ||
| ^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.