Skip to content

Commit 2d06003

Browse files
committed
Update track_caller logic/lint after rebase
1 parent e28a07a commit 2d06003

File tree

5 files changed

+52
-37
lines changed

5 files changed

+52
-37
lines changed

compiler/rustc_ast_lowering/src/expr.rs

+27-26
Original file line numberDiff line numberDiff line change
@@ -656,34 +656,35 @@ impl<'hir> LoweringContext<'_, 'hir> {
656656
hir::ExprKind::Closure(c)
657657
};
658658

659-
let track_caller = self
660-
.attrs
661-
.get(&outer_hir_id.local_id)
662-
.map_or(false, |attrs| attrs.into_iter().any(|attr| attr.has_name(sym::track_caller)));
663-
664659
let hir_id = self.lower_node_id(closure_node_id);
665-
if track_caller {
666-
let unstable_span = self.mark_span_with_reason(
667-
DesugaringKind::Async,
668-
span,
669-
self.allow_gen_future.clone(),
670-
);
671-
self.lower_attrs(
672-
hir_id,
673-
&[Attribute {
674-
kind: AttrKind::Normal(ptr::P(NormalAttr {
675-
item: AttrItem {
676-
path: Path::from_ident(Ident::new(sym::track_caller, span)),
677-
args: AttrArgs::Empty,
660+
let unstable_span = self.mark_span_with_reason(
661+
DesugaringKind::Async,
662+
span,
663+
self.allow_gen_future.clone(),
664+
);
665+
if self.tcx.features().closure_track_caller {
666+
let track_caller = self
667+
.attrs
668+
.get(&outer_hir_id.local_id)
669+
.map_or(false, |attrs| attrs.into_iter().any(|attr| attr.has_name(sym::track_caller)));
670+
if track_caller {
671+
self.lower_attrs(
672+
hir_id,
673+
&[Attribute {
674+
kind: AttrKind::Normal(ptr::P(NormalAttr {
675+
item: AttrItem {
676+
path: Path::from_ident(Ident::new(sym::track_caller, span)),
677+
args: AttrArgs::Empty,
678+
tokens: None,
679+
},
678680
tokens: None,
679-
},
680-
tokens: None,
681-
})),
682-
id: self.tcx.sess.parse_sess.attr_id_generator.mk_attr_id(),
683-
style: AttrStyle::Outer,
684-
span: unstable_span,
685-
}],
686-
);
681+
})),
682+
id: self.tcx.sess.parse_sess.attr_id_generator.mk_attr_id(),
683+
style: AttrStyle::Outer,
684+
span: unstable_span,
685+
}],
686+
);
687+
}
687688
}
688689

689690
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
@@ -1397,7 +1397,7 @@ impl<'tcx> LateLintPass<'tcx> for UngatedAsyncFnTrackCaller {
13971397
span: Span,
13981398
hir_id: HirId,
13991399
) {
1400-
if let HirFnKind::ItemFn(_, _, _) = fn_kind && fn_kind.asyncness() == IsAsync::Async && !cx.tcx.features().closure_track_caller {
1400+
if fn_kind.asyncness() == IsAsync::Async && !cx.tcx.features().closure_track_caller {
14011401
// Now, check if the function has the `#[track_caller]` attribute
14021402
let attrs = cx.tcx.hir().attrs(hir_id);
14031403
let maybe_track_caller = attrs.iter().find(|attr| attr.has_name(sym::track_caller));
@@ -1407,12 +1407,20 @@ impl<'tcx> LateLintPass<'tcx> for UngatedAsyncFnTrackCaller {
14071407
attr.span,
14081408
fluent::lint_ungated_async_fn_track_caller,
14091409
|lint| {
1410-
lint.span_label(span, "this function will not propagate the caller location");
1410+
lint.span_label(
1411+
span,
1412+
"this function will not propagate the caller location",
1413+
);
14111414
if cx.tcx.sess.is_nightly_build() {
1412-
lint.span_suggestion(attr.span, fluent::suggestion, "closure_track_caller", Applicability::MachineApplicable);
1415+
lint.span_suggestion(
1416+
attr.span,
1417+
fluent::suggestion,
1418+
"closure_track_caller",
1419+
Applicability::MachineApplicable,
1420+
);
14131421
}
14141422
lint
1415-
}
1423+
},
14161424
);
14171425
}
14181426
}

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

+1-6
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
}
@@ -104,9 +104,4 @@ fn main() {
104104
assert_eq!(panicked_at(|| block_on(foo_assoc())), 69);
105105
#[cfg(nofeat)]
106106
assert_eq!(panicked_at(|| block_on(foo_assoc())), 64);
107-
108-
#[cfg(feat)]
109-
assert_eq!(panicked_at(|| block_on(foo_closure())), 76);
110-
#[cfg(feat)]
111-
assert_eq!(panicked_at(|| block_on(foo_closure())), 74);
112107
}

0 commit comments

Comments
 (0)