Merge pull request #354 from Pyriphlegethon/master

Add "unnecessary mut passed" lint
This commit is contained in:
Manish Goregaokar 2015-10-07 04:18:02 +05:30
commit 3e475e9588
5 changed files with 126 additions and 2 deletions

View file

@ -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];

View 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);
}