-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The codegen implementation already works for this, so we're: * propagating track_caller attr from trait def to impl * relaxing errors * adding tests Approved in a recent lang team meeting: https://github.com/rust-lang/lang-team/blob/master/minutes/2020-01-09.md
- Loading branch information
Showing
15 changed files
with
215 additions
and
107 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
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,79 @@ | ||
// run-pass | ||
|
||
#![feature(track_caller)] | ||
|
||
macro_rules! assert_expansion_site_is_tracked { | ||
() => {{ | ||
let location = std::panic::Location::caller(); | ||
assert_eq!(location.file(), file!()); | ||
assert_ne!(location.line(), line!(), "line should be outside this fn"); | ||
}} | ||
} | ||
|
||
trait Tracked { | ||
fn local_tracked(&self); | ||
|
||
#[track_caller] | ||
fn blanket_tracked(&self); | ||
|
||
#[track_caller] | ||
fn default_tracked(&self) { | ||
assert_expansion_site_is_tracked!(); | ||
} | ||
} | ||
|
||
impl Tracked for () { | ||
#[track_caller] | ||
fn local_tracked(&self) { | ||
assert_expansion_site_is_tracked!(); | ||
} | ||
|
||
fn blanket_tracked(&self) { | ||
assert_expansion_site_is_tracked!(); | ||
} | ||
} | ||
|
||
impl Tracked for bool { | ||
#[track_caller] | ||
fn local_tracked(&self) { | ||
assert_expansion_site_is_tracked!(); | ||
} | ||
|
||
fn blanket_tracked(&self) { | ||
assert_expansion_site_is_tracked!(); | ||
} | ||
|
||
fn default_tracked(&self) { | ||
assert_expansion_site_is_tracked!(); | ||
} | ||
} | ||
|
||
impl Tracked for u8 { | ||
#[track_caller] | ||
fn local_tracked(&self) { | ||
assert_expansion_site_is_tracked!(); | ||
} | ||
|
||
fn blanket_tracked(&self) { | ||
assert_expansion_site_is_tracked!(); | ||
} | ||
|
||
#[track_caller] | ||
fn default_tracked(&self) { | ||
assert_expansion_site_is_tracked!(); | ||
} | ||
} | ||
|
||
fn main() { | ||
().local_tracked(); | ||
().default_tracked(); | ||
().blanket_tracked(); | ||
|
||
true.local_tracked(); | ||
true.default_tracked(); | ||
true.blanket_tracked(); | ||
|
||
0u8.local_tracked(); | ||
0u8.default_tracked(); | ||
0u8.blanket_tracked(); | ||
} |