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_qualification removes generic params #113808

Closed
matthiaskrgr opened this issue Jul 17, 2023 · 3 comments · Fixed by #113811
Closed

unused_qualification removes generic params #113808

matthiaskrgr opened this issue Jul 17, 2023 · 3 comments · Fixed by #113811
Labels
A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. D-papercut Diagnostics: An error or lint that needs small tweaks.

Comments

@matthiaskrgr
Copy link
Member

I tried this code:

// run-pass

#![feature(unsized_fn_params)]

use std::ops;
use std::ops::Index;

pub struct A;

impl ops::Index<str> for A {
    type Output = ();
    fn index(&self, _: str) -> &Self::Output {
        &()
    }
}

rustc --force-warn unused-qualifications

warning: unnecessary qualification
  --> ./tests/ui/unsized-locals/unsized-index.rs:10:6
   |
10 | impl ops::Index<str> for A {
   |      ^^^^^^^^^^^^^^^
   |
   = note: requested on the command line with `--force-warn unused-qualifications`
help: replace it with the unqualified path
   |
10 | impl Index for A {
   |      ~~~~~

Somehow the generic info gets lost completely? :S

@matthiaskrgr matthiaskrgr added the C-bug Category: This is a bug. label Jul 17, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 17, 2023
@matthiaskrgr
Copy link
Member Author

#112729 cc @jieyouxu

@matthiaskrgr matthiaskrgr added A-diagnostics Area: Messages for errors, warnings, and lints D-papercut Diagnostics: An error or lint that needs small tweaks. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. and removed A-diagnostics Area: Messages for errors, warnings, and lints labels Jul 17, 2023
@asquared31415
Copy link
Contributor

asquared31415 commented Jul 17, 2023

Minimized and not requiring nightly:

#![warn(unused_qualifications)]

mod inner {
    pub trait Trait<T> {}
}

// the import needs to be here for the lint to show up
#[allow(unused_imports)]
use inner::Trait;

impl inner::Trait<u8> for () {}

playground

@jieyouxu
Copy link
Contributor

Thanks for the ping, investigating

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jul 18, 2023
…-suggestion, r=oli-obk

Fix removal span calculation of `unused_qualifications` suggestion

Given a path such as `std::ops::Index<str>`, calculate the unnecessary qualification removal span by computing the beginning of the entire span until the ident span of the last path segment, which handles generic arguments and lifetime arguments in the last path segment. Previous logic only kept the ident span of the last path segment which is incorrect.

Closes rust-lang#113808.
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Jul 18, 2023
…-suggestion, r=oli-obk

Fix removal span calculation of `unused_qualifications` suggestion

Given a path such as `std::ops::Index<str>`, calculate the unnecessary qualification removal span by computing the beginning of the entire span until the ident span of the last path segment, which handles generic arguments and lifetime arguments in the last path segment. Previous logic only kept the ident span of the last path segment which is incorrect.

Closes rust-lang#113808.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jul 18, 2023
…-suggestion, r=oli-obk

Fix removal span calculation of `unused_qualifications` suggestion

Given a path such as `std::ops::Index<str>`, calculate the unnecessary qualification removal span by computing the beginning of the entire span until the ident span of the last path segment, which handles generic arguments and lifetime arguments in the last path segment. Previous logic only kept the ident span of the last path segment which is incorrect.

Closes rust-lang#113808.
@bors bors closed this as completed in 931d9f0 Jul 18, 2023
@Nilstrieb Nilstrieb removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. D-papercut Diagnostics: An error or lint that needs small tweaks.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants