Update based on wesleywiser review

This commit is contained in:
George Bateman 2023-10-31 23:41:40 +00:00
parent 9d6ce61376
commit e742f809f6
No known key found for this signature in database
GPG Key ID: C417AA9C4039EFCF
4 changed files with 15 additions and 8 deletions

View File

@ -467,9 +467,9 @@ fn eval_to_const(&mut self, value: VnIndex) -> Option<OpTy<'tcx>> {
let val = match null_op {
NullOp::SizeOf => layout.size.bytes(),
NullOp::AlignOf => layout.align.abi.bytes(),
NullOp::OffsetOf(fields) => layout
.offset_of_subfield(&self.ecx, fields.iter().map(|f| f.index()))
.bytes(),
NullOp::OffsetOf(fields) => {
layout.offset_of_subfield(&self.ecx, fields.iter()).bytes()
}
};
let usize_layout = self.ecx.layout_of(self.tcx.types.usize).unwrap();
let imm = ImmTy::try_from_uint(val, usize_layout)?;

View File

@ -1299,8 +1299,8 @@ impl<T> SizedTypeProperties for T {}
/// Enum variants may be traversed as if they were fields. Variants themselves do
/// not have an offset.
///
/// Note that type layout is, in general, [platform-specific, and subject to
/// change](https://doc.rust-lang.org/reference/type-layout.html).
/// Note that type layout is, in general, [subject to change and
/// platform-specific](https://doc.rust-lang.org/reference/type-layout.html).
///
/// # Examples
///

View File

@ -14,4 +14,5 @@ fn main() {
offset_of!(Alpha, Two.1); //~ ERROR no field named `1` on enum variant `Alpha::Two`
offset_of!(Alpha, Two.foo); //~ ERROR no field named `foo` on enum variant `Alpha::Two`
offset_of!(Alpha, NonExistent); //~ ERROR no variant named `NonExistent` found for enum `Alpha`
offset_of!(Beta, One); //~ ERROR cannot find type `Beta` in this scope
}

View File

@ -7,6 +7,12 @@ LL | offset_of!(Alpha::One, 0);
| not a type
| help: try using the variant's enum: `Alpha`
error[E0412]: cannot find type `Beta` in this scope
--> $DIR/offset-of-enum.rs:17:16
|
LL | offset_of!(Beta, One);
| ^^^^ not found in this scope
error[E0795]: `One` is an enum variant; expected field at end of `offset_of`
--> $DIR/offset-of-enum.rs:12:23
|
@ -35,7 +41,7 @@ error[E0599]: no variant named `NonExistent` found for enum `Alpha`
LL | offset_of!(Alpha, NonExistent);
| ^^^^^^^^^^^ variant not found
error: aborting due to 5 previous errors
error: aborting due to 6 previous errors
Some errors have detailed explanations: E0573, E0599, E0609, E0795.
For more information about an error, try `rustc --explain E0573`.
Some errors have detailed explanations: E0412, E0573, E0599, E0609, E0795.
For more information about an error, try `rustc --explain E0412`.