use reexport::*;
use rustc::hir::*;
-use rustc::hir::intravisit::{FnKind, Visitor, walk_ty};
+use rustc::hir::intravisit::{FnKind, Visitor, walk_ty, NestedVisitorMap};
use rustc::lint::*;
use rustc::ty;
use std::cmp::Ordering;
}
}
-impl LateLintPass for TypePass {
- fn check_ty(&mut self, cx: &LateContext, ast_ty: &Ty) {
+impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypePass {
+ fn check_ty(&mut self, cx: &LateContext<'a, 'tcx>, ast_ty: &'tcx Ty) {
if in_macro(cx, ast_ty.span) {
return;
}
}
}
-impl LateLintPass for LetPass {
- fn check_decl(&mut self, cx: &LateContext, decl: &Decl) {
+impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetPass {
+ fn check_decl(&mut self, cx: &LateContext<'a, 'tcx>, decl: &'tcx Decl) {
check_let_unit(cx, decl)
}
}
}
}
-impl LateLintPass for UnitCmp {
- fn check_expr(&mut self, cx: &LateContext, expr: &Expr) {
+impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnitCmp {
+ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
if in_macro(cx, expr.span) {
return;
}
}
}
-impl LateLintPass for CastPass {
- fn check_expr(&mut self, cx: &LateContext, expr: &Expr) {
+impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CastPass {
+ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
if let ExprCast(ref ex, _) = expr.node {
let (cast_from, cast_to) = (cx.tcx.tables().expr_ty(ex), cx.tcx.tables().expr_ty(expr));
if cast_from.is_numeric() && cast_to.is_numeric() && !in_external_macro(cx, expr.span) {
}
}
-impl LateLintPass for TypeComplexityPass {
- fn check_fn(&mut self, cx: &LateContext, _: FnKind, decl: &FnDecl, _: &Expr, _: Span, _: NodeId) {
+impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeComplexityPass {
+ fn check_fn(&mut self, cx: &LateContext<'a, 'tcx>, _: FnKind<'tcx>, decl: &'tcx FnDecl, _: &'tcx Expr, _: Span, _: NodeId) {
self.check_fndecl(cx, decl);
}
- fn check_struct_field(&mut self, cx: &LateContext, field: &StructField) {
+ fn check_struct_field(&mut self, cx: &LateContext<'a, 'tcx>, field: &'tcx StructField) {
// enum variants are also struct fields now
self.check_type(cx, &field.ty);
}
- fn check_item(&mut self, cx: &LateContext, item: &Item) {
+ fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
match item.node {
ItemStatic(ref ty, _, _) |
ItemConst(ref ty, _) => self.check_type(cx, ty),
}
}
- fn check_trait_item(&mut self, cx: &LateContext, item: &TraitItem) {
+ fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx TraitItem) {
match item.node {
ConstTraitItem(ref ty, _) |
TypeTraitItem(_, Some(ref ty)) => self.check_type(cx, ty),
}
}
- fn check_impl_item(&mut self, cx: &LateContext, item: &ImplItem) {
+ fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx ImplItem) {
match item.node {
ImplItemKind::Const(ref ty, _) |
ImplItemKind::Type(ref ty) => self.check_type(cx, ty),
}
}
- fn check_local(&mut self, cx: &LateContext, local: &Local) {
+ fn check_local(&mut self, cx: &LateContext<'a, 'tcx>, local: &'tcx Local) {
if let Some(ref ty) = local.ty {
self.check_type(cx, ty);
}
}
}
-impl TypeComplexityPass {
- fn check_fndecl(&self, cx: &LateContext, decl: &FnDecl) {
+impl<'a, 'tcx> TypeComplexityPass {
+ fn check_fndecl(&self, cx: &LateContext<'a, 'tcx>, decl: &'tcx FnDecl) {
for arg in &decl.inputs {
self.check_type(cx, &arg.ty);
}
}
}
- fn check_type(&self, cx: &LateContext, ty: &Ty) {
+ fn check_type(&self, cx: &LateContext<'a, 'tcx>, ty: &'tcx Ty) {
if in_macro(cx, ty.span) {
return;
}
let mut visitor = TypeComplexityVisitor {
score: 0,
nest: 1,
+ cx: cx,
};
visitor.visit_ty(ty);
visitor.score
}
/// Walks a type and assigns a complexity score to it.
-struct TypeComplexityVisitor {
+struct TypeComplexityVisitor<'a, 'tcx: 'a> {
/// total complexity score of the type
score: u64,
/// current nesting level
nest: u64,
+ cx: &'a LateContext<'a, 'tcx>,
}
-impl<'v> Visitor<'v> for TypeComplexityVisitor {
- fn visit_ty(&mut self, ty: &'v Ty) {
+impl<'a, 'tcx: 'a> Visitor<'tcx> for TypeComplexityVisitor<'a, 'tcx> {
+ fn visit_ty(&mut self, ty: &'tcx Ty) {
let (add_score, sub_nest) = match ty.node {
// _, &x and *x have only small overhead; don't mess with nesting level
TyInfer | TyPtr(..) | TyRptr(..) => (1, 0),
walk_ty(self, ty);
self.nest -= sub_nest;
}
+ fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
+ NestedVisitorMap::All(&self.cx.tcx.map)
+ }
}
/// **What it does:** Checks for expressions where a character literal is cast
}
}
-impl LateLintPass for CharLitAsU8 {
- fn check_expr(&mut self, cx: &LateContext, expr: &Expr) {
+impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CharLitAsU8 {
+ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
use syntax::ast::{LitKind, UintTy};
if let ExprCast(ref e, _) = expr.node {
use types::ExtremeType::*;
use types::AbsurdComparisonResult::*;
use utils::comparisons::*;
- type Extr<'a> = ExtremeExpr<'a>;
let normalized = normalize_comparison(op, lhs, rhs);
let (rel, normalized_lhs, normalized_rhs) = if let Some(val) = normalized {
Some(match rel {
Rel::Lt => {
match (lx, rx) {
- (Some(l @ Extr { which: Maximum, .. }), _) => (l, AlwaysFalse), // max < x
- (_, Some(r @ Extr { which: Minimum, .. })) => (r, AlwaysFalse), // x < min
+ (Some(l @ ExtremeExpr { which: Maximum, .. }), _) => (l, AlwaysFalse), // max < x
+ (_, Some(r @ ExtremeExpr { which: Minimum, .. })) => (r, AlwaysFalse), // x < min
_ => return None,
}
}
Rel::Le => {
match (lx, rx) {
- (Some(l @ Extr { which: Minimum, .. }), _) => (l, AlwaysTrue), // min <= x
- (Some(l @ Extr { which: Maximum, .. }), _) => (l, InequalityImpossible), //max <= x
- (_, Some(r @ Extr { which: Minimum, .. })) => (r, InequalityImpossible), // x <= min
- (_, Some(r @ Extr { which: Maximum, .. })) => (r, AlwaysTrue), // x <= max
+ (Some(l @ ExtremeExpr { which: Minimum, .. }), _) => (l, AlwaysTrue), // min <= x
+ (Some(l @ ExtremeExpr { which: Maximum, .. }), _) => (l, InequalityImpossible), //max <= x
+ (_, Some(r @ ExtremeExpr { which: Minimum, .. })) => (r, InequalityImpossible), // x <= min
+ (_, Some(r @ ExtremeExpr { which: Maximum, .. })) => (r, AlwaysTrue), // x <= max
_ => return None,
}
}
})
}
-impl LateLintPass for AbsurdExtremeComparisons {
- fn check_expr(&mut self, cx: &LateContext, expr: &Expr) {
+impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AbsurdExtremeComparisons {
+ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
use types::ExtremeType::*;
use types::AbsurdComparisonResult::*;
}
}
-impl LateLintPass for InvalidUpcastComparisons {
- fn check_expr(&mut self, cx: &LateContext, expr: &Expr) {
+impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidUpcastComparisons {
+ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
if let ExprBinary(ref cmp, ref lhs, ref rhs) = expr.node {
let normalized = comparisons::normalize_comparison(cmp.node, lhs, rhs);