diff --git a/compiler/rustc_ast_lowering/src/block.rs b/compiler/rustc_ast_lowering/src/block.rs index 4eab936f85fa0..082c5bb783347 100644 --- a/compiler/rustc_ast_lowering/src/block.rs +++ b/compiler/rustc_ast_lowering/src/block.rs @@ -152,6 +152,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { let block = self.lower_block(els, false); self.arena.alloc(self.expr_block(block, AttrVec::new())) }; + self.alias_attrs(let_expr.hir_id, local_hir_id); self.alias_attrs(else_expr.hir_id, local_hir_id); let if_expr = self.arena.alloc(hir::Expr { hir_id: stmt_hir_id, diff --git a/src/test/ui/let-else/let-else-allow-unused.rs b/src/test/ui/let-else/let-else-allow-unused.rs new file mode 100644 index 0000000000000..bcd8c987628b3 --- /dev/null +++ b/src/test/ui/let-else/let-else-allow-unused.rs @@ -0,0 +1,14 @@ +// check-pass +// issue #89807 + +#![feature(let_else)] + +#[deny(unused_variables)] + +fn main() { + let value = Some(String::new()); + #[allow(unused)] + let banana = 1; + #[allow(unused)] + let Some(chaenomeles) = value else { return }; // OK +}