]> git.lizzy.rs Git - rust.git/blobdiff - src/tools/clippy/clippy_lints/src/ptr_offset_with_cast.rs
Auto merge of #86031 - ssomers:btree_lazy_iterator, r=Mark-Simulacrum
[rust.git] / src / tools / clippy / clippy_lints / src / ptr_offset_with_cast.rs
index e0996804a5934a8ad77c83a30fc363c3452c7e82..f1975056ddc9ba40751c82161bdc96f14cafc0fd 100644 (file)
@@ -1,4 +1,5 @@
-use crate::utils::{snippet_opt, span_lint, span_lint_and_sugg};
+use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg};
+use clippy_utils::source::snippet_opt;
 use rustc_errors::Applicability;
 use rustc_hir::{Expr, ExprKind};
 use rustc_lint::{LateContext, LateLintPass};
@@ -7,15 +8,15 @@
 use std::fmt;
 
 declare_clippy_lint! {
-    /// **What it does:** Checks for usage of the `offset` pointer method with a `usize` casted to an
+    /// ### What it does
+    /// Checks for usage of the `offset` pointer method with a `usize` casted to an
     /// `isize`.
     ///
-    /// **Why is this bad?** If we’re always increasing the pointer address, we can avoid the numeric
+    /// ### Why is this bad?
+    /// If we’re always increasing the pointer address, we can avoid the numeric
     /// cast by using the `add` method instead.
     ///
-    /// **Known problems:** None
-    ///
-    /// **Example:**
+    /// ### Example
     /// ```rust
     /// let vec = vec![b'a', b'b', b'c'];
     /// let ptr = vec.as_ptr();
@@ -77,8 +78,8 @@ fn check_expr(&mut self, cx: &LateContext<'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<'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) {
+    if let ExprKind::Cast(cast_lhs_expr, _) = expr.kind {
+        if is_expr_ty_usize(cx, cast_lhs_expr) {
             return Some(cast_lhs_expr);
         }
     }
@@ -91,7 +92,7 @@ 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 let ExprKind::MethodCall(path_segment, _, args, _) = expr.kind {
         if is_expr_ty_raw_ptr(cx, &args[0]) {
             if path_segment.ident.name == sym::offset {
                 return Some((&args[0], &args[1], Method::Offset));