]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/types.rs
Fix a couple warnings
[rust.git] / clippy_lints / src / types.rs
index f18dfdbc35bee6851f479c4ef42c161a40c4195d..930c44c88633b8af60fc0931cf5a3de7487e7c61 100644 (file)
@@ -1,25 +1,26 @@
 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;
 use syntax::ast::{IntTy, UintTy, FloatTy};
 use syntax::codemap::Span;
 use utils::{comparisons, higher, in_external_macro, in_macro, match_def_path, snippet,
-            span_help_and_lint, span_lint};
+            span_help_and_lint, span_lint, opt_def_id, last_path_segment};
 use utils::paths;
 
 /// Handles all the linting of funky types
 #[allow(missing_copy_implementations)]
 pub struct TypePass;
 
-/// **What it does:** This lint checks for use of `Box<Vec<_>>` anywhere in the code.
+/// **What it does:** Checks for use of `Box<Vec<_>>` anywhere in the code.
 ///
-/// **Why is this bad?** `Vec` already keeps its contents in a separate area on the heap. So if you
-/// `Box` it, you just add another level of indirection without any benefit whatsoever.
+/// **Why is this bad?** `Vec` already keeps its contents in a separate area on
+/// the heap. So if you `Box` it, you just add another level of indirection
+/// without any benefit whatsoever.
 ///
-/// **Known problems:** None
+/// **Known problems:** None.
 ///
 /// **Example:**
 /// ```rust
 /// }
 /// ```
 declare_lint! {
-    pub BOX_VEC, Warn,
+    pub BOX_VEC,
+    Warn,
     "usage of `Box<Vec<T>>`, vector elements are already on the heap"
 }
 
-/// **What it does:** This lint checks for usage of any `LinkedList`, suggesting to use a `Vec` or
-/// a `VecDeque` (formerly called `RingBuf`).
+/// **What it does:** Checks for usage of any `LinkedList`, suggesting to use a
+/// `Vec` or a `VecDeque` (formerly called `RingBuf`).
 ///
 /// **Why is this bad?** Gankro says:
 ///
 /// > if you're doing a lot of insertion in the middle of the list, `RingBuf` can still be better
 /// > because of how expensive it is to seek to the middle of a `LinkedList`.
 ///
-/// **Known problems:** False positives – the instances where using a `LinkedList` makes sense are
-/// few and far between, but they can still happen.
+/// **Known problems:** False positives – the instances where using a
+/// `LinkedList` makes sense are few and far between, but they can still happen.
 ///
 /// **Example:**
 /// ```rust
 /// let x = LinkedList::new();
 /// ```
 declare_lint! {
-    pub LINKEDLIST, Warn,
+    pub LINKEDLIST,
+    Warn,
     "usage of LinkedList, usually a vector is faster, or a more specialized data \
      structure like a VecDeque"
 }
@@ -66,22 +69,23 @@ fn get_lints(&self) -> LintArray {
     }
 }
 
-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;
         }
