From 9b45713b6c1775f0103a1ebee6ab7c6d9b781a21 Mon Sep 17 00:00:00 2001 From: Cormac Relf Date: Wed, 13 Oct 2021 18:08:43 +1100 Subject: [PATCH] let-else: fix attribute aliasing + add test for issue 89807 --- compiler/rustc_ast_lowering/src/block.rs | 1 + src/test/ui/let-else/let-else-allow-unused.rs | 14 ++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 src/test/ui/let-else/let-else-allow-unused.rs 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 +}