Skip to content
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

unused-qualifications causes syntax error #121999

Closed
matthiaskrgr opened this issue Mar 4, 2024 · 1 comment · Fixed by #122038
Closed

unused-qualifications causes syntax error #121999

matthiaskrgr opened this issue Mar 4, 2024 · 1 comment · Fixed by #122038
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

Code

fn main() {
    println!("{}", <bool as ::std::default::Default>::default());
}

Current output

warning: unnecessary qualification
 --> ./src/tools/rustfmt/tests/target/associated-items.rs:2:29
  |
2 |     println!("{}", <bool as ::std::default::Default>::default());
  |                             ^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: requested on the command line with `--force-warn unused-qualifications`
help: remove the unnecessary path segments
  |
2 -     println!("{}", <bool as ::std::default::Default>::default());
2 +     println!("{}", <bool as Default>::default());
  |

warning: unnecessary qualification
 --> ./src/tools/rustfmt/tests/target/associated-items.rs:2:20
  |
2 |     println!("{}", <bool as ::std::default::Default>::default());
  |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
help: remove the unnecessary path segments
  |
2 -     println!("{}", <bool as ::std::default::Default>::default());
2 +     println!("{}", Default>::default());
  |

warning: 2 warnings emitted

Desired output

The second suggestion has a syntax error since we only remove `<` but leave `>` in.

Rationale and extra context

No response

Other cases

No response

Rust Version

rustc 1.78.0-nightly (7606c1396 2024-03-04)
binary: rustc
commit-hash: 7606c13961ddc1174b70638e934df0439b7dc515
commit-date: 2024-03-04
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 18.1.0

Anything else?

rustc ./src/tools/rustfmt/tests/target/associated-items.rs --force-warn unused-qualifications

@matthiaskrgr matthiaskrgr added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 4, 2024
@matthiaskrgr
Copy link
Member Author

I suspect this is a regression of #121528 cc @Alexendoo

@jieyouxu jieyouxu added the D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. label Mar 4, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 6, 2024
…=petrochenkov

Fix linting paths with qself in `unused_qualifications`

Fixes rust-lang#121999

`resolve_qpath` ends up being called again with `qself` set to `None` to check trait items from fully qualified paths. To avoid this the lint is moved to a place that accounts for this already

https://github.com/rust-lang/rust/blob/96561a8fd134e8f2b205769a4fca03b392d9f484/compiler/rustc_resolve/src/late.rs#L4074-L4088

r? `@petrochenkov`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 6, 2024
…=petrochenkov

Fix linting paths with qself in `unused_qualifications`

Fixes rust-lang#121999

`resolve_qpath` ends up being called again with `qself` set to `None` to check trait items from fully qualified paths. To avoid this the lint is moved to a place that accounts for this already

https://github.com/rust-lang/rust/blob/96561a8fd134e8f2b205769a4fca03b392d9f484/compiler/rustc_resolve/src/late.rs#L4074-L4088

r? ``@petrochenkov``
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 6, 2024
…=petrochenkov

Fix linting paths with qself in `unused_qualifications`

Fixes rust-lang#121999

`resolve_qpath` ends up being called again with `qself` set to `None` to check trait items from fully qualified paths. To avoid this the lint is moved to a place that accounts for this already

https://github.com/rust-lang/rust/blob/96561a8fd134e8f2b205769a4fca03b392d9f484/compiler/rustc_resolve/src/late.rs#L4074-L4088

r? ```@petrochenkov```
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 6, 2024
…=petrochenkov

Fix linting paths with qself in `unused_qualifications`

Fixes rust-lang#121999

`resolve_qpath` ends up being called again with `qself` set to `None` to check trait items from fully qualified paths. To avoid this the lint is moved to a place that accounts for this already

https://github.com/rust-lang/rust/blob/96561a8fd134e8f2b205769a4fca03b392d9f484/compiler/rustc_resolve/src/late.rs#L4074-L4088

r? ````@petrochenkov````
@bors bors closed this as completed in e93a3d1 Mar 6, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 6, 2024
Rollup merge of rust-lang#122038 - Alexendoo:unused-qualifications, r=petrochenkov

Fix linting paths with qself in `unused_qualifications`

Fixes rust-lang#121999

`resolve_qpath` ends up being called again with `qself` set to `None` to check trait items from fully qualified paths. To avoid this the lint is moved to a place that accounts for this already

https://github.com/rust-lang/rust/blob/96561a8fd134e8f2b205769a4fca03b392d9f484/compiler/rustc_resolve/src/late.rs#L4074-L4088

r? `````@petrochenkov`````
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants