-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
add FCW to invalid #[should_panic] and #[ignore]
#150416
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| use super::prelude::*; | ||
|
|
||
| pub(crate) struct TestTraceParser; | ||
|
|
||
| impl<S: Stage> NoArgsAttributeParser<S> for TestTraceParser { | ||
| const PATH: &[Symbol] = &[sym::test_trace]; | ||
|
|
||
| const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Ignore; | ||
|
|
||
| const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Fn)]); | ||
|
|
||
| const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::TestTrace; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1316,3 +1316,13 @@ pub(crate) struct FunctionNamesDuplicated { | |
| #[primary_span] | ||
| pub spans: Vec<Span>, | ||
| } | ||
|
|
||
| #[derive(Diagnostic)] | ||
| #[diag(passes_attr_must_be_applied_to_test_or_bench)] | ||
| pub(crate) struct MustBeAppliedToTest { | ||
| #[primary_span] | ||
| pub attr_span: Span, | ||
| #[warning] | ||
| pub warning: bool, | ||
|
Contributor
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. Is there a reason (you can do this by applying
Contributor
Author
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. this is what all the other FCW in
JonathanBrouwer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| pub attr_name: Symbol, | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| //@ check-pass | ||
| #![feature(test)] | ||
|
|
||
| #[ignore] | ||
| //~^ WARN `#[ignore]` should only be applied to functions annotated with `#[test]` or `#[bench]` | ||
| //~| WARN this was previously accepted | ||
| pub fn foo() {} | ||
|
|
||
|
|
||
| #[test] | ||
| #[ignore] | ||
| pub fn bar() {} | ||
|
|
||
| #[ignore] | ||
| #[bench] | ||
| pub fn bazz() {} | ||
|
|
||
| fn main() { } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| warning: `#[ignore]` should only be applied to functions annotated with `#[test]` or `#[bench]` | ||
| --> $DIR/ignore.rs:4:1 | ||
| | | ||
| LL | #[ignore] | ||
| | ^^^^^^^^^ | ||
| | | ||
| = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
|
|
||
| warning: 1 warning emitted | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| //@ check-pass | ||
| #![feature(test)] | ||
|
|
||
| #[should_panic] | ||
| //~^ WARN `#[should_panic]` should only be applied to functions annotated with `#[test]` or `#[bench]` | ||
| //~| WARN this was previously accepted | ||
| pub fn foo() {} | ||
|
|
||
|
|
||
| #[test] | ||
| #[should_panic] | ||
| pub fn bar() {} | ||
|
|
||
| #[should_panic] | ||
| #[bench] | ||
| pub fn bazz() {} | ||
|
|
||
| fn main() { } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| warning: `#[should_panic]` should only be applied to functions annotated with `#[test]` or `#[bench]` | ||
| --> $DIR/should-panic.rs:4:1 | ||
| | | ||
| LL | #[should_panic] | ||
| | ^^^^^^^^^^^^^^^ | ||
| | | ||
| = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
|
|
||
| warning: 1 warning emitted | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| //@ compile-flags: --test | ||
|
|
||
| fn main() {} | ||
|
|
||
| #[test_trace] | ||
| //~^ ERROR cannot find attribute `test_trace` in this scope | ||
| fn foo() {} | ||
|
|
||
|
|
||
| #[test] | ||
| #[test_trace] | ||
| //~^ ERROR cannot find attribute `test_trace` in this scope | ||
| fn bar() {} | ||
|
|
||
| #[test] | ||
| #[test_trace] | ||
| //~^ ERROR cannot find attribute `test_trace` in this scope | ||
| #[test] | ||
| //~^ WARN duplicated attribute | ||
| fn bazz() {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| error: cannot find attribute `test_trace` in this scope | ||
| --> $DIR/test_trace.rs:5:3 | ||
| | | ||
| LL | #[test_trace] | ||
| | ^^^^^^^^^^ | ||
| | | ||
| help: a built-in attribute with a similar name exists | ||
| | | ||
| LL - #[test_trace] | ||
| LL + #[<test_trace>] | ||
| | | ||
|
|
||
| error: cannot find attribute `test_trace` in this scope | ||
| --> $DIR/test_trace.rs:11:3 | ||
| | | ||
| LL | #[test_trace] | ||
| | ^^^^^^^^^^ | ||
| | | ||
| help: a built-in attribute with a similar name exists | ||
| | | ||
| LL - #[test_trace] | ||
| LL + #[<test_trace>] | ||
| | | ||
|
|
||
| error: cannot find attribute `test_trace` in this scope | ||
| --> $DIR/test_trace.rs:16:3 | ||
| | | ||
| LL | #[test_trace] | ||
| | ^^^^^^^^^^ | ||
| | | ||
| help: a built-in attribute with a similar name exists | ||
| | | ||
| LL - #[test_trace] | ||
| LL + #[<test_trace>] | ||
| | | ||
|
|
||
| warning: duplicated attribute | ||
| --> $DIR/test_trace.rs:18:1 | ||
| | | ||
| LL | #[test] | ||
| | ^^^^^^^ | ||
| | | ||
| = note: `#[warn(duplicate_macro_attributes)]` on by default | ||
|
|
||
| error: aborting due to 3 previous errors; 1 warning emitted | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The crater run in #150727 (comment) had a bunch of failures (such as https://crater-reports.s3.amazonaws.com/pr-150727/try%2366388cc165a6c4ac98c074dc9f0281ff23528c55/gh/0958436455sarayut.master/log.txt) because this creates an attribute without a TokenStream. Can you look into this and make a regression test if easily possible?