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

#[forbid(unused_qualifications)] is incompatible with all builtin derives #71898

Closed
jonas-schievink opened this issue May 4, 2020 · 9 comments · Fixed by #99485
Closed

#[forbid(unused_qualifications)] is incompatible with all builtin derives #71898

jonas-schievink opened this issue May 4, 2020 · 9 comments · Fixed by #99485
Assignees
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jonas-schievink
Copy link
Contributor

jonas-schievink commented May 4, 2020

#![forbid(unused_qualifications)]

#[derive(Clone)]
pub struct S;
error[E0453]: allow(unused_qualifications) overruled by outer forbid(unused_qualifications)
 --> src/main.rs:3:10
  |
1 | #![forbid(unused_qualifications)]
  |           --------------------- `forbid` level set here
2 | 
3 | #[derive(Clone)]
  |          ^^^^^ overruled by previous forbid

All built-in custom derives put #[allow(unused_qualifications)] on the generated impl, but the forbid level can not be overridden by that.

Custom derives are not able to trigger the deprecated lint, despite not attaching #[allow(deprecated)], so maybe the same mechanism should be used for unused_qualifications?

@jonas-schievink jonas-schievink added A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels May 4, 2020
@jonas-schievink
Copy link
Contributor Author

Ah, the deprecation lint has this check:

if span.in_derive_expansion() {
return;
}

@varkor varkor added the E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. label May 5, 2020
@samrat
Copy link
Contributor

samrat commented May 6, 2020

@rustbot claim

@rustbot rustbot self-assigned this May 6, 2020
@samrat
Copy link
Contributor

samrat commented May 7, 2020

If my understanding is correct, Derives(custom and builtin) will always be defined in a crate that will be external to the one using them. And it seems we turn off suggestions for lints originating from external crates:

// If this code originates in a foreign macro, aka something that this crate

My original approach to this issue was to avoid adding the #[allow(unused_qualifications)] to the impl and add a in_derive_expansion check in

if path.len() > 1
but I couldn't figure out a case where the in_derive_expansion check makes a difference in the suggestion displayed(I did verify that the lint is captured in the lint_buffer in the case the unnecessary qualification is in an external crate, just not displayed).

Any thoughts on this approach, and suggestions on how I can go about testing this change?

@Alexendoo
Copy link
Member

Triage: Hi, are you still working on this issue @samrat?

@samrat
Copy link
Contributor

samrat commented Aug 19, 2020

Hi @Alexendoo, I don't think I'll be able to devote sufficient time to work on this issue anytime soon.

@Alexendoo
Copy link
Member

No problem

@rustbot release-assignment

@rustbot rustbot removed their assignment Aug 20, 2020
@bugadani
Copy link
Contributor

@rustbot claim

@dtolnay
Copy link
Member

dtolnay commented Jan 27, 2022

@rustbot release-assignment

@mdholloway
Copy link
Contributor

I think @samrat had the right solution to this one. I'd be happy to pick it up and drag it over the finish line.

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
9 participants