-        if let Some(did) = cx.tcx.def_map.borrow().get(&ast_ty.id) {
-            if let def::Def::Struct(..) = did.full_def() {
-                if Some(did.full_def().def_id()) == cx.tcx.lang_items.owned_box() {
+        if let TyPath(ref qpath) = ast_ty.node {
+            let def = cx.tcx.tables().qpath_def(qpath, ast_ty.id);
+            if let Some(def_id) = opt_def_id(def) {
+                if Some(def_id) == cx.tcx.lang_items.owned_box() {
+                    let last = last_path_segment(qpath);
                     if_let_chain! {[
-                        let TyPath(_, ref path) = ast_ty.node,
-                        let Some(ref last) = path.segments.last(),
                         let PathParameters::AngleBracketedParameters(ref ag) = last.parameters,
                         let Some(ref vec) = ag.types.get(0),
-                        let Some(did) = cx.tcx.def_map.borrow().get(&vec.id),
-                        let def::Def::Struct(..) = did.full_def(),
-                        match_def_path(cx, did.full_def().def_id(), &paths::VEC),
+                        let TyPath(ref qpath) = vec.node,
+                        let def::Def::Struct(..) = cx.tcx.tables().qpath_def(qpath, vec.id),
+                        let Some(did) = opt_def_id(cx.tcx.tables().qpath_def(qpath, vec.id)),
+                        match_def_path(cx, did, &paths::VEC),
                     ], {
                         span_help_and_lint(cx,
                                            BOX_VEC,
@@ -89,12 +93,12 @@ fn check_ty(&mut self, cx: &LateContext, ast_ty: &Ty) {
                                            "you seem to be trying to use `Box<Vec<T>>`. Consider using just `Vec<T>`",
                                            "`Vec<T>` is already on the heap, `Box<Vec<T>>` makes an extra allocation.");
                     }}
-                } else if match_def_path(cx, did.full_def().def_id(), &paths::LINKED_LIST) {
+                } else if match_def_path(cx, def_id, &paths::LINKED_LIST) {
                     span_help_and_lint(cx,
-                                       LINKEDLIST,
-                                       ast_ty.span,
-                                       "I see you're using a LinkedList! Perhaps you meant some other data structure?",
-                                       "a VecDeque might work");
+                                        LINKEDLIST,
+                                        ast_ty.span,
+                                        "I see you're using a LinkedList! Perhaps you meant some other data structure?",
+                                        "a VecDeque might work");
                 }
             }
         }
@@ -104,33 +108,41 @@ fn check_ty(&mut self, cx: &LateContext, ast_ty: &Ty) {
 #[allow(missing_copy_implementations)]
 pub struct LetPass;
 
-/// **What it does:** This lint checks for binding a unit value.
+/// **What it does:** Checks for binding a unit value.
 ///
-/// **Why is this bad?** A unit value cannot usefully be used anywhere. So binding one is kind of pointless.
+/// **Why is this bad?** A unit value cannot usefully be used anywhere. So
+/// binding one is kind of pointless.
 ///
-/// **Known problems:** None
+/// **Known problems:** None.
 ///
-/// **Example:** `let x = { 1; };`
+/// **Example:**
+/// ```rust
+/// let x = { 1; };
+/// ```
 declare_lint! {
-    pub LET_UNIT_VALUE, Warn,
+    pub LET_UNIT_VALUE,
+    Warn,
     "creating a let binding to a value of unit type, which usually can't be used afterwards"
 }
 
 fn check_let_unit(cx: &LateContext, decl: &Decl) {
     if let DeclLocal(ref local) = decl.node {
-        let bindtype = &cx.tcx.pat_ty(&local.pat).sty;
-        if *bindtype == ty::TyTuple(&[]) {
-            if in_external_macro(cx, decl.span) || in_macro(cx, local.pat.span) {
-                return;
-            }
-            if higher::is_from_for_desugar(decl) {
-                return;
+        let bindtype = &cx.tcx.tables().pat_ty(&local.pat).sty;
+        match *bindtype {
+            ty::TyTuple(slice) if slice.is_empty() => {
+                if in_external_macro(cx, decl.span) || in_macro(cx, local.pat.span) {
+                    return;
+                }
+                if higher::is_from_for_desugar(decl) {
+                    return;
+                }
+                span_lint(cx,
+                          LET_UNIT_VALUE,
+                          decl.span,
+                          &format!("this let-binding has unit value. Consider omitting `let {} =`",
+                                   snippet(cx, local.pat.span, "..")));
             }
-            span_lint(cx,
-                      LET_UNIT_VALUE,
-                      decl.span,
-                      &format!("this let-binding has unit value. Consider omitting `let {} =`",
-                               snippet(cx, local.pat.span, "..")));
+            _ => (),
         }
     }
 }
@@ -141,22 +153,32 @@ fn get_lints(&self) -> LintArray {
     }
 }
 
-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)
     }
 }
 
-/// **What it does:** This lint checks for comparisons to unit.
+/// **What it does:** Checks for comparisons to unit.
 ///
-/// **Why is this bad?** Unit is always equal to itself, and thus is just a clumsily written constant. Mostly this happens when someone accidentally adds semicolons at the end of the operands.
+/// **Why is this bad?** Unit is always equal to itself, and thus is just a
+/// clumsily written constant. Mostly this happens when someone accidentally
+/// adds semicolons at the end of the operands.
 ///
-/// **Known problems:** None
+/// **Known problems:** None.
 ///
-/// **Example:** `if { foo(); } == { bar(); } { baz(); }` is equal to `{ foo(); bar(); baz(); }`
+/// **Example:**
+/// ```rust
+/// if { foo(); } == { bar(); } { baz(); }
+/// ```
+/// is equal to
+/// ```rust
+/// { foo(); bar(); baz(); }
+/// ```
 declare_lint! {
-    pub UNIT_CMP, Warn,
-    "comparing unit values (which is always `true` or `false`, respectively)"
+    pub UNIT_CMP,
+    Warn,
+    "comparing unit values"
 }
 
 #[allow(missing_copy_implementations)]
@@ -168,25 +190,30 @@ fn get_lints(&self) -> LintArray {
     }
 }
 
-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;
         }
         if let ExprBinary(ref cmp, ref left, _) = expr.node {
             let op = cmp.node;
-            let sty = &cx.tcx.expr_ty(left).sty;
-            if *sty == ty::TyTuple(&[]) && op.is_comparison() {
-                let result = match op {
-                    BiEq | BiLe | BiGe => "true",
-                    _ => "false",
-                };
-                span_lint(cx,
-                          UNIT_CMP,
-                          expr.span,
-                          &format!("{}-comparison of unit values detected. This will always be {}",
-                                   op.as_str(),
-                                   result));
+            if op.is_comparison() {
+                let sty = &cx.tcx.tables().expr_ty(left).sty;
+                match *sty {
+                    ty::TyTuple(slice) if slice.is_empty() => {
+                        let result = match op {
+                            BiEq | BiLe | BiGe => "true",
+                            _ => "false",
+                        };
+                        span_lint(cx,
+                                  UNIT_CMP,
+                                  expr.span,
+                                  &format!("{}-comparison of unit values detected. This will always be {}",
+                                           op.as_str(),
+                                           result));
+                    }
+                    _ => ()
+                }
             }
         }
     }
