Update based on wesleywiser review
This commit is contained in:
parent
9d6ce61376
commit
e742f809f6
4 changed files with 15 additions and 8 deletions
|
@ -467,9 +467,9 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
|
||||||
let val = match null_op {
|
let val = match null_op {
|
||||||
NullOp::SizeOf => layout.size.bytes(),
|
NullOp::SizeOf => layout.size.bytes(),
|
||||||
NullOp::AlignOf => layout.align.abi.bytes(),
|
NullOp::AlignOf => layout.align.abi.bytes(),
|
||||||
NullOp::OffsetOf(fields) => layout
|
NullOp::OffsetOf(fields) => {
|
||||||
.offset_of_subfield(&self.ecx, fields.iter().map(|f| f.index()))
|
layout.offset_of_subfield(&self.ecx, fields.iter()).bytes()
|
||||||
.bytes(),
|
}
|
||||||
};
|
};
|
||||||
let usize_layout = self.ecx.layout_of(self.tcx.types.usize).unwrap();
|
let usize_layout = self.ecx.layout_of(self.tcx.types.usize).unwrap();
|
||||||
let imm = ImmTy::try_from_uint(val, usize_layout)?;
|
let imm = ImmTy::try_from_uint(val, usize_layout)?;
|
||||||
|
|
|
@ -1299,8 +1299,8 @@ impl<T> SizedTypeProperties for T {}
|
||||||
/// Enum variants may be traversed as if they were fields. Variants themselves do
|
/// Enum variants may be traversed as if they were fields. Variants themselves do
|
||||||
/// not have an offset.
|
/// not have an offset.
|
||||||
///
|
///
|
||||||
/// Note that type layout is, in general, [platform-specific, and subject to
|
/// Note that type layout is, in general, [subject to change and
|
||||||
/// change](https://doc.rust-lang.org/reference/type-layout.html).
|
/// platform-specific](https://doc.rust-lang.org/reference/type-layout.html).
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
|
|
|
@ -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.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, 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!(Alpha, NonExistent); //~ ERROR no variant named `NonExistent` found for enum `Alpha`
|
||||||
|
offset_of!(Beta, One); //~ ERROR cannot find type `Beta` in this scope
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,12 @@ LL | offset_of!(Alpha::One, 0);
|
||||||
| not a type
|
| not a type
|
||||||
| help: try using the variant's enum: `Alpha`
|
| 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`
|
error[E0795]: `One` is an enum variant; expected field at end of `offset_of`
|
||||||
--> $DIR/offset-of-enum.rs:12:23
|
--> $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);
|
LL | offset_of!(Alpha, NonExistent);
|
||||||
| ^^^^^^^^^^^ variant not found
|
| ^^^^^^^^^^^ 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.
|
Some errors have detailed explanations: E0412, E0573, E0599, E0609, E0795.
|
||||||
For more information about an error, try `rustc --explain E0573`.
|
For more information about an error, try `rustc --explain E0412`.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue