Skip to content

Commit

Permalink
Rustup to 1.9.0-nightly (c9629d6 2016-03-10)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcarton committed Mar 11, 2016
1 parent 233000d commit c6316df
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 30 deletions.
7 changes: 4 additions & 3 deletions src/cyclomatic_complexity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
9 changes: 6 additions & 3 deletions src/eta_reduction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
27 changes: 15 additions & 12 deletions src/mut_reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
_ => {}
}
_ => {}
}
}
_ => (),
}
}
25 changes: 14 additions & 11 deletions tests/compile-fail/mut_reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);

}

0 comments on commit c6316df

Please sign in to comment.