Skip to content

Commit 9da3638

Browse files
committed
Move a span_bug under a condition that cx is tainted
Fixes an ICE caused when a with expression is not a struct
1 parent 5c08cc7 commit 9da3638

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)