@@ -194,54 +221,94 @@ fn check_expr(&mut self, cx: &LateContext, expr: &Expr) {
 
 pub struct CastPass;
 
-/// **What it does:** This lint checks for casts from any numerical to a float type where the receiving type cannot store all values from the original type without rounding errors. This possible rounding is to be expected, so this lint is `Allow` by default.
+/// **What it does:** Checks for casts from any numerical to a float type where
+/// the receiving type cannot store all values from the original type without
+/// rounding errors. This possible rounding is to be expected, so this lint is
+/// `Allow` by default.
 ///
-/// Basically, this warns on casting any integer with 32 or more bits to `f32` or any 64-bit integer to `f64`.
+/// Basically, this warns on casting any integer with 32 or more bits to `f32`
+/// or any 64-bit integer to `f64`.
 ///
-/// **Why is this bad?** It's not bad at all. But in some applications it can be helpful to know where precision loss can take place. This lint can help find those places in the code.
+/// **Why is this bad?** It's not bad at all. But in some applications it can be
+/// helpful to know where precision loss can take place. This lint can help find
+/// those places in the code.
 ///
-/// **Known problems:** None
+/// **Known problems:** None.
 ///
-/// **Example:** `let x = u64::MAX; x as f64`
+/// **Example:**
+/// ```rust
+/// let x = u64::MAX; x as f64
+/// ```
 declare_lint! {
-    pub CAST_PRECISION_LOSS, Allow,
+    pub CAST_PRECISION_LOSS,
+    Allow,
     "casts that cause loss of precision, e.g `x as f32` where `x: u64`"
 }
 
-/// **What it does:** This lint checks for casts from a signed to an unsigned numerical type. In this case, negative values wrap around to large positive values, which can be quite surprising in practice. However, as the cast works as defined, this lint is `Allow` by default.
+/// **What it does:** Checks for casts from a signed to an unsigned numerical
+/// type. In this case, negative values wrap around to large positive values,
+/// which can be quite surprising in practice. However, as the cast works as
+/// defined, this lint is `Allow` by default.
 ///
-/// **Why is this bad?** Possibly surprising results. You can activate this lint as a one-time check to see where numerical wrapping can arise.
+/// **Why is this bad?** Possibly surprising results. You can activate this lint
+/// as a one-time check to see where numerical wrapping can arise.
 ///
-/// **Known problems:** None
+/// **Known problems:** None.
 ///
-/// **Example:** `let y : i8 = -1; y as u64` will return 18446744073709551615
+/// **Example:**
+/// ```rust
+/// let y: i8 = -1;
+/// y as u64  // will return 18446744073709551615
+/// ```
 declare_lint! {
-    pub CAST_SIGN_LOSS, Allow,
+    pub CAST_SIGN_LOSS,
+    Allow,
     "casts from signed types to unsigned types, e.g `x as u32` where `x: i32`"
 }
 
-/// **What it does:** This lint checks for on casts between numerical types that may truncate large values. This is expected behavior, so the cast is `Allow` by default.
+/// **What it does:** Checks for on casts between numerical types that may
+/// truncate large values. This is expected behavior, so the cast is `Allow` by
+/// default.
 ///
-/// **Why is this bad?** In some problem domains, it is good practice to avoid truncation. This lint can be activated to help assess where additional checks could be beneficial.
+/// **Why is this bad?** In some problem domains, it is good practice to avoid
+/// truncation. This lint can be activated to help assess where additional
+/// checks could be beneficial.
 ///
-/// **Known problems:** None
+/// **Known problems:** None.
 ///
-/// **Example:** `fn as_u8(x: u64) -> u8 { x as u8 }`
+/// **Example:**
+/// ```rust
+/// fn as_u8(x: u64) -> u8 { x as u8 }
+/// ```
 declare_lint! {
-    pub CAST_POSSIBLE_TRUNCATION, Allow,
-    "casts that may cause truncation of the value, e.g `x as u8` where `x: u32`, or `x as i32` where `x: f32`"
+    pub CAST_POSSIBLE_TRUNCATION,
+    Allow,
+    "casts that may cause truncation of the value, e.g `x as u8` where `x: u32`, \
+     or `x as i32` where `x: f32`"
 }
 
-/// **What it does:** This lint checks for casts from an unsigned type to a signed type of the same size. Performing such a cast is a 'no-op' for the compiler, i.e. nothing is changed at the bit level, and the binary representation of the value is reinterpreted. This can cause wrapping if the value is too big for the target signed type. However, the cast works as defined, so this lint is `Allow` by default.
+/// **What it does:** Checks for casts from an unsigned type to a signed type of
+/// the same size. Performing such a cast is a 'no-op' for the compiler,
+/// i.e. nothing is changed at the bit level, and the binary representation of
+/// the value is reinterpreted. This can cause wrapping if the value is too big
+/// for the target signed type. However, the cast works as defined, so this lint
+/// is `Allow` by default.
 ///
-/// **Why is this bad?** While such a cast is not bad in itself, the results can be surprising when this is not the intended behavior, as demonstrated by the example below.
+/// **Why is this bad?** While such a cast is not bad in itself, the results can
+/// be surprising when this is not the intended behavior, as demonstrated by the
+/// example below.
 ///
-/// **Known problems:** None
+/// **Known problems:** None.
 ///
-/// **Example:** `u32::MAX as i32` will yield a value of `-1`.
+/// **Example:**
+/// ```rust
+/// u32::MAX as i32  // will yield a value of `-1`
+/// ```
 declare_lint! {
-    pub CAST_POSSIBLE_WRAP, Allow,
-    "casts that may cause wrapping around the value, e.g `x as i32` where `x: u32` and `x > i32::MAX`"
+    pub CAST_POSSIBLE_WRAP,
+    Allow,
+    "casts that may cause wrapping around the value, e.g `x as i32` where `x: u32` \
+     and `x > i32::MAX`"
 }
 
 /// Returns the size in bits of an integral type.
@@ -380,10 +447,10 @@ fn get_lints(&self) -> LintArray {
     }
 }
 
