]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/ptr_offset_with_cast.rs
Merge commit '4911ab124c481430672a3833b37075e6435ec34d' into clippyup
[rust.git] / clippy_lints / src / ptr_offset_with_cast.rs
index b35a7e64bff2740bddfe01b7299da39f4d014162..e0996804a5934a8ad77c83a30fc363c3452c7e82 100644 (file)
@@ -3,6 +3,7 @@
 use rustc_hir::{Expr, ExprKind};
 use rustc_lint::{LateContext, LateLintPass};
 use rustc_session::{declare_lint_pass, declare_tool_lint};
+use rustc_span::sym;
 use std::fmt;
 
 declare_clippy_lint! {
@@ -43,8 +44,8 @@
 
 declare_lint_pass!(PtrOffsetWithCast => [PTR_OFFSET_WITH_CAST]);
 
-impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PtrOffsetWithCast {
-    fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
+impl<'tcx> LateLintPass<'tcx> for PtrOffsetWithCast {
+    fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
         // Check if the expressions is a ptr.offset or ptr.wrapping_offset method call
         let (receiver_expr, arg_expr, method) = match expr_as_ptr_offset_call(cx, expr) {
             Some(call_arg) => call_arg,
@@ -75,7 +76,7 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
 }
 
 // If the given expression is a cast from a usize, return the lhs of the cast
-fn expr_as_cast_from_usize<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'tcx>) -> Option<&'tcx Expr<'tcx>> {
+fn expr_as_cast_from_usize<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Option<&'tcx Expr<'tcx>> {
     if let ExprKind::Cast(ref cast_lhs_expr, _) = expr.kind {
         if is_expr_ty_usize(cx, &cast_lhs_expr) {
             return Some(cast_lhs_expr);
@@ -86,13 +87,13 @@ fn expr_as_cast_from_usize<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Exp
 
 // If the given expression is a ptr::offset  or ptr::wrapping_offset method call, return the
 // receiver, the arg of the method call, and the method.
-fn expr_as_ptr_offset_call<'a, 'tcx>(
-    cx: &LateContext<'a, 'tcx>,
+fn expr_as_ptr_offset_call<'tcx>(
+    cx: &LateContext<'tcx>,
     expr: &'tcx Expr<'_>,
 ) -> Option<(&'tcx Expr<'tcx>, &'tcx Expr<'tcx>, Method)> {
     if let ExprKind::MethodCall(ref path_segment, _, ref args, _) = expr.kind {
         if is_expr_ty_raw_ptr(cx, &args[0]) {
-            if path_segment.ident.name == sym!(offset) {
+            if path_segment.ident.name == sym::offset {
                 return Some((&args[0], &args[1], Method::Offset));
             }
             if path_segment.ident.name == sym!(wrapping_offset) {
@@ -104,17 +105,17 @@ fn expr_as_ptr_offset_call<'a, 'tcx>(
 }
 
 // Is the type of the expression a usize?
-fn is_expr_ty_usize<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr<'_>) -> bool {
-    cx.tables().expr_ty(expr) == cx.tcx.types.usize
+fn is_expr_ty_usize<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>) -> bool {
+    cx.typeck_results().expr_ty(expr) == cx.tcx.types.usize
 }
 
 // Is the type of the expression a raw pointer?
-fn is_expr_ty_raw_ptr<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr<'_>) -> bool {
-    cx.tables().expr_ty(expr).is_unsafe_ptr()
+fn is_expr_ty_raw_ptr<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>) -> bool {
+    cx.typeck_results().expr_ty(expr).is_unsafe_ptr()
 }
 
-fn build_suggestion<'a, 'tcx>(
-    cx: &LateContext<'a, 'tcx>,
+fn build_suggestion<'tcx>(
+    cx: &LateContext<'tcx>,
     method: Method,
     receiver_expr: &Expr<'_>,
     cast_lhs_expr: &Expr<'_>,