Skip to content

Commit e742f80

Browse files
committed
Update based on wesleywiser review
1 parent 9d6ce61 commit e742f80

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

compiler/rustc_mir_transform/src/gvn.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -467,9 +467,9 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
467467
let val = match null_op {
468468
NullOp::SizeOf => layout.size.bytes(),
469469
NullOp::AlignOf => layout.align.abi.bytes(),
470-
NullOp::OffsetOf(fields) => layout
471-
.offset_of_subfield(&self.ecx, fields.iter().map(|f| f.index()))
472-
.bytes(),
470+
NullOp::OffsetOf(fields) => {
471+
layout.offset_of_subfield(&self.ecx, fields.iter()).bytes()
472+
}
473473
};
474474
let usize_layout = self.ecx.layout_of(self.tcx.types.usize).unwrap();
475475
let imm = ImmTy::try_from_uint(val, usize_layout)?;

library/core/src/mem/mod.rs

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

tests/ui/offset-of/offset-of-enum.rs

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

tests/ui/offset-of/offset-of-enum.stderr

+9-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ LL | offset_of!(Alpha::One, 0);
77
| not a type
88
| help: try using the variant's enum: `Alpha`
99

10+
error[E0412]: cannot find type `Beta` in this scope
11+
--> $DIR/offset-of-enum.rs:17:16
12+
|
13+
LL | offset_of!(Beta, One);
14+
| ^^^^ not found in this scope
15+
1016
error[E0795]: `One` is an enum variant; expected field at end of `offset_of`
1117
--> $DIR/offset-of-enum.rs:12:23
1218
|
@@ -35,7 +41,7 @@ error[E0599]: no variant named `NonExistent` found for enum `Alpha`
3541
LL | offset_of!(Alpha, NonExistent);
3642
| ^^^^^^^^^^^ variant not found
3743

38-
error: aborting due to 5 previous errors
44+
error: aborting due to 6 previous errors
3945

40-
Some errors have detailed explanations: E0573, E0599, E0609, E0795.
41-
For more information about an error, try `rustc --explain E0573`.
46+
Some errors have detailed explanations: E0412, E0573, E0599, E0609, E0795.
47+
For more information about an error, try `rustc --explain E0412`.

0 commit comments

Comments
 (0)