about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_ast_lowering/src/expr.rs53
-rw-r--r--compiler/rustc_lint/src/builtin.rs16
-rw-r--r--compiler/rustc_lint/src/lib.rs1
-rw-r--r--src/test/ui/async-await/track-caller/panic-track-caller.nofeat.stderr12
-rw-r--r--src/test/ui/async-await/track-caller/panic-track-caller.rs7
5 files changed, 52 insertions, 37 deletions
diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs
index a3f5c18f2e7..a58c74dbc33 100644
--- a/compiler/rustc_ast_lowering/src/expr.rs
+++ b/compiler/rustc_ast_lowering/src/expr.rs
@@ -656,34 +656,35 @@ impl<'hir> LoweringContext<'_, 'hir> {
             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);
-        if track_caller {
-            let unstable_span = self.mark_span_with_reason(
-                DesugaringKind::Async,
-                span,
-                self.allow_gen_future.clone(),
-            );
-            self.lower_attrs(
-                hir_id,
-                &[Attribute {
-                    kind: AttrKind::Normal(ptr::P(NormalAttr {
-                        item: AttrItem {
-                            path: Path::from_ident(Ident::new(sym::track_caller, span)),
-                            args: AttrArgs::Empty,
+        let unstable_span = self.mark_span_with_reason(
+            DesugaringKind::Async,
+            span,
+            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(
+                    hir_id,
+                    &[Attribute {
+                        kind: AttrKind::Normal(ptr::P(NormalAttr {
+                            item: AttrItem {
+                                path: Path::from_ident(Ident::new(sym::track_caller, span)),
+                                args: AttrArgs::Empty,
+                                tokens: None,
+                            },
                             tokens: None,
-                        },
-                        tokens: None,
-                    })),
-                    id: self.tcx.sess.parse_sess.attr_id_generator.mk_attr_id(),
-                    style: AttrStyle::Outer,
-                    span: unstable_span,
-                }],
-            );
+                        })),
+                        id: self.tcx.sess.parse_sess.attr_id_generator.mk_attr_id(),
+                        style: AttrStyle::Outer,
+                        span: unstable_span,
+                    }],
+                    );
+            }
         }
 
         let generator = hir::Expr { hir_id, kind: generator_kind, span: self.lower_span(span) };
diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs
index c353f742516..6d3e33f2b62 100644
--- a/compiler/rustc_lint/src/builtin.rs
+++ b/compiler/rustc_lint/src/builtin.rs
@@ -1397,7 +1397,7 @@ impl<'tcx> LateLintPass<'tcx> for UngatedAsyncFnTrackCaller {
         span: Span,
         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
             let attrs = cx.tcx.hir().attrs(hir_id);
             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,
                     fluent::lint_ungated_async_fn_track_caller,
                     |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() {
-                            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
-                    }
+                    },
                 );
             }
         }
diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs
index 11022eb80ea..1275d6f223c 100644
--- a/compiler/rustc_lint/src/lib.rs
+++ b/compiler/rustc_lint/src/lib.rs
@@ -219,6 +219,7 @@ late_lint_methods!(
             // May Depend on constants elsewhere
             UnusedBrokenConst: UnusedBrokenConst,
             UnstableFeatures: UnstableFeatures,
+            UngatedAsyncFnTrackCaller: UngatedAsyncFnTrackCaller,
             ArrayIntoIter: ArrayIntoIter::default(),
             DropTraitConstraints: DropTraitConstraints,
             TemporaryCStringAsPtr: TemporaryCStringAsPtr,
diff --git a/src/test/ui/async-await/track-caller/panic-track-caller.nofeat.stderr b/src/test/ui/async-await/track-caller/panic-track-caller.nofeat.stderr
index 71d4b00cc6e..f313658c446 100644
--- a/src/test/ui/async-await/track-caller/panic-track-caller.nofeat.stderr
+++ b/src/test/ui/async-await/track-caller/panic-track-caller.nofeat.stderr
@@ -10,5 +10,15 @@ LL | | }
    |
    = 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
 
diff --git a/src/test/ui/async-await/track-caller/panic-track-caller.rs b/src/test/ui/async-await/track-caller/panic-track-caller.rs
index ee37e64be4f..02077db7c62 100644
--- a/src/test/ui/async-await/track-caller/panic-track-caller.rs
+++ b/src/test/ui/async-await/track-caller/panic-track-caller.rs
@@ -59,7 +59,7 @@ async fn foo_track_caller() {
 struct Foo;
 
 impl Foo {
-    #[track_caller]
+    #[track_caller] //[nofeat]~ WARN `#[track_caller]` on async functions is a no-op
     async fn bar_assoc() {
         panic!();
     }
@@ -104,9 +104,4 @@ fn main() {
     assert_eq!(panicked_at(|| block_on(foo_assoc())), 69);
     #[cfg(nofeat)]
     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);
 }