1
Fork 0

Update track_caller logic/lint after rebase

This commit is contained in:
Bryan Garza 2022-12-07 20:13:22 +00:00
parent e28a07a0a1
commit 2d060034f0
5 changed files with 52 additions and 37 deletions

View file

@ -656,18 +656,18 @@ impl<'hir> LoweringContext<'_, 'hir> {
hir::ExprKind::Closure(c) hir::ExprKind::Closure(c)
}; };
let track_caller = self
.attrs
.get(&outer_hir_id.local_id)
.map_or(false, |attrs| attrs.into_iter().any(|attr| attr.has_name(sym::track_caller)));
let hir_id = self.lower_node_id(closure_node_id); let hir_id = self.lower_node_id(closure_node_id);
if track_caller {
let unstable_span = self.mark_span_with_reason( let unstable_span = self.mark_span_with_reason(
DesugaringKind::Async, DesugaringKind::Async,
span, span,
self.allow_gen_future.clone(), self.allow_gen_future.clone(),
); );
if self.tcx.features().closure_track_caller {
let track_caller = self
.attrs
.get(&outer_hir_id.local_id)
.map_or(false, |attrs| attrs.into_iter().any(|attr| attr.has_name(sym::track_caller)));
if track_caller {
self.lower_attrs( self.lower_attrs(
hir_id, hir_id,
&[Attribute { &[Attribute {
@ -685,6 +685,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
}], }],
); );
} }
}
let generator = hir::Expr { hir_id, kind: generator_kind, span: self.lower_span(span) }; let generator = hir::Expr { hir_id, kind: generator_kind, span: self.lower_span(span) };

View file

@ -1397,7 +1397,7 @@ impl<'tcx> LateLintPass<'tcx> for UngatedAsyncFnTrackCaller {
span: Span, span: Span,
hir_id: HirId, hir_id: HirId,
) { ) {
if let HirFnKind::ItemFn(_, _, _) = fn_kind && fn_kind.asyncness() == IsAsync::Async && !cx.tcx.features().closure_track_caller { if fn_kind.asyncness() == IsAsync::Async && !cx.tcx.features().closure_track_caller {
// Now, check if the function has the `#[track_caller]` attribute // Now, check if the function has the `#[track_caller]` attribute
let attrs = cx.tcx.hir().attrs(hir_id); let attrs = cx.tcx.hir().attrs(hir_id);
let maybe_track_caller = attrs.iter().find(|attr| attr.has_name(sym::track_caller)); let maybe_track_caller = attrs.iter().find(|attr| attr.has_name(sym::track_caller));
@ -1407,12 +1407,20 @@ impl<'tcx> LateLintPass<'tcx> for UngatedAsyncFnTrackCaller {
attr.span, attr.span,
fluent::lint_ungated_async_fn_track_caller, fluent::lint_ungated_async_fn_track_caller,
|lint| { |lint| {
lint.span_label(span, "this function will not propagate the caller location"); lint.span_label(
span,
"this function will not propagate the caller location",
);
if cx.tcx.sess.is_nightly_build() { if cx.tcx.sess.is_nightly_build() {
lint.span_suggestion(attr.span, fluent::suggestion, "closure_track_caller", Applicability::MachineApplicable); lint.span_suggestion(
attr.span,
fluent::suggestion,
"closure_track_caller",
Applicability::MachineApplicable,
);
} }
lint lint
} },
); );
} }
} }

View file

@ -219,6 +219,7 @@ late_lint_methods!(
// May Depend on constants elsewhere // May Depend on constants elsewhere
UnusedBrokenConst: UnusedBrokenConst, UnusedBrokenConst: UnusedBrokenConst,
UnstableFeatures: UnstableFeatures, UnstableFeatures: UnstableFeatures,
UngatedAsyncFnTrackCaller: UngatedAsyncFnTrackCaller,
ArrayIntoIter: ArrayIntoIter::default(), ArrayIntoIter: ArrayIntoIter::default(),
DropTraitConstraints: DropTraitConstraints, DropTraitConstraints: DropTraitConstraints,
TemporaryCStringAsPtr: TemporaryCStringAsPtr, TemporaryCStringAsPtr: TemporaryCStringAsPtr,

View file

@ -10,5 +10,15 @@ LL | | }
| |
= note: `#[warn(ungated_async_fn_track_caller)]` on by default = note: `#[warn(ungated_async_fn_track_caller)]` on by default
warning: 1 warning emitted warning: `#[track_caller]` on async functions is a no-op
--> $DIR/panic-track-caller.rs:62:5
|
LL | #[track_caller]
| ^^^^^^^^^^^^^^^ help: enable this unstable feature: `closure_track_caller`
LL | / async fn bar_assoc() {
LL | | panic!();
LL | | }
| |_____- this function will not propagate the caller location
warning: 2 warnings emitted

View file

@ -59,7 +59,7 @@ async fn foo_track_caller() {
struct Foo; struct Foo;
impl Foo { impl Foo {
#[track_caller] #[track_caller] //[nofeat]~ WARN `#[track_caller]` on async functions is a no-op
async fn bar_assoc() { async fn bar_assoc() {
panic!(); panic!();
} }
@ -104,9 +104,4 @@ fn main() {
assert_eq!(panicked_at(|| block_on(foo_assoc())), 69); assert_eq!(panicked_at(|| block_on(foo_assoc())), 69);
#[cfg(nofeat)] #[cfg(nofeat)]
assert_eq!(panicked_at(|| block_on(foo_assoc())), 64); assert_eq!(panicked_at(|| block_on(foo_assoc())), 64);
#[cfg(feat)]
assert_eq!(panicked_at(|| block_on(foo_closure())), 76);
#[cfg(feat)]
assert_eq!(panicked_at(|| block_on(foo_closure())), 74);
} }