Skip to content

Commit 38f8561

Browse files
committed
Update track_caller logic/lint after rebase
1 parent b2de435 commit 38f8561

File tree

5 files changed

+52
-26
lines changed

5 files changed

+52
-26
lines changed

compiler/rustc_ast_lowering/src/expr.rs

+22-20
Original file line numberDiff line numberDiff line change
@@ -678,30 +678,32 @@ impl<'hir> LoweringContext<'_, 'hir> {
678678
hir::ExprKind::Closure(c)
679679
};
680680

681-
let track_caller = outer_hir_id
682-
.and_then(|id| self.attrs.get(&id.local_id))
683-
.map_or(false, |attrs| attrs.into_iter().any(|attr| attr.has_name(sym::track_caller)));
684-
685681
let hir_id = self.lower_node_id(closure_node_id);
686682
let unstable_span =
687683
self.mark_span_with_reason(DesugaringKind::Async, span, self.allow_gen_future.clone());
688-
if track_caller {
689-
self.lower_attrs(
690-
hir_id,
691-
&[Attribute {
692-
kind: AttrKind::Normal(ptr::P(NormalAttr {
693-
item: AttrItem {
694-
path: Path::from_ident(Ident::new(sym::track_caller, span)),
695-
args: AttrArgs::Empty,
684+
if self.tcx.features().closure_track_caller {
685+
let track_caller =
686+
outer_hir_id.and_then(|id| self.attrs.get(&id.local_id)).map_or(false, |attrs| {
687+
attrs.into_iter().any(|attr| attr.has_name(sym::track_caller))
688+
});
689+
if track_caller {
690+
self.lower_attrs(
691+
hir_id,
692+
&[Attribute {
693+
kind: AttrKind::Normal(ptr::P(NormalAttr {
694+
item: AttrItem {
695+
path: Path::from_ident(Ident::new(sym::track_caller, span)),
696+
args: AttrArgs::Empty,
697+
tokens: None,
698+
},
696699
tokens: None,
697-
},
698-
tokens: None,
699-
})),
700-
id: self.tcx.sess.parse_sess.attr_id_generator.mk_attr_id(),
701-
style: AttrStyle::Outer,
702-
span: unstable_span,
703-
}],
704-
);
700+
})),
701+
id: self.tcx.sess.parse_sess.attr_id_generator.mk_attr_id(),
702+
style: AttrStyle::Outer,
703+
span: unstable_span,
704+
}],
705+
);
706+
}
705707
}
706708

707709
let generator = hir::Expr { hir_id, kind: generator_kind, span: self.lower_span(span) };

compiler/rustc_lint/src/builtin.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -1364,7 +1364,7 @@ impl<'tcx> LateLintPass<'tcx> for UngatedAsyncFnTrackCaller {
13641364
span: Span,
13651365
hir_id: HirId,
13661366
) {
1367-
if let HirFnKind::ItemFn(_, _, _) = fn_kind && fn_kind.asyncness() == IsAsync::Async && !cx.tcx.features().closure_track_caller {
1367+
if fn_kind.asyncness() == IsAsync::Async && !cx.tcx.features().closure_track_caller {
13681368
// Now, check if the function has the `#[track_caller]` attribute
13691369
let attrs = cx.tcx.hir().attrs(hir_id);
13701370
let maybe_track_caller = attrs.iter().find(|attr| attr.has_name(sym::track_caller));
@@ -1374,12 +1374,20 @@ impl<'tcx> LateLintPass<'tcx> for UngatedAsyncFnTrackCaller {
13741374
attr.span,
13751375
fluent::lint_ungated_async_fn_track_caller,
13761376
|lint| {
1377-
lint.span_label(span, "this function will not propagate the caller location");
1377+
lint.span_label(
1378+
span,
1379+
"this function will not propagate the caller location",
1380+
);
13781381
if cx.tcx.sess.is_nightly_build() {
1379-
lint.span_suggestion(attr.span, fluent::suggestion, "closure_track_caller", Applicability::MachineApplicable);
1382+
lint.span_suggestion(
1383+
attr.span,
1384+
fluent::suggestion,
1385+
"closure_track_caller",
1386+
Applicability::MachineApplicable,
1387+
);
13801388
}
13811389
lint
1382-
}
1390+
},
13831391
);
13841392
}
13851393
}

compiler/rustc_lint/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ late_lint_methods!(
219219
// May Depend on constants elsewhere
220220
UnusedBrokenConst: UnusedBrokenConst,
221221
UnstableFeatures: UnstableFeatures,
222+
UngatedAsyncFnTrackCaller: UngatedAsyncFnTrackCaller,
222223
ArrayIntoIter: ArrayIntoIter::default(),
223224
DropTraitConstraints: DropTraitConstraints,
224225
TemporaryCStringAsPtr: TemporaryCStringAsPtr,

src/test/ui/async-await/track-caller/panic-track-caller.nofeat.stderr

+11-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,15 @@ LL | | }
1010
|
1111
= note: `#[warn(ungated_async_fn_track_caller)]` on by default
1212

13-
warning: 1 warning emitted
13+
warning: `#[track_caller]` on async functions is a no-op
14+
--> $DIR/panic-track-caller.rs:62:5
15+
|
16+
LL | #[track_caller]
17+
| ^^^^^^^^^^^^^^^ help: enable this unstable feature: `closure_track_caller`
18+
LL | / async fn bar_assoc() {
19+
LL | | panic!();
20+
LL | | }
21+
| |_____- this function will not propagate the caller location
22+
23+
warning: 2 warnings emitted
1424

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ async fn foo_track_caller() {
5959
struct Foo;
6060

6161
impl Foo {
62-
#[track_caller]
62+
#[track_caller] //[nofeat]~ WARN `#[track_caller]` on async functions is a no-op
6363
async fn bar_assoc() {
6464
panic!();
6565
}
@@ -91,4 +91,9 @@ fn main() {
9191
assert_eq!(panicked_at(|| block_on(foo_track_caller())), 56);
9292
#[cfg(nofeat)]
9393
assert_eq!(panicked_at(|| block_on(foo_track_caller())), 52);
94+
95+
#[cfg(feat)]
96+
assert_eq!(panicked_at(|| block_on(foo_assoc())), 69);
97+
#[cfg(nofeat)]
98+
assert_eq!(panicked_at(|| block_on(foo_assoc())), 64);
9499
}

0 commit comments

Comments
 (0)