-
Notifications
You must be signed in to change notification settings - Fork 13.4k
#[track_caller]
feature gate (RFC 2091 1/N)
#65037
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
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
543449d
[RFC 2091] Add #[track_caller] attribute.
ayosec 6c04c8e
track_caller run-pass test, lint cleanup, PR review.
anp 43d4b70
track_caller feature gate starts in 1.40.0.
anp d931afe
Mark #![feature(track_caller)] as incomplete.
anp 9900211
track_caller error numbers and text.
anp 53096c5
track_caller tests account for incomplete feature warning.
anp 8992c30
E0735 -> E0739
anp bdc4bd1
E073[6-8] include failing code examples.
anp 130be6d
Expand E0738 to cover different cases.
anp f70ed29
Update expected error output.
anp 190212c
Prohibit #[track_caller] within trait impls as well as decls.
anp c49966b
Clarify variable names when checking track_caller methods.
anp cca58d1
Fix syntax typo in error message.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# `track_caller` | ||
|
||
The tracking issue for this feature is: [#47809](https://github.com/rust-lang/rust/issues/47809). | ||
|
||
------------------------ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -172,6 +172,18 @@ pub fn check_trait_item(tcx: TyCtxt<'_>, def_id: DefId) { | |
_ => None | ||
}; | ||
check_associated_item(tcx, trait_item.hir_id, trait_item.span, method_sig); | ||
|
||
// Prohibits applying `#[track_caller]` to trait decls | ||
for attr in &trait_item.attrs { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why isn't this in |
||
if attr.check_name(sym::track_caller) { | ||
struct_span_err!( | ||
tcx.sess, | ||
attr.span, | ||
E0738, | ||
"`#[track_caller]` is not supported in trait declarations." | ||
).emit(); | ||
} | ||
} | ||
} | ||
|
||
pub fn check_impl_item(tcx: TyCtxt<'_>, def_id: DefId) { | ||
|
@@ -182,6 +194,30 @@ pub fn check_impl_item(tcx: TyCtxt<'_>, def_id: DefId) { | |
hir::ImplItemKind::Method(ref sig, _) => Some(sig), | ||
_ => None | ||
}; | ||
|
||
// Prohibits applying `#[track_caller]` to trait impls | ||
if method_sig.is_some() { | ||
let track_caller_attr = impl_item.attrs.iter() | ||
.find(|a| a.check_name(sym::track_caller)); | ||
if let Some(tc_attr) = track_caller_attr { | ||
let parent_hir_id = tcx.hir().get_parent_item(hir_id); | ||
let containing_item = tcx.hir().expect_item(parent_hir_id); | ||
let containing_impl_is_for_trait = match &containing_item.kind { | ||
hir::ItemKind::Impl(_, _, _, _, tr, _, _) => tr.is_some(), | ||
_ => bug!("parent of an ImplItem must be an Impl"), | ||
}; | ||
|
||
if containing_impl_is_for_trait { | ||
struct_span_err!( | ||
tcx.sess, | ||
tc_attr.span, | ||
E0738, | ||
"`#[track_caller]` is not supported in traits yet." | ||
).emit(); | ||
} | ||
} | ||
} | ||
|
||
check_associated_item(tcx, impl_item.hir_id, impl_item.span, method_sig); | ||
} | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#[track_caller] | ||
fn f() {} | ||
//~^^ ERROR the `#[track_caller]` attribute is an experimental feature | ||
|
||
fn main() {} |
12 changes: 12 additions & 0 deletions
12
src/test/ui/feature-gates/feature-gate-track_caller.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
error[E0658]: the `#[track_caller]` attribute is an experimental feature | ||
--> $DIR/feature-gate-track_caller.rs:1: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`. |
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,7 @@ | ||
#![feature(track_caller)] //~ WARN the feature `track_caller` is incomplete | ||
|
||
#[track_caller(1)] | ||
fn f() {} | ||
//~^^ ERROR malformed `track_caller` attribute input | ||
|
||
fn main() {} |
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,16 @@ | ||
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]` | ||
|
||
warning: the feature `track_caller` is incomplete and may cause the compiler to crash | ||
--> $DIR/error-odd-syntax.rs:1:12 | ||
| | ||
LL | #![feature(track_caller)] | ||
| ^^^^^^^^^^^^ | ||
| | ||
= note: `#[warn(incomplete_features)]` on by default | ||
|
||
error: aborting due to previous error | ||
|
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,7 @@ | ||
#![feature(track_caller)] //~ WARN the feature `track_caller` is incomplete | ||
|
||
#[track_caller] | ||
extern "C" fn f() {} | ||
//~^^ ERROR rust ABI is required to use `#[track_caller]` | ||
|
||
fn main() {} |
17 changes: 17 additions & 0 deletions
17
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
warning: the feature `track_caller` is incomplete and may cause the compiler to crash | ||
--> $DIR/error-with-invalid-abi.rs:1:12 | ||
| | ||
LL | #![feature(track_caller)] | ||
| ^^^^^^^^^^^^ | ||
| | ||
= note: `#[warn(incomplete_features)]` on by default | ||
|
||
error[E0737]: 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 E0737`. |
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,8 @@ | ||
#![feature(naked_functions, track_caller)] //~ WARN the feature `track_caller` is incomplete | ||
|
||
#[track_caller] | ||
#[naked] | ||
fn f() {} | ||
//~^^^ ERROR cannot use `#[track_caller]` with `#[naked]` | ||
|
||
fn main() {} |
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,17 @@ | ||
warning: the feature `track_caller` is incomplete and may cause the compiler to crash | ||
--> $DIR/error-with-naked.rs:1:29 | ||
| | ||
LL | #![feature(naked_functions, track_caller)] | ||
| ^^^^^^^^^^^^ | ||
| | ||
= note: `#[warn(incomplete_features)]` on by default | ||
|
||
error[E0736]: 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 E0736`. |
13 changes: 13 additions & 0 deletions
13
src/test/ui/rfc-2091-track-caller/error-with-trait-decl.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,13 @@ | ||
#![feature(track_caller)] //~ WARN the feature `track_caller` is incomplete | ||
|
||
trait Trait { | ||
#[track_caller] | ||
fn unwrap(&self); | ||
//~^^ ERROR: `#[track_caller]` is not supported in trait declarations. | ||
} | ||
|
||
impl Trait for u64 { | ||
fn unwrap(&self) {} | ||
} | ||
|
||
fn main() {} |
Oops, something went wrong.
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.