Skip to content

Commit d5b2d88

Browse files
committed
Don't drop a hir node after lowering
1 parent f645628 commit d5b2d88

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
@@ -555,7 +555,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
555555

556556
fn lower_arm(&mut self, arm: &Arm) -> hir::Arm<'hir> {
557557
let pat = self.lower_pat(&arm.pat);
558-
let mut guard = arm.guard.as_ref().map(|cond| {
558+
let guard = arm.guard.as_ref().map(|cond| {
559559
if let ExprKind::Let(pat, scrutinee, span, is_recovered) = &cond.kind {
560560
hir::Guard::IfLet(self.arena.alloc(hir::Let {
561561
hir_id: self.next_id(),
@@ -587,10 +587,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
587587
}
588588
} else if let Some(body) = &arm.body {
589589
self.dcx().emit_err(NeverPatternWithBody { span: body.span });
590-
guard = None;
591590
} else if let Some(g) = &arm.guard {
592591
self.dcx().emit_err(NeverPatternWithGuard { span: g.span });
593-
guard = None;
594592
}
595593

596594
// 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)