From 64a9c9cfea7f454bcc48852f0e1b99074d615ddc Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 15 Feb 2024 08:31:46 +1100 Subject: [PATCH] Reinstate some delayed bugs. These were changed to `has_errors` assertions in #121071 because that seemed reasonable, but evidently not. Fixes #121103. Fixes #121108. --- compiler/rustc_ast_lowering/src/expr.rs | 4 +++- compiler/rustc_mir_transform/src/lib.rs | 3 ++- tests/ui/lowering/issue-121108.rs | 9 +++++++++ tests/ui/lowering/issue-121108.stderr | 25 +++++++++++++++++++++++++ tests/ui/mir/issue-121103.rs | 3 +++ tests/ui/mir/issue-121103.stderr | 15 +++++++++++++++ 6 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 tests/ui/lowering/issue-121108.rs create mode 100644 tests/ui/lowering/issue-121108.stderr create mode 100644 tests/ui/mir/issue-121103.rs create mode 100644 tests/ui/mir/issue-121103.stderr diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index 73d1d891bb9..942aae3d536 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -323,7 +323,9 @@ pub(super) fn lower_expr_mut(&mut self, e: &Expr) -> hir::Expr<'hir> { ) } ExprKind::Yield(opt_expr) => self.lower_expr_yield(e.span, opt_expr.as_deref()), - ExprKind::Err => hir::ExprKind::Err(self.dcx().has_errors().unwrap()), + ExprKind::Err => { + hir::ExprKind::Err(self.dcx().span_delayed_bug(e.span, "lowered ExprKind::Err")) + } ExprKind::Try(sub_expr) => self.lower_expr_try(e.span, sub_expr), ExprKind::Paren(_) | ExprKind::ForLoop { .. } => { diff --git a/compiler/rustc_mir_transform/src/lib.rs b/compiler/rustc_mir_transform/src/lib.rs index c11fd5fcc90..b4fa7f3bea6 100644 --- a/compiler/rustc_mir_transform/src/lib.rs +++ b/compiler/rustc_mir_transform/src/lib.rs @@ -265,7 +265,8 @@ fn mir_const_qualif(tcx: TyCtxt<'_>, def: LocalDefId) -> ConstQualifs { let body = &tcx.mir_const(def).borrow(); if body.return_ty().references_error() { - assert!(tcx.dcx().has_errors().is_some(), "mir_const_qualif: MIR had errors"); + // It's possible to reach here without an error being emitted (#121103). + tcx.dcx().span_delayed_bug(body.span, "mir_const_qualif: MIR had errors"); return Default::default(); } diff --git a/tests/ui/lowering/issue-121108.rs b/tests/ui/lowering/issue-121108.rs new file mode 100644 index 00000000000..6b2dd24e4a8 --- /dev/null +++ b/tests/ui/lowering/issue-121108.rs @@ -0,0 +1,9 @@ +#![derive(Clone, Copy)] //~ ERROR `derive` attribute cannot be used at crate level + +use std::ptr::addr_of; + +const UNINHABITED_VARIANT: () = unsafe { + let v = *addr_of!(data).cast(); //~ ERROR cannot determine resolution for the macro `addr_of` +}; + +fn main() {} diff --git a/tests/ui/lowering/issue-121108.stderr b/tests/ui/lowering/issue-121108.stderr new file mode 100644 index 00000000000..c2c5746d6f1 --- /dev/null +++ b/tests/ui/lowering/issue-121108.stderr @@ -0,0 +1,25 @@ +error: `derive` attribute cannot be used at crate level + --> $DIR/issue-121108.rs:1:1 + | +LL | #![derive(Clone, Copy)] + | ^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | use std::ptr::addr_of; + | ------- the inner attribute doesn't annotate this `use` import + | +help: perhaps you meant to use an outer attribute + | +LL - #![derive(Clone, Copy)] +LL + #[derive(Clone, Copy)] + | + +error: cannot determine resolution for the macro `addr_of` + --> $DIR/issue-121108.rs:6:14 + | +LL | let v = *addr_of!(data).cast(); + | ^^^^^^^ + | + = note: import resolution is stuck, try simplifying macro imports + +error: aborting due to 2 previous errors + diff --git a/tests/ui/mir/issue-121103.rs b/tests/ui/mir/issue-121103.rs new file mode 100644 index 00000000000..e06361a6964 --- /dev/null +++ b/tests/ui/mir/issue-121103.rs @@ -0,0 +1,3 @@ +fn main(_: as lib2::TypeFn>::Output) {} +//~^ ERROR failed to resolve: use of undeclared crate or module `lib2` +//~| ERROR failed to resolve: use of undeclared crate or module `lib2` diff --git a/tests/ui/mir/issue-121103.stderr b/tests/ui/mir/issue-121103.stderr new file mode 100644 index 00000000000..913eee9e0c5 --- /dev/null +++ b/tests/ui/mir/issue-121103.stderr @@ -0,0 +1,15 @@ +error[E0433]: failed to resolve: use of undeclared crate or module `lib2` + --> $DIR/issue-121103.rs:1:38 + | +LL | fn main(_: as lib2::TypeFn>::Output) {} + | ^^^^ use of undeclared crate or module `lib2` + +error[E0433]: failed to resolve: use of undeclared crate or module `lib2` + --> $DIR/issue-121103.rs:1:13 + | +LL | fn main(_: as lib2::TypeFn>::Output) {} + | ^^^^ use of undeclared crate or module `lib2` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0433`.