From ef01d099ca280ba3aa79a672c4c96425a9963697 Mon Sep 17 00:00:00 2001 From: Gurinder Singh Date: Sat, 6 Jul 2024 11:32:32 +0530 Subject: [PATCH] Change a span_bug to span_delayed_bug to fix an ICE caused when a with expression is not a struct --- .../rustc_hir_typeck/src/expr_use_visitor.rs | 5 +++- tests/crashes/127332.rs | 9 -------- .../typeck/ice-with-expr-not-struct-127332.rs | 23 +++++++++++++++++++ .../ice-with-expr-not-struct-127332.stderr | 9 ++++++++ 4 files changed, 36 insertions(+), 10 deletions(-) delete mode 100644 tests/crashes/127332.rs create mode 100644 tests/ui/typeck/ice-with-expr-not-struct-127332.rs create mode 100644 tests/ui/typeck/ice-with-expr-not-struct-127332.stderr diff --git a/compiler/rustc_hir_typeck/src/expr_use_visitor.rs b/compiler/rustc_hir_typeck/src/expr_use_visitor.rs index c8ab0429ffc70..c27197f0554a6 100644 --- a/compiler/rustc_hir_typeck/src/expr_use_visitor.rs +++ b/compiler/rustc_hir_typeck/src/expr_use_visitor.rs @@ -734,7 +734,10 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx // struct; however, when EUV is run during typeck, it // may not. This will generate an error earlier in typeck, // so we can just ignore it. - span_bug!(with_expr.span, "with expression doesn't evaluate to a struct"); + self.cx.tcx().dcx().span_delayed_bug( + with_expr.span, + "with expression doesn't evaluate to a struct", + ); } } diff --git a/tests/crashes/127332.rs b/tests/crashes/127332.rs deleted file mode 100644 index 5c14af01cece8..0000000000000 --- a/tests/crashes/127332.rs +++ /dev/null @@ -1,9 +0,0 @@ -//@ known-bug: rust-lang/rust #127332 - -async fn fun() { - enum Foo { - A { x: u32 }, - } - let orig = Foo::A { x: 5 }; - Foo::A { x: 6, ..orig }; -} diff --git a/tests/ui/typeck/ice-with-expr-not-struct-127332.rs b/tests/ui/typeck/ice-with-expr-not-struct-127332.rs new file mode 100644 index 0000000000000..a7793aab56d16 --- /dev/null +++ b/tests/ui/typeck/ice-with-expr-not-struct-127332.rs @@ -0,0 +1,23 @@ +// Regression test for ICE #127332 + +// Tests that we do not ICE when a with expr +// is not a struct but something else like an +// enum in this case +// This ICE occurred only when the enclosing +// function was async + + +// Using 2018 edition to supporess an irrelevant +// error about async fn's +//@ edition:2018 + +async fn fun() { + enum Foo { + A { x: u32 }, + } + let orig = Foo::A { x: 5 }; + Foo::A { x: 6, ..orig }; + //~^ ERROR functional record update syntax requires a struct +} + +fn main() {} diff --git a/tests/ui/typeck/ice-with-expr-not-struct-127332.stderr b/tests/ui/typeck/ice-with-expr-not-struct-127332.stderr new file mode 100644 index 0000000000000..48f19891a19d9 --- /dev/null +++ b/tests/ui/typeck/ice-with-expr-not-struct-127332.stderr @@ -0,0 +1,9 @@ +error[E0436]: functional record update syntax requires a struct + --> $DIR/ice-with-expr-not-struct-127332.rs:19:22 + | +LL | Foo::A { x: 6, ..orig }; + | ^^^^ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0436`.