Fix mut_mut false positive, make Allow (fixes #309)

This commit is contained in:
Manish Goregaokar 2015-09-08 02:28:15 +05:30
parent 54932dee1c
commit 0e658afc1b
4 changed files with 10 additions and 4 deletions

View file

@ -33,7 +33,7 @@ name
[match_ref_pats](https://github.com/Manishearth/rust-clippy/wiki#match_ref_pats) | warn | a match has all arms prefixed with `&`; the match expression can be dereferenced instead [match_ref_pats](https://github.com/Manishearth/rust-clippy/wiki#match_ref_pats) | warn | a match has all arms prefixed with `&`; the match expression can be dereferenced instead
[min_max](https://github.com/Manishearth/rust-clippy/wiki#min_max) | warn | `min(_, max(_, _))` (or vice versa) with bounds clamping the result to a constant [min_max](https://github.com/Manishearth/rust-clippy/wiki#min_max) | warn | `min(_, max(_, _))` (or vice versa) with bounds clamping the result to a constant
[modulo_one](https://github.com/Manishearth/rust-clippy/wiki#modulo_one) | warn | taking a number modulo 1, which always returns 0 [modulo_one](https://github.com/Manishearth/rust-clippy/wiki#modulo_one) | warn | taking a number modulo 1, which always returns 0
[mut_mut](https://github.com/Manishearth/rust-clippy/wiki#mut_mut) | warn | usage of double-mut refs, e.g. `&mut &mut ...` (either copy'n'paste error, or shows a fundamental misunderstanding of references) [mut_mut](https://github.com/Manishearth/rust-clippy/wiki#mut_mut) | allow | usage of double-mut refs, e.g. `&mut &mut ...` (either copy'n'paste error, or shows a fundamental misunderstanding of references)
[needless_bool](https://github.com/Manishearth/rust-clippy/wiki#needless_bool) | warn | if-statements with plain booleans in the then- and else-clause, e.g. `if p { true } else { false }` [needless_bool](https://github.com/Manishearth/rust-clippy/wiki#needless_bool) | warn | if-statements with plain booleans in the then- and else-clause, e.g. `if p { true } else { false }`
[needless_lifetimes](https://github.com/Manishearth/rust-clippy/wiki#needless_lifetimes) | warn | using explicit lifetimes for references in function arguments when elision rules would allow omitting them [needless_lifetimes](https://github.com/Manishearth/rust-clippy/wiki#needless_lifetimes) | warn | using explicit lifetimes for references in function arguments when elision rules would allow omitting them
[needless_range_loop](https://github.com/Manishearth/rust-clippy/wiki#needless_range_loop) | warn | for-looping over a range of indices where an iterator over items would do [needless_range_loop](https://github.com/Manishearth/rust-clippy/wiki#needless_range_loop) | warn | for-looping over a range of indices where an iterator over items would do

View file

@ -92,6 +92,7 @@ pub fn plugin_registrar(reg: &mut Registry) {
methods::OPTION_UNWRAP_USED, methods::OPTION_UNWRAP_USED,
methods::RESULT_UNWRAP_USED, methods::RESULT_UNWRAP_USED,
methods::WRONG_PUB_SELF_CONVENTION, methods::WRONG_PUB_SELF_CONVENTION,
mut_mut::MUT_MUT,
ptr_arg::PTR_ARG, ptr_arg::PTR_ARG,
shadow::SHADOW_REUSE, shadow::SHADOW_REUSE,
shadow::SHADOW_SAME, shadow::SHADOW_SAME,
@ -135,7 +136,6 @@ pub fn plugin_registrar(reg: &mut Registry) {
misc::MODULO_ONE, misc::MODULO_ONE,
misc::REDUNDANT_PATTERN, misc::REDUNDANT_PATTERN,
misc::TOPLEVEL_REF_ARG, misc::TOPLEVEL_REF_ARG,
mut_mut::MUT_MUT,
needless_bool::NEEDLESS_BOOL, needless_bool::NEEDLESS_BOOL,
precedence::PRECEDENCE, precedence::PRECEDENCE,
ranges::RANGE_STEP_BY_ZERO, ranges::RANGE_STEP_BY_ZERO,

View file

@ -4,7 +4,7 @@ use rustc::middle::ty::{TypeAndMut, TyRef};
use utils::{in_external_macro, span_lint}; use utils::{in_external_macro, span_lint};
declare_lint!(pub MUT_MUT, Warn, declare_lint!(pub MUT_MUT, Allow,
"usage of double-mut refs, e.g. `&mut &mut ...` (either copy'n'paste error, \ "usage of double-mut refs, e.g. `&mut &mut ...` (either copy'n'paste error, \
or shows a fundamental misunderstanding of references)"); or shows a fundamental misunderstanding of references)");
@ -53,7 +53,6 @@ fn check_expr_mut(cx: &Context, expr: &Expr) {
fn unwrap_mut(ty : &Ty) -> Option<&Ty> { fn unwrap_mut(ty : &Ty) -> Option<&Ty> {
match ty.node { match ty.node {
TyPtr(MutTy{ ty: ref pty, mutbl: MutMutable }) => Option::Some(pty),
TyRptr(_, MutTy{ ty: ref pty, mutbl: MutMutable }) => Option::Some(pty), TyRptr(_, MutTy{ ty: ref pty, mutbl: MutMutable }) => Option::Some(pty),
_ => Option::None _ => Option::None
} }

View file

@ -1,6 +1,8 @@
#![feature(plugin)] #![feature(plugin)]
#![plugin(clippy)] #![plugin(clippy)]
#![allow(unused)]
//#![plugin(regex_macros)] //#![plugin(regex_macros)]
//extern crate regex; //extern crate regex;
@ -9,6 +11,11 @@ fn fun(x : &mut &mut u32) -> bool { //~ERROR generally you want to avoid `&mut &
**x > 0 **x > 0
} }
#[deny(mut_mut)]
fn less_fun(x : *mut *mut u32) {
let y = x;
}
macro_rules! mut_ptr { macro_rules! mut_ptr {
($p:expr) => { &mut $p } ($p:expr) => { &mut $p }
} }