Skip to content

Don't drop a hir node after lowering #119284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ impl<'hir> LoweringContext<'_, 'hir> {

fn lower_arm(&mut self, arm: &Arm) -> hir::Arm<'hir> {
let pat = self.lower_pat(&arm.pat);
let mut guard = arm.guard.as_ref().map(|cond| {
let guard = arm.guard.as_ref().map(|cond| {
if let ExprKind::Let(pat, scrutinee, span, is_recovered) = &cond.kind {
hir::Guard::IfLet(self.arena.alloc(hir::Let {
hir_id: self.next_id(),
Expand Down Expand Up @@ -587,10 +587,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
} else if let Some(body) = &arm.body {
self.dcx().emit_err(NeverPatternWithBody { span: body.span });
guard = None;
} else if let Some(g) = &arm.guard {
self.dcx().emit_err(NeverPatternWithGuard { span: g.span });
guard = None;
}

// We add a fake `loop {}` arm body so that it typecks to `!`.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
fn main() {}

fn attr_in_guard() {
match None::<u32> {
Some(!) //~ ERROR `!` patterns are experimental
if #[deny(unused_mut)] //~ ERROR attributes on expressions are experimental
false //~ ERROR a guard on a never pattern will never be run
}
match false {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
error[E0658]: attributes on expressions are experimental
--> $DIR/ICE-119271-never-arm-attr-in-guard.rs:6:16
|
LL | if #[deny(unused_mut)]
| ^^^^^^^^^^^^^^^^^^^
|
= note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
= help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable

error[E0658]: `!` patterns are experimental
--> $DIR/ICE-119271-never-arm-attr-in-guard.rs:5:14
|
LL | Some(!)
| ^
|
= note: see issue #118155 <https://github.com/rust-lang/rust/issues/118155> for more information
= help: add `#![feature(never_patterns)]` to the crate attributes to enable

error: a guard on a never pattern will never be run
--> $DIR/ICE-119271-never-arm-attr-in-guard.rs:7:13
|
LL | false
| ^^^^^ help: remove this guard

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0658`.