mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-16 21:15:18 +03:00
Autoderef in librustc_lint
This commit is contained in:
@@ -125,7 +125,7 @@ fn check_expr(&mut self, cx: &LateContext, e: &hir::Expr) {
|
||||
}
|
||||
},
|
||||
hir::ExprBinary(binop, ref l, ref r) => {
|
||||
if is_comparison(binop) && !check_limits(cx.tcx, binop, &**l, &**r) {
|
||||
if is_comparison(binop) && !check_limits(cx.tcx, binop, &l, &r) {
|
||||
cx.span_lint(UNUSED_COMPARISONS, e.span,
|
||||
"comparison is useless due to type limits");
|
||||
}
|
||||
@@ -174,7 +174,7 @@ fn check_expr(&mut self, cx: &LateContext, e: &hir::Expr) {
|
||||
if (negative && v > max as u64 + 1) ||
|
||||
(!negative && v > max as u64) {
|
||||
cx.span_lint(OVERFLOWING_LITERALS, e.span,
|
||||
&*format!("literal out of range for {:?}", t));
|
||||
&format!("literal out of range for {:?}", t));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -196,7 +196,7 @@ fn check_expr(&mut self, cx: &LateContext, e: &hir::Expr) {
|
||||
};
|
||||
if lit_val < min || lit_val > max {
|
||||
cx.span_lint(OVERFLOWING_LITERALS, e.span,
|
||||
&*format!("literal out of range for {:?}", t));
|
||||
&format!("literal out of range for {:?}", t));
|
||||
}
|
||||
},
|
||||
ty::TyFloat(t) => {
|
||||
@@ -213,7 +213,7 @@ fn check_expr(&mut self, cx: &LateContext, e: &hir::Expr) {
|
||||
};
|
||||
if lit_val < min || lit_val > max {
|
||||
cx.span_lint(OVERFLOWING_LITERALS, e.span,
|
||||
&*format!("literal out of range for {:?}", t));
|
||||
&format!("literal out of range for {:?}", t));
|
||||
}
|
||||
},
|
||||
_ => ()
|
||||
@@ -666,7 +666,7 @@ fn check_ty(cx: &LateContext, ty: &hir::Ty) {
|
||||
|
||||
fn check_foreign_fn(cx: &LateContext, decl: &hir::FnDecl) {
|
||||
for input in &decl.inputs {
|
||||
check_ty(cx, &*input.ty);
|
||||
check_ty(cx, &input.ty);
|
||||
}
|
||||
if let hir::Return(ref ret_ty) = decl.output {
|
||||
let tty = ast_ty_to_normalized(cx.tcx, ret_ty.id);
|
||||
@@ -680,8 +680,8 @@ fn check_foreign_fn(cx: &LateContext, decl: &hir::FnDecl) {
|
||||
if nmod.abi != Abi::RustIntrinsic && nmod.abi != Abi::PlatformIntrinsic {
|
||||
for ni in &nmod.items {
|
||||
match ni.node {
|
||||
hir::ForeignItemFn(ref decl, _) => check_foreign_fn(cx, &**decl),
|
||||
hir::ForeignItemStatic(ref t, _) => check_ty(cx, &**t)
|
||||
hir::ForeignItemFn(ref decl, _) => check_foreign_fn(cx, &decl),
|
||||
hir::ForeignItemStatic(ref t, _) => check_ty(cx, &t)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -248,7 +248,7 @@ fn check_attribute(&mut self, cx: &LateContext, attr: &ast::Attribute) {
|
||||
|
||||
let plugin_attributes = cx.sess().plugin_attributes.borrow_mut();
|
||||
for &(ref name, ty) in plugin_attributes.iter() {
|
||||
if ty == AttributeType::Whitelisted && attr.check_name(&*name) {
|
||||
if ty == AttributeType::Whitelisted && attr.check_name(&name) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -265,7 +265,7 @@ fn check_attribute(&mut self, cx: &LateContext, attr: &ast::Attribute) {
|
||||
// the crate level?
|
||||
let plugin_crate = plugin_attributes.iter()
|
||||
.find(|&&(ref x, t)| {
|
||||
&*attr.name() == &*x &&
|
||||
&*attr.name() == x &&
|
||||
AttributeType::CrateLevel == t
|
||||
}).is_some();
|
||||
if known_crate || plugin_crate {
|
||||
@@ -294,7 +294,7 @@ impl UnusedParens {
|
||||
fn check_unused_parens_core(&self, cx: &EarlyContext, value: &ast::Expr, msg: &str,
|
||||
struct_lit_needs_parens: bool) {
|
||||
if let ast::ExprKind::Paren(ref inner) = value.node {
|
||||
let necessary = struct_lit_needs_parens && contains_exterior_struct_lit(&**inner);
|
||||
let necessary = struct_lit_needs_parens && contains_exterior_struct_lit(&inner);
|
||||
if !necessary {
|
||||
cx.span_lint(UNUSED_PARENS, value.span,
|
||||
&format!("unnecessary parentheses around {}", msg))
|
||||
@@ -314,8 +314,8 @@ fn contains_exterior_struct_lit(value: &ast::Expr) -> bool {
|
||||
ast::ExprKind::AssignOp(_, ref lhs, ref rhs) |
|
||||
ast::ExprKind::Binary(_, ref lhs, ref rhs) => {
|
||||
// X { y: 1 } + X { y: 2 }
|
||||
contains_exterior_struct_lit(&**lhs) ||
|
||||
contains_exterior_struct_lit(&**rhs)
|
||||
contains_exterior_struct_lit(&lhs) ||
|
||||
contains_exterior_struct_lit(&rhs)
|
||||
}
|
||||
ast::ExprKind::Unary(_, ref x) |
|
||||
ast::ExprKind::Cast(ref x, _) |
|
||||
@@ -324,12 +324,12 @@ fn contains_exterior_struct_lit(value: &ast::Expr) -> bool {
|
||||
ast::ExprKind::TupField(ref x, _) |
|
||||
ast::ExprKind::Index(ref x, _) => {
|
||||
// &X { y: 1 }, X { y: 1 }.y
|
||||
contains_exterior_struct_lit(&**x)
|
||||
contains_exterior_struct_lit(&x)
|
||||
}
|
||||
|
||||
ast::ExprKind::MethodCall(_, _, ref exprs) => {
|
||||
// X { y: 1 }.bar(...)
|
||||
contains_exterior_struct_lit(&*exprs[0])
|
||||
contains_exterior_struct_lit(&exprs[0])
|
||||
}
|
||||
|
||||
_ => false
|
||||
@@ -360,7 +360,7 @@ fn check_expr(&mut self, cx: &EarlyContext, e: &ast::Expr) {
|
||||
InPlace(_, ref value) => (value, "emplacement value", false),
|
||||
_ => return
|
||||
};
|
||||
self.check_unused_parens_core(cx, &**value, msg, struct_lit_needs_parens);
|
||||
self.check_unused_parens_core(cx, &value, msg, struct_lit_needs_parens);
|
||||
}
|
||||
|
||||
fn check_stmt(&mut self, cx: &EarlyContext, s: &ast::Stmt) {
|
||||
@@ -374,7 +374,7 @@ fn check_stmt(&mut self, cx: &EarlyContext, s: &ast::Stmt) {
|
||||
},
|
||||
_ => return
|
||||
};
|
||||
self.check_unused_parens_core(cx, &**value, msg, false);
|
||||
self.check_unused_parens_core(cx, &value, msg, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user