Skip to content

Try to fix #1914 #1915

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion clippy_lints/src/let_if_seq.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use rustc::lint::*;
use rustc::hir;
use rustc::hir::BindingAnnotation;
use syntax_pos::{Span, NO_EXPANSION};
use utils::{snippet, span_lint_and_then};

Expand Down Expand Up @@ -94,7 +95,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetIfSeq {
};

let mutability = match mode {
hir::BindByRef(hir::MutMutable) | hir::BindByValue(hir::MutMutable) => "<mut> ",
BindingAnnotation::RefMut | BindingAnnotation::Mutable => "<mut> ",
_ => "",
};

Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/matches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ fn check_single_match_opt_like(cx: &LateContext, ex: &Expr, arms: &[Arm], expr:
}
print::to_string(print::NO_ANN, |s| s.print_qpath(path, false))
},
PatKind::Binding(BindByValue(MutImmutable), _, ident, None) => ident.node.to_string(),
PatKind::Binding(BindingAnnotation::Unannotated, _, ident, None) => ident.node.to_string(),
PatKind::Path(ref path) => print::to_string(print::NO_ANN, |s| s.print_qpath(path, false)),
_ => return,
};
Expand Down
65 changes: 35 additions & 30 deletions clippy_lints/src/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
return;
}
for arg in iter_input_pats(decl, body) {
if let PatKind::Binding(BindByRef(_), _, _, _) = arg.pat.node {
span_lint(cx,
TOPLEVEL_REF_ARG,
arg.pat.span,
"`ref` directly on a function argument is ignored. Consider using a reference type instead.");
match arg.pat.node {
PatKind::Binding(BindingAnnotation::Ref, _, _, _) | PatKind::Binding(BindingAnnotation::RefMut, _, _, _) => {
span_lint(cx,
TOPLEVEL_REF_ARG,
arg.pat.span,
"`ref` directly on a function argument is ignored. Consider using a reference type instead.");
},
_ => {}
}
}
}
Expand All @@ -238,33 +241,35 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
if_let_chain! {[
let StmtDecl(ref d, _) = s.node,
let DeclLocal(ref l) = d.node,
let PatKind::Binding(BindByRef(mt), _, i, None) = l.pat.node,
let PatKind::Binding(an, _, i, None) = l.pat.node,
let Some(ref init) = l.init
], {
let init = Sugg::hir(cx, init, "..");
let (mutopt,initref) = if mt == Mutability::MutMutable {
("mut ", init.mut_addr())
} else {
("", init.addr())
};
let tyopt = if let Some(ref ty) = l.ty {
format!(": &{mutopt}{ty}", mutopt=mutopt, ty=snippet(cx, ty.span, "_"))
} else {
"".to_owned()
};
span_lint_and_then(cx,
TOPLEVEL_REF_ARG,
l.pat.span,
"`ref` on an entire `let` pattern is discouraged, take a reference with `&` instead",
|db| {
db.span_suggestion(s.span,
"try",
format!("let {name}{tyopt} = {initref};",
name=snippet(cx, i.span, "_"),
tyopt=tyopt,
initref=initref));
}
);
if an == BindingAnnotation::Ref || an == BindingAnnotation::RefMut {
let init = Sugg::hir(cx, init, "..");
let (mutopt,initref) = if an == BindingAnnotation::RefMut {
("mut ", init.mut_addr())
} else {
("", init.addr())
};
let tyopt = if let Some(ref ty) = l.ty {
format!(": &{mutopt}{ty}", mutopt=mutopt, ty=snippet(cx, ty.span, "_"))
} else {
"".to_owned()
};
span_lint_and_then(cx,
TOPLEVEL_REF_ARG,
l.pat.span,
"`ref` on an entire `let` pattern is discouraged, take a reference with `&` instead",
|db| {
db.span_suggestion(s.span,
"try",
format!("let {name}{tyopt} = {initref};",
name=snippet(cx, i.span, "_"),
tyopt=tyopt,
initref=initref));
}
);
}
}};
if_let_chain! {[
let StmtSemi(ref expr, _) = s.node,
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/needless_borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! This lint is **warn** by default

use rustc::lint::*;
use rustc::hir::{ExprAddrOf, Expr, MutImmutable, Pat, PatKind, BindingMode};
use rustc::hir::{ExprAddrOf, Expr, MutImmutable, Pat, PatKind, BindingAnnotation};
use rustc::ty;
use rustc::ty::adjustment::{Adjustment, Adjust};
use utils::{span_lint, in_macro};
Expand Down Expand Up @@ -63,7 +63,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrow {
return;
}
if_let_chain! {[
let PatKind::Binding(BindingMode::BindByRef(MutImmutable), _, _, _) = pat.node,
let PatKind::Binding(BindingAnnotation::Ref, _, _, _) = pat.node,
let ty::TyRef(_, ref tam) = cx.tables.pat_ty(pat).sty,
tam.mutbl == MutImmutable,
let ty::TyRef(_, ref tam) = tam.ty.sty,
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/needless_borrowed_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! This lint is **warn** by default

use rustc::lint::*;
use rustc::hir::{MutImmutable, Pat, PatKind, BindingMode};
use rustc::hir::{MutImmutable, Pat, PatKind, BindingAnnotation};
use rustc::ty;
use utils::{span_lint, in_macro};

Expand Down Expand Up @@ -47,7 +47,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrowedRef {
if_let_chain! {[
// Pat is a pattern whose node
// is a binding which "involves" a immutable reference...
let PatKind::Binding(BindingMode::BindByRef(MutImmutable), ..) = pat.node,
let PatKind::Binding(BindingAnnotation::Ref, ..) = pat.node,
// Pattern's type is a reference. Get the type and mutability of referenced value (tam: TypeAndMut).
let ty::TyRef(_, ref tam) = cx.tables.pat_ty(pat).sty,
// This is an immutable reference.
Expand Down
5 changes: 1 addition & 4 deletions clippy_lints/src/needless_pass_by_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
!moved_vars.contains(&defid),
], {
// Note: `toplevel_ref_arg` warns if `BindByRef`
let m = match mode {
BindingMode::BindByRef(m) | BindingMode::BindByValue(m) => m,
};
if m == Mutability::MutMutable {
if mode == BindingAnnotation::Mutable || mode == BindingAnnotation::RefMut {
continue;
}

Expand Down