[RFC 2091] Add #[track_caller] attribute.

- The attribute is behind a feature gate.
- Error if both #[naked] and #[track_caller] are applied to the same function.
- Error if #[track_caller] is applied to a non-function item.
- Error if ABI is not "rust"
- Error if #[track_caller] is applied to a trait function.

Error codes and descriptions are pending.
This commit is contained in:
Ayose 2019-07-20 00:55:58 +00:00 committed by Adam Perry
parent e3cb9ea15a
commit 543449d4fd
22 changed files with 199 additions and 1 deletions

View file

@ -0,0 +1,6 @@
#[track_caller]
fn f() {}
//~^^ ERROR the `#[track_caller]` attribute is an experimental feature
fn main() {}

View file

@ -0,0 +1,12 @@
error[E0658]: the `#[track_caller]` attribute is an experimental feature
--> $DIR/feature-gate-track_caller.rs:2:1
|
LL | #[track_caller]
| ^^^^^^^^^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/47809
= help: add `#![feature(track_caller)]` to the crate attributes to enable
error: aborting due to previous error
For more information about this error, try `rustc --explain E0658`.

View file

@ -0,0 +1,7 @@
#![feature(track_caller)]
#[track_caller(1)]
fn f() {}
//~^^ ERROR malformed `track_caller` attribute input
fn main() {}

View file

@ -0,0 +1,8 @@
error: malformed `track_caller` attribute input
--> $DIR/error-odd-syntax.rs:3:1
|
LL | #[track_caller(1)]
| ^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[track_caller]`
error: aborting due to previous error

View file

@ -0,0 +1,7 @@
#![feature(track_caller)]
#[track_caller]
extern "C" fn f() {}
//~^^ ERROR rust ABI is required to use `#[track_caller]`
fn main() {}

View file

@ -0,0 +1,9 @@
error[E0902]: rust ABI is required to use `#[track_caller]`
--> $DIR/error-with-invalid-abi.rs:3:1
|
LL | #[track_caller]
| ^^^^^^^^^^^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0902`.

View file

@ -0,0 +1,8 @@
#![feature(naked_functions, track_caller)]
#[track_caller]
#[naked]
fn f() {}
//~^^^ ERROR cannot use `#[track_caller]` with `#[naked]`
fn main() {}

View file

@ -0,0 +1,9 @@
error[E0901]: cannot use `#[track_caller]` with `#[naked]`
--> $DIR/error-with-naked.rs:3:1
|
LL | #[track_caller]
| ^^^^^^^^^^^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0901`.

View file

@ -0,0 +1,13 @@
#![feature(track_caller)]
trait Trait {
#[track_caller]
fn unwrap(&self);
//~^^ ERROR: `#[track_caller]` is not supported for trait items yet.
}
impl Trait for u64 {
fn unwrap(&self) {}
}
fn main() {}

View file

@ -0,0 +1,9 @@
error[E0903]: `#[track_caller]` is not supported for trait items yet.
--> $DIR/error-with-trait-fns.rs:4:5
|
LL | #[track_caller]
| ^^^^^^^^^^^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0903`.

View file

@ -0,0 +1,7 @@
#![feature(track_caller)]
#[track_caller]
struct S;
//~^^ ERROR attribute should be applied to function
fn main() {}

View file

@ -0,0 +1,11 @@
error[E0900]: attribute should be applied to function
--> $DIR/only-for-fns.rs:3:1
|
LL | #[track_caller]
| ^^^^^^^^^^^^^^^
LL | struct S;
| --------- not a function
error: aborting due to previous error
For more information about this error, try `rustc --explain E0900`.