-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.expr_ty(ex), cx.tcx.expr_ty(expr));
+            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) {
                 match (cast_from.is_integral(), cast_to.is_integral()) {
                     (true, false) => {
@@ -433,16 +500,22 @@ fn check_expr(&mut self, cx: &LateContext, expr: &Expr) {
     }
 }
 
-/// **What it does:** This lint checks for types used in structs, parameters and `let` declarations above a certain complexity threshold.
+/// **What it does:** Checks for types used in structs, parameters and `let`
+/// declarations above a certain complexity threshold.
 ///
-/// **Why is this bad?** Too complex types make the code less readable. Consider using a `type` definition to simplify them.
+/// **Why is this bad?** Too complex types make the code less readable. Consider
+/// using a `type` definition to simplify them.
 ///
-/// **Known problems:** None
+/// **Known problems:** None.
 ///
-/// **Example:** `struct Foo { inner: Rc<Vec<Vec<Box<(u32, u32, u32, u32)>>>> }`
+/// **Example:**
+/// ```rust
+/// struct Foo { inner: Rc<Vec<Vec<Box<(u32, u32, u32, u32)>>>> }
+/// ```
 declare_lint! {
-    pub TYPE_COMPLEXITY, Warn,
-    "usage of very complex types; recommends factoring out parts into `type` definitions"
+    pub TYPE_COMPLEXITY,
+    Warn,
+    "usage of very complex types that might be better factored into `type` definitions"
 }
 
 #[allow(missing_copy_implementations)]
@@ -462,17 +535,17 @@ fn get_lints(&self) -> LintArray {
     }
 }
 
-impl LateLintPass for TypeComplexityPass {
-    fn check_fn(&mut self, cx: &LateContext, _: FnKind, decl: &FnDecl, _: &Block, _: 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),
@@ -481,7 +554,7 @@ fn check_item(&mut self, cx: &LateContext, item: &Item) {
         }
     }
 
-    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),
@@ -491,7 +564,7 @@ fn check_trait_item(&mut self, cx: &LateContext, item: &TraitItem) {
         }
     }
 
