diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index 46886c518afd..61d91874e617 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -617,8 +617,26 @@ impl<'hir> LoweringContext<'_, 'hir> { hir::ExprKind::Closure(c) }; + let generator_hir_id = self.lower_node_id(closure_node_id); + // FIXME: only add track caller if the parent is track_caller + self.lower_attrs( + generator_hir_id, + &[Attribute { + kind: AttrKind::Normal(ptr::P(NormalAttr { + item: AttrItem { + path: Path::from_ident(Ident::new(sym::track_caller, span)), + args: MacArgs::Empty, + tokens: None, + }, + tokens: None, + })), + id: self.tcx.sess.parse_sess.attr_id_generator.mk_attr_id(), + style: AttrStyle::Outer, + span, + }], + ); let generator = hir::Expr { - hir_id: self.lower_node_id(closure_node_id), + hir_id: generator_hir_id, kind: generator_kind, span: self.lower_span(span), }; diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index 9a46444d8239..e9cc53b7138c 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -86,7 +86,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> { impl_trait_defs: Vec::new(), impl_trait_bounds: Vec::new(), allow_try_trait: Some([sym::try_trait_v2, sym::yeet_desugar_details][..].into()), - allow_gen_future: Some([sym::gen_future][..].into()), + allow_gen_future: Some([sym::gen_future, sym::closure_track_caller][..].into()), allow_into_future: Some([sym::into_future][..].into()), generics_def_id_map: Default::default(), }; diff --git a/src/test/ui/async-await/panic-no-track-caller.rs b/src/test/ui/async-await/panic-track-caller.rs similarity index 98% rename from src/test/ui/async-await/panic-no-track-caller.rs rename to src/test/ui/async-await/panic-track-caller.rs index 934764912d35..76776d41c57c 100644 --- a/src/test/ui/async-await/panic-no-track-caller.rs +++ b/src/test/ui/async-await/panic-track-caller.rs @@ -1,5 +1,6 @@ // run-pass // edition:2021 +#![feature(closure_track_caller)] use std::future::Future; use std::panic;