Skip to content

FP use_self requires generic_const_exprs #10756

@matthiaskrgr

Description

@matthiaskrgr

Summary

.

Lint Name

use_self

Reproducer

I tried this code:

struct Foo; impl Foo { fn foo<const N: usize>(&self) -> usize { let f = self; f.bar::<{ let f = Foo; f.bar::<7>() }>() + N } const fn bar<const M: usize>(&self) -> usize { M } } fn main() { let f = Foo; assert_eq!(f.foo::<13>(), 20) }

I saw this happen:

warning: unnecessary structure name repetition --> const-arg-in-const-arg.rs:7:21 | 7 | let f = Foo; | ^^^ help: use the applicable keyword: `Self` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#use_self = note: requested on the command line with `-W clippy::use-self` 

I expected to see this happen:
Suggestion does not compile wif const_generic_exprs feature is not enabled

error: generic parameters may not be used in const operations --> const-arg-in-const-arg.rs:7:21 | 7 | let f = Self; | ^^^^ cannot perform const operation using `Self` | = note: type parameters may not be used in const expressions = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error: aborting due to previous error 

Version

rustc 1.71.0-nightly (6d140d59b 2023-05-06) binary: rustc commit-hash: 6d140d59bb957903b02ddb993450509d8d92b448 commit-date: 2023-05-06 host: x86_64-unknown-linux-gnu release: 1.71.0-nightly LLVM version: 16.0.2 

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions