rust-lang / rust-lang/rust-clippy
FP use_self requires generic_const_exprs
Open
Nobody has claimed this yet.
C-bug
I-false-positive
I-suggestion-causes-error
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the use_self lint implementation and the const-arg-in-const-arg.rs reproducer described in the report. Check how suggestions involving Self interact with generic_const_exprs, then add or update a regression test showing that the lint does not emit an uncompilable suggestion when the feature is unavailable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100