]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/unused_unit.rs
Auto merge of #6304 - matthiaskrgr:crash_6302, r=llogiq
[rust.git] / clippy_lints / src / unused_unit.rs
index 7548c6afa973afec4838369bb06ed8b6bd5efd3c..f61fd2ecd735d915964c5b3ce80bfaa6da56e29e 100644 (file)
@@ -7,7 +7,7 @@
 use rustc_span::source_map::Span;
 use rustc_span::BytePos;
 
-use crate::utils::span_lint_and_sugg;
+use crate::utils::{position_before_rarrow, span_lint_and_sugg};
 
 declare_clippy_lint! {
     /// **What it does:** Checks for unit (`()`) expressions that can be removed.
@@ -120,15 +120,13 @@ fn is_unit_expr(expr: &ast::Expr) -> bool {
 
 fn lint_unneeded_unit_return(cx: &EarlyContext<'_>, ty: &ast::Ty, span: Span) {
     let (ret_span, appl) = if let Ok(fn_source) = cx.sess().source_map().span_to_snippet(span.with_hi(ty.span.hi())) {
-        fn_source
-            .rfind("->")
-            .map_or((ty.span, Applicability::MaybeIncorrect), |rpos| {
-                (
-                    #[allow(clippy::cast_possible_truncation)]
-                    ty.span.with_lo(BytePos(span.lo().0 + rpos as u32)),
-                    Applicability::MachineApplicable,
-                )
-            })
+        position_before_rarrow(fn_source).map_or((ty.span, Applicability::MaybeIncorrect), |rpos| {
+            (
+                #[allow(clippy::cast_possible_truncation)]
+                ty.span.with_lo(BytePos(span.lo().0 + rpos as u32)),
+                Applicability::MachineApplicable,
+            )
+        })
     } else {
         (ty.span, Applicability::MaybeIncorrect)
     };