1
Fork 0
This commit is contained in:
Oliver Schneider 2017-08-09 09:30:56 +02:00
parent 705c6ec2a4
commit b25b6b3355
No known key found for this signature in database
GPG key ID: A69F8D225B3AD7D9
95 changed files with 3090 additions and 2022 deletions

View file

@ -24,7 +24,7 @@ declare_lint! {
}
#[derive(Copy,Clone)]
#[derive(Copy, Clone)]
pub struct UnnecessaryMutPassed;
impl LintPass for UnnecessaryMutPassed {
@ -38,10 +38,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnnecessaryMutPassed {
match e.node {
ExprCall(ref fn_expr, ref arguments) => {
if let ExprPath(ref path) = fn_expr.node {
check_arguments(cx,
arguments,
cx.tables.expr_ty(fn_expr),
&print::to_string(print::NO_ANN, |s| s.print_qpath(path, false)));
check_arguments(
cx,
arguments,
cx.tables.expr_ty(fn_expr),
&print::to_string(print::NO_ANN, |s| s.print_qpath(path, false)),
);
}
},
ExprMethodCall(ref path, _, ref arguments) => {
@ -64,10 +66,12 @@ fn check_arguments<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, arguments: &[Expr], typ
ty::TyRef(_, ty::TypeAndMut { mutbl: MutImmutable, .. }) |
ty::TyRawPtr(ty::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));
span_lint(
cx,
UNNECESSARY_MUT_PASSED,
argument.span,
&format!("The function/method `{}` doesn't need a mutable reference", name),
);
}
},
_ => (),