forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#69251 - anp:track-caller-in-traits, r=eddyb
#[track_caller] in traits Per rust-lang#47809 (comment), this allows the `#[track_caller]` attribute on trait methods. Includes tests for `#[track_caller]` with: * "regular" trait impls * default trait impls * "blanket-tracked" trait impls, where the annotation is in the trait definition and is inherited by "regular" impls of the trait
- Loading branch information
Showing
15 changed files
with
217 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,11 @@ | ||
`#[track_caller]` cannot be used in traits yet. This is due to limitations in | ||
the compiler which are likely to be temporary. See [RFC 2091] for details on | ||
this and other restrictions. | ||
`#[track_caller]` cannot be used to annotate foreign functions. | ||
|
||
Erroneous example with a trait method implementation: | ||
Erroneous example: | ||
|
||
```compile_fail,E0738 | ||
#![feature(track_caller)] | ||
trait Foo { | ||
fn bar(&self); | ||
} | ||
impl Foo for u64 { | ||
#[track_caller] | ||
fn bar(&self) {} | ||
} | ||
``` | ||
|
||
Erroneous example with a blanket trait method implementation: | ||
|
||
```compile_fail,E0738 | ||
#![feature(track_caller)] | ||
trait Foo { | ||
extern "Rust" { | ||
#[track_caller] | ||
fn bar(&self) {} | ||
fn baz(&self); | ||
fn bar(); | ||
} | ||
``` | ||
|
||
Erroneous example with a trait method declaration: | ||
|
||
```compile_fail,E0738 | ||
#![feature(track_caller)] | ||
trait Foo { | ||
fn bar(&self) {} | ||
#[track_caller] | ||
fn baz(&self); | ||
} | ||
``` | ||
|
||
Note that while the compiler may be able to support the attribute in traits in | ||
the future, [RFC 2091] prohibits their implementation without a follow-up RFC. | ||
|
||
[RFC 2091]: https://github.com/rust-lang/rfcs/blob/master/text/2091-inline-semantic.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#![feature(track_caller)] | ||
#![allow(dead_code)] | ||
|
||
extern "Rust" { | ||
#[track_caller] //~ ERROR: `#[track_caller]` is not supported on foreign functions | ||
fn bar(); | ||
} | ||
|
||
fn main() {} |
4 changes: 2 additions & 2 deletions
4
...track-caller/error-with-trait-decl.stderr → ...-2091-track-caller/error-extern-fn.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 0 additions & 12 deletions
12
src/test/ui/rfc-2091-track-caller/error-with-trait-decl.rs
This file was deleted.
Oops, something went wrong.
8 changes: 0 additions & 8 deletions
8
src/test/ui/rfc-2091-track-caller/error-with-trait-default-impl.rs
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
src/test/ui/rfc-2091-track-caller/error-with-trait-default-impl.stderr
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
src/test/ui/rfc-2091-track-caller/error-with-trait-fn-impl.rs
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
src/test/ui/rfc-2091-track-caller/error-with-trait-fn-impl.stderr
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.