-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Running rustdoc on code using quote generates false lint warnings for unused_braces #70814
Comments
/cc @lcnr |
Hang on, could this be because of the transformation |
Simplified repro source, both inner blocks are necessary for some reason: pub fn repro() {
{
{
use std;
}
}
} |
@Nemo157 My guess it's because |
I just hit a similar error message in rustc (not rustdoc). Unused braces lint with no span or other information. I don't have a reproducer currently, since it's from a big crate and I don't have much to go by. |
Workaround for rust-lang/rust#70814
I'm getting
Is this related or should I create a new issue? Using Nightly 1.44.0 2020-04-16 |
@grantperry is this inside a macro? |
@lcnr yes it is. Sounds like it's something you already know about? |
If you are using a proc macro using |
I tried to fix this by checking if the surrounding expression comes from an expansion, but this didn't actually fix this. 🤔 @matklad do you have an idea/can this be fixed in quote? My approach stilled warned for the following, which seems to be the same issue afaict. rust/src/librustc_macros/src/query.rs Lines 362 to 370 in 4ca5fd2
|
I don't think I am familiar with the code in question @lcnr |
Sorry, mb 😓 meant @dtolnay as he is the owner of |
Labeling regression-from-stable-to-nightly. I would consider accepting a workaround in quote if somebody who is not me sends a PR and it is a very simple fix, but really this needs to be fixed in rustdoc / rustc. |
Let’s try to find the cause of the regression |
Error: Only Rust team members can ping teams. Please let |
@rustbot ping cleanup |
Hey Cleanup Crew ICE-breakers! This bug has been identified as a good cc @AminArria @chrissimpkins @contrun @DutchGhost @elshize @ethanboxx @h-michael @HallerPatrick @hdhoang @hellow554 @imtsuki @jakevossen5 @kanru @KarlK90 @LeSeulArtichaut @MAdrianMattocks @matheus-consoli @mental32 @nmccarty @Noah-Kennedy @pard68 @PeytonT @pierreN @Redblueflame @RobbieClarken @RobertoSnap @robjtede @SarthakSingh31 @senden9 @shekohex @sinato @spastorino @turboladen @woshilapin @yerke |
Quick and dirty fix of the unused_braces lint cc @lcnr Adresses rust-lang#70814 This at least prevents lint output, if no span is available. Even though this also prevents the `unused_parens` lint from emitting, when the `DUMMY_SP` is used there, but I think that should be ok, since error messages without a span are quite useless anyway. Clippy CI is currently blocked on this bug. If this quick and dirty fix should be rejected, I could try to work around this in Clippy. r? @shepmaster
* Remove serde-derive dependency * Fix clippy * Fix nightly clippy * Remove some extern crate * 0.5.0 is unreleased! * Tweak deny warnings - According to https://users.rust-lang.org/t/how-to-fail-a-build-with-warnings/2687/7 * Check in Cargo.lock for more reproducible tests * Tighten ring dependency version requirement * Fix url crate to 2.1.0 - Pending regression * Fix doctest * Workaround regression cf. rust-lang/rust#70814 * Fix format * Rearrange steps to check fmt first * Relax url and exclude 2.1.1 * Fix tests
I think e42337b a fixed this issue. It didn't add a test though so perhaps mark as needs-test? |
Workaround for rust-lang/rust#70814
@osa1 it didn't :
|
The modified lint correctly provide a span in its suggestion. ```shell error: unnecessary braces around block return value --> /rust/src/test/rustdoc-ui/unused-braces-lint.rs:9:5 | LL | / { LL | | { | |________^ LL | use std; LL | } | __________^ LL | | } | |_____^ | note: the lint level is defined here --> /rust/src/test/rustdoc-ui/unused-braces-lint.rs:6:9 | LL | #![deny(unused_braces)] | ^^^^^^^^^^^^^ help: remove these braces | LL ~ { LL | use std; LL ~ } | ``` It is unclear to which extend rust-lang#70814 is still an issue, as the inital MCVE does not trigger the lint on stable either,[rust playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=b6ff31a449c0b73a08daac8ee43b1fa6)
Currently the lint faces a severe limitation: since it only catches single-line block, running rustfmt beforehand will remove all occurences of it, because it breaks them into multiline blocks. We do not check match `Arm` for two reasons: - In case it does not use commas to separate arms, removing the block would result in a compilation error Example: ``` match expr { pat => {()} _ => println!("foo") } ``` - Do not lint multiline match arms used for formatting reasons ``` match expr { pat => { somewhat_long_expression } // ... } Delete `unused-braces-lint` test The modified lint correctly provide a span in its suggestion. ```shell error: unnecessary braces around block return value --> /rust/src/test/rustdoc-ui/unused-braces-lint.rs:9:5 | LL | / { LL | | { | |________^ LL | use std; LL | } | __________^ LL | | } | |_____^ | note: the lint level is defined here --> /rust/src/test/rustdoc-ui/unused-braces-lint.rs:6:9 | LL | #![deny(unused_braces)] | ^^^^^^^^^^^^^ help: remove these braces | LL ~ { LL | use std; LL ~ } | ``` It is unclear to which extend rust-lang#70814 is still an issue, as the inital MCVE does not trigger the lint on stable either,[rust playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=b6ff31a449c0b73a08daac8ee43b1fa6) Fix code with expanded `unused_braces` lint Also allow `unused_braces` on tests
Currently the lint faces a severe limitation: since it only catches single-line block, running rustfmt beforehand will remove all occurences of it, because it breaks them into multiline blocks. We do not check match `Arm` for two reasons: - In case it does not use commas to separate arms, removing the block would result in a compilation error Example: ``` match expr { pat => {()} _ => println!("foo") } ``` - Do not lint multiline match arms used for formatting reasons ``` match expr { pat => { somewhat_long_expression } // ... } ``` Delete `unused-braces-lint` test The modified lint correctly provide a span in its suggestion. ```shell error: unnecessary braces around block return value --> /rust/src/test/rustdoc-ui/unused-braces-lint.rs:9:5 | LL | / { LL | | { | |________^ LL | use std; LL | } | __________^ LL | | } | |_____^ | note: the lint level is defined here --> /rust/src/test/rustdoc-ui/unused-braces-lint.rs:6:9 | LL | #![deny(unused_braces)] | ^^^^^^^^^^^^^ help: remove these braces | LL ~ { LL | use std; LL ~ } | ``` It is unclear to which extend rust-lang#70814 is still an issue, as the inital MCVE does not trigger the lint on stable either,[rust playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=b6ff31a449c0b73a08daac8ee43b1fa6) Fix code with expanded `unused_braces` lint Also allow `unused_braces` on tests Mute `unused_braces` on `match_ast!`
Currently the lint faces a severe limitation: since it only catches single-line block, running rustfmt beforehand will remove all occurences of it, because it breaks them into multiline blocks. We do not check match `Arm` for two reasons: - In case it does not use commas to separate arms, removing the block would result in a compilation error Example: ``` match expr { pat => {()} _ => println!("foo") } ``` - Do not lint multiline match arms used for formatting reasons ``` match expr { pat => { somewhat_long_expression } // ... } ``` Delete `unused-braces-lint` test The modified lint correctly provide a span in its suggestion. ```shell error: unnecessary braces around block return value --> /rust/src/test/rustdoc-ui/unused-braces-lint.rs:9:5 | LL | / { LL | | { | |________^ LL | use std; LL | } | __________^ LL | | } | |_____^ | note: the lint level is defined here --> /rust/src/test/rustdoc-ui/unused-braces-lint.rs:6:9 | LL | #![deny(unused_braces)] | ^^^^^^^^^^^^^ help: remove these braces | LL ~ { LL | use std; LL ~ } | ``` It is unclear to which extend rust-lang#70814 is still an issue, as the inital MCVE does not trigger the lint on stable either,[rust playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=b6ff31a449c0b73a08daac8ee43b1fa6) Fix code with expanded `unused_braces` lint Also allow `unused_braces` on tests Mute `unused_braces` on `match_ast!`
I tried this code:
I think this is a basic and common usage of the quote crate.
I expected to see no warnings:
Instead, warnings are generated (and my CI build fails due to the
deny
):Note that the warning only appears when running rustdoc.
Meta
rustc +nightly-2020-04-04 --version --verbose
:The text was updated successfully, but these errors were encountered: