Skip to content

Commit 4d71cec

Browse files
committed
Update code based on PR comments
This patch does the following: - Refactor some repeated lines into a single one - Split the `ungated_async_fn_caller` lint into multiple lines, and make one of those lines only print out on nightly - Use test revisions instead of copying an existing test
1 parent 776560d commit 4d71cec

8 files changed

+41
-106
lines changed

compiler/rustc_error_messages/locales/en-US/lint.ftl

+2-1
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,8 @@ lint_builtin_mutable_transmutes =
350350
351351
lint_builtin_unstable_features = unstable feature
352352
353-
lint_ungated_async_fn_track_caller = `#[track_caller]` on async functions is a no-op, unless the `closure_track_caller` feature is enabled
353+
lint_ungated_async_fn_track_caller = `#[track_caller]` on async functions is a no-op
354+
.suggestion = enable this feature
354355
355356
lint_builtin_unreachable_pub = unreachable `pub` {$what}
356357
.suggestion = consider restricting its visibility

compiler/rustc_lint/src/builtin.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -1371,10 +1371,16 @@ impl<'tcx> LateLintPass<'tcx> for UngatedAsyncFnTrackCaller {
13711371
if let Some(attr) = maybe_track_caller {
13721372
cx.struct_span_lint(
13731373
UNGATED_ASYNC_FN_TRACK_CALLER,
1374-
span.with_hi(attr.span.hi()),
1374+
attr.span,
13751375
fluent::lint_ungated_async_fn_track_caller,
1376-
|lint| lint,
1377-
);
1376+
|lint| {
1377+
lint.span_label(span, "this function will not propagate the caller location");
1378+
if cx.tcx.sess.is_nightly_build() {
1379+
lint.span_suggestion(attr.span, fluent::suggestion, "#[closure_track_caller]", Applicability::MachineApplicable);
1380+
}
1381+
lint
1382+
}
1383+
);
13781384
}
13791385
}
13801386
}

src/test/ui/async-await/track-caller/issue-104588-no-op-panic-track-caller.rs

-78
This file was deleted.

src/test/ui/async-await/track-caller/issue-104588-no-op-panic-track-caller.stderr

-12
This file was deleted.

src/test/ui/async-await/track-caller/issue-104588-no-op-track-caller.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// check-pass
22
// edition:2021
33

4-
#[track_caller] //~ WARN `#[track_caller]` on async functions is a no-op, unless the `closure_track_caller` feature is enabled
4+
#[track_caller] //~ WARN `#[track_caller]` on async functions is a no-op
55
async fn foo() {}
66

77
fn main() {

src/test/ui/async-await/track-caller/issue-104588-no-op-track-caller.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
warning: `#[track_caller]` on async functions is a no-op, unless the `closure_track_caller` feature is enabled
2-
--> $DIR/issue-104588-no-op-track-caller.rs:4:16
1+
warning: `#[track_caller]` on async functions is a no-op
2+
--> $DIR/issue-104588-no-op-track-caller.rs:4:1
33
|
4-
LL | #[track_caller]
5-
| ________________^
6-
LL | | async fn foo() {}
7-
| |_
4+
LL | #[track_caller]
5+
| ^^^^^^^^^^^^^^^ help: enable this feature: `#[closure_track_caller]`
6+
LL | async fn foo() {}
7+
| ----------------- this function will not propagate the caller location
88
|
99
= note: `#[warn(ungated_async_fn_track_caller)]` on by default
1010

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
warning: `#[track_caller]` on async functions is a no-op
2+
--> $DIR/panic-track-caller.rs:50:1
3+
|
4+
LL | #[track_caller]
5+
| ^^^^^^^^^^^^^^^ help: enable this feature: `#[closure_track_caller]`
6+
LL | / async fn bar_track_caller() {
7+
LL | | panic!()
8+
LL | | }
9+
| |_- this function will not propagate the caller location
10+
|
11+
= note: `#[warn(ungated_async_fn_track_caller)]` on by default
12+
13+
warning: 1 warning emitted
14+

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

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// run-pass
22
// edition:2021
3+
// revisions: feat nofeat
34
// needs-unwind
4-
#![feature(closure_track_caller)]
5+
6+
#![cfg_attr(feat, feature(closure_track_caller))]
57

68
use std::future::Future;
79
use std::panic;
@@ -45,7 +47,7 @@ async fn foo() {
4547
bar().await
4648
}
4749

48-
#[track_caller]
50+
#[track_caller] //[nofeat]~ WARN `#[track_caller]` on async functions is a no-op
4951
async fn bar_track_caller() {
5052
panic!()
5153
}
@@ -84,7 +86,9 @@ fn panicked_at(f: impl FnOnce() + panic::UnwindSafe) -> u32 {
8486
}
8587

8688
fn main() {
87-
assert_eq!(panicked_at(|| block_on(foo())), 41);
88-
assert_eq!(panicked_at(|| block_on(foo_track_caller())), 54);
89-
assert_eq!(panicked_at(|| block_on(foo_assoc())), 67);
89+
assert_eq!(panicked_at(|| block_on(foo())), 43);
90+
#[cfg(feat)]
91+
assert_eq!(panicked_at(|| block_on(foo_track_caller())), 56);
92+
#[cfg(nofeat)]
93+
assert_eq!(panicked_at(|| block_on(foo_track_caller())), 52);
9094
}

0 commit comments

Comments
 (0)