-    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),
@@ -500,15 +573,15 @@ fn check_impl_item(&mut self, cx: &LateContext, item: &ImplItem) {
         }
     }
 
-    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);
         }
@@ -517,7 +590,7 @@ fn check_fndecl(&self, cx: &LateContext, decl: &FnDecl) {
         }
     }
 
-    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;
         }
@@ -525,6 +598,7 @@ fn check_type(&self, cx: &LateContext, ty: &Ty) {
             let mut visitor = TypeComplexityVisitor {
                 score: 0,
                 nest: 1,
+                cx: cx,
             };
             visitor.visit_ty(ty);
             visitor.score
@@ -540,24 +614,25 @@ fn check_type(&self, cx: &LateContext, ty: &Ty) {
 }
 
 /// 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),
 
             // the "normal" components of a type: named types, arrays/tuples
             TyPath(..) |
-            TyVec(..) |
+            TySlice(..) |
             TyTup(..) |
-            TyFixedLengthVec(..) => (10 * self.nest, 1),
+            TyArray(..) => (10 * self.nest, 1),
 
             // "Sum" of trait bounds
             TyObjectSum(..) => (20 * self.nest, 0),
@@ -573,18 +648,30 @@ fn visit_ty(&mut self, ty: &'v Ty) {
         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:** This lint points out expressions where a character literal is casted to `u8` and suggests using a byte literal instead.
+/// **What it does:** Checks for expressions where a character literal is cast
+/// to `u8` and suggests using a byte literal instead.
 ///
-/// **Why is this bad?** In general, casting values to smaller types is error-prone and should be avoided where possible. In the particular case of converting a character literal to u8, it is easy to avoid by just using a byte literal instead. As an added bonus, `b'a'` is even slightly shorter than `'a' as u8`.
+/// **Why is this bad?** In general, casting values to smaller types is
+/// error-prone and should be avoided where possible. In the particular case of
+/// converting a character literal to u8, it is easy to avoid by just using a
+/// byte literal instead. As an added bonus, `b'a'` is even slightly shorter
+/// than `'a' as u8`.
 ///
-/// **Known problems:** None
+/// **Known problems:** None.
 ///
-/// **Example:** `'x' as u8`
+/// **Example:**
+/// ```rust
+/// 'x' as u8
+/// ```
 declare_lint! {
-    pub CHAR_LIT_AS_U8, Warn,
-    "Casting a character literal to u8"
+    pub CHAR_LIT_AS_U8,
+    Warn,
+    "casting a character literal to u8"
 }
 
 pub struct CharLitAsU8;
@@ -595,14 +682,14 @@ fn get_lints(&self) -> LintArray {
     }
 }
 
-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 {
             if let ExprLit(ref l) = e.node {
                 if let LitKind::Char(_) = l.node {
-                    if ty::TyUint(UintTy::U8) == cx.tcx.expr_ty(expr).sty && !in_macro(cx, expr.span) {
+                    if ty::TyUint(UintTy::U8) == cx.tcx.tables().expr_ty(expr).sty && !in_macro(cx, expr.span) {
                         let msg = "casting character literal to u8. `char`s \
                                    are 4 bytes wide in rust, so casting to u8 \
                                    truncates them";
@@ -617,17 +704,26 @@ fn check_expr(&mut self, cx: &LateContext, expr: &Expr) {
     }
 }
 
-/// **What it does:** This lint checks for comparisons where one side of the relation is either the minimum or maximum value for its type and warns if it involves a case that is always true or always false. Only integer and boolean types are checked.
+/// **What it does:** Checks for comparisons where one side of the relation is
+/// either the minimum or maximum value for its type and warns if it involves a
+/// case that is always true or always false. Only integer and boolean types are
+/// checked.
 ///
-/// **Why is this bad?** An expression like `min <= x` may misleadingly imply that is is possible for `x` to be less than the minimum. Expressions like `max < x` are probably mistakes.
+/// **Why is this bad?** An expression like `min <= x` may misleadingly imply
+/// that is is possible for `x` to be less than the minimum. Expressions like
+/// `max < x` are probably mistakes.
 ///
-/// **Known problems:** None
+/// **Known problems:** None.
 ///
-/// **Example:** `vec.len() <= 0`, `100 > std::i32::MAX`
+/// **Example:**
+/// ```rust
+/// vec.len() <= 0
+/// 100 > std::i32::MAX
+/// ```
 declare_lint! {
-    pub ABSURD_EXTREME_COMPARISONS, Warn,
-    "a comparison involving a maximum or minimum value involves a case that is always \
-    true or always false"
+    pub ABSURD_EXTREME_COMPARISONS,
+    Warn,
+    "a comparison with a maximum or minimum value that is always true or false"
 }
 
 pub struct AbsurdExtremeComparisons;
@@ -661,7 +757,6 @@ fn detect_absurd_comparison<'a>(cx: &LateContext, op: BinOp_, lhs: &'a Expr, rhs
     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 {
@@ -676,17 +771,17 @@ fn detect_absurd_comparison<'a>(cx: &LateContext, op: BinOp_, lhs: &'a Expr, rhs
     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,
             }
         }
@@ -701,7 +796,7 @@ fn detect_extreme_expr<'a>(cx: &LateContext, expr: &'a Expr) -> Option<ExtremeEx
     use rustc_const_eval::*;
     use types::ExtremeType::*;
 
-    let ty = &cx.tcx.expr_ty(expr).sty;
+    let ty = &cx.tcx.tables().expr_ty(expr).sty;
 
     match *ty {
         ty::TyBool | ty::TyInt(_) | ty::TyUint(_) => (),
@@ -750,8 +845,8 @@ fn detect_extreme_expr<'a>(cx: &LateContext, expr: &'a Expr) -> Option<ExtremeEx
     })
 }
 
