Skip to content

unused_qualifications lints on macro-generated paths which happen to have spans from the input #122519

Closed
@kpreid

Description

@kpreid

Code

#![warn(unused_qualifications)]

#[derive(Copy, Clone, bytemuck::Pod, bytemuck::Zeroable)]
#[repr(C)]
pub struct Foo {}

Current output

warning: unnecessary qualification
 --> src/lib.rs:5:12
  |
5 | pub struct Foo {}
  |            ^^^
  |
note: the lint level is defined here
 --> src/lib.rs:1:9
  |
1 | #![warn(unused_qualifications)]
  |         ^^^^^^^^^^^^^^^^^^^^^
help: remove the unnecessary path segments
  |
5 | pub struct Foo {}
  |

Desired output

No warning.

Rationale and extra context

Rationale:

  1. The warning is non-actionable. The suggestion is useless, showing literally zero changed characters.
  2. Proc-macros idiomatically use absolute paths even when not necessary, to maximize their compatibility. In principle, macros could internally #[allow(unused_qualifications)] to solve this problem, but that would be additional busywork for macro authors.

Therefore, I propose that unused_qualifications should not lint on a path unless the tokens that it proposes deleting all have spans from the original source text (not any other spans that a macro might produce).

There is currently a PR out for not linting on absolute paths, which would also fix this problem, but I don't understand the rationale for doing that outside of macros, so I'm filing this issue for consideration of the specific case of macros.

Other cases

This occurs only on nightly, not on stable 1.76.0 or beta.

For some reason, among all the proc macros in use in the project I'm testing on nightly, only bytemuck is affected.

Rust Version

rustc 1.78.0-nightly (9c3ad802d 2024-03-07)
binary: rustc
commit-hash: 9c3ad802d9b9633d60d3a74668eb1be819212d34
commit-date: 2024-03-07
host: x86_64-apple-darwin
release: 1.78.0-nightly
LLVM version: 18.1.0

Anything else?

@rustbot label +regression-from-stable-to-nightly

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.L-unused_qualificationsLint: unused_qualificationsP-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions