-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Passing mutable references #353
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
Comments
I like this idea. Though I'm surprised the compiler doesn't complain here.
It's stuff like this which makes me love Rust. 😄
You're welcome! Glad you enjoyed it! |
We should tread carefully here. The The former can be detected, the latter probably not, short of a mind-reading extension to clippy. |
This comment has been minimized.
This comment has been minimized.
This may be problematic though, as @llogiq says. At least trait impls should be excluded, and for |
This comment has been minimized.
This comment has been minimized.
Yeah, didn't know that a trait impl couldn't strengthen the constraints for its arguments. That really seems like it should be allowed. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
// increase this counter if you ran into this problem again and still didn't fix it: 3 |
Not just that; when there is unsafe code around, the pub fn as_mut_slice<T>(self_: &Vec<T>) -> &mut [T] {
unsafe {
from_raw_parts_mut(self_.as_ptr() as *mut T, self_.len())
}
} |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I came here from TWIR call for participation. Isn't it better to put the second part of the issue directly into |
Triaging. This is implemented in the |
Passing a mutable reference to a function that takes an immutable reference:
If I'd find this code in somebody's code base I'd think that the function will mutate the argument and I'd have to make a copy if I want to preserve the original value. This lint should only be applied if the argument is actually passed as
&mut
, the following code should be ok:Taking a mutable reference and not mutating it:
The rust compiler will complain whenever it sees a mutable binding that is not mutated. Strangely enough, it won't complain about mutable arguments that are never mutated. I guess this might be a hard problem?
Thanks for rust-clippy! It's an awesome tool!
The text was updated successfully, but these errors were encountered: