Skip to content

Commit

Permalink
Update based on wesleywiser review
Browse files Browse the repository at this point in the history
  • Loading branch information
GKFX committed Oct 31, 2023
1 parent 9d6ce61 commit e742f80
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
6 changes: 3 additions & 3 deletions compiler/rustc_mir_transform/src/gvn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,9 +467,9 @@ impl<'body, 'tcx> VnState<'body, '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)?;
Expand Down
4 changes: 2 additions & 2 deletions library/core/src/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand Down
1 change: 1 addition & 0 deletions tests/ui/offset-of/offset-of-enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
12 changes: 9 additions & 3 deletions tests/ui/offset-of/offset-of-enum.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
|
Expand Down Expand Up @@ -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`.

0 comments on commit e742f80

Please sign in to comment.