Skip to content

Commit 3db41d1

Browse files
committed
wip: trying to enable #[track_caller] on async fn
1 parent 0c158f0 commit 3db41d1

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,8 +617,26 @@ impl<'hir> LoweringContext<'_, 'hir> {
617617

618618
hir::ExprKind::Closure(c)
619619
};
620+
let generator_hir_id = self.lower_node_id(closure_node_id);
621+
// FIXME: only add track caller if the parent is track_caller
622+
self.lower_attrs(
623+
generator_hir_id,
624+
&[Attribute {
625+
kind: AttrKind::Normal(ptr::P(NormalAttr {
626+
item: AttrItem {
627+
path: Path::from_ident(Ident::new(sym::track_caller, span)),
628+
args: MacArgs::Empty,
629+
tokens: None,
630+
},
631+
tokens: None,
632+
})),
633+
id: self.tcx.sess.parse_sess.attr_id_generator.mk_attr_id(),
634+
style: AttrStyle::Outer,
635+
span,
636+
}],
637+
);
620638
let generator = hir::Expr {
621-
hir_id: self.lower_node_id(closure_node_id),
639+
hir_id: generator_hir_id,
622640
kind: generator_kind,
623641
span: self.lower_span(span),
624642
};

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
8686
impl_trait_defs: Vec::new(),
8787
impl_trait_bounds: Vec::new(),
8888
allow_try_trait: Some([sym::try_trait_v2, sym::yeet_desugar_details][..].into()),
89-
allow_gen_future: Some([sym::gen_future][..].into()),
89+
allow_gen_future: Some([sym::gen_future, sym::closure_track_caller][..].into()),
9090
allow_into_future: Some([sym::into_future][..].into()),
9191
generics_def_id_map: Default::default(),
9292
};

src/test/ui/async-await/panic-no-track-caller.rs renamed to src/test/ui/async-await/panic-track-caller.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// run-pass
22
// edition:2021
3+
#![feature(closure_track_caller)]
34

45
use std::future::Future;
56
use std::panic;

0 commit comments

Comments
 (0)