mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 13:13:34 +00:00
MutImmutable -> Immutable, MutMutable -> Mutable, CaptureClause -> CaptureBy
This commit is contained in:
parent
79d3b30cd7
commit
e9a3e54910
19 changed files with 59 additions and 55 deletions
|
@ -548,7 +548,7 @@ fn is_mutable_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>, span: Span,
|
||||||
Tuple(ref substs) => substs.types().any(|ty| is_mutable_ty(cx, ty, span, tys)),
|
Tuple(ref substs) => substs.types().any(|ty| is_mutable_ty(cx, ty, span, tys)),
|
||||||
Array(ty, _) | Slice(ty) => is_mutable_ty(cx, ty, span, tys),
|
Array(ty, _) | Slice(ty) => is_mutable_ty(cx, ty, span, tys),
|
||||||
RawPtr(ty::TypeAndMut { ty, mutbl }) | Ref(_, ty, mutbl) => {
|
RawPtr(ty::TypeAndMut { ty, mutbl }) | Ref(_, ty, mutbl) => {
|
||||||
mutbl == hir::Mutability::MutMutable || is_mutable_ty(cx, ty, span, tys)
|
mutbl == hir::Mutability::Mutable || is_mutable_ty(cx, ty, span, tys)
|
||||||
},
|
},
|
||||||
// calling something constitutes a side effect, so return true on all callables
|
// calling something constitutes a side effect, so return true on all callables
|
||||||
// also never calls need not be used, so return true for them, too
|
// also never calls need not be used, so return true for them, too
|
||||||
|
@ -653,7 +653,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for StaticMutVisitor<'a, 'tcx> {
|
||||||
tys.clear();
|
tys.clear();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Assign(ref target, _) | AssignOp(_, ref target, _) | AddrOf(hir::Mutability::MutMutable, ref target) => {
|
Assign(ref target, _) | AssignOp(_, ref target, _) | AddrOf(hir::Mutability::Mutable, ref target) => {
|
||||||
self.mutates_static |= is_mutated_static(self.cx, target)
|
self.mutates_static |= is_mutated_static(self.cx, target)
|
||||||
},
|
},
|
||||||
_ => {},
|
_ => {},
|
||||||
|
|
|
@ -1506,8 +1506,8 @@ fn make_iterator_snippet(cx: &LateContext<'_, '_>, arg: &Expr, applic_ref: &mut
|
||||||
match &arg.kind {
|
match &arg.kind {
|
||||||
ExprKind::AddrOf(mutability, arg_inner) if has_iter_method(cx, cx.tables.expr_ty(&arg_inner)).is_some() => {
|
ExprKind::AddrOf(mutability, arg_inner) if has_iter_method(cx, cx.tables.expr_ty(&arg_inner)).is_some() => {
|
||||||
let meth_name = match mutability {
|
let meth_name = match mutability {
|
||||||
MutMutable => "iter_mut",
|
Mutability::Mutable => "iter_mut",
|
||||||
MutImmutable => "iter",
|
Mutability::Immutable => "iter",
|
||||||
};
|
};
|
||||||
format!(
|
format!(
|
||||||
"{}.{}()",
|
"{}.{}()",
|
||||||
|
@ -1539,14 +1539,14 @@ fn check_for_loop_over_map_kv<'a, 'tcx>(
|
||||||
let (new_pat_span, kind, ty, mutbl) = match cx.tables.expr_ty(arg).kind {
|
let (new_pat_span, kind, ty, mutbl) = match cx.tables.expr_ty(arg).kind {
|
||||||
ty::Ref(_, ty, mutbl) => match (&pat[0].kind, &pat[1].kind) {
|
ty::Ref(_, ty, mutbl) => match (&pat[0].kind, &pat[1].kind) {
|
||||||
(key, _) if pat_is_wild(key, body) => (pat[1].span, "value", ty, mutbl),
|
(key, _) if pat_is_wild(key, body) => (pat[1].span, "value", ty, mutbl),
|
||||||
(_, value) if pat_is_wild(value, body) => (pat[0].span, "key", ty, MutImmutable),
|
(_, value) if pat_is_wild(value, body) => (pat[0].span, "key", ty, Mutability::Immutable),
|
||||||
_ => return,
|
_ => return,
|
||||||
},
|
},
|
||||||
_ => return,
|
_ => return,
|
||||||
};
|
};
|
||||||
let mutbl = match mutbl {
|
let mutbl = match mutbl {
|
||||||
MutImmutable => "",
|
Mutability::Immutable => "",
|
||||||
MutMutable => "_mut",
|
Mutability::Mutable => "_mut",
|
||||||
};
|
};
|
||||||
let arg = match arg.kind {
|
let arg = match arg.kind {
|
||||||
ExprKind::AddrOf(_, ref expr) => &**expr,
|
ExprKind::AddrOf(_, ref expr) => &**expr,
|
||||||
|
@ -1874,7 +1874,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
|
||||||
self.visit_expr(rhs);
|
self.visit_expr(rhs);
|
||||||
},
|
},
|
||||||
ExprKind::AddrOf(mutbl, ref expr) => {
|
ExprKind::AddrOf(mutbl, ref expr) => {
|
||||||
if mutbl == MutMutable {
|
if mutbl == Mutability::Mutable {
|
||||||
self.prefer_mutable = true;
|
self.prefer_mutable = true;
|
||||||
}
|
}
|
||||||
self.visit_expr(expr);
|
self.visit_expr(expr);
|
||||||
|
@ -1885,7 +1885,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
|
||||||
let ty = self.cx.tables.expr_ty_adjusted(expr);
|
let ty = self.cx.tables.expr_ty_adjusted(expr);
|
||||||
self.prefer_mutable = false;
|
self.prefer_mutable = false;
|
||||||
if let ty::Ref(_, _, mutbl) = ty.kind {
|
if let ty::Ref(_, _, mutbl) = ty.kind {
|
||||||
if mutbl == MutMutable {
|
if mutbl == Mutability::Mutable {
|
||||||
self.prefer_mutable = true;
|
self.prefer_mutable = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1897,7 +1897,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
|
||||||
for (ty, expr) in self.cx.tcx.fn_sig(def_id).inputs().skip_binder().iter().zip(args) {
|
for (ty, expr) in self.cx.tcx.fn_sig(def_id).inputs().skip_binder().iter().zip(args) {
|
||||||
self.prefer_mutable = false;
|
self.prefer_mutable = false;
|
||||||
if let ty::Ref(_, _, mutbl) = ty.kind {
|
if let ty::Ref(_, _, mutbl) = ty.kind {
|
||||||
if mutbl == MutMutable {
|
if mutbl == Mutability::Mutable {
|
||||||
self.prefer_mutable = true;
|
self.prefer_mutable = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2090,7 +2090,7 @@ impl<'a, 'tcx> Visitor<'tcx> for IncrementVisitor<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ExprKind::Assign(ref lhs, _) if lhs.hir_id == expr.hir_id => *state = VarState::DontWarn,
|
ExprKind::Assign(ref lhs, _) if lhs.hir_id == expr.hir_id => *state = VarState::DontWarn,
|
||||||
ExprKind::AddrOf(mutability, _) if mutability == MutMutable => *state = VarState::DontWarn,
|
ExprKind::AddrOf(mutability, _) if mutability == Mutability::Mutable => *state = VarState::DontWarn,
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2172,7 +2172,9 @@ impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> {
|
||||||
VarState::DontWarn
|
VarState::DontWarn
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ExprKind::AddrOf(mutability, _) if mutability == MutMutable => self.state = VarState::DontWarn,
|
ExprKind::AddrOf(mutability, _) if mutability == Mutability::Mutable => {
|
||||||
|
self.state = VarState::DontWarn
|
||||||
|
},
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -570,7 +570,7 @@ fn is_panic_block(block: &Block) -> bool {
|
||||||
fn check_match_ref_pats(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm], expr: &Expr) {
|
fn check_match_ref_pats(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm], expr: &Expr) {
|
||||||
if has_only_ref_pats(arms) {
|
if has_only_ref_pats(arms) {
|
||||||
let mut suggs = Vec::new();
|
let mut suggs = Vec::new();
|
||||||
let (title, msg) = if let ExprKind::AddrOf(Mutability::MutImmutable, ref inner) = ex.kind {
|
let (title, msg) = if let ExprKind::AddrOf(Mutability::Immutable, ref inner) = ex.kind {
|
||||||
let span = ex.span.source_callsite();
|
let span = ex.span.source_callsite();
|
||||||
suggs.push((span, Sugg::hir_with_macro_callsite(cx, inner, "..").to_string()));
|
suggs.push((span, Sugg::hir_with_macro_callsite(cx, inner, "..").to_string()));
|
||||||
(
|
(
|
||||||
|
|
|
@ -2,7 +2,7 @@ use crate::utils::{
|
||||||
match_def_path, match_qpath, paths, snippet_with_applicability, span_help_and_lint, span_lint_and_sugg,
|
match_def_path, match_qpath, paths, snippet_with_applicability, span_help_and_lint, span_lint_and_sugg,
|
||||||
};
|
};
|
||||||
use if_chain::if_chain;
|
use if_chain::if_chain;
|
||||||
use rustc::hir::{Expr, ExprKind, MutMutable, QPath};
|
use rustc::hir::{Expr, ExprKind, Mutability, QPath};
|
||||||
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
||||||
use rustc::{declare_lint_pass, declare_tool_lint};
|
use rustc::{declare_lint_pass, declare_tool_lint};
|
||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
|
@ -90,7 +90,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MemReplace {
|
||||||
// argument's type. All that's left is to get
|
// argument's type. All that's left is to get
|
||||||
// replacee's path.
|
// replacee's path.
|
||||||
let replaced_path = match func_args[0].kind {
|
let replaced_path = match func_args[0].kind {
|
||||||
ExprKind::AddrOf(MutMutable, ref replaced) => {
|
ExprKind::AddrOf(Mutability::Mutable, ref replaced) => {
|
||||||
if let ExprKind::Path(QPath::Resolved(None, ref replaced_path)) = replaced.kind {
|
if let ExprKind::Path(QPath::Resolved(None, ref replaced_path)) = replaced.kind {
|
||||||
replaced_path
|
replaced_path
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -2764,8 +2764,8 @@ fn ty_has_iter_method(cx: &LateContext<'_, '_>, self_ref_ty: Ty<'_>) -> Option<(
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
};
|
};
|
||||||
let method_name = match mutbl {
|
let method_name = match mutbl {
|
||||||
hir::MutImmutable => "iter",
|
hir::Mutability::Immutable => "iter",
|
||||||
hir::MutMutable => "iter_mut",
|
hir::Mutability::Mutable => "iter_mut",
|
||||||
};
|
};
|
||||||
(ty_name, method_name)
|
(ty_name, method_name)
|
||||||
})
|
})
|
||||||
|
@ -2955,8 +2955,8 @@ impl SelfKind {
|
||||||
}
|
}
|
||||||
|
|
||||||
let trait_path = match mutability {
|
let trait_path = match mutability {
|
||||||
hir::Mutability::MutImmutable => &paths::ASREF_TRAIT,
|
hir::Mutability::Immutable => &paths::ASREF_TRAIT,
|
||||||
hir::Mutability::MutMutable => &paths::ASMUT_TRAIT,
|
hir::Mutability::Mutable => &paths::ASMUT_TRAIT,
|
||||||
};
|
};
|
||||||
|
|
||||||
let trait_def_id = match get_trait_def_id(cx, trait_path) {
|
let trait_def_id = match get_trait_def_id(cx, trait_path) {
|
||||||
|
@ -2969,9 +2969,9 @@ impl SelfKind {
|
||||||
match self {
|
match self {
|
||||||
Self::Value => matches_value(parent_ty, ty),
|
Self::Value => matches_value(parent_ty, ty),
|
||||||
Self::Ref => {
|
Self::Ref => {
|
||||||
matches_ref(cx, hir::Mutability::MutImmutable, parent_ty, ty) || ty == parent_ty && is_copy(cx, ty)
|
matches_ref(cx, hir::Mutability::Immutable, parent_ty, ty) || ty == parent_ty && is_copy(cx, ty)
|
||||||
},
|
},
|
||||||
Self::RefMut => matches_ref(cx, hir::Mutability::MutMutable, parent_ty, ty),
|
Self::RefMut => matches_ref(cx, hir::Mutability::Mutable, parent_ty, ty),
|
||||||
Self::No => ty != parent_ty,
|
Self::No => ty != parent_ty,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -627,8 +627,8 @@ fn check_cast(cx: &LateContext<'_, '_>, span: Span, e: &Expr, ty: &Ty) {
|
||||||
if !in_constant(cx, e.hir_id);
|
if !in_constant(cx, e.hir_id);
|
||||||
then {
|
then {
|
||||||
let (msg, sugg_fn) = match mut_ty.mutbl {
|
let (msg, sugg_fn) = match mut_ty.mutbl {
|
||||||
Mutability::MutMutable => ("`0 as *mut _` detected", "std::ptr::null_mut"),
|
Mutability::Mutable => ("`0 as *mut _` detected", "std::ptr::null_mut"),
|
||||||
Mutability::MutImmutable => ("`0 as *const _` detected", "std::ptr::null"),
|
Mutability::Immutable => ("`0 as *const _` detected", "std::ptr::null"),
|
||||||
};
|
};
|
||||||
|
|
||||||
let (sugg, appl) = if let TyKind::Infer = mut_ty.ty.kind {
|
let (sugg, appl) = if let TyKind::Infer = mut_ty.ty.kind {
|
||||||
|
|
|
@ -57,15 +57,15 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for MutVisitor<'a, 'tcx> {
|
||||||
// Let's ignore the generated code.
|
// Let's ignore the generated code.
|
||||||
intravisit::walk_expr(self, arg);
|
intravisit::walk_expr(self, arg);
|
||||||
intravisit::walk_expr(self, body);
|
intravisit::walk_expr(self, body);
|
||||||
} else if let hir::ExprKind::AddrOf(hir::MutMutable, ref e) = expr.kind {
|
} else if let hir::ExprKind::AddrOf(hir::Mutability::Mutable, ref e) = expr.kind {
|
||||||
if let hir::ExprKind::AddrOf(hir::MutMutable, _) = e.kind {
|
if let hir::ExprKind::AddrOf(hir::Mutability::Mutable, _) = e.kind {
|
||||||
span_lint(
|
span_lint(
|
||||||
self.cx,
|
self.cx,
|
||||||
MUT_MUT,
|
MUT_MUT,
|
||||||
expr.span,
|
expr.span,
|
||||||
"generally you want to avoid `&mut &mut _` if possible",
|
"generally you want to avoid `&mut &mut _` if possible",
|
||||||
);
|
);
|
||||||
} else if let ty::Ref(_, _, hir::MutMutable) = self.cx.tables.expr_ty(e).kind {
|
} else if let ty::Ref(_, _, hir::Mutability::Mutable) = self.cx.tables.expr_ty(e).kind {
|
||||||
span_lint(
|
span_lint(
|
||||||
self.cx,
|
self.cx,
|
||||||
MUT_MUT,
|
MUT_MUT,
|
||||||
|
@ -81,14 +81,15 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for MutVisitor<'a, 'tcx> {
|
||||||
_,
|
_,
|
||||||
hir::MutTy {
|
hir::MutTy {
|
||||||
ty: ref pty,
|
ty: ref pty,
|
||||||
mutbl: hir::MutMutable,
|
mutbl: hir::Mutability::Mutable,
|
||||||
},
|
},
|
||||||
) = ty.kind
|
) = ty.kind
|
||||||
{
|
{
|
||||||
if let hir::TyKind::Rptr(
|
if let hir::TyKind::Rptr(
|
||||||
_,
|
_,
|
||||||
hir::MutTy {
|
hir::MutTy {
|
||||||
mutbl: hir::MutMutable, ..
|
mutbl: hir::Mutability::Mutable,
|
||||||
|
..
|
||||||
},
|
},
|
||||||
) = pty.kind
|
) = pty.kind
|
||||||
{
|
{
|
||||||
|
|
|
@ -55,11 +55,12 @@ fn check_arguments<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, arguments: &[Expr], typ
|
||||||
let parameters = type_definition.fn_sig(cx.tcx).skip_binder().inputs();
|
let parameters = type_definition.fn_sig(cx.tcx).skip_binder().inputs();
|
||||||
for (argument, parameter) in arguments.iter().zip(parameters.iter()) {
|
for (argument, parameter) in arguments.iter().zip(parameters.iter()) {
|
||||||
match parameter.kind {
|
match parameter.kind {
|
||||||
ty::Ref(_, _, MutImmutable)
|
ty::Ref(_, _, Mutability::Immutable)
|
||||||
| ty::RawPtr(ty::TypeAndMut {
|
| ty::RawPtr(ty::TypeAndMut {
|
||||||
mutbl: MutImmutable, ..
|
mutbl: Mutability::Immutable,
|
||||||
|
..
|
||||||
}) => {
|
}) => {
|
||||||
if let ExprKind::AddrOf(MutMutable, _) = argument.kind {
|
if let ExprKind::AddrOf(Mutability::Mutable, _) = argument.kind {
|
||||||
span_lint(
|
span_lint(
|
||||||
cx,
|
cx,
|
||||||
UNNECESSARY_MUT_PASSED,
|
UNNECESSARY_MUT_PASSED,
|
||||||
|
|
|
@ -128,7 +128,7 @@ impl<'a, 'tcx> MutArgVisitor<'a, 'tcx> {
|
||||||
impl<'a, 'tcx> Visitor<'tcx> for MutArgVisitor<'a, 'tcx> {
|
impl<'a, 'tcx> Visitor<'tcx> for MutArgVisitor<'a, 'tcx> {
|
||||||
fn visit_expr(&mut self, expr: &'tcx Expr) {
|
fn visit_expr(&mut self, expr: &'tcx Expr) {
|
||||||
match expr.kind {
|
match expr.kind {
|
||||||
ExprKind::AddrOf(Mutability::MutMutable, _) => {
|
ExprKind::AddrOf(Mutability::Mutable, _) => {
|
||||||
self.found = true;
|
self.found = true;
|
||||||
return;
|
return;
|
||||||
},
|
},
|
||||||
|
@ -136,7 +136,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MutArgVisitor<'a, 'tcx> {
|
||||||
if let Some(adj) = self.cx.tables.adjustments().get(expr.hir_id) {
|
if let Some(adj) = self.cx.tables.adjustments().get(expr.hir_id) {
|
||||||
if adj
|
if adj
|
||||||
.iter()
|
.iter()
|
||||||
.any(|a| matches!(a.target.kind, ty::Ref(_, _, Mutability::MutMutable)))
|
.any(|a| matches!(a.target.kind, ty::Ref(_, _, Mutability::Mutable)))
|
||||||
{
|
{
|
||||||
self.found = true;
|
self.found = true;
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
use crate::utils::{snippet_opt, span_lint_and_then};
|
use crate::utils::{snippet_opt, span_lint_and_then};
|
||||||
use if_chain::if_chain;
|
use if_chain::if_chain;
|
||||||
use rustc::hir::{BindingAnnotation, Expr, ExprKind, HirId, Item, MutImmutable, Pat, PatKind};
|
use rustc::hir::{BindingAnnotation, Expr, ExprKind, HirId, Item, Mutability, Pat, PatKind};
|
||||||
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
||||||
use rustc::ty;
|
use rustc::ty;
|
||||||
use rustc::ty::adjustment::{Adjust, Adjustment};
|
use rustc::ty::adjustment::{Adjust, Adjustment};
|
||||||
|
@ -41,7 +41,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrow {
|
||||||
if e.span.from_expansion() || self.derived_item.is_some() {
|
if e.span.from_expansion() || self.derived_item.is_some() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if let ExprKind::AddrOf(MutImmutable, ref inner) = e.kind {
|
if let ExprKind::AddrOf(Mutability::Immutable, ref inner) = e.kind {
|
||||||
if let ty::Ref(..) = cx.tables.expr_ty(inner).kind {
|
if let ty::Ref(..) = cx.tables.expr_ty(inner).kind {
|
||||||
for adj3 in cx.tables.expr_adjustments(e).windows(3) {
|
for adj3 in cx.tables.expr_adjustments(e).windows(3) {
|
||||||
if let [Adjustment {
|
if let [Adjustment {
|
||||||
|
@ -82,10 +82,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrow {
|
||||||
if_chain! {
|
if_chain! {
|
||||||
if let PatKind::Binding(BindingAnnotation::Ref, .., name, _) = pat.kind;
|
if let PatKind::Binding(BindingAnnotation::Ref, .., name, _) = pat.kind;
|
||||||
if let ty::Ref(_, tam, mutbl) = cx.tables.pat_ty(pat).kind;
|
if let ty::Ref(_, tam, mutbl) = cx.tables.pat_ty(pat).kind;
|
||||||
if mutbl == MutImmutable;
|
if mutbl == Mutability::Immutable;
|
||||||
if let ty::Ref(_, _, mutbl) = tam.kind;
|
if let ty::Ref(_, _, mutbl) = tam.kind;
|
||||||
// only lint immutable refs, because borrowed `&mut T` cannot be moved out
|
// only lint immutable refs, because borrowed `&mut T` cannot be moved out
|
||||||
if mutbl == MutImmutable;
|
if mutbl == Mutability::Immutable;
|
||||||
then {
|
then {
|
||||||
span_lint_and_then(
|
span_lint_and_then(
|
||||||
cx,
|
cx,
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
use crate::utils::{snippet_with_applicability, span_lint_and_then};
|
use crate::utils::{snippet_with_applicability, span_lint_and_then};
|
||||||
use if_chain::if_chain;
|
use if_chain::if_chain;
|
||||||
use rustc::hir::{BindingAnnotation, MutImmutable, Node, Pat, PatKind};
|
use rustc::hir::{BindingAnnotation, Mutability, Node, Pat, PatKind};
|
||||||
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
||||||
use rustc::{declare_lint_pass, declare_tool_lint};
|
use rustc::{declare_lint_pass, declare_tool_lint};
|
||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
|
@ -61,7 +61,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrowedRef {
|
||||||
|
|
||||||
if_chain! {
|
if_chain! {
|
||||||
// Only lint immutable refs, because `&mut ref T` may be useful.
|
// Only lint immutable refs, because `&mut ref T` may be useful.
|
||||||
if let PatKind::Ref(ref sub_pat, MutImmutable) = pat.kind;
|
if let PatKind::Ref(ref sub_pat, Mutability::Immutable) = pat.kind;
|
||||||
|
|
||||||
// Check sub_pat got a `ref` keyword (excluding `ref mut`).
|
// Check sub_pat got a `ref` keyword (excluding `ref mut`).
|
||||||
if let PatKind::Binding(BindingAnnotation::Ref, .., spanned_name, _) = sub_pat.kind;
|
if let PatKind::Binding(BindingAnnotation::Ref, .., spanned_name, _) = sub_pat.kind;
|
||||||
|
|
|
@ -150,7 +150,7 @@ fn check_fn(cx: &LateContext<'_, '_>, decl: &FnDecl, fn_id: HirId, opt_body_id:
|
||||||
let fn_ty = sig.skip_binder();
|
let fn_ty = sig.skip_binder();
|
||||||
|
|
||||||
for (idx, (arg, ty)) in decl.inputs.iter().zip(fn_ty.inputs()).enumerate() {
|
for (idx, (arg, ty)) in decl.inputs.iter().zip(fn_ty.inputs()).enumerate() {
|
||||||
if let ty::Ref(_, ty, MutImmutable) = ty.kind {
|
if let ty::Ref(_, ty, Mutability::Immutable) = ty.kind {
|
||||||
if is_type_diagnostic_item(cx, ty, Symbol::intern("vec_type")) {
|
if is_type_diagnostic_item(cx, ty, Symbol::intern("vec_type")) {
|
||||||
let mut ty_snippet = None;
|
let mut ty_snippet = None;
|
||||||
if_chain! {
|
if_chain! {
|
||||||
|
@ -254,7 +254,7 @@ fn check_fn(cx: &LateContext<'_, '_>, decl: &FnDecl, fn_id: HirId, opt_body_id:
|
||||||
}
|
}
|
||||||
|
|
||||||
if let FunctionRetTy::Return(ref ty) = decl.output {
|
if let FunctionRetTy::Return(ref ty) = decl.output {
|
||||||
if let Some((out, MutMutable, _)) = get_rptr_lm(ty) {
|
if let Some((out, Mutability::Mutable, _)) = get_rptr_lm(ty) {
|
||||||
let mut immutables = vec![];
|
let mut immutables = vec![];
|
||||||
for (_, ref mutbl, ref argspan) in decl
|
for (_, ref mutbl, ref argspan) in decl
|
||||||
.inputs
|
.inputs
|
||||||
|
@ -262,7 +262,7 @@ fn check_fn(cx: &LateContext<'_, '_>, decl: &FnDecl, fn_id: HirId, opt_body_id:
|
||||||
.filter_map(|ty| get_rptr_lm(ty))
|
.filter_map(|ty| get_rptr_lm(ty))
|
||||||
.filter(|&(lt, _, _)| lt.name == out.name)
|
.filter(|&(lt, _, _)| lt.name == out.name)
|
||||||
{
|
{
|
||||||
if *mutbl == MutMutable {
|
if *mutbl == Mutability::Mutable {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
immutables.push(*argspan);
|
immutables.push(*argspan);
|
||||||
|
|
|
@ -361,7 +361,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
|
||||||
),
|
),
|
||||||
|db| {
|
|db| {
|
||||||
let arg = sugg::Sugg::hir(cx, &args[0], "..");
|
let arg = sugg::Sugg::hir(cx, &args[0], "..");
|
||||||
let (deref, cast) = if mutbl == Mutability::MutMutable {
|
let (deref, cast) = if mutbl == Mutability::Mutable {
|
||||||
("&mut *", "*mut")
|
("&mut *", "*mut")
|
||||||
} else {
|
} else {
|
||||||
("&*", "*const")
|
("&*", "*const")
|
||||||
|
@ -409,7 +409,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
|
||||||
if let ty::Uint(ast::UintTy::U8) = slice_ty.kind;
|
if let ty::Uint(ast::UintTy::U8) = slice_ty.kind;
|
||||||
if from_mutbl == to_mutbl;
|
if from_mutbl == to_mutbl;
|
||||||
then {
|
then {
|
||||||
let postfix = if from_mutbl == Mutability::MutMutable {
|
let postfix = if from_mutbl == Mutability::Mutable {
|
||||||
"_mut"
|
"_mut"
|
||||||
} else {
|
} else {
|
||||||
""
|
""
|
||||||
|
@ -449,7 +449,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
|
||||||
let sugg_paren = arg
|
let sugg_paren = arg
|
||||||
.as_ty(cx.tcx.mk_ptr(ty_from_and_mut))
|
.as_ty(cx.tcx.mk_ptr(ty_from_and_mut))
|
||||||
.as_ty(cx.tcx.mk_ptr(ty_to_and_mut));
|
.as_ty(cx.tcx.mk_ptr(ty_to_and_mut));
|
||||||
let sugg = if to_mutbl == Mutability::MutMutable {
|
let sugg = if to_mutbl == Mutability::Mutable {
|
||||||
sugg_paren.mut_addr_deref()
|
sugg_paren.mut_addr_deref()
|
||||||
} else {
|
} else {
|
||||||
sugg_paren.addr_deref()
|
sugg_paren.addr_deref()
|
||||||
|
|
|
@ -97,7 +97,7 @@ impl<'a, 'tcx> TriviallyCopyPassByRef {
|
||||||
}
|
}
|
||||||
|
|
||||||
if_chain! {
|
if_chain! {
|
||||||
if let ty::Ref(input_lt, ty, Mutability::MutImmutable) = ty.kind;
|
if let ty::Ref(input_lt, ty, Mutability::Immutable) = ty.kind;
|
||||||
if !output_lts.contains(&input_lt);
|
if !output_lts.contains(&input_lt);
|
||||||
if is_copy(cx, ty);
|
if is_copy(cx, ty);
|
||||||
if let Some(size) = cx.layout_of(ty).ok().map(|l| l.size.bytes());
|
if let Some(size) = cx.layout_of(ty).ok().map(|l| l.size.bytes());
|
||||||
|
|
|
@ -393,7 +393,7 @@ fn check_ty_rptr(cx: &LateContext<'_, '_>, hir_ty: &hir::Ty, is_local: bool, lt:
|
||||||
} else {
|
} else {
|
||||||
format!("{} ", lt.name.ident().as_str())
|
format!("{} ", lt.name.ident().as_str())
|
||||||
};
|
};
|
||||||
let mutopt = if mut_ty.mutbl == Mutability::MutMutable {
|
let mutopt = if mut_ty.mutbl == Mutability::Mutable {
|
||||||
"mut "
|
"mut "
|
||||||
} else {
|
} else {
|
||||||
""
|
""
|
||||||
|
@ -2377,9 +2377,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RefToMut {
|
||||||
if_chain! {
|
if_chain! {
|
||||||
if let ExprKind::Unary(UnOp::UnDeref, e) = &expr.kind;
|
if let ExprKind::Unary(UnOp::UnDeref, e) = &expr.kind;
|
||||||
if let ExprKind::Cast(e, t) = &e.kind;
|
if let ExprKind::Cast(e, t) = &e.kind;
|
||||||
if let TyKind::Ptr(MutTy { mutbl: Mutability::MutMutable, .. }) = t.kind;
|
if let TyKind::Ptr(MutTy { mutbl: Mutability::Mutable, .. }) = t.kind;
|
||||||
if let ExprKind::Cast(e, t) = &e.kind;
|
if let ExprKind::Cast(e, t) = &e.kind;
|
||||||
if let TyKind::Ptr(MutTy { mutbl: Mutability::MutImmutable, .. }) = t.kind;
|
if let TyKind::Ptr(MutTy { mutbl: Mutability::Immutable, .. }) = t.kind;
|
||||||
if let ty::Ref(..) = cx.tables.node_type(e.hir_id).kind;
|
if let ty::Ref(..) = cx.tables.node_type(e.hir_id).kind;
|
||||||
then {
|
then {
|
||||||
span_lint(
|
span_lint(
|
||||||
|
|
|
@ -427,7 +427,7 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor {
|
||||||
},
|
},
|
||||||
ExprKind::AddrOf(mutability, ref inner) => {
|
ExprKind::AddrOf(mutability, ref inner) => {
|
||||||
let inner_pat = self.next("inner");
|
let inner_pat = self.next("inner");
|
||||||
println!("AddrOf({:?}, ref {}) = {};", mutability, inner_pat, current);
|
println!("AddrOf(Mutability::{:?}, ref {}) = {};", mutability, inner_pat, current);
|
||||||
self.current = inner_pat;
|
self.current = inner_pat;
|
||||||
self.visit_expr(inner);
|
self.visit_expr(inner);
|
||||||
},
|
},
|
||||||
|
|
|
@ -447,8 +447,8 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
|
||||||
},
|
},
|
||||||
ExprKind::Closure(cap, _, eid, _, _) => {
|
ExprKind::Closure(cap, _, eid, _, _) => {
|
||||||
match cap {
|
match cap {
|
||||||
CaptureClause::CaptureByValue => 0,
|
CaptureBy::Value => 0,
|
||||||
CaptureClause::CaptureByRef => 1,
|
CaptureBy::Ref => 1,
|
||||||
}
|
}
|
||||||
.hash(&mut self.s);
|
.hash(&mut self.s);
|
||||||
// closures inherit TypeckTables
|
// closures inherit TypeckTables
|
||||||
|
|
|
@ -145,7 +145,7 @@ impl_lint_pass!(LintWithoutLintPass => [LINT_WITHOUT_LINT_PASS]);
|
||||||
|
|
||||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LintWithoutLintPass {
|
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LintWithoutLintPass {
|
||||||
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
|
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
|
||||||
if let hir::ItemKind::Static(ref ty, MutImmutable, _) = item.kind {
|
if let hir::ItemKind::Static(ref ty, Mutability::Immutable, _) = item.kind {
|
||||||
if is_lint_ref_type(cx, ty) {
|
if is_lint_ref_type(cx, ty) {
|
||||||
self.declared_lints.insert(item.ident.name, item.span);
|
self.declared_lints.insert(item.ident.name, item.span);
|
||||||
}
|
}
|
||||||
|
@ -198,7 +198,7 @@ fn is_lint_ref_type<'tcx>(cx: &LateContext<'_, 'tcx>, ty: &Ty) -> bool {
|
||||||
_,
|
_,
|
||||||
MutTy {
|
MutTy {
|
||||||
ty: ref inner,
|
ty: ref inner,
|
||||||
mutbl: MutImmutable,
|
mutbl: Mutability::Immutable,
|
||||||
},
|
},
|
||||||
) = ty.kind
|
) = ty.kind
|
||||||
{
|
{
|
||||||
|
|
|
@ -22,7 +22,7 @@ if_chain! {
|
||||||
if let ExprKind::Path(ref path2) = func1.kind;
|
if let ExprKind::Path(ref path2) = func1.kind;
|
||||||
if match_qpath(path2, &["{{root}}", "std", "iter", "Iterator", "next"]);
|
if match_qpath(path2, &["{{root}}", "std", "iter", "Iterator", "next"]);
|
||||||
if args1.len() == 1;
|
if args1.len() == 1;
|
||||||
if let ExprKind::AddrOf(MutMutable, ref inner) = args1[0].kind;
|
if let ExprKind::AddrOf(Mutability::Mutable, ref inner) = args1[0].kind;
|
||||||
if let ExprKind::Path(ref path3) = inner.kind;
|
if let ExprKind::Path(ref path3) = inner.kind;
|
||||||
if match_qpath(path3, &["iter"]);
|
if match_qpath(path3, &["iter"]);
|
||||||
if arms1.len() == 2;
|
if arms1.len() == 2;
|
||||||
|
|
Loading…
Reference in a new issue