diff options
| author | Yuki Okushi <jtitor@2k36.org> | 2021-06-19 10:14:14 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-06-19 10:14:14 +0900 |
| commit | 84d6c68822bc7c6312a00226de90fb7cdf79494c (patch) | |
| tree | f6be3106e2402ceefee0f8ae32cb8792c043558d | |
| parent | 90e5fe5f86a65fbd102e76f439f8c8d284d309d0 (diff) | |
| parent | e7a1186c6d4793a5265690dfd17fb05b15bf04ec (diff) | |
| download | rust-84d6c68822bc7c6312a00226de90fb7cdf79494c.tar.gz rust-84d6c68822bc7c6312a00226de90fb7cdf79494c.zip | |
Rollup merge of #86444 - FabianWolff:issue-83505, r=LeSeulArtichaut
Fix ICE with `#[repr(simd)]` on enum This pull request fixes #83505. `#[repr(simd)]` may only be applied to structs, which correctly causes `E0517` for the example given in #83505, but the compiler attempts to recover from this error, which leads to an ICE later, when `.non_enum_variant()` is called on the `AdtDef`. I have added a check that prevents this from happening.
| -rw-r--r-- | compiler/rustc_middle/src/ty/layout.rs | 9 | ||||
| -rw-r--r-- | src/test/ui/repr/issue-83505-repr-simd.rs | 10 | ||||
| -rw-r--r-- | src/test/ui/repr/issue-83505-repr-simd.stderr | 30 |
3 files changed, 49 insertions, 0 deletions
diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index 28a44b09de2..6b1ec1b0646 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -672,6 +672,15 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { // SIMD vector types. ty::Adt(def, substs) if def.repr.simd() => { + if !def.is_struct() { + // Should have yielded E0517 by now. + tcx.sess.delay_span_bug( + DUMMY_SP, + "#[repr(simd)] was applied to an ADT that is not a struct", + ); + return Err(LayoutError::Unknown(ty)); + } + // Supported SIMD vectors are homogeneous ADTs with at least one field: // // * #[repr(simd)] struct S(T, T, T, T); diff --git a/src/test/ui/repr/issue-83505-repr-simd.rs b/src/test/ui/repr/issue-83505-repr-simd.rs new file mode 100644 index 00000000000..280b771d015 --- /dev/null +++ b/src/test/ui/repr/issue-83505-repr-simd.rs @@ -0,0 +1,10 @@ +// Regression test for the ICE described in #83505. + +#![crate_type="lib"] + +#[repr(simd)] +//~^ ERROR: attribute should be applied to a struct [E0517] +//~| ERROR: unsupported representation for zero-variant enum [E0084] +enum Es {} +static CLs: Es; +//~^ ERROR: free static item without body diff --git a/src/test/ui/repr/issue-83505-repr-simd.stderr b/src/test/ui/repr/issue-83505-repr-simd.stderr new file mode 100644 index 00000000000..f1390a65201 --- /dev/null +++ b/src/test/ui/repr/issue-83505-repr-simd.stderr @@ -0,0 +1,30 @@ +error: free static item without body + --> $DIR/issue-83505-repr-simd.rs:9:1 + | +LL | static CLs: Es; + | ^^^^^^^^^^^^^^- + | | + | help: provide a definition for the static: `= <expr>;` + +error[E0517]: attribute should be applied to a struct + --> $DIR/issue-83505-repr-simd.rs:5:8 + | +LL | #[repr(simd)] + | ^^^^ +... +LL | enum Es {} + | ---------- not a struct + +error[E0084]: unsupported representation for zero-variant enum + --> $DIR/issue-83505-repr-simd.rs:5:1 + | +LL | #[repr(simd)] + | ^^^^^^^^^^^^^ +... +LL | enum Es {} + | ---------- zero-variant enum + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0084, E0517. +For more information about an error, try `rustc --explain E0084`. |