-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::*;
 
@@ -787,15 +882,23 @@ fn check_expr(&mut self, cx: &LateContext, expr: &Expr) {
     }
 }
 
-/// **What it does:** This lint checks for comparisons where the relation is always either true or false, but where one side has been upcast so that the comparison is necessary. Only integer types are checked.
+/// **What it does:** Checks for comparisons where the relation is always either
+/// true or false, but where one side has been upcast so that the comparison is
+/// necessary. Only integer types are checked.
 ///
-/// **Why is this bad?** An expression like `let x : u8 = ...; (x as u32) > 300` will mistakenly imply that it is possible for `x` to be outside the range of `u8`.
+/// **Why is this bad?** An expression like `let x : u8 = ...; (x as u32) > 300`
+/// will mistakenly imply that it is possible for `x` to be outside the range of
+/// `u8`.
 ///
 /// **Known problems:** https://github.com/Manishearth/rust-clippy/issues/886
 ///
-/// **Example:** `let x : u8 = ...; (x as u32) > 300`
+/// **Example:**
+/// ```rust
+/// let x : u8 = ...; (x as u32) > 300
+/// ```
 declare_lint! {
-    pub INVALID_UPCAST_COMPARISONS, Allow,
+    pub INVALID_UPCAST_COMPARISONS,
+    Allow,
     "a comparison involving an upcast which is always true or false"
 }
 
@@ -855,7 +958,7 @@ fn numeric_cast_precast_bounds<'a>(cx: &LateContext, expr: &'a Expr) -> Option<(
     use std::*;
 
     if let ExprCast(ref cast_exp, _) = expr.node {
-        match cx.tcx.expr_ty(cast_exp).sty {
+        match cx.tcx.tables().expr_ty(cast_exp).sty {
             TyInt(int_ty) => {
                 Some(match int_ty {
                     IntTy::I8 => (FullInt::S(i8::min_value() as i64), FullInt::S(i8::max_value() as i64)),
@@ -967,8 +1070,8 @@ fn upcast_comparison_bounds_err(cx: &LateContext, span: &Span, rel: comparisons:
     }
 }
 
-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);