about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMax Baumann <max@bmn.dev>2022-03-17 19:13:44 +0100
committerMax Baumann <max@bmn.dev>2022-03-17 19:13:44 +0100
commit3f00f074de3f6debe594e11066864a0da1dfe4af (patch)
tree577d2fa8f59c5386a819d4c16735a8832d6f8383
parentf49a2c345780abca24d4f5a5f9f821ea961c8fb6 (diff)
downloadrust-3f00f074de3f6debe594e11066864a0da1dfe4af.tar.gz
rust-3f00f074de3f6debe594e11066864a0da1dfe4af.zip
fix: fix tests
-rw-r--r--clippy_lints/src/use_unwrap_or.rs22
-rw-r--r--tests/ui/use_unwrap_or.rs6
-rw-r--r--tests/ui/use_unwrap_or.stderr4
3 files changed, 15 insertions, 17 deletions
diff --git a/clippy_lints/src/use_unwrap_or.rs b/clippy_lints/src/use_unwrap_or.rs
index f42e28246d4..05369000444 100644
--- a/clippy_lints/src/use_unwrap_or.rs
+++ b/clippy_lints/src/use_unwrap_or.rs
@@ -1,11 +1,10 @@
+use clippy_utils::diagnostics::span_lint_and_help;
+use clippy_utils::ty::is_type_diagnostic_item;
 use if_chain::if_chain;
-use rustc_hir::*;
+use rustc_hir::{Expr, ExprKind, QPath};
 use rustc_lint::{LateContext, LateLintPass};
 use rustc_session::{declare_lint_pass, declare_tool_lint};
-use rustc_span::{Span, sym};
-use clippy_utils::diagnostics::span_lint_and_help;
-use clippy_utils::ty::is_type_diagnostic_item;
-
+use rustc_span::{sym, Span};
 
 declare_clippy_lint! {
     /// ### What it does
@@ -39,7 +38,6 @@ declare_lint_pass!(UseUnwrapOr => [USE_UNWRAP_OR]);
 
 impl<'tcx> LateLintPass<'tcx> for UseUnwrapOr {
     fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
-
         // look for x.or().unwrap()
         if_chain! {
             if let ExprKind::MethodCall(path, args, unwrap_span) = expr.kind;
@@ -52,13 +50,13 @@ impl<'tcx> LateLintPass<'tcx> for UseUnwrapOr {
                 let title;
                 let arg = &caller_args[1]; // the argument or(xyz) is called with
 
-                if is_type_diagnostic_item(&cx, ty, sym::Option) {
+                if is_type_diagnostic_item(cx, ty, sym::Option) {
                     title = ".or(Some(…)).unwrap() found";
                     if !is(arg, "Some") {
                         return;
                     }
 
-                } else if is_type_diagnostic_item(&cx, ty, sym::Result) {
+                } else if is_type_diagnostic_item(cx, ty, sym::Result) {
                     title = ".or(Ok(…)).unwrap() found";
                     if !is(arg, "Ok") {
                         return;
@@ -90,16 +88,14 @@ impl<'tcx> LateLintPass<'tcx> for UseUnwrapOr {
 fn is<'a>(expr: &Expr<'a>, name: &str) -> bool {
     if_chain! {
         if let ExprKind::Call(some_expr, _some_args) = expr.kind;
-        if let ExprKind::Path(path) = &some_expr.kind;
-        if let QPath::Resolved(_, path) = path;
+        if let ExprKind::Path(QPath::Resolved(_, path)) = &some_expr.kind;
         if let Some(path_segment) = path.segments.first();
         if path_segment.ident.name.as_str() == name;
         then {
-            return true;
+            true
         }
         else {
-            return false;
+            false
         }
     }
 }
-
diff --git a/tests/ui/use_unwrap_or.rs b/tests/ui/use_unwrap_or.rs
index 0bfabaae885..685fab80206 100644
--- a/tests/ui/use_unwrap_or.rs
+++ b/tests/ui/use_unwrap_or.rs
@@ -2,8 +2,10 @@
 
 struct SomeStruct {}
 impl SomeStruct {
-    fn or(self, _: Option<Self>) -> Self { self }
-    fn unwrap(&self){}
+    fn or(self, _: Option<Self>) -> Self {
+        self
+    }
+    fn unwrap(&self) {}
 }
 
 fn main() {
diff --git a/tests/ui/use_unwrap_or.stderr b/tests/ui/use_unwrap_or.stderr
index 5bbba41f7ac..2e1e920795d 100644
--- a/tests/ui/use_unwrap_or.stderr
+++ b/tests/ui/use_unwrap_or.stderr
@@ -1,5 +1,5 @@
 error: .or(Some(…)).unwrap() found
-  --> $DIR/use_unwrap_or.rs:11:20
+  --> $DIR/use_unwrap_or.rs:13:20
    |
 LL |     let _ = option.or(Some("fallback")).unwrap(); // should trigger lint
    |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -8,7 +8,7 @@ LL |     let _ = option.or(Some("fallback")).unwrap(); // should trigger lint
    = help: use `unwrap_or()` instead
 
 error: .or(Ok(…)).unwrap() found
-  --> $DIR/use_unwrap_or.rs:14:20
+  --> $DIR/use_unwrap_or.rs:16:20
    |
 LL |     let _ = result.or::<&str>(Ok("fallback")).unwrap(); // should trigger lint
    |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^