-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Support float-like tuple indices in offset_of!() #112216
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
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// run-pass | ||
// Test for issue #112204 -- make sure this goes through the entire compilation pipeline, | ||
// similar to why `offset-of-unsized.rs` is also build-pass | ||
|
||
#![feature(offset_of)] | ||
#![feature(builtin_syntax)] | ||
|
||
use std::mem::offset_of; | ||
|
||
type ComplexTup = ((u8, (u8, (u8, u16), u8)), (u8, u32, u16)); | ||
|
||
fn main() { | ||
println!("{}", offset_of!(((u8, u8), u8), 0)); | ||
println!("{}", offset_of!(((u8, u8), u8), 1)); | ||
println!("{}", offset_of!(((u8, (u8, u8)), (u8, u8, u8)), 0.1.0)); | ||
|
||
// Complex case: do all combinations of spacings because the spacing determines what gets | ||
// sent to the lexer. | ||
println!("{}", offset_of!(ComplexTup, 0.1.1.1)); | ||
println!("{}", builtin # offset_of(ComplexTup, 0. 1.1.1)); | ||
println!("{}", offset_of!(ComplexTup, 0 . 1.1.1)); | ||
println!("{}", offset_of!(ComplexTup, 0 .1.1.1)); | ||
println!("{}", offset_of!(ComplexTup, 0.1 .1.1)); | ||
println!("{}", offset_of!(ComplexTup, 0.1 . 1.1)); | ||
println!("{}", offset_of!(ComplexTup, 0.1. 1.1)); | ||
println!("{}", builtin # offset_of(ComplexTup, 0.1.1. 1)); | ||
println!("{}", offset_of!(ComplexTup, 0.1.1 . 1)); | ||
println!("{}", offset_of!(ComplexTup, 0.1.1 .1)); | ||
|
||
println!("{}", offset_of!(((u8, u16), (u32, u16, u8)), 0.0)); | ||
println!("{}", offset_of!(((u8, u16), (u32, u16, u8)), 1.2)); | ||
} |
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,10 +1,54 @@ | ||
#![feature(offset_of)] | ||
#![feature(builtin_syntax)] | ||
|
||
use std::mem::offset_of; | ||
|
||
fn main() { | ||
core::mem::offset_of!((u8, u8), _0); //~ ERROR no field `_0` | ||
core::mem::offset_of!((u8, u8), +1); //~ ERROR no rules expected | ||
core::mem::offset_of!((u8, u8), -1); //~ ERROR no rules expected | ||
offset_of!((u8, u8), _0); //~ ERROR no field `_0` | ||
offset_of!((u8, u8), 01); //~ ERROR no field `01` | ||
offset_of!((u8, u8), 1e2); //~ ERROR no field `1e2` | ||
offset_of!((u8, u8), 1_u8); //~ ERROR no field `1_` | ||
//~| ERROR suffixes on a tuple index | ||
offset_of!((u8, u8), +1); //~ ERROR no rules expected | ||
offset_of!((u8, u8), -1); //~ ERROR no rules expected | ||
offset_of!((u8, u8), 1.); //~ ERROR expected identifier, found `)` | ||
offset_of!((u8, u8), 1 .); //~ ERROR unexpected end of macro | ||
builtin # offset_of((u8, u8), 1e2); //~ ERROR no field `1e2` | ||
builtin # offset_of((u8, u8), _0); //~ ERROR no field `_0` | ||
builtin # offset_of((u8, u8), +1); //~ ERROR expected identifier | ||
builtin # offset_of((u8, u8), 01); //~ ERROR no field `01` | ||
builtin # offset_of((u8, u8), 1_u8); //~ ERROR no field `1_` | ||
//~| ERROR suffixes on a tuple index | ||
// We need to put these into curly braces, otherwise only one of the | ||
// errors will be emitted and the others suppressed. | ||
{ builtin # offset_of((u8, u8), +1) }; //~ ERROR expected identifier, found `+` | ||
{ builtin # offset_of((u8, u8), 1.) }; //~ ERROR expected identifier, found `)` | ||
{ builtin # offset_of((u8, u8), 1 .) }; //~ ERROR expected identifier, found `)` | ||
} | ||
|
||
type ComplexTup = ((u8, (u8, u8)), u8); | ||
|
||
fn nested() { | ||
offset_of!(((u8, u16), (u32, u16, u8)), 0.2); //~ ERROR no field `2` | ||
offset_of!(((u8, u16), (u32, u16, u8)), 1.2); | ||
offset_of!(((u8, u16), (u32, u16, u8)), 1.2.0); //~ ERROR no field `0` | ||
|
||
// All combinations of spaces (this sends different tokens to the parser) | ||
offset_of!(ComplexTup, 0.0.1.); //~ ERROR expected identifier | ||
offset_of!(ComplexTup, 0 .0.1.); //~ ERROR unexpected end of macro | ||
offset_of!(ComplexTup, 0 . 0.1.); //~ ERROR unexpected end of macro | ||
offset_of!(ComplexTup, 0. 0.1.); //~ ERROR no rules expected | ||
offset_of!(ComplexTup, 0.0 .1.); //~ ERROR expected identifier, found `)` | ||
offset_of!(ComplexTup, 0.0 . 1.); //~ ERROR expected identifier, found `)` | ||
offset_of!(ComplexTup, 0.0. 1.); //~ ERROR expected identifier, found `)` | ||
|
||
// Test for builtin too to ensure that the builtin syntax can also handle these cases | ||
// We need to put these into curly braces, otherwise only one of the | ||
// errors will be emitted and the others suppressed. | ||
{ builtin # offset_of(ComplexTup, 0.0.1.) }; //~ ERROR expected identifier, found `)` | ||
{ builtin # offset_of(ComplexTup, 0 .0.1.) }; //~ ERROR expected identifier, found `)` | ||
{ builtin # offset_of(ComplexTup, 0 . 0.1.) }; //~ ERROR expected identifier, found `)` | ||
{ builtin # offset_of(ComplexTup, 0. 0.1.) }; //~ ERROR expected identifier, found `)` | ||
{ builtin # offset_of(ComplexTup, 0.0 .1.) }; //~ ERROR expected identifier, found `)` | ||
{ builtin # offset_of(ComplexTup, 0.0 . 1.) }; //~ ERROR expected identifier, found `)` | ||
{ builtin # offset_of(ComplexTup, 0.0. 1.) }; //~ ERROR expected identifier, found `)` | ||
} |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this isn't supported by the
offset_of!()
macro's declaration:Does it make sense to change it to:
and then let the builtin syntax deal with it?
This pattern is supported for normal tuple field access.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm yeah that's a bit complicated to do because it means that the builtin
offset_of
needs to get way better when it comes to errors... maybe it would be good for a follow up PR?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the
macro
arguments weren't somewhat important as documentation, I'd rather go withand do all the work in the parser.