-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Implement #[track_caller] attribute. (RFC 2091 4/N) #65881
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+286
−141
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
9ab065d
Implement #[track_caller] in const.
anp de44f09
Rename test filename to match others.
anp d47043b
Add failing test for codegen'd track_caller attribute.
anp f1d942b
Add field to FunctionCx for passing caller location.
anp 4773ded
Generate &core::panic::Location type in a single place.
anp fa6bb39
Add caller_location paramter to FnAbi::new_internal.
anp 207f520
Pass a location to #[track_caller] functions in codegen_call_terminator.
anp ebaebd9
Remove #[track_caller] from incomplete features list.
anp bc6e66e
Implement core::panic::Location::caller using #[track_caller].
anp eb679c9
Add test for Location::caller in a macro.
anp 28b2257
Error message no longer implies #[track_caller] is a requirement for …
anp cc574be
`#[track_caller]` suppresses MIR inlining.
anp 7afbbf7
Always call const fns with #[track_caller].
anp 99165ce
Caller location is propagated via immediates rather than memory.
anp 1c2483e
Address review feedback.
anp 15d1f7c
Add additional layer of #[track_caller] to test, avoid const prop.
anp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 was deleted.
Oops, something went wrong.
18 changes: 12 additions & 6 deletions
18
src/test/ui/rfc-2091-track-caller/caller-location-intrinsic.rs
This file contains hidden or 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,21 +1,27 @@ | ||
// run-pass | ||
anp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#![feature(core_intrinsics)] | ||
#![feature(track_caller)] | ||
|
||
#[inline(never)] | ||
#[track_caller] | ||
fn defeat_const_prop() -> &'static core::panic::Location<'static> { | ||
anp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
core::panic::Location::caller() | ||
} | ||
|
||
macro_rules! caller_location_from_macro { | ||
() => (core::intrinsics::caller_location()); | ||
() => (defeat_const_prop()); | ||
} | ||
|
||
fn main() { | ||
let loc = core::intrinsics::caller_location(); | ||
let loc = defeat_const_prop(); | ||
assert_eq!(loc.file(), file!()); | ||
assert_eq!(loc.line(), 10); | ||
assert_eq!(loc.line(), 16); | ||
assert_eq!(loc.column(), 15); | ||
|
||
// `caller_location()` in a macro should behave similarly to `file!` and `line!`, | ||
// `Location::caller()` in a macro should behave similarly to `file!` and `line!`, | ||
// i.e. point to where the macro was invoked, instead of the macro itself. | ||
let loc2 = caller_location_from_macro!(); | ||
assert_eq!(loc2.file(), file!()); | ||
assert_eq!(loc2.line(), 17); | ||
assert_eq!(loc2.line(), 23); | ||
assert_eq!(loc2.column(), 16); | ||
} |
41 changes: 41 additions & 0 deletions
41
src/test/ui/rfc-2091-track-caller/const-caller-location.rs
This file contains hidden or 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,41 @@ | ||
// run-pass | ||
|
||
#![feature(const_fn, track_caller)] | ||
|
||
use std::panic::Location; | ||
|
||
const LOCATION: &Location = Location::caller(); | ||
|
||
const TRACKED: &Location = tracked(); | ||
#[track_caller] | ||
const fn tracked() -> &'static Location <'static> { | ||
Location::caller() | ||
} | ||
|
||
const NESTED: &Location = nested_location(); | ||
const fn nested_location() -> &'static Location<'static> { | ||
Location::caller() | ||
} | ||
|
||
const CONTAINED: &Location = contained(); | ||
const fn contained() -> &'static Location<'static> { | ||
tracked() | ||
} | ||
|
||
fn main() { | ||
assert_eq!(LOCATION.file(), file!()); | ||
assert_eq!(LOCATION.line(), 7); | ||
assert_eq!(LOCATION.column(), 29); | ||
|
||
assert_eq!(TRACKED.file(), file!()); | ||
assert_eq!(TRACKED.line(), 9); | ||
assert_eq!(TRACKED.column(), 28); | ||
|
||
assert_eq!(NESTED.file(), file!()); | ||
assert_eq!(NESTED.line(), 17); | ||
assert_eq!(NESTED.column(), 5); | ||
|
||
assert_eq!(CONTAINED.file(), file!()); | ||
assert_eq!(CONTAINED.line(), 22); | ||
assert_eq!(CONTAINED.column(), 5); | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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,6 +1,7 @@ | ||
#![feature(track_caller)] //~ WARN the feature `track_caller` is incomplete | ||
#![feature(track_caller)] | ||
|
||
#[track_caller] //~ ERROR Rust ABI is required to use `#[track_caller]` | ||
#[track_caller] | ||
extern "C" fn f() {} | ||
//~^^ ERROR `#[track_caller]` requires Rust ABI | ||
|
||
fn main() {} |
10 changes: 1 addition & 9 deletions
10
src/test/ui/rfc-2091-track-caller/error-with-invalid-abi.stderr
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
8 changes: 0 additions & 8 deletions
8
src/test/ui/rfc-2091-track-caller/error-with-trait-decl.stderr
This file contains hidden or 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
2 changes: 1 addition & 1 deletion
2
src/test/ui/rfc-2091-track-caller/error-with-trait-default-impl.rs
This file contains hidden or 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
8 changes: 0 additions & 8 deletions
8
src/test/ui/rfc-2091-track-caller/error-with-trait-default-impl.stderr
This file contains hidden or 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 hidden or 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
8 changes: 0 additions & 8 deletions
8
src/test/ui/rfc-2091-track-caller/error-with-trait-fn-impl.stderr
This file contains hidden or 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 hidden or 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,21 @@ | ||
// run-pass | ||
|
||
#![feature(track_caller)] | ||
|
||
macro_rules! caller_location_from_macro { | ||
() => (core::panic::Location::caller()); | ||
} | ||
|
||
fn main() { | ||
let loc = core::panic::Location::caller(); | ||
assert_eq!(loc.file(), file!()); | ||
assert_eq!(loc.line(), 10); | ||
assert_eq!(loc.column(), 15); | ||
|
||
// `Location::caller()` in a macro should behave similarly to `file!` and `line!`, | ||
// i.e. point to where the macro was invoked, instead of the macro itself. | ||
let loc2 = caller_location_from_macro!(); | ||
assert_eq!(loc2.file(), file!()); | ||
assert_eq!(loc2.line(), 17); | ||
assert_eq!(loc2.column(), 16); | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 was deleted.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
src/test/ui/rfc-2091-track-caller/track-caller-attribute.rs
This file contains hidden or 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,40 @@ | ||
// run-pass | ||
|
||
#![feature(const_fn, track_caller)] | ||
anp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
use std::panic::Location; | ||
|
||
#[track_caller] | ||
fn tracked() -> &'static Location<'static> { | ||
Location::caller() | ||
} | ||
|
||
fn nested_intrinsic() -> &'static Location<'static> { | ||
Location::caller() | ||
} | ||
|
||
fn nested_tracked() -> &'static Location<'static> { | ||
tracked() | ||
} | ||
|
||
fn main() { | ||
let location = Location::caller(); | ||
assert_eq!(location.file(), file!()); | ||
assert_eq!(location.line(), 21); | ||
assert_eq!(location.column(), 20); | ||
|
||
let tracked = tracked(); | ||
assert_eq!(tracked.file(), file!()); | ||
assert_eq!(tracked.line(), 26); | ||
assert_eq!(tracked.column(), 19); | ||
|
||
let nested = nested_intrinsic(); | ||
assert_eq!(nested.file(), file!()); | ||
assert_eq!(nested.line(), 13); | ||
assert_eq!(nested.column(), 5); | ||
|
||
let contained = nested_tracked(); | ||
assert_eq!(contained.file(), file!()); | ||
assert_eq!(contained.line(), 17); | ||
assert_eq!(contained.column(), 5); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.