Skip to content

use_self where type parameters can't be used #3463

@detrumi

Description

@detrumi
clippy 0.0.212 (754b4c0 2018-11-23)

The following function triggers the use_self lint:

enum MyEnum { A, B }

impl MyEnum {
    pub fn iterator<'a>(self) -> impl Iterator<Item=&'a Self> {
        static ITEMS: [MyEnum; 2] = [MyEnum::A, MyEnum::B];
        ITEMS.iter()
    }
}

Replacing [MyEnum; 2] with [Self; 2], as suggested, leads to this error:

error[E0401]: can't use type parameters from outer function

Playground link

Minimal example:

enum MyEnum { A }

impl MyEnum {
    fn foo() {
        static FOO: MyEnum = MyEnum::A;
    }
}

Clippy suggests changing FOO: MyEnum to FOO: Self, which doesn't compile

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 suggestions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions