Skip to content

Commit dc2c4ce

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 04926e0 commit dc2c4ce

8 files changed

+51
-106
lines changed

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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,10 +1404,16 @@ impl<'tcx> LateLintPass<'tcx> for UngatedAsyncFnTrackCaller {
14041404
if let Some(attr) = maybe_track_caller {
14051405
cx.struct_span_lint(
14061406
UNGATED_ASYNC_FN_TRACK_CALLER,
1407-
span.with_hi(attr.span.hi()),
1407+
attr.span,
14081408
fluent::lint_ungated_async_fn_track_caller,
1409-
|lint| lint,
1410-
);
1409+
|lint| {
1410+
lint.span_label(span, "this function will not propagate the caller location");
1411+
if cx.tcx.sess.is_nightly_build() {
1412+
lint.span_suggestion(attr.span, fluent::suggestion, "#[closure_track_caller]", Applicability::MachineApplicable);
1413+
}
1414+
lint
1415+
}
1416+
);
14111417
}
14121418
}
14131419
}

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

Lines changed: 0 additions & 78 deletions
This file was deleted.

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

Lines changed: 0 additions & 12 deletions
This file was deleted.

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 6 additions & 6 deletions
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

Lines changed: 14 additions & 0 deletions
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

Lines changed: 19 additions & 5 deletions
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, async_closure, stmt_expr_attributes)]
5+
#![feature(async_closure, stmt_expr_attributes)]
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
}
@@ -91,8 +93,20 @@ fn panicked_at(f: impl FnOnce() + panic::UnwindSafe) -> u32 {
9193
}
9294

9395
fn main() {
94-
assert_eq!(panicked_at(|| block_on(foo())), 41);
95-
assert_eq!(panicked_at(|| block_on(foo_track_caller())), 54);
96-
assert_eq!(panicked_at(|| block_on(foo_assoc())), 67);
96+
assert_eq!(panicked_at(|| block_on(foo())), 43);
97+
98+
#[cfg(feat)]
99+
assert_eq!(panicked_at(|| block_on(foo_track_caller())), 56);
100+
#[cfg(nofeat)]
101+
assert_eq!(panicked_at(|| block_on(foo_track_caller())), 52);
102+
103+
#[cfg(feat)]
104+
assert_eq!(panicked_at(|| block_on(foo_assoc())), 69);
105+
#[cfg(nofeat)]
106+
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)]
97111
assert_eq!(panicked_at(|| block_on(foo_closure())), 74);
98112
}

0 commit comments

Comments
 (0)