Skip to content

use_self lint suggests changing code to use outer type parameters breaking build #3859

Closed
@gnzlbg

Description

@gnzlbg

Here (playground):

#![crate_type = "rlib"]
#![deny(clippy::pedantic)]

pub struct Foo;
pub struct Bar([usize; 3]);

impl Foo {
    pub const BAR: usize = 3;
    
    pub fn foo() {
        const _X: usize = Foo::BAR;
        // const _Y: usize = Self::BAR;
    }
}

this example compiles, but clippy errors with

error: unnecessary structure name repetition
  --> src/lib.rs:11:27
   |
11 |         const _X: usize = Foo::BAR;
   |                           ^^^ help: use the applicable keyword: `Self`
   |

Applying the proposed fix results in a compilation error:

error[E0401]: can't use type parameters from outer function
  --> src/lib.rs:12:27
   |
7  | impl Foo {
   | ---- `Self` type implicitly declared here, by this `impl`
...
12 |         const _X: usize = Self::BAR;
   |                           ^^^^^^^^^
   |                           |
   |                           use of type variable from outer function
   |                           use a type here instead

error: aborting due to previous error

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedL-suggestionLint: Improving, adding or fixing lint suggestionsgood first issueThese issues are a good way to get started with Clippy

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions