rust-lang / rust-lang/rust-clippy

redundant_field_names: spans messed up inside macro

Open
#6,516 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug E-medium L-suggestion
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

In Rustc we have this code

macro_rules! late_lint_mod_passes {
    ($macro:path, $args:tt) => {
        $macro!(
            $args,
            [
                HardwiredLints: HardwiredLints,
                ImproperCTypesDeclarations: ImproperCTypesDeclarations,
                ImproperCTypesDefinitions: ImproperCTypesDefinitions,
                VariantSizeDifferences: VariantSizeDifferences,
                BoxPointers: BoxPointers,
                PathStatements: PathStatements,
                // Depends on referenced function signatures in expressions
                UnusedResults: UnusedResults,
                NonUpperCaseGlobals: NonUpperCaseGlobals,
                NonShorthandFieldPatterns: NonShorthandFieldPatterns,
                UnusedAllocation: UnusedAllocation,
                // Depends on types used in type definitions
                MissingCopyImplementations: MissingCopyImplementations,
                // Depends on referenced function signatures in expressions
                MutableTransmutes: MutableTransmutes,
                TypeAliasBounds: TypeAliasBounds,
                TrivialConstraints: TrivialConstraints,
                TypeLimits: TypeLimits::new(),
                NonSnakeCase: NonSnakeCase,
                InvalidNoMangleItems: InvalidNoMangleItems,
                // Depends on access levels
                UnreachablePub: UnreachablePub,
                ExplicitOutlivesRequirements: ExplicitOutlivesRequirements,
                InvalidValue: InvalidValue,
            ]
        );
    };
}

which triggers clippy::redundant_field_names, but a the spans seems kinda messed up

..,
warning: redundant field names in struct initialization
   --> compiler/rustc_lint/src/lib.rs:198:37
    |
131 | |                 RedundantSemicolons: RedundantSemicolons,
    | |_____________________________^ help: replace it with: `TrivialConstraints`
...
198 |                   TrivialConstraints: TrivialConstraints,
    |  _____________________________________^
...
220 |   late_lint_mod_passes!(declare_combined_late_pass, [BuiltinCombinedModuleLateLintPass]);
    |   --------------------------------------------------------------------------------------- in this macro invocation
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names
    = note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

warning: redundant field names in struct initialization
   --> compiler/rustc_lint/src/lib.rs:200:31
    |
131 | |                 RedundantSemicolons: RedundantSemicolons,
    | |_____________________________^ help: replace it with: `NonSnakeCase`
...
200 |                   NonSnakeCase: NonSnakeCase,
    |  _______________________________^
...
220 |   late_lint_mod_passes!(declare_combined_late_pass, [BuiltinCombinedModuleLateLintPass]);
    |   --------------------------------------------------------------------------------------- in this macro invocation
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names
    = note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

warning: redundant field names in struct initialization
   --> compiler/rustc_lint/src/lib.rs:201:39
    |
131 | |                 RedundantSemicolons: RedundantSemicolons,
    | |_____________________________^ help: replace it with: `InvalidNoMangleItems`
...
201 |                   InvalidNoMangleItems: InvalidNoMangleItems,
    |  _______________________________________^
...
220 |   late_lint_mod_passes!(declare_combined_late_pass, [BuiltinCombinedModuleLateLintPass]);
    |   --------------------------------------------------------------------------------------- in this macro invocation
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names
    = note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

warning: redundant field names in struct initialization
   --> compiler/rustc_lint/src/lib.rs:203:33
    |
131 | |                 RedundantSemicolons: RedundantSemicolons,
    | |_____________________________^ help: replace it with: `UnreachablePub`
...
203 |                   UnreachablePub: UnreachablePub,
    |  _________________________________^
...
220 |   late_lint_mod_passes!(declare_combined_late_pass, [BuiltinCombinedModuleLateLintPass]);
    |   --------------------------------------------------------------------------------------- in this macro invocation
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names
    = note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

warning: redundant field names in struct initialization
   --> compiler/rustc_lint/src/lib.rs:204:47
    |
131 | |                 RedundantSemicolons: RedundantSemicolons,
    | |_____________________________^ help: replace it with: `ExplicitOutlivesRequirements`
...
204 |                   ExplicitOutlivesRequirements: ExplicitOutlivesRequirements,
    |  _______________________________________________^
...
220 |   late_lint_mod_passes!(declare_combined_late_pass, [BuiltinCombinedModuleLateLintPass]);
    |   --------------------------------------------------------------------------------------- in this macro invocation
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names
    = note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

warning: redundant field names in struct initialization
   --> compiler/rustc_lint/src/lib.rs:205:31
    |
131 | |                 RedundantSemicolons: RedundantSemicolons,
    | |_____________________________^ help: replace it with: `InvalidValue`
...
205 |                   InvalidValue: InvalidValue,
    |  _______________________________^
...
220 |   late_lint_mod_passes!(declare_combined_late_pass, [BuiltinCombinedModuleLateLintPass]);
    |   --------------------------------------------------------------------------------------- in this macro invocation
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names
    = note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
    ````
    
    
![spans](https://user-images.githubusercontent.com/476013/103308423-b6b34200-4a12-11eb-87d6-84f780cc3869.png)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the reported warnings from the macro example and start in compiler/rustc_lint/src/lib.rs, focusing on redundant_field_names handling during macro expansion. Trace how the lint computes spans and suggestions for the listed fields; done means diagnostics point to the corresponding field names and offer the correct replacement instead of unrelated spans.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.