-
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?
Conversation
|
|
||
if !is_bench { | ||
err.with_span_suggestion(attr_sp, | ||
"replace with conditional compilation to make the item only exist when tests are being run", |
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
@@ -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 comment
The 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!
// 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 comment
The reason will be displayed to describe this comment to others. Learn more.
these were weird here anyway, test
isn't a built-in attribute but a built-in macro!
@@ -5,8 +5,8 @@ macro_rules! cbor_map { | |||
} | |||
|
|||
fn main() { | |||
cbor_map! { #[test(test)] 4}; | |||
//~^ ERROR removing an expression is not supported in this position | |||
cbor_map! { #[test(test)] 4i32}; |
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.
changed to an i32 cause signum wouldn't be valid on just 4
cbor_map! { #[test(test)] 4}; | ||
//~^ ERROR removing an expression is not supported in this position | ||
cbor_map! { #[test(test)] 4i32}; | ||
//~^ ERROR the `#[test]` attribute may only be used on a non-associated function |
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.
I think this is the correct error here, not something about removing expressions. I think noting that the target is wrong is more important.
@@ -0,0 +1,8 @@ | |||
// ICE when applying `#![test]` to the crate root, | |||
// though only when specified with a full path. `#![test]` is not enough. | |||
#![core::prelude::v1::test] |
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.
tests the specific ICE from the PR description
LL | let _ = #[test] 0; | ||
| ^^^^^^^ | ||
|
||
error: removing an expression is not supported in this position |
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.
this test was testing for "empty expressions". this is super niche, can only happen with ast-based attributes (only like 10 in the compiler) and none of the examples in this test should actually remove the expression, they should instead report that the target is wrong. I can't find any other examples of node-removing attributes so I think this test is simply superfluous now.
@bors try |
🚨 Error: missing start toolchain 🆘 If you have any trouble with Crater please ask in t-infra on Zulip |
This comment has been minimized.
This comment has been minimized.
Fix ICE when applying test macro to crate root
does this fix #114920 ? |
This comment has been minimized.
This comment has been minimized.
yea, that's actually exactly what it fixes. there was a crashtest for it I just notice but the fix is rather trivial in the end |
@bors try cancel |
Try build cancelled. Cancelled workflows: |
3e897fe
to
a9e4630
Compare
This PR changes a file inside |
@bors try |
This comment has been minimized.
This comment has been minimized.
Fix ICE when applying test macro to crate root
@craterbot check |
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
This PR does a couple of things. First of all, I found an ICE that happens when applying
#![core::prelude::v1::test]
to the crate root. This is caused by the test macro not expanding to an item when--test
isn't applied. For the crate root, that means it deletes the crate....The fix now first does target checking, and only if the target is valid discards the item when
--test
isn't applied. The discarding is, I think, important for perf.The problem with this PR is that it means that
#[test]
applied to structs previously would give no errors unless--test
is applied! That sounds like a bug to me, but maybe we should crater run it just in case, since technically that's a breaking change. Errors in such items wouldn't be reported previously.Also fixed a smol diagnostics bug with
#[bench]
's error messages refering to#[test]
accidentally.r? noratrieb (since I already explained you a bunch, feel free to re-assign)
Fixes #114920