-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Check tuple elements are Sized
in offset_of
#112193
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3117,16 +3117,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |
} | ||
} | ||
ty::Tuple(tys) => { | ||
let fstr = field.as_str(); | ||
|
||
if let Ok(index) = fstr.parse::<usize>() { | ||
if fstr == index.to_string() { | ||
if let Some(&field_ty) = tys.get(index) { | ||
field_indices.push(index.into()); | ||
current_container = field_ty; | ||
if let Ok(index) = field.as_str().parse::<usize>() | ||
&& field.name == sym::integer(index) | ||
{ | ||
for ty in tys.iter().take(index + 1) { | ||
self.require_type_is_sized(ty, expr.span, traits::MiscObligation); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the reason for checking all fields of the tuple (that are before the indexed field)? For ADTs we only check the field we are indexing, and the same should be enough for tuples. So I don't see the point of this loop. In #126150 I am removing it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At this point I can't remember 🤔 I think all good if it's caught by code elsewhere |
||
if let Some(&field_ty) = tys.get(index) { | ||
field_indices.push(index.into()); | ||
current_container = field_ty; | ||
|
||
continue; | ||
} | ||
continue; | ||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#![feature(offset_of)] | ||
#![feature(builtin_syntax)] | ||
|
||
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 | ||
builtin # offset_of((u8, u8), _0); //~ ERROR no field `_0` | ||
builtin # offset_of((u8, u8), +1); //~ ERROR expected identifier | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
error: expected identifier, found `+` | ||
--> $DIR/offset-of-tuple.rs:9:35 | ||
| | ||
LL | builtin # offset_of((u8, u8), +1); | ||
| ^ expected identifier | ||
|
||
error: no rules expected the token `1` | ||
--> $DIR/offset-of-tuple.rs:6:38 | ||
| | ||
LL | core::mem::offset_of!((u8, u8), +1); | ||
| ^ no rules expected this token in macro call | ||
| | ||
= note: while trying to match sequence start | ||
|
||
error: no rules expected the token `1` | ||
--> $DIR/offset-of-tuple.rs:7:38 | ||
| | ||
LL | core::mem::offset_of!((u8, u8), -1); | ||
| ^ no rules expected this token in macro call | ||
| | ||
= note: while trying to match sequence start | ||
|
||
error[E0609]: no field `_0` on type `(u8, u8)` | ||
--> $DIR/offset-of-tuple.rs:5:37 | ||
| | ||
LL | core::mem::offset_of!((u8, u8), _0); | ||
| ^^ | ||
|
||
error[E0609]: no field `_0` on type `(u8, u8)` | ||
--> $DIR/offset-of-tuple.rs:8:35 | ||
| | ||
LL | builtin # offset_of((u8, u8), _0); | ||
| ^^ | ||
|
||
error: aborting due to 5 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0609`. |
Uh oh!
There was an error while loading. Please reload this page.