forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for computing the minimum offset for an enum variant (rust-lang#468)
- Loading branch information
1 parent
145aa97
commit 6236188
Showing
2 changed files
with
38 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
// Check that we properly handle structs for which the compiler reorders the | ||
// fields to optimize the layout. In such cases, the field with minimum offset | ||
// need not be the first field in the original struct (e.g. in "Foo" below, "b" | ||
// is the field with minimum offset even though "a" is the leftmost field in the | ||
// original struct). | ||
|
||
enum E { | ||
Foo { a: u64, b: u16 }, | ||
Bar, | ||
} | ||
|
||
fn main() { | ||
let e = E::Foo { a: 32, b: 100 }; | ||
match e { | ||
E::Foo { a, b } => { | ||
assert!(a == 32); | ||
assert!(b == 100); | ||
} | ||
E::Bar => assert!(false), | ||
} | ||
} |