Skip to content

Commit d868bc2

Browse files
committed
Auto merge of rust-lang#119284 - Nadrieril:fix-bodiless-arm-parse, r=cjgillot
Don't drop a hir node after lowering Fixes rust-lang#119271. It seems that all hir nodes that get allocated an id must be placed within the hir on pain of ICEs. In rust-lang#118527 I dropped guards on never patterns since they're not useful, which caused the ICE.
2 parents 2a3e635 + d5b2d88 commit d868bc2

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

compiler/rustc_ast_lowering/src/expr.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
546546

547547
fn lower_arm(&mut self, arm: &Arm) -> hir::Arm<'hir> {
548548
let pat = self.lower_pat(&arm.pat);
549-
let mut guard = arm.guard.as_ref().map(|cond| {
549+
let guard = arm.guard.as_ref().map(|cond| {
550550
if let ExprKind::Let(pat, scrutinee, span, is_recovered) = &cond.kind {
551551
hir::Guard::IfLet(self.arena.alloc(hir::Let {
552552
hir_id: self.next_id(),
@@ -578,10 +578,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
578578
}
579579
} else if let Some(body) = &arm.body {
580580
self.dcx().emit_err(NeverPatternWithBody { span: body.span });
581-
guard = None;
582581
} else if let Some(g) = &arm.guard {
583582
self.dcx().emit_err(NeverPatternWithGuard { span: g.span });
584-
guard = None;
585583
}
586584

587585
// We add a fake `loop {}` arm body so that it typecks to `!`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
fn main() {}
2+
3+
fn attr_in_guard() {
4+
match None::<u32> {
5+
Some(!) //~ ERROR `!` patterns are experimental
6+
if #[deny(unused_mut)] //~ ERROR attributes on expressions are experimental
7+
false //~ ERROR a guard on a never pattern will never be run
8+
}
9+
match false {}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
error[E0658]: attributes on expressions are experimental
2+
--> $DIR/ICE-119271-never-arm-attr-in-guard.rs:6:16
3+
|
4+
LL | if #[deny(unused_mut)]
5+
| ^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
8+
= help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
9+
10+
error[E0658]: `!` patterns are experimental
11+
--> $DIR/ICE-119271-never-arm-attr-in-guard.rs:5:14
12+
|
13+
LL | Some(!)
14+
| ^
15+
|
16+
= note: see issue #118155 <https://github.com/rust-lang/rust/issues/118155> for more information
17+
= help: add `#![feature(never_patterns)]` to the crate attributes to enable
18+
19+
error: a guard on a never pattern will never be run
20+
--> $DIR/ICE-119271-never-arm-attr-in-guard.rs:7:13
21+
|
22+
LL | false
23+
| ^^^^^ help: remove this guard
24+
25+
error: aborting due to 3 previous errors
26+
27+
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)