Skip to content

Commit c6316df

Browse files
committed
Rustup to 1.9.0-nightly (c9629d6 2016-03-10)
1 parent 233000d commit c6316df

File tree

5 files changed

+40
-30
lines changed

5 files changed

+40
-30
lines changed

src/cyclomatic_complexity.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,14 @@ impl<'a, 'b, 'tcx> Visitor<'a> for CCHelper<'b, 'tcx> {
124124
ExprCall(ref callee, _) => {
125125
walk_expr(self, e);
126126
let ty = self.tcx.node_id_to_type(callee.id);
127-
if let ty::TyBareFn(_, ty) = ty.sty {
128-
if ty.sig.skip_binder().output.diverges() {
127+
match ty.sty {
128+
ty::TyFnDef(_, _, ty) | ty::TyFnPtr(ty) if ty.sig.skip_binder().output.diverges() => {
129129
self.divergence += 1;
130130
}
131+
_ => (),
131132
}
132133
}
133-
ExprClosure(..) => {}
134+
ExprClosure(..) => (),
134135
ExprBinary(op, _, _) => {
135136
walk_expr(self, e);
136137
match op.node {

src/derive.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ fn check_copy_clone<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, item: &Item, trait_ref
155155
TypeVariants::TyArray(_, size) if size > 32 => {
156156
return;
157157
}
158-
TypeVariants::TyBareFn(..) => {
158+
TypeVariants::TyFnPtr(..) => {
159159
return;
160160
}
161161
TypeVariants::TyTuple(ref tys) if tys.len() > 12 => {

src/eta_reduction.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,14 @@ fn check_closure(cx: &LateContext, expr: &Expr) {
5858
return;
5959
}
6060
let fn_ty = cx.tcx.expr_ty(caller);
61-
if let ty::TyBareFn(_, fn_ty) = fn_ty.sty {
61+
match fn_ty.sty {
6262
// Is it an unsafe function? They don't implement the closure traits
63-
if fn_ty.unsafety == Unsafety::Unsafe {
64-
return;
63+
ty::TyFnDef(_, _, fn_ty) | ty::TyFnPtr(fn_ty) => {
64+
if fn_ty.unsafety == Unsafety::Unsafe {
65+
return;
66+
}
6567
}
68+
_ => (),
6669
}
6770
for (ref a1, ref a2) in decl.inputs.iter().zip(args) {
6871
if let PatKind::Ident(_, ident, _) = a1.pat.node {

src/mut_reference.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,24 @@ impl LateLintPass for UnnecessaryMutPassed {
5353
}
5454

5555
fn check_arguments(cx: &LateContext, arguments: &[P<Expr>], type_definition: &TyS, name: &str) {
56-
if let TypeVariants::TyBareFn(_, ref fn_type) = type_definition.sty {
57-
let parameters = &fn_type.sig.skip_binder().inputs;
58-
for (argument, parameter) in arguments.iter().zip(parameters.iter()) {
59-
match parameter.sty {
60-
TypeVariants::TyRef(_, TypeAndMut {mutbl: MutImmutable, ..}) |
61-
TypeVariants::TyRawPtr(TypeAndMut {mutbl: MutImmutable, ..}) => {
62-
if let ExprAddrOf(MutMutable, _) = argument.node {
63-
span_lint(cx,
64-
UNNECESSARY_MUT_PASSED,
65-
argument.span,
66-
&format!("The function/method \"{}\" doesn't need a mutable reference", name));
56+
match type_definition.sty {
57+
TypeVariants::TyFnDef(_, _, ref fn_type) | TypeVariants::TyFnPtr(ref fn_type) => {
58+
let parameters = &fn_type.sig.skip_binder().inputs;
59+
for (argument, parameter) in arguments.iter().zip(parameters.iter()) {
60+
match parameter.sty {
61+
TypeVariants::TyRef(_, TypeAndMut {mutbl: MutImmutable, ..}) |
62+
TypeVariants::TyRawPtr(TypeAndMut {mutbl: MutImmutable, ..}) => {
63+
if let ExprAddrOf(MutMutable, _) = argument.node {
64+
span_lint(cx,
65+
UNNECESSARY_MUT_PASSED,
66+
argument.span,
67+
&format!("The function/method \"{}\" doesn't need a mutable reference", name));
68+
}
6769
}
70+
_ => {}
6871
}
69-
_ => {}
7072
}
7173
}
74+
_ => (),
7275
}
7376
}

tests/compile-fail/mut_reference.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,8 @@
33

44
#![allow(unused_variables)]
55

6-
fn takes_an_immutable_reference(a: &i32) {
7-
}
8-
9-
10-
fn takes_a_mutable_reference(a: &mut i32) {
11-
}
6+
fn takes_an_immutable_reference(a: &i32) {}
7+
fn takes_a_mutable_reference(a: &mut i32) {}
128

139
struct MyStruct;
1410

@@ -24,23 +20,30 @@ impl MyStruct {
2420
fn main() {
2521
// Functions
2622
takes_an_immutable_reference(&mut 42); //~ERROR The function/method "takes_an_immutable_reference" doesn't need a mutable reference
27-
23+
let foo: fn(&i32) = takes_an_immutable_reference;
24+
foo(&mut 42); //~ERROR The function/method "foo" doesn't need a mutable reference
25+
2826
// Methods
2927
let my_struct = MyStruct;
3028
my_struct.takes_an_immutable_reference(&mut 42); //~ERROR The function/method "takes_an_immutable_reference" doesn't need a mutable reference
31-
29+
3230

3331
// No error
34-
32+
3533
// Functions
3634
takes_an_immutable_reference(&42);
35+
let foo: fn(&i32) = takes_an_immutable_reference;
36+
foo(&42);
37+
3738
takes_a_mutable_reference(&mut 42);
39+
let foo: fn(&mut i32) = takes_a_mutable_reference;
40+
foo(&mut 42);
41+
3842
let a = &mut 42;
3943
takes_an_immutable_reference(a);
40-
44+
4145
// Methods
4246
my_struct.takes_an_immutable_reference(&42);
4347
my_struct.takes_a_mutable_reference(&mut 42);
4448
my_struct.takes_an_immutable_reference(a);
45-
4649
}

0 commit comments

Comments
 (0)