-
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
tests/ui/macros/issue-111749.rs
Outdated
| 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 |
|
@rustbot review (@Noratrieb?) |
|
do you think it would make sense to get quick lang team signoff here? given that it already errors in test mode I'm not sure whether we should treat it as breakage or not |
|
sure, let's do it. cc @rust-lang/lang |
|
relevant part of the description
From the description. Should either be an easy FCP or a decision to not even FCP, given that test mode already errored. |
| // test is a built-in macro, not a built-in attribute, but it kind of acts like both. | ||
| // check its target checking anyway here | ||
| #[test] | ||
| //~^ 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.
This is inconsistent with the terminology we use in the reference and elsewhere.
| //~^ ERROR the `#[test]` attribute may only be used on a non-associated function | |
| //~^ ERROR the `#[test]` attribute may only be used on a free 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'm not sure I like that convention, but I do agree with wanting it to be consistent. Changed it :)
|
Sounds right. Thanks @jdonszelmann, @Noratrieb. This brings us closer in line with what the Reference says in: @rfcbot fcp merge |
|
Team member @traviscross has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns. |
|
@rfcbot reviewed |
1 similar comment
|
@rfcbot reviewed |
|
🔔 This is now entering its final comment period, as per the review above. 🔔 |
a9e4630 to
98703b0
Compare
|
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
98703b0 to
5aa296b
Compare
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--testisn'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
--testisn'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--testis 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