From ce78042a42d68d41004803c117c56f5e789dbe67 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 9 Aug 2022 15:03:56 +1000 Subject: [PATCH] Avoid lowering a `MacArgs::Eq` twice. Fixes #96847. --- compiler/rustc_ast_lowering/src/expr.rs | 4 +--- src/test/ui/lowering/issue-96847.rs | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 src/test/ui/lowering/issue-96847.rs diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index fb6715ff17e..3218951c715 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -1534,15 +1534,13 @@ impl<'hir> LoweringContext<'_, 'hir> { hir::MatchSource::ForLoopDesugar, )); - let attrs: Vec<_> = e.attrs.iter().map(|a| self.lower_attr(a)).collect(); - // This is effectively `{ let _result = ...; _result }`. // The construct was introduced in #21984 and is necessary to make sure that // temporaries in the `head` expression are dropped and do not leak to the // surrounding scope of the `match` since the `match` is not a terminating scope. // // Also, add the attributes to the outer returned expr node. - self.expr_drop_temps_mut(for_span, match_expr, attrs.into()) + self.expr_drop_temps_mut(for_span, match_expr, e.attrs.clone()) } /// Desugar `ExprKind::Try` from: `?` into: diff --git a/src/test/ui/lowering/issue-96847.rs b/src/test/ui/lowering/issue-96847.rs new file mode 100644 index 00000000000..2aa34c8b335 --- /dev/null +++ b/src/test/ui/lowering/issue-96847.rs @@ -0,0 +1,14 @@ +// run-pass + +// Test that this doesn't abort during AST lowering. In #96847 it did abort +// because the attribute was being lowered twice. + +#![feature(stmt_expr_attributes)] +#![feature(lang_items)] + +fn main() { + for _ in [1,2,3] { + #![lang="foo"] + println!("foo"); + } +}