-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Fix ICE when applying test macro to crate root #147841
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: master
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
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#![feature(test)] | ||
|
||
// test is a built-in macro, not a built-in attribute, but it kind of acts like both. | ||
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. New test for test attributes. The previous tests simply asserted no errors would be given but that's not true anymore, and I think they should error! |
||
// check its target checking anyway here | ||
#[test] | ||
//~^ ERROR the `#[test]` attribute may only be used on a non-associated function | ||
mod test { | ||
mod inner { #![test] } | ||
//~^ ERROR inner macro attributes are unstable | ||
//~| ERROR the `#[test]` attribute may only be used on a non-associated function | ||
|
||
#[test] | ||
//~^ ERROR the `#[test]` attribute may only be used on a non-associated function | ||
struct S; | ||
|
||
#[test] | ||
//~^ ERROR the `#[test]` attribute may only be used on a non-associated function | ||
type T = S; | ||
|
||
#[test] | ||
//~^ ERROR the `#[test]` attribute may only be used on a non-associated function | ||
impl S { } | ||
} | ||
|
||
// At time of unit test authorship, if compiling without `--test` then | ||
// non-crate-level #[bench] attributes seem to be ignored. | ||
|
||
#[bench] | ||
//~^ ERROR the `#[bench]` attribute may only be used on a non-associated function | ||
mod bench { | ||
mod inner { #![bench] } | ||
//~^ ERROR inner macro attributes are unstable | ||
//~| ERROR the `#[bench]` attribute may only be used on a non-associated function | ||
|
||
#[bench] | ||
//~^ ERROR the `#[bench]` attribute may only be used on a non-associated function | ||
struct S; | ||
|
||
#[bench] | ||
//~^ ERROR the `#[bench]` attribute may only be used on a non-associated function | ||
type T = S; | ||
|
||
#[bench] | ||
//~^ ERROR the `#[bench]` attribute may only be used on a non-associated function | ||
impl S { } | ||
} | ||
|
||
fn main() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
error: the `#[test]` attribute may only be used on a non-associated function | ||
--> $DIR/gating-of-test-attrs.rs:5:1 | ||
| | ||
LL | #[test] | ||
| ^^^^^^^ the `#[test]` macro causes a function to be run as a test and has no effect on non-functions | ||
LL | | ||
LL | / mod test { | ||
LL | | mod inner { #![test] } | ||
... | | ||
LL | | impl S { } | ||
LL | | } | ||
| |_- expected a non-associated function, found a module | ||
| | ||
help: replace with conditional compilation to make the item only exist when tests are being run | ||
| | ||
LL - #[test] | ||
LL + #[cfg(test)] | ||
| | ||
|
||
error[E0658]: inner macro attributes are unstable | ||
--> $DIR/gating-of-test-attrs.rs:8:20 | ||
| | ||
LL | mod inner { #![test] } | ||
| ^^^^ | ||
| | ||
= note: see issue #54726 <https://github.com/rust-lang/rust/issues/54726> for more information | ||
= help: add `#![feature(custom_inner_attributes)]` to the crate attributes to enable | ||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
||
error: the `#[test]` attribute may only be used on a non-associated function | ||
--> $DIR/gating-of-test-attrs.rs:8:17 | ||
| | ||
LL | mod inner { #![test] } | ||
| ------------^^^^^^^^-- | ||
| | | | ||
| | the `#[test]` macro causes a function to be run as a test and has no effect on non-functions | ||
| expected a non-associated function, found a module | ||
| | ||
help: replace with conditional compilation to make the item only exist when tests are being run | ||
| | ||
LL - mod inner { #![test] } | ||
LL + mod inner { #[cfg(test)] } | ||
| | ||
|
||
error: the `#[test]` attribute may only be used on a non-associated function | ||
--> $DIR/gating-of-test-attrs.rs:12:5 | ||
| | ||
LL | #[test] | ||
| ^^^^^^^ the `#[test]` macro causes a function to be run as a test and has no effect on non-functions | ||
LL | | ||
LL | struct S; | ||
| --------- expected a non-associated function, found a struct | ||
| | ||
help: replace with conditional compilation to make the item only exist when tests are being run | ||
| | ||
LL - #[test] | ||
LL + #[cfg(test)] | ||
| | ||
|
||
error: the `#[test]` attribute may only be used on a non-associated function | ||
--> $DIR/gating-of-test-attrs.rs:16:5 | ||
| | ||
LL | #[test] | ||
| ^^^^^^^ the `#[test]` macro causes a function to be run as a test and has no effect on non-functions | ||
LL | | ||
LL | type T = S; | ||
| ----------- expected a non-associated function, found a type alias | ||
| | ||
help: replace with conditional compilation to make the item only exist when tests are being run | ||
| | ||
LL - #[test] | ||
LL + #[cfg(test)] | ||
| | ||
|
||
error: the `#[test]` attribute may only be used on a non-associated function | ||
--> $DIR/gating-of-test-attrs.rs:20:5 | ||
| | ||
LL | #[test] | ||
| ^^^^^^^ the `#[test]` macro causes a function to be run as a test and has no effect on non-functions | ||
LL | | ||
LL | impl S { } | ||
| ---------- expected a non-associated function, found an implementation | ||
| | ||
help: replace with conditional compilation to make the item only exist when tests are being run | ||
| | ||
LL - #[test] | ||
LL + #[cfg(test)] | ||
| | ||
|
||
error: the `#[bench]` attribute may only be used on a non-associated function | ||
--> $DIR/gating-of-test-attrs.rs:28:1 | ||
| | ||
LL | #[bench] | ||
| ^^^^^^^^ the `#[bench]` macro causes a function to be run as a test and has no effect on non-functions | ||
LL | | ||
LL | / mod bench { | ||
LL | | mod inner { #![bench] } | ||
... | | ||
LL | | impl S { } | ||
LL | | } | ||
| |_- expected a non-associated function, found a module | ||
|
||
error[E0658]: inner macro attributes are unstable | ||
--> $DIR/gating-of-test-attrs.rs:31:20 | ||
| | ||
LL | mod inner { #![bench] } | ||
| ^^^^^ | ||
| | ||
= note: see issue #54726 <https://github.com/rust-lang/rust/issues/54726> for more information | ||
= help: add `#![feature(custom_inner_attributes)]` to the crate attributes to enable | ||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
||
error: the `#[bench]` attribute may only be used on a non-associated function | ||
--> $DIR/gating-of-test-attrs.rs:31:17 | ||
| | ||
LL | mod inner { #![bench] } | ||
| ------------^^^^^^^^^-- | ||
| | | | ||
| | the `#[bench]` macro causes a function to be run as a test and has no effect on non-functions | ||
| expected a non-associated function, found a module | ||
|
||
error: the `#[bench]` attribute may only be used on a non-associated function | ||
--> $DIR/gating-of-test-attrs.rs:35:5 | ||
| | ||
LL | #[bench] | ||
| ^^^^^^^^ the `#[bench]` macro causes a function to be run as a test and has no effect on non-functions | ||
LL | | ||
LL | struct S; | ||
| --------- expected a non-associated function, found a struct | ||
|
||
error: the `#[bench]` attribute may only be used on a non-associated function | ||
--> $DIR/gating-of-test-attrs.rs:39:5 | ||
| | ||
LL | #[bench] | ||
| ^^^^^^^^ the `#[bench]` macro causes a function to be run as a test and has no effect on non-functions | ||
LL | | ||
LL | type T = S; | ||
| ----------- expected a non-associated function, found a type alias | ||
|
||
error: the `#[bench]` attribute may only be used on a non-associated function | ||
--> $DIR/gating-of-test-attrs.rs:43:5 | ||
| | ||
LL | #[bench] | ||
| ^^^^^^^^ the `#[bench]` macro causes a function to be run as a test and has no effect on non-functions | ||
LL | | ||
LL | impl S { } | ||
| ---------- expected a non-associated function, found an implementation | ||
|
||
error: aborting due to 12 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0658`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -250,38 +250,6 @@ mod macro_export { | |
//~| HELP remove the attribute | ||
} | ||
|
||
// At time of unit test authorship, if compiling without `--test` then | ||
// non-crate-level #[test] attributes seem to be ignored. | ||
|
||
#[test] | ||
mod test { mod inner { #![test] } | ||
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. these were weird here anyway, |
||
|
||
fn f() { } | ||
|
||
struct S; | ||
|
||
type T = S; | ||
|
||
impl S { } | ||
} | ||
|
||
// At time of unit test authorship, if compiling without `--test` then | ||
// non-crate-level #[bench] attributes seem to be ignored. | ||
|
||
#[bench] | ||
mod bench { | ||
mod inner { #![bench] } | ||
|
||
#[bench] | ||
struct S; | ||
|
||
#[bench] | ||
type T = S; | ||
|
||
#[bench] | ||
impl S { } | ||
} | ||
|
||
#[path = "3800"] | ||
mod path { | ||
mod inner { #![path="3800"] } | ||
|
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.
only give the suggestion of
cfg(test)
when we're dealing with test attrs