Skip to content

false negative unused_mut #57248

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

Closed
matthiaskrgr opened this issue Jan 1, 2019 · 4 comments
Closed

false negative unused_mut #57248

matthiaskrgr opened this issue Jan 1, 2019 · 4 comments
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut.

Comments

@matthiaskrgr
Copy link
Member

struct SomeStruct {
	path: std::path::PathBuf,
}

impl SomeStruct {
	fn path_exists(&mut self) -> bool { // false negative unused_mut
		// path.exists() does not need mutable reference:
		// pub fn exists(&self) -> bool { ... } 
		self.path.exists()
	}
}

fn main() {
    let mut s = SomeStruct { path: std::path::PathBuf::from("/tmp/a"), };
    println!("{}", s.path_exists());
}
@estebank estebank added the A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. label Jan 2, 2019
@zackmdavis
Copy link
Member

I'm pretty sure the unused-mut lint is specifically about the mut mutability modifier keyword (as in let mut a = ...). Changing &mut to & where possible sounds like a candidate Clippy lint?

@scottmcm
Copy link
Member

scottmcm commented Jan 3, 2019

I think this is by design, since that's not a let mut, and there are potential reasons for an API to take &uniq even if it only calls shared stuff (or nothing).

@zackmdavis
Copy link
Member

jinx

@sanxiyn
Copy link
Member

sanxiyn commented Mar 13, 2019

This is rust-lang/rust-clippy#1230. I agree it is out of scope for built-in unused_mut lint. Closing.

@sanxiyn sanxiyn closed this as completed Mar 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut.
Projects
None yet
Development

No branches or pull requests

5 participants