Skip to content

Commit 4899108

Browse files
authored
Rollup merge of #121116 - nnethercote:fix-121103-121108, r=oli-obk
Reinstate some delayed bugs. These were changed to `has_errors` assertions in #121071 because that seemed reasonable, but evidently not. Fixes #121103. Fixes #121108.
2 parents 888fe70 + 64a9c9c commit 4899108

File tree

6 files changed

+57
-2
lines changed

6 files changed

+57
-2
lines changed

compiler/rustc_ast_lowering/src/expr.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
323323
)
324324
}
325325
ExprKind::Yield(opt_expr) => self.lower_expr_yield(e.span, opt_expr.as_deref()),
326-
ExprKind::Err => hir::ExprKind::Err(self.dcx().has_errors().unwrap()),
326+
ExprKind::Err => {
327+
hir::ExprKind::Err(self.dcx().span_delayed_bug(e.span, "lowered ExprKind::Err"))
328+
}
327329
ExprKind::Try(sub_expr) => self.lower_expr_try(e.span, sub_expr),
328330

329331
ExprKind::Paren(_) | ExprKind::ForLoop { .. } => {

compiler/rustc_mir_transform/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,8 @@ fn mir_const_qualif(tcx: TyCtxt<'_>, def: LocalDefId) -> ConstQualifs {
265265
let body = &tcx.mir_const(def).borrow();
266266

267267
if body.return_ty().references_error() {
268-
assert!(tcx.dcx().has_errors().is_some(), "mir_const_qualif: MIR had errors");
268+
// It's possible to reach here without an error being emitted (#121103).
269+
tcx.dcx().span_delayed_bug(body.span, "mir_const_qualif: MIR had errors");
269270
return Default::default();
270271
}
271272

tests/ui/lowering/issue-121108.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#![derive(Clone, Copy)] //~ ERROR `derive` attribute cannot be used at crate level
2+
3+
use std::ptr::addr_of;
4+
5+
const UNINHABITED_VARIANT: () = unsafe {
6+
let v = *addr_of!(data).cast(); //~ ERROR cannot determine resolution for the macro `addr_of`
7+
};
8+
9+
fn main() {}

tests/ui/lowering/issue-121108.stderr

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
error: `derive` attribute cannot be used at crate level
2+
--> $DIR/issue-121108.rs:1:1
3+
|
4+
LL | #![derive(Clone, Copy)]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^
6+
LL |
7+
LL | use std::ptr::addr_of;
8+
| ------- the inner attribute doesn't annotate this `use` import
9+
|
10+
help: perhaps you meant to use an outer attribute
11+
|
12+
LL - #![derive(Clone, Copy)]
13+
LL + #[derive(Clone, Copy)]
14+
|
15+
16+
error: cannot determine resolution for the macro `addr_of`
17+
--> $DIR/issue-121108.rs:6:14
18+
|
19+
LL | let v = *addr_of!(data).cast();
20+
| ^^^^^^^
21+
|
22+
= note: import resolution is stuck, try simplifying macro imports
23+
24+
error: aborting due to 2 previous errors
25+

tests/ui/mir/issue-121103.rs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main(_: <lib2::GenericType<42> as lib2::TypeFn>::Output) {}
2+
//~^ ERROR failed to resolve: use of undeclared crate or module `lib2`
3+
//~| ERROR failed to resolve: use of undeclared crate or module `lib2`

tests/ui/mir/issue-121103.stderr

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0433]: failed to resolve: use of undeclared crate or module `lib2`
2+
--> $DIR/issue-121103.rs:1:38
3+
|
4+
LL | fn main(_: <lib2::GenericType<42> as lib2::TypeFn>::Output) {}
5+
| ^^^^ use of undeclared crate or module `lib2`
6+
7+
error[E0433]: failed to resolve: use of undeclared crate or module `lib2`
8+
--> $DIR/issue-121103.rs:1:13
9+
|
10+
LL | fn main(_: <lib2::GenericType<42> as lib2::TypeFn>::Output) {}
11+
| ^^^^ use of undeclared crate or module `lib2`
12+
13+
error: aborting due to 2 previous errors
14+
15+
For more information about this error, try `rustc --explain E0433`.

0 commit comments

Comments
 (0)