-
Notifications
You must be signed in to change notification settings - Fork 1.7k
needless_borrow
suggestion doesn't compile
#8367
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
Labels
C-bug
Category: Clippy is not doing the correct thing
Comments
struct ThingA;
struct ThingB;
impl From<&ThingA> for ThingB {
fn from(_: &ThingA) -> ThingB {
ThingB
}
}
impl From<ThingA> for ThingB {
fn from(a: ThingA) -> ThingB {
(&a).into()
}
}
fn main() {
let _: ThingB = ThingA.into();
}
|
Here is another false positive: use rand::distributions::Alphanumeric;
use rand::Rng;
#[derive(Debug)]
pub struct GameEntity {
pub name: String,
pub hp: i32,
pub godmode: bool,
}
impl GameEntity {
pub fn rand() -> Self {
let mut rng = rand::thread_rng();
let name_len = rng.gen_range(3..24);
Self {
name: (&mut rng)
.sample_iter(&Alphanumeric)
.take(name_len)
.map(char::from)
.collect(),
hp: rng.gen_range(0..100),
godmode: rng.gen(),
}
}
}
|
This will be fixed by #8355 whenever that gets merged. |
unageek
added a commit
to unageek/graphest
that referenced
this issue
Jan 30, 2022
unageek
added a commit
to unageek/graphest
that referenced
this issue
Jan 30, 2022
unageek
added a commit
to unageek/graphest
that referenced
this issue
Jan 30, 2022
bors
added a commit
that referenced
this issue
Jun 28, 2022
Add lint `explicit_auto_deref` take 2 fixes: #234 fixes: #8367 fixes: #8380 Still things to do: * ~~This currently only lints `&*<expr>` when it doesn't trigger `needless_borrow`.~~ * ~~This requires a borrow after a deref to trigger. So `*<expr>` changing `&&T` to `&T` won't be caught.~~ * The `deref` and `deref_mut` trait methods aren't linted. * Neither ~~field accesses~~, nor method receivers are linted. * ~~This probably shouldn't lint reborrowing.~~ * Full slicing to deref should probably be handled here as well. e.g. `&vec[..]` when just `&vec` would do changelog: new lint `explicit_auto_deref`
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Summary
On the most recent nightly, the
needless_borrow
lint produces a suggestion that doesn't compile.cargo +nightly-2022-01-29 clippy
triggers this bug, butcargo +nightly-2022-01-28 clippy
does not.cc: @Jarcho (maybe?)
Reproducer
I tried this code:
I expected to see this happen:
Nothing.
Instead, this happened:
If you make the suggested change, you get:
Version
Additional Labels
No response
The text was updated successfully, but these errors were encountered: