-
Notifications
You must be signed in to change notification settings - Fork 1.7k
assigning_clones: Wrong suggestion with deref #12437
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
I-suggestion-causes-error
Issue: The suggestions provided by this Lint cause an ICE/error when applied
Comments
I'm seeing a similar issue but where the variable is being assigned to itself. Not sure if this counts as a separate issue. Example code (taken from one of my projects where it locates the root of the repo) use std::{env, error::Error, fmt::Display};
#[derive(Debug)]
struct NoJustfile;
impl Display for NoJustfile {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{self:?}")
}
}
impl Error for NoJustfile {}
fn main() -> Result<(), Box<dyn Error>> {
let mut path_to_search = env::current_dir()?;
while !path_to_search.join("justfile").exists() {
path_to_search = path_to_search
.parent()
.ok_or_else(|| Box::new(NoJustfile))?
.to_owned();
}
println!("{}", path_to_search.display());
Ok(())
} you get the suggestion:
but if you do that you get:
Version:
|
Thanks for the report, I'll take a look. |
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-suggestion-causes-error
Issue: The suggestions provided by this Lint cause an ICE/error when applied
Summary
assigning_clones suggests code that fails to compile when the original code has deref.
Mentioning @Kobzol, who implemented this lint in #12077.
Reproducer
I tried this code:
I expected to see this happen: lint suggests code that can compile
Instead, this happened:
Suggested code
prev.clone_from(cx.waker())
fails to compile because deref (*prev
) is dropped:The correct code is
(*prev).clone_from(cx.waker());
(preserve deref).Version
Additional Labels
@rustbot label +I-suggestion-causes-error
The text was updated successfully, but these errors were encountered: