mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 21:23:56 +00:00
Rustup to 1.9.0-nightly (c9629d61c 2016-03-10)
This commit is contained in:
parent
233000da3d
commit
c6316df19f
5 changed files with 40 additions and 30 deletions
|
@ -124,13 +124,14 @@ impl<'a, 'b, 'tcx> Visitor<'a> for CCHelper<'b, 'tcx> {
|
|||
ExprCall(ref callee, _) => {
|
||||
walk_expr(self, e);
|
||||
let ty = self.tcx.node_id_to_type(callee.id);
|
||||
if let ty::TyBareFn(_, ty) = ty.sty {
|
||||
if ty.sig.skip_binder().output.diverges() {
|
||||
match ty.sty {
|
||||
ty::TyFnDef(_, _, ty) | ty::TyFnPtr(ty) if ty.sig.skip_binder().output.diverges() => {
|
||||
self.divergence += 1;
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
ExprClosure(..) => {}
|
||||
ExprClosure(..) => (),
|
||||
ExprBinary(op, _, _) => {
|
||||
walk_expr(self, e);
|
||||
match op.node {
|
||||
|
|
|
@ -155,7 +155,7 @@ fn check_copy_clone<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, item: &Item, trait_ref
|
|||
TypeVariants::TyArray(_, size) if size > 32 => {
|
||||
return;
|
||||
}
|
||||
TypeVariants::TyBareFn(..) => {
|
||||
TypeVariants::TyFnPtr(..) => {
|
||||
return;
|
||||
}
|
||||
TypeVariants::TyTuple(ref tys) if tys.len() > 12 => {
|
||||
|
|
|
@ -58,11 +58,14 @@ fn check_closure(cx: &LateContext, expr: &Expr) {
|
|||
return;
|
||||
}
|
||||
let fn_ty = cx.tcx.expr_ty(caller);
|
||||
if let ty::TyBareFn(_, fn_ty) = fn_ty.sty {
|
||||
match fn_ty.sty {
|
||||
// Is it an unsafe function? They don't implement the closure traits
|
||||
if fn_ty.unsafety == Unsafety::Unsafe {
|
||||
return;
|
||||
ty::TyFnDef(_, _, fn_ty) | ty::TyFnPtr(fn_ty) => {
|
||||
if fn_ty.unsafety == Unsafety::Unsafe {
|
||||
return;
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
for (ref a1, ref a2) in decl.inputs.iter().zip(args) {
|
||||
if let PatKind::Ident(_, ident, _) = a1.pat.node {
|
||||
|
|
|
@ -53,21 +53,24 @@ impl LateLintPass for UnnecessaryMutPassed {
|
|||
}
|
||||
|
||||
fn check_arguments(cx: &LateContext, arguments: &[P<Expr>], type_definition: &TyS, name: &str) {
|
||||
if let TypeVariants::TyBareFn(_, ref fn_type) = type_definition.sty {
|
||||
let parameters = &fn_type.sig.skip_binder().inputs;
|
||||
for (argument, parameter) in arguments.iter().zip(parameters.iter()) {
|
||||
match parameter.sty {
|
||||
TypeVariants::TyRef(_, TypeAndMut {mutbl: MutImmutable, ..}) |
|
||||
TypeVariants::TyRawPtr(TypeAndMut {mutbl: MutImmutable, ..}) => {
|
||||
if let ExprAddrOf(MutMutable, _) = argument.node {
|
||||
span_lint(cx,
|
||||
UNNECESSARY_MUT_PASSED,
|
||||
argument.span,
|
||||
&format!("The function/method \"{}\" doesn't need a mutable reference", name));
|
||||
match type_definition.sty {
|
||||
TypeVariants::TyFnDef(_, _, ref fn_type) | TypeVariants::TyFnPtr(ref fn_type) => {
|
||||
let parameters = &fn_type.sig.skip_binder().inputs;
|
||||
for (argument, parameter) in arguments.iter().zip(parameters.iter()) {
|
||||
match parameter.sty {
|
||||
TypeVariants::TyRef(_, TypeAndMut {mutbl: MutImmutable, ..}) |
|
||||
TypeVariants::TyRawPtr(TypeAndMut {mutbl: MutImmutable, ..}) => {
|
||||
if let ExprAddrOf(MutMutable, _) = argument.node {
|
||||
span_lint(cx,
|
||||
UNNECESSARY_MUT_PASSED,
|
||||
argument.span,
|
||||
&format!("The function/method \"{}\" doesn't need a mutable reference", name));
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,12 +3,8 @@
|
|||
|
||||
#![allow(unused_variables)]
|
||||
|
||||
fn takes_an_immutable_reference(a: &i32) {
|
||||
}
|
||||
|
||||
|
||||
fn takes_a_mutable_reference(a: &mut i32) {
|
||||
}
|
||||
fn takes_an_immutable_reference(a: &i32) {}
|
||||
fn takes_a_mutable_reference(a: &mut i32) {}
|
||||
|
||||
struct MyStruct;
|
||||
|
||||
|
@ -24,23 +20,30 @@ impl MyStruct {
|
|||
fn main() {
|
||||
// Functions
|
||||
takes_an_immutable_reference(&mut 42); //~ERROR The function/method "takes_an_immutable_reference" doesn't need a mutable reference
|
||||
|
||||
let foo: fn(&i32) = takes_an_immutable_reference;
|
||||
foo(&mut 42); //~ERROR The function/method "foo" 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);
|
||||
let foo: fn(&i32) = takes_an_immutable_reference;
|
||||
foo(&42);
|
||||
|
||||
takes_a_mutable_reference(&mut 42);
|
||||
let foo: fn(&mut i32) = takes_a_mutable_reference;
|
||||
foo(&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…
Reference in a new issue