Skip to content

Commit 130be6d

Browse files
committed
Expand E0738 to cover different cases.
1 parent bdc4bd1 commit 130be6d

8 files changed

+93
-12
lines changed

src/librustc_typeck/check/wfcheck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ pub fn check_trait_item(tcx: TyCtxt<'_>, def_id: DefId) {
180180
tcx.sess,
181181
attr.span,
182182
E0738,
183-
"`#[track_caller]` is not supported for trait items yet."
183+
"`#[track_caller]` is not supported in trait declarations."
184184
).emit();
185185
}
186186
}

src/librustc_typeck/error_codes.rs

+32-7
Original file line numberDiff line numberDiff line change
@@ -4926,12 +4926,11 @@ extern "C" fn foo() {}
49264926
"##,
49274927

49284928
E0738: r##"
4929-
#[track_caller] cannot be applied to trait methods.
4929+
#[track_caller] cannot be used in traits yet. This is due to limitations in the
4930+
compiler which are likely to be temporary. See [RFC 2091] for details on this
4931+
and other restrictions.
49304932
4931-
This is due to limitations in the compiler which are likely to be temporary.
4932-
See [RFC 2091] for details on this and other restrictions.
4933-
4934-
Erroneous code example:
4933+
Erroneous example with a trait method implementation:
49354934
49364935
```compile_fail,E0738
49374936
#![feature(track_caller)]
@@ -4940,14 +4939,40 @@ trait Foo {
49404939
fn bar(&self);
49414940
}
49424941
4943-
struct Bar;
4942+
impl Foo for u64 {
4943+
#[track_caller]
4944+
fn bar(&self) {}
4945+
}
4946+
```
49444947
4945-
impl Foo for Bar {
4948+
Erroneous example with a blanket trait method implementation:
4949+
4950+
```compile_fail,E0738
4951+
#![feature(track_caller)]
4952+
4953+
trait Foo {
49464954
#[track_caller]
49474955
fn bar(&self) {}
4956+
fn baz(&self);
4957+
}
4958+
```
4959+
4960+
Erroneous example with a trait method declaration:
4961+
4962+
```compile_fail,E0738
4963+
#[!feature(track_caller)]
4964+
4965+
trait Foo {
4966+
fn bar(&self) {}
4967+
4968+
#[track_caller]
4969+
fn baz(&self);
49484970
}
49494971
```
49504972
4973+
Note that while the compiler may be able to support the attribute in traits in
4974+
the future, [RFC 2091] prohibits their implementation without a follow-up RFC.
4975+
49514976
[RFC 2091]: https://github.com/rust-lang/rfcs/blob/master/text/2091-inline-semantic.md
49524977
"##,
49534978

src/test/ui/rfc-2091-track-caller/error-with-trait-fns.rs renamed to src/test/ui/rfc-2091-track-caller/error-with-trait-decl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
trait Trait {
44
#[track_caller]
55
fn unwrap(&self);
6-
//~^^ ERROR: `#[track_caller]` is not supported for trait items yet.
6+
//~^^ ERROR: `#[track_caller]` is not supported in traits yet.
77
}
88

99
impl Trait for u64 {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
warning: the feature `track_caller` is incomplete and may cause the compiler to crash
2+
--> $DIR/error-with-trait-decl.rs:1:12
3+
|
4+
LL | #![feature(track_caller)]
5+
| ^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
8+
9+
error[E0738]: `#[track_caller]` is not supported in trait declarations.
10+
--> $DIR/error-with-trait-decl.rs:4:5
11+
|
12+
LL | #[track_caller]
13+
| ^^^^^^^^^^^^^^^
14+
15+
error: aborting due to previous error
16+
17+
For more information about this error, try `rustc --explain E0738`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#![feature(track_caller)] //~ WARN the feature `track_caller` is incomplete
2+
3+
trait Trait {
4+
#[track_caller]
5+
fn unwrap(&self) {}
6+
//~^^ ERROR: `#[track_caller]` is not supported in trait declarations.
7+
}
8+
9+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
warning: the feature `track_caller` is incomplete and may cause the compiler to crash
2+
--> $DIR/error-with-trait-default-impl.rs:1:12
3+
|
4+
LL | #![feature(track_caller)]
5+
| ^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
8+
9+
error[E0738]: `#[track_caller]` is not supported in traits yet.
10+
--> $DIR/error-with-trait-default-impl.rs:4:5
11+
|
12+
LL | #[track_caller]
13+
| ^^^^^^^^^^^^^^^
14+
15+
error: aborting due to previous error
16+
17+
For more information about this error, try `rustc --explain E0738`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![feature(track_caller)] //~ WARN the feature `track_caller` is incomplete
2+
3+
trait Trait {
4+
fn unwrap(&self);
5+
}
6+
7+
impl Trait for u64 {
8+
#[track_caller]
9+
fn unwrap(&self) {}
10+
//~^^ ERROR: `#[track_caller]` is not supported in traits yet.
11+
}
12+
13+
fn main() {}

src/test/ui/rfc-2091-track-caller/error-with-trait-fns.stderr renamed to src/test/ui/rfc-2091-track-caller/error-with-trait-fn-impl.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
warning: the feature `track_caller` is incomplete and may cause the compiler to crash
2-
--> $DIR/error-with-trait-fns.rs:1:12
2+
--> $DIR/error-with-trait-fn-impl.rs:1:12
33
|
44
LL | #![feature(track_caller)]
55
| ^^^^^^^^^^^^
66
|
77
= note: `#[warn(incomplete_features)]` on by default
88

9-
error[E0738]: `#[track_caller]` is not supported for trait items yet.
10-
--> $DIR/error-with-trait-fns.rs:4:5
9+
error[E0738]: `#[track_caller]` is not supported in traits yet.
10+
--> $DIR/error-with-trait-fn-impl.rs:4:5
1111
|
1212
LL | #[track_caller]
1313
| ^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)