Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FP use_self requires generic_const_exprs #10756

Open
matthiaskrgr opened this issue May 6, 2023 · 0 comments
Open

FP use_self requires generic_const_exprs #10756

matthiaskrgr opened this issue May 6, 2023 · 0 comments
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@matthiaskrgr
Copy link
Member

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

@matthiaskrgr matthiaskrgr added C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied I-false-positive Issue: The lint was triggered on code it shouldn't have labels May 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

No branches or pull requests

1 participant