Merge pull request #354 from Pyriphlegethon/master
Add "unnecessary mut passed" lint
This commit is contained in:
commit
3e475e9588
5 changed files with 126 additions and 2 deletions
|
|
@ -16,7 +16,7 @@ impl Unrelated {
|
|||
|
||||
#[deny(needless_range_loop, explicit_iter_loop, iter_next_loop, reverse_range_loop, explicit_counter_loop)]
|
||||
#[deny(unused_collect)]
|
||||
#[allow(linkedlist,shadow_unrelated)]
|
||||
#[allow(linkedlist,shadow_unrelated,unnecessary_mut_passed)]
|
||||
fn main() {
|
||||
let mut vec = vec![1, 2, 3, 4];
|
||||
let vec2 = vec![1, 2, 3, 4];
|
||||
|
|
|
|||
46
tests/compile-fail/mut_reference.rs
Normal file
46
tests/compile-fail/mut_reference.rs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
#![feature(plugin)]
|
||||
#![plugin(clippy)]
|
||||
|
||||
#![allow(unused_variables)]
|
||||
|
||||
fn takes_an_immutable_reference(a: &i32) {
|
||||
}
|
||||
|
||||
|
||||
fn takes_a_mutable_reference(a: &mut i32) {
|
||||
}
|
||||
|
||||
struct MyStruct;
|
||||
|
||||
impl MyStruct {
|
||||
fn takes_an_immutable_reference(&self, a: &i32) {
|
||||
}
|
||||
|
||||
fn takes_a_mutable_reference(&self, a: &mut i32) {
|
||||
}
|
||||
}
|
||||
|
||||
#[deny(unnecessary_mut_passed)]
|
||||
fn main() {
|
||||
// Functions
|
||||
takes_an_immutable_reference(&mut 42); //~ERROR The function/method "takes_an_immutable_reference" doesn't need a mutable reference
|
||||
|
||||
// Methods
|
||||
let my_struct = MyStruct;
|
||||
my_struct.takes_an_immutable_reference(&mut 42); //~ERROR The function/method "takes_an_immutable_reference" doesn't need a mutable reference
|
||||
|
||||
|
||||
// No error
|
||||
|
||||
// Functions
|
||||
takes_an_immutable_reference(&42);
|
||||
takes_a_mutable_reference(&mut 42);
|
||||
let a = &mut 42;
|
||||
takes_an_immutable_reference(a);
|
||||
|
||||
// Methods
|
||||
my_struct.takes_an_immutable_reference(&42);
|
||||
my_struct.takes_a_mutable_reference(&mut 42);
|
||||
my_struct.takes_an_immutable_reference(a);
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue