Skip to content

Commit 1ee6345

Browse files
authored
Rollup merge of rust-lang#127409 - gurry:127332-ice-with-expr-not-struct, r=oli-obk
Emit a wrap expr span_bug only if context is not tainted Fixes rust-lang#127332 The ICE occurs because of this `span_bug`: https://github.com/rust-lang/rust/blob/51917e2e69702e5752bce6a4f3bfd285d0f4ae39/compiler/rustc_hir_typeck/src/expr_use_visitor.rs#L732-L738 which is triggered by the fact that we're trying to use an `enum` in a `with` expression instead of a `struct`. The issue originates in commit rust-lang@814bfe9 from PR rust-lang#127202. As per the title of that commit the ICEing code should not be reachable any more, but looks like it still is. This PR changes the code so that the `span_bug` will be emitted only if the context is not tainted by a previous error.
2 parents c40530d + 9da3638 commit 1ee6345

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

compiler/rustc_hir_typeck/src/expr_use_visitor.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,9 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
734734
// struct; however, when EUV is run during typeck, it
735735
// may not. This will generate an error earlier in typeck,
736736
// so we can just ignore it.
737-
span_bug!(with_expr.span, "with expression doesn't evaluate to a struct");
737+
if self.cx.tainted_by_errors().is_ok() {
738+
span_bug!(with_expr.span, "with expression doesn't evaluate to a struct");
739+
}
738740
}
739741
}
740742

tests/crashes/127332.rs

-9
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Regression test for ICE #127332
2+
3+
// Tests that we do not ICE when a with expr is
4+
// not a struct but something else like an enum
5+
6+
fn main() {
7+
let x = || {
8+
enum Foo {
9+
A { x: u32 },
10+
}
11+
let orig = Foo::A { x: 5 };
12+
Foo::A { x: 6, ..orig };
13+
//~^ ERROR functional record update syntax requires a struct
14+
};
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0436]: functional record update syntax requires a struct
2+
--> $DIR/ice-with-expr-not-struct-127332.rs:12:26
3+
|
4+
LL | Foo::A { x: 6, ..orig };
5+
| ^^^^
6+
7+
error: aborting due to 1 previous error
8+
9+
For more information about this error, try `rustc --explain E0436`.

0 commit comments

Comments
 (0)