mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-10 23:24:24 +00:00
Apply clippy suggestions
Signed-off-by: Mateusz Mikuła <mati865@gmail.com>
This commit is contained in:
parent
8749927973
commit
cfb9b982c5
35 changed files with 101 additions and 107 deletions
|
@ -202,9 +202,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
|
|||
};
|
||||
|
||||
let mut visitor = ExprVisitor {
|
||||
assignee: assignee,
|
||||
assignee,
|
||||
counter: 0,
|
||||
cx: cx
|
||||
cx
|
||||
};
|
||||
|
||||
walk_expr(&mut visitor, e);
|
||||
|
@ -253,7 +253,7 @@ struct ExprVisitor<'a, 'tcx: 'a> {
|
|||
|
||||
impl<'a, 'tcx: 'a> Visitor<'tcx> for ExprVisitor<'a, 'tcx> {
|
||||
fn visit_expr(&mut self, expr: &'tcx hir::Expr) {
|
||||
if SpanlessEq::new(self.cx).ignore_fn().eq_expr(self.assignee, &expr) {
|
||||
if SpanlessEq::new(self.cx).ignore_fn().eq_expr(self.assignee, expr) {
|
||||
self.counter += 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -96,7 +96,7 @@ pub struct BitMask {
|
|||
impl BitMask {
|
||||
pub fn new(verbose_bit_mask_threshold: u64) -> Self {
|
||||
Self {
|
||||
verbose_bit_mask_threshold: verbose_bit_mask_threshold,
|
||||
verbose_bit_mask_threshold,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ pub struct BlackListedName {
|
|||
impl BlackListedName {
|
||||
pub fn new(blacklist: Vec<String>) -> Self {
|
||||
Self {
|
||||
blacklist: blacklist,
|
||||
blacklist,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -124,7 +124,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlockInIfCondition {
|
|||
} else {
|
||||
let mut visitor = ExVisitor {
|
||||
found_block: None,
|
||||
cx: cx,
|
||||
cx,
|
||||
};
|
||||
walk_expr(&mut visitor, check);
|
||||
if let Some(block) = visitor.found_block {
|
||||
|
|
|
@ -69,7 +69,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonminimalBool {
|
|||
_: Span,
|
||||
_: NodeId,
|
||||
) {
|
||||
NonminimalBoolVisitor { cx: cx }.visit_body(body)
|
||||
NonminimalBoolVisitor { cx }.visit_body(body)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -261,8 +261,8 @@ impl<'a, 'tcx, 'v> SuggestContext<'a, 'tcx, 'v> {
|
|||
// The boolean part of the return indicates whether some simplifications have been applied.
|
||||
fn suggest(cx: &LateContext, suggestion: &Bool, terminals: &[&Expr]) -> (String, bool) {
|
||||
let mut suggest_context = SuggestContext {
|
||||
terminals: terminals,
|
||||
cx: cx,
|
||||
terminals,
|
||||
cx,
|
||||
output: String::new(),
|
||||
simplified: false,
|
||||
};
|
||||
|
|
|
@ -73,7 +73,7 @@ impl PartialEq for Constant {
|
|||
// we want `Fw32 == FwAny` and `FwAny == Fw64`, by transitivity we must have
|
||||
// `Fw32 == Fw64` so don’t compare them
|
||||
// mem::transmute is required to catch non-matching 0.0, -0.0, and NaNs
|
||||
unsafe { mem::transmute::<f64, u64>(l as f64) == mem::transmute::<f64, u64>(r as f64) }
|
||||
unsafe { mem::transmute::<f64, u64>(f64::from(l)) == mem::transmute::<f64, u64>(f64::from(r)) }
|
||||
},
|
||||
(&Constant::Bool(l), &Constant::Bool(r)) => l == r,
|
||||
(&Constant::Vec(ref l), &Constant::Vec(ref r)) | (&Constant::Tuple(ref l), &Constant::Tuple(ref r)) => l == r,
|
||||
|
@ -102,7 +102,7 @@ impl Hash for Constant {
|
|||
i.hash(state);
|
||||
},
|
||||
Constant::F32(f) => {
|
||||
unsafe { mem::transmute::<f64, u64>(f as f64) }.hash(state);
|
||||
unsafe { mem::transmute::<f64, u64>(f64::from(f)) }.hash(state);
|
||||
},
|
||||
Constant::F64(f) => {
|
||||
unsafe { mem::transmute::<f64, u64>(f) }.hash(state);
|
||||
|
@ -143,12 +143,12 @@ impl PartialOrd for Constant {
|
|||
}
|
||||
|
||||
/// parse a `LitKind` to a `Constant`
|
||||
pub fn lit_to_constant<'a, 'tcx>(lit: &LitKind, ty: Ty<'tcx>) -> Constant {
|
||||
pub fn lit_to_constant<'tcx>(lit: &LitKind, ty: Ty<'tcx>) -> Constant {
|
||||
use syntax::ast::*;
|
||||
|
||||
match *lit {
|
||||
LitKind::Str(ref is, _) => Constant::Str(is.to_string()),
|
||||
LitKind::Byte(b) => Constant::Int(b as u128),
|
||||
LitKind::Byte(b) => Constant::Int(u128::from(b)),
|
||||
LitKind::ByteStr(ref s) => Constant::Binary(Rc::clone(s)),
|
||||
LitKind::Char(c) => Constant::Char(c),
|
||||
LitKind::Int(n, _) => Constant::Int(n),
|
||||
|
@ -177,7 +177,7 @@ pub fn constant_simple(lcx: &LateContext, e: &Expr) -> Option<Constant> {
|
|||
constant(lcx, e).and_then(|(cst, res)| if res { None } else { Some(cst) })
|
||||
}
|
||||
|
||||
/// Creates a ConstEvalLateContext from the given LateContext and TypeckTables
|
||||
/// Creates a `ConstEvalLateContext` from the given `LateContext` and `TypeckTables`
|
||||
pub fn constant_context<'c, 'cc>(lcx: &LateContext<'c, 'cc>, tables: &'cc ty::TypeckTables<'cc>) -> ConstEvalLateContext<'c, 'cc> {
|
||||
ConstEvalLateContext {
|
||||
tcx: lcx.tcx,
|
||||
|
@ -215,7 +215,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
|
|||
},
|
||||
ExprUnary(op, ref operand) => self.expr(operand).and_then(|o| match op {
|
||||
UnNot => self.constant_not(&o, self.tables.expr_ty(e)),
|
||||
UnNeg => self.constant_negate(o, self.tables.expr_ty(e)),
|
||||
UnNeg => self.constant_negate(&o, self.tables.expr_ty(e)),
|
||||
UnDeref => Some(o),
|
||||
}),
|
||||
ExprBinary(op, ref left, ref right) => self.binop(op, left, right),
|
||||
|
@ -240,9 +240,9 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
|
|||
}
|
||||
}
|
||||
|
||||
fn constant_negate(&self, o: Constant, ty: ty::Ty) -> Option<Constant> {
|
||||
fn constant_negate(&self, o: &Constant, ty: ty::Ty) -> Option<Constant> {
|
||||
use self::Constant::*;
|
||||
match o {
|
||||
match *o {
|
||||
Int(value) => {
|
||||
let ity = match ty.sty {
|
||||
ty::TyInt(ity) => ity,
|
||||
|
|
|
@ -63,7 +63,7 @@ impl CyclomaticComplexity {
|
|||
divergence: 0,
|
||||
short_circuits: 0,
|
||||
returns: 0,
|
||||
cx: cx,
|
||||
cx,
|
||||
};
|
||||
helper.visit_expr(expr);
|
||||
let CCHelper {
|
||||
|
|
|
@ -39,7 +39,7 @@ pub struct Doc {
|
|||
impl Doc {
|
||||
pub fn new(valid_idents: Vec<String>) -> Self {
|
||||
Self {
|
||||
valid_idents: valid_idents,
|
||||
valid_idents,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ struct Parser<'a> {
|
|||
|
||||
impl<'a> Parser<'a> {
|
||||
fn new(parser: pulldown_cmark::Parser<'a>) -> Self {
|
||||
Self { parser: parser }
|
||||
Self { parser }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -55,12 +55,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for HashMapLint {
|
|||
};
|
||||
|
||||
let mut visitor = InsertVisitor {
|
||||
cx: cx,
|
||||
cx,
|
||||
span: expr.span,
|
||||
ty: ty,
|
||||
map: map,
|
||||
key: key,
|
||||
sole_expr: sole_expr,
|
||||
ty,
|
||||
map,
|
||||
key,
|
||||
sole_expr,
|
||||
};
|
||||
|
||||
walk_expr(&mut visitor, &**then_block);
|
||||
|
@ -68,11 +68,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for HashMapLint {
|
|||
} else if let Some(ref else_block) = *else_block {
|
||||
if let Some((ty, map, key)) = check_cond(cx, check) {
|
||||
let mut visitor = InsertVisitor {
|
||||
cx: cx,
|
||||
cx,
|
||||
span: expr.span,
|
||||
ty: ty,
|
||||
map: map,
|
||||
key: key,
|
||||
ty,
|
||||
map,
|
||||
key,
|
||||
sole_expr: false,
|
||||
};
|
||||
|
||||
|
|
|
@ -70,11 +70,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnportableVariant {
|
|||
match ty.sty {
|
||||
ty::TyInt(IntTy::Isize) => {
|
||||
let val = ((val as i128) << 64) >> 64;
|
||||
if val <= i32::max_value() as i128 && val >= i32::min_value() as i128 {
|
||||
if val <= i128::from(i32::max_value()) && val >= i128::from(i32::min_value()) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
ty::TyUint(UintTy::Usize) if val > u32::max_value() as u128 => {},
|
||||
ty::TyUint(UintTy::Usize) if val > u128::from(u32::max_value()) => {},
|
||||
_ => continue,
|
||||
}
|
||||
span_lint(
|
||||
|
|
|
@ -107,7 +107,7 @@ impl EnumVariantNames {
|
|||
pub fn new(threshold: u64) -> Self {
|
||||
Self {
|
||||
modules: Vec::new(),
|
||||
threshold: threshold,
|
||||
threshold,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
|||
) {
|
||||
let fn_def_id = cx.tcx.hir.local_def_id(node_id);
|
||||
let mut v = EscapeDelegate {
|
||||
cx: cx,
|
||||
cx,
|
||||
set: NodeSet(),
|
||||
too_large_for_stack: self.too_large_for_stack,
|
||||
};
|
||||
|
|
|
@ -67,8 +67,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EvalOrderDependence {
|
|||
if path.segments.len() == 1 {
|
||||
if let def::Def::Local(var) = cx.tables.qpath_def(qpath, lhs.hir_id) {
|
||||
let mut visitor = ReadVisitor {
|
||||
cx: cx,
|
||||
var: var,
|
||||
cx,
|
||||
var,
|
||||
write_expr: expr,
|
||||
last_expr: expr,
|
||||
};
|
||||
|
@ -82,13 +82,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EvalOrderDependence {
|
|||
}
|
||||
fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt) {
|
||||
match stmt.node {
|
||||
StmtExpr(ref e, _) | StmtSemi(ref e, _) => DivergenceVisitor { cx: cx }.maybe_walk_expr(e),
|
||||
StmtExpr(ref e, _) | StmtSemi(ref e, _) => DivergenceVisitor { cx }.maybe_walk_expr(e),
|
||||
StmtDecl(ref d, _) => if let DeclLocal(ref local) = d.node {
|
||||
if let Local {
|
||||
init: Some(ref e), ..
|
||||
} = **local
|
||||
{
|
||||
DivergenceVisitor { cx: cx }.visit_expr(e);
|
||||
DivergenceVisitor { cx }.visit_expr(e);
|
||||
}
|
||||
},
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ pub struct Functions {
|
|||
impl Functions {
|
||||
pub fn new(threshold: u64) -> Self {
|
||||
Self {
|
||||
threshold: threshold,
|
||||
threshold,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -156,7 +156,7 @@ impl<'a, 'tcx> Functions {
|
|||
if !raw_ptrs.is_empty() {
|
||||
let tables = cx.tcx.body_tables(body.id());
|
||||
let mut v = DerefVisitor {
|
||||
cx: cx,
|
||||
cx,
|
||||
ptrs: raw_ptrs,
|
||||
tables,
|
||||
};
|
||||
|
|
|
@ -37,11 +37,8 @@ impl LintPass for Pass {
|
|||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
||||
fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx TraitItem) {
|
||||
match item.node {
|
||||
TraitItemKind::Method(_, TraitMethod::Required(_)) => {
|
||||
check_attrs(cx, &item.name, &item.attrs);
|
||||
},
|
||||
_ => {},
|
||||
if let TraitItemKind::Method(_, TraitMethod::Required(_)) = item.node {
|
||||
check_attrs(cx, &item.name, &item.attrs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ pub struct LargeEnumVariant {
|
|||
impl LargeEnumVariant {
|
||||
pub fn new(maximum_size_difference_allowed: u64) -> Self {
|
||||
Self {
|
||||
maximum_size_difference_allowed: maximum_size_difference_allowed,
|
||||
maximum_size_difference_allowed,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -170,7 +170,7 @@ fn check_assign<'a, 'tcx>(
|
|||
if decl == local_id;
|
||||
then {
|
||||
let mut v = UsedVisitor {
|
||||
cx: cx,
|
||||
cx,
|
||||
id: decl,
|
||||
used: false,
|
||||
};
|
||||
|
@ -192,8 +192,8 @@ fn check_assign<'a, 'tcx>(
|
|||
|
||||
fn used_in_expr<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, id: ast::NodeId, expr: &'tcx hir::Expr) -> bool {
|
||||
let mut v = UsedVisitor {
|
||||
cx: cx,
|
||||
id: id,
|
||||
cx,
|
||||
id,
|
||||
used: false,
|
||||
};
|
||||
hir::intravisit::walk_expr(&mut v, expr);
|
||||
|
|
|
@ -261,7 +261,7 @@ struct RefVisitor<'a, 'tcx: 'a> {
|
|||
impl<'v, 't> RefVisitor<'v, 't> {
|
||||
fn new(cx: &'v LateContext<'v, 't>) -> Self {
|
||||
Self {
|
||||
cx: cx,
|
||||
cx,
|
||||
lts: Vec::new(),
|
||||
abort: false,
|
||||
}
|
||||
|
|
|
@ -138,11 +138,11 @@ impl<'a> DigitInfo<'a> {
|
|||
let suffix_start = if last_d == '_' { d_idx - 1 } else { d_idx };
|
||||
let (digits, suffix) = sans_prefix.split_at(suffix_start);
|
||||
return Self {
|
||||
digits: digits,
|
||||
radix: radix,
|
||||
prefix: prefix,
|
||||
digits,
|
||||
radix,
|
||||
prefix,
|
||||
suffix: Some(suffix),
|
||||
float: float,
|
||||
float,
|
||||
};
|
||||
}
|
||||
last_d = d
|
||||
|
@ -151,10 +151,10 @@ impl<'a> DigitInfo<'a> {
|
|||
// No suffix found
|
||||
Self {
|
||||
digits: sans_prefix,
|
||||
radix: radix,
|
||||
prefix: prefix,
|
||||
radix,
|
||||
prefix,
|
||||
suffix: None,
|
||||
float: float,
|
||||
float,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -426,7 +426,7 @@ impl EarlyLintPass for LiteralRepresentation {
|
|||
impl LiteralRepresentation {
|
||||
pub fn new(threshold: u64) -> Self {
|
||||
Self {
|
||||
threshold: threshold,
|
||||
threshold,
|
||||
}
|
||||
}
|
||||
fn check_lit(&self, cx: &EarlyContext, lit: &Lit) {
|
||||
|
@ -444,7 +444,7 @@ impl LiteralRepresentation {
|
|||
.filter(|&c| c != '_')
|
||||
.collect::<String>()
|
||||
.parse::<u128>().unwrap();
|
||||
if val < self.threshold as u128 {
|
||||
if val < u128::from(self.threshold) {
|
||||
return
|
||||
}
|
||||
let hex = format!("{:#X}", val);
|
||||
|
|
|
@ -975,7 +975,7 @@ fn check_for_loop_range<'a, 'tcx>(
|
|||
// the var must be a single name
|
||||
if let PatKind::Binding(_, canonical_id, ref ident, _) = pat.node {
|
||||
let mut visitor = VarVisitor {
|
||||
cx: cx,
|
||||
cx,
|
||||
var: canonical_id,
|
||||
indexed_mut: HashSet::new(),
|
||||
indexed_indirectly: HashMap::new(),
|
||||
|
@ -1289,7 +1289,7 @@ fn check_for_loop_explicit_counter<'a, 'tcx>(
|
|||
) {
|
||||
// Look for variables that are incremented once per loop iteration.
|
||||
let mut visitor = IncrementVisitor {
|
||||
cx: cx,
|
||||
cx,
|
||||
states: HashMap::new(),
|
||||
depth: 0,
|
||||
done: false,
|
||||
|
@ -1309,7 +1309,7 @@ fn check_for_loop_explicit_counter<'a, 'tcx>(
|
|||
.filter(|&(_, v)| *v == VarState::IncrOnce)
|
||||
{
|
||||
let mut visitor2 = InitializeVisitor {
|
||||
cx: cx,
|
||||
cx,
|
||||
end_expr: expr,
|
||||
var_id: *id,
|
||||
state: VarState::IncrOnce,
|
||||
|
@ -1728,8 +1728,8 @@ fn is_iterator_used_after_while_let<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, it
|
|||
None => return false,
|
||||
};
|
||||
let mut visitor = VarUsedAfterLoopVisitor {
|
||||
cx: cx,
|
||||
def_id: def_id,
|
||||
cx,
|
||||
def_id,
|
||||
iter_expr_id: iter_expr.id,
|
||||
past_while_let: false,
|
||||
var_used_after_while_let: false,
|
||||
|
@ -2048,7 +2048,7 @@ fn is_loop_nested(cx: &LateContext, loop_expr: &Expr, iter_expr: &Expr) -> bool
|
|||
},
|
||||
Some(NodeBlock(block)) => {
|
||||
let mut block_visitor = LoopNestVisitor {
|
||||
id: id,
|
||||
id,
|
||||
iterator: iter_name,
|
||||
nesting: Unknown,
|
||||
};
|
||||
|
@ -2189,7 +2189,7 @@ struct MutableVarsVisitor<'a, 'tcx: 'a> {
|
|||
impl<'a, 'tcx> Visitor<'tcx> for MutableVarsVisitor<'a, 'tcx> {
|
||||
fn visit_expr(&mut self, ex: &'tcx Expr) {
|
||||
match ex.node {
|
||||
ExprPath(_) => if let Some(node_id) = check_for_mutability(self.cx, &ex) {
|
||||
ExprPath(_) => if let Some(node_id) = check_for_mutability(self.cx, ex) {
|
||||
self.ids.insert(node_id, None);
|
||||
},
|
||||
|
||||
|
@ -2213,7 +2213,7 @@ struct MutVarsDelegate {
|
|||
|
||||
impl<'tcx> MutVarsDelegate {
|
||||
fn update(&mut self, cat: &'tcx Categorization, sp: Span) {
|
||||
if let &Categorization::Local(id) = cat {
|
||||
if let Categorization::Local(id) = *cat {
|
||||
if let Some(span) = self.mut_spans.get_mut(&id) {
|
||||
*span = Some(sp)
|
||||
}
|
||||
|
|
|
@ -760,7 +760,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
|||
},
|
||||
hir::ExprBinary(op, ref lhs, ref rhs) if op.node == hir::BiEq || op.node == hir::BiNe => {
|
||||
let mut info = BinaryExprInfo {
|
||||
expr: expr,
|
||||
expr,
|
||||
chain: lhs,
|
||||
other: rhs,
|
||||
eq: op.node == hir::BiEq,
|
||||
|
|
|
@ -33,13 +33,13 @@ impl LintPass for MutMut {
|
|||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MutMut {
|
||||
fn check_block(&mut self, cx: &LateContext<'a, 'tcx>, block: &'tcx hir::Block) {
|
||||
intravisit::walk_block(&mut MutVisitor { cx: cx }, block);
|
||||
intravisit::walk_block(&mut MutVisitor { cx }, block);
|
||||
}
|
||||
|
||||
fn check_ty(&mut self, cx: &LateContext<'a, 'tcx>, ty: &'tcx hir::Ty) {
|
||||
use rustc::hir::intravisit::Visitor;
|
||||
|
||||
MutVisitor { cx: cx }.visit_ty(ty);
|
||||
MutVisitor { cx }.visit_ty(ty);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -337,10 +337,10 @@ fn check_and_warn<'a>(ctx: &EarlyContext, expr: &'a ast::Expr) {
|
|||
with_if_expr(stmt, |if_expr, cond, then_block, else_expr| {
|
||||
let data = &LintData {
|
||||
stmt_idx: i,
|
||||
if_expr: if_expr,
|
||||
if_expr,
|
||||
if_cond: cond,
|
||||
if_block: then_block,
|
||||
else_expr: else_expr,
|
||||
else_expr,
|
||||
block_stmts: &loop_block.stmts,
|
||||
};
|
||||
if needless_continue_in_else(else_expr) {
|
||||
|
|
|
@ -203,7 +203,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
|
|||
|
||||
// Dereference suggestion
|
||||
let sugg = |db: &mut DiagnosticBuilder| {
|
||||
if let ty::TypeVariants::TyAdt(ref def, ..) = ty.sty {
|
||||
if let ty::TypeVariants::TyAdt(def, ..) = ty.sty {
|
||||
if let Some(span) = cx.tcx.hir.span_if_local(def.did) {
|
||||
let param_env = ty::ParamEnv::empty();
|
||||
if param_env.can_type_implement_copy(cx.tcx, ty, span).is_ok() {
|
||||
|
@ -307,7 +307,7 @@ struct MovedVariablesCtxt<'a, 'tcx: 'a> {
|
|||
impl<'a, 'tcx> MovedVariablesCtxt<'a, 'tcx> {
|
||||
fn new(cx: &'a LateContext<'a, 'tcx>) -> Self {
|
||||
Self {
|
||||
cx: cx,
|
||||
cx,
|
||||
moved_vars: HashSet::new(),
|
||||
spans_need_deref: HashMap::new(),
|
||||
}
|
||||
|
|
|
@ -267,7 +267,7 @@ impl<'a, 'tcx, 'b> SimilarNamesNameVisitor<'a, 'tcx, 'b> {
|
|||
self.0.names.push(ExistingName {
|
||||
whitelist: get_whitelist(&interned_name).unwrap_or(&[]),
|
||||
interned: interned_name,
|
||||
span: span,
|
||||
span,
|
||||
len: count,
|
||||
});
|
||||
}
|
||||
|
@ -329,8 +329,8 @@ fn do_check(lint: &mut NonExpressiveNames, cx: &EarlyContext, attrs: &[Attribute
|
|||
if !attr::contains_name(attrs, "test") {
|
||||
let mut visitor = SimilarNamesLocalVisitor {
|
||||
names: Vec::new(),
|
||||
cx: cx,
|
||||
lint: lint,
|
||||
cx,
|
||||
lint,
|
||||
single_char_names: Vec::new(),
|
||||
};
|
||||
// initialize with function arguments
|
||||
|
|
|
@ -225,19 +225,16 @@ fn check_fn(cx: &LateContext, decl: &FnDecl, fn_id: NodeId, opt_body_id: Option<
|
|||
if let [ref inner] = *params.types;
|
||||
then {
|
||||
let replacement = snippet_opt(cx, inner.span);
|
||||
match replacement {
|
||||
Some(r) => {
|
||||
span_lint_and_then(
|
||||
cx,
|
||||
PTR_ARG,
|
||||
arg.span,
|
||||
"using a reference to `Cow` is not recommended.",
|
||||
|db| {
|
||||
db.span_suggestion(arg.span, "change this to", "&".to_owned() + &r);
|
||||
},
|
||||
);
|
||||
},
|
||||
None => (),
|
||||
if let Some(r) = replacement {
|
||||
span_lint_and_then(
|
||||
cx,
|
||||
PTR_ARG,
|
||||
arg.span,
|
||||
"using a reference to `Cow` is not recommended.",
|
||||
|db| {
|
||||
db.span_suggestion(arg.span, "change this to", "&".to_owned() + &r);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ impl QuestionMarkPass {
|
|||
if let ExprIf(ref if_expr, ref body, _) = expr.node;
|
||||
if let ExprMethodCall(ref segment, _, ref args) = if_expr.node;
|
||||
if segment.name == "is_none";
|
||||
if Self::expression_returns_none(cx, &body);
|
||||
if Self::expression_returns_none(cx, body);
|
||||
if let Some(subject) = args.get(0);
|
||||
if Self::is_option(cx, subject);
|
||||
|
||||
|
@ -64,7 +64,7 @@ impl QuestionMarkPass {
|
|||
cx,
|
||||
QUESTION_MARK,
|
||||
expr.span,
|
||||
&format!("this block may be rewritten with the `?` operator"),
|
||||
"this block may be rewritten with the `?` operator",
|
||||
|db| {
|
||||
let receiver_str = &Sugg::hir(cx, subject, "..");
|
||||
|
||||
|
@ -82,7 +82,7 @@ impl QuestionMarkPass {
|
|||
fn is_option(cx: &LateContext, expression: &Expr) -> bool {
|
||||
let expr_ty = cx.tables.expr_ty(expression);
|
||||
|
||||
return match_type(cx, expr_ty, &OPTION);
|
||||
match_type(cx, expr_ty, &OPTION)
|
||||
}
|
||||
|
||||
fn expression_returns_none(cx: &LateContext, expression: &Expr) -> bool {
|
||||
|
@ -127,7 +127,7 @@ impl QuestionMarkPass {
|
|||
return Some(ret_expr.clone());
|
||||
}
|
||||
|
||||
return None;
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -985,7 +985,7 @@ pub struct TypeComplexityPass {
|
|||
impl TypeComplexityPass {
|
||||
pub fn new(threshold: u64) -> Self {
|
||||
Self {
|
||||
threshold: threshold,
|
||||
threshold,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1241,7 +1241,7 @@ fn is_cast_between_fixed_and_target<'a, 'tcx>(
|
|||
return is_isize_or_usize(precast_ty) != is_isize_or_usize(cast_ty)
|
||||
}
|
||||
|
||||
return false;
|
||||
false
|
||||
}
|
||||
|
||||
fn detect_absurd_comparison<'a, 'tcx>(
|
||||
|
@ -1315,8 +1315,8 @@ fn detect_extreme_expr<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) -
|
|||
_ => return None,
|
||||
};
|
||||
Some(ExtremeExpr {
|
||||
which: which,
|
||||
expr: expr,
|
||||
which,
|
||||
expr,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedLabel {
|
|||
}
|
||||
|
||||
let mut v = UnusedLabelVisitor {
|
||||
cx: cx,
|
||||
cx,
|
||||
labels: HashMap::new(),
|
||||
};
|
||||
walk_fn(&mut v, kind, decl, body.id(), span, fn_id);
|
||||
|
|
|
@ -66,8 +66,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UseSelf {
|
|||
};
|
||||
if should_check {
|
||||
let visitor = &mut UseSelfVisitor {
|
||||
item_path: item_path,
|
||||
cx: cx,
|
||||
item_path,
|
||||
cx,
|
||||
};
|
||||
for impl_item_ref in refs {
|
||||
visitor.visit_impl_item(cx.tcx.hir.impl_item(impl_item_ref.id));
|
||||
|
|
|
@ -274,7 +274,7 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor {
|
|||
if let Ty_::TyPath(ref qp) = ty.node {
|
||||
println!(" if let Ty_::TyPath(ref {}) = {}.node;", qp_label, cast_ty);
|
||||
self.current = qp_label;
|
||||
self.print_qpath(&qp);
|
||||
self.print_qpath(qp);
|
||||
}
|
||||
self.current = cast_pat;
|
||||
self.visit_expr(expr);
|
||||
|
|
|
@ -24,7 +24,7 @@ pub struct SpanlessEq<'a, 'tcx: 'a> {
|
|||
impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
|
||||
pub fn new(cx: &'a LateContext<'a, 'tcx>) -> Self {
|
||||
Self {
|
||||
cx: cx,
|
||||
cx,
|
||||
ignore_fn: false,
|
||||
}
|
||||
}
|
||||
|
@ -295,7 +295,7 @@ pub struct SpanlessHash<'a, 'tcx: 'a> {
|
|||
impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
|
||||
pub fn new(cx: &'a LateContext<'a, 'tcx>) -> Self {
|
||||
Self {
|
||||
cx: cx,
|
||||
cx,
|
||||
s: DefaultHasher::new(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -123,7 +123,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LintWithoutLintPass {
|
|||
} else if is_lint_array_type(ty) && item.vis == Visibility::Inherited && item.name == "ARRAY" {
|
||||
let mut collector = LintCollector {
|
||||
output: &mut self.registered_lints,
|
||||
cx: cx,
|
||||
cx,
|
||||
};
|
||||
collector.visit_expr(&cx.tcx.hir.body(body_id).value);
|
||||
}
|
||||
|
|
|
@ -390,7 +390,7 @@ impl<'tcx> Visitor<'tcx> for ContainsName {
|
|||
/// check if an `Expr` contains a certain name
|
||||
pub fn contains_name(name: Name, expr: &Expr) -> bool {
|
||||
let mut cn = ContainsName {
|
||||
name: name,
|
||||
name,
|
||||
result: false,
|
||||
};
|
||||
cn.visit_expr(expr);
|
||||
|
|
|
@ -220,8 +220,8 @@ impl<T> ParenHelper<T> {
|
|||
/// Build a `ParenHelper`.
|
||||
fn new(paren: bool, wrapped: T) -> Self {
|
||||
Self {
|
||||
paren: paren,
|
||||
wrapped: wrapped,
|
||||
paren,
|
||||
wrapped,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue