Skip to content

Commit ec4080b

Browse files
committed
Fix async track caller for assoc fn and trait impl fn
1 parent 4c73b64 commit ec4080b

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

compiler/rustc_ast_lowering/src/item.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
771771

772772
fn lower_trait_item(&mut self, i: &AssocItem) -> &'hir hir::TraitItem<'hir> {
773773
let hir_id = self.lower_node_id(i.id);
774+
self.lower_attrs(hir_id, &i.attrs);
774775
let trait_item_def_id = hir_id.expect_owner();
775776

776777
let (generics, kind, has_default) = match &i.kind {
@@ -829,7 +830,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
829830
AssocItemKind::MacCall(..) => panic!("macro item shouldn't exist at this point"),
830831
};
831832

832-
self.lower_attrs(hir_id, &i.attrs);
833833
let item = hir::TraitItem {
834834
owner_id: trait_item_def_id,
835835
ident: self.lower_ident(i.ident),
@@ -869,6 +869,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
869869
let has_value = true;
870870
let (defaultness, _) = self.lower_defaultness(i.kind.defaultness(), has_value);
871871
let hir_id = self.lower_node_id(i.id);
872+
self.lower_attrs(hir_id, &i.attrs);
872873

873874
let (generics, kind) = match &i.kind {
874875
AssocItemKind::Const(_, ty, expr) => {
@@ -920,7 +921,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
920921
AssocItemKind::MacCall(..) => panic!("`TyMac` should have been expanded by now"),
921922
};
922923

923-
self.lower_attrs(hir_id, &i.attrs);
924924
let item = hir::ImplItem {
925925
owner_id: hir_id.expect_owner(),
926926
ident: self.lower_ident(i.ident),

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

+14
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,19 @@ async fn foo_track_caller() {
5454
bar_track_caller().await
5555
}
5656

57+
struct Foo;
58+
59+
impl Foo {
60+
#[track_caller]
61+
async fn bar_assoc() {
62+
panic!();
63+
}
64+
}
65+
66+
async fn foo_assoc() {
67+
Foo::bar_assoc().await
68+
}
69+
5770
fn panicked_at(f: impl FnOnce() + panic::UnwindSafe) -> u32 {
5871
let loc = Arc::new(Mutex::new(None));
5972

@@ -73,4 +86,5 @@ fn panicked_at(f: impl FnOnce() + panic::UnwindSafe) -> u32 {
7386
fn main() {
7487
assert_eq!(panicked_at(|| block_on(foo())), 41);
7588
assert_eq!(panicked_at(|| block_on(foo_track_caller())), 54);
89+
assert_eq!(panicked_at(|| block_on(foo_assoc())), 67);
7690
}

0 commit comments

Comments
 (0)