]> git.lizzy.rs Git - rust.git/commitdiff
Merge pull request #2991 from mikerite/issue2979
authorPhilipp Hansch <dev@phansch.net>
Sun, 5 Aug 2018 19:35:55 +0000 (20:35 +0100)
committerGitHub <noreply@github.com>
Sun, 5 Aug 2018 19:35:55 +0000 (20:35 +0100)
Fix #2979

clippy_lints/src/methods.rs
tests/ui/methods.rs
tests/ui/methods.stderr

index 9a6d3df3088f8b4f84e066f4a5de46e18c6b6704..c8f3e0db3240895644170399d9f26ed69c1ab2a9 100644 (file)
@@ -1047,10 +1047,21 @@ fn check_general_case(
             return;
         }
 
-        // don't lint for constant values
-        let owner_def = cx.tcx.hir.get_parent_did(arg.id);
-        let promotable = cx.tcx.rvalue_promotable_map(owner_def).contains(&arg.hir_id.local_id);
-        if promotable {
+        fn is_call(node: &hir::ExprKind) -> bool {
+            match node {
+                hir::ExprKind::AddrOf(_, expr) => {
+                    is_call(&expr.node)
+                },
+                hir::ExprKind::Call(..)
+                | hir::ExprKind::MethodCall(..)
+                // These variants are debatable or require further examination
+                | hir::ExprKind::If(..)
+                | hir::ExprKind::Match(..) => true,
+                _ => false,
+            }
+        }
+
+        if !is_call(&arg.node) {
             return;
         }
 
index 7f0da364c7a35c8604230ae6e0079ae59bb919b3..220b08caaf760b3b73bef7c355a25d7965f5c5f0 100644 (file)
@@ -389,6 +389,10 @@ fn expect(&self, msg: &str) {
 
     let with_dummy_type_and_as_str = Foo::new();
     with_dummy_type_and_as_str.expect(format!("Error {}: fake error", error_code).as_str());
+
+    //Issue #2979 - this should not lint
+    let msg = "bar";
+    Some("foo").expect(msg);
 }
 
 /// Checks implementation of `ITER_NTH` lint
index 12665244b9d59488c434587c99e598ec3c83ae5a..a3b67bf9f6d23487b334ba74c81741b15387e050 100644 (file)
@@ -358,79 +358,79 @@ error: use of `expect` followed by a function call
     |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|_| panic!(format!("Error {}: fake error", error_code).as_str()))`
 
 error: called `.iter().nth()` on a Vec. Calling `.get()` is both faster and more readable
-   --> $DIR/methods.rs:402:23
+   --> $DIR/methods.rs:406:23
     |
-402 |         let bad_vec = some_vec.iter().nth(3);
+406 |         let bad_vec = some_vec.iter().nth(3);
     |                       ^^^^^^^^^^^^^^^^^^^^^^
     |
     = note: `-D iter-nth` implied by `-D warnings`
 
 error: called `.iter().nth()` on a slice. Calling `.get()` is both faster and more readable
-   --> $DIR/methods.rs:403:26
+   --> $DIR/methods.rs:407:26
     |
-403 |         let bad_slice = &some_vec[..].iter().nth(3);
+407 |         let bad_slice = &some_vec[..].iter().nth(3);
     |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error: called `.iter().nth()` on a slice. Calling `.get()` is both faster and more readable
-   --> $DIR/methods.rs:404:31
+   --> $DIR/methods.rs:408:31
     |
-404 |         let bad_boxed_slice = boxed_slice.iter().nth(3);
+408 |         let bad_boxed_slice = boxed_slice.iter().nth(3);
     |                               ^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error: called `.iter().nth()` on a VecDeque. Calling `.get()` is both faster and more readable
-   --> $DIR/methods.rs:405:29
+   --> $DIR/methods.rs:409:29
     |
-405 |         let bad_vec_deque = some_vec_deque.iter().nth(3);
+409 |         let bad_vec_deque = some_vec_deque.iter().nth(3);
     |                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error: called `.iter_mut().nth()` on a Vec. Calling `.get_mut()` is both faster and more readable
-   --> $DIR/methods.rs:410:23
+   --> $DIR/methods.rs:414:23
     |
-410 |         let bad_vec = some_vec.iter_mut().nth(3);
+414 |         let bad_vec = some_vec.iter_mut().nth(3);
     |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error: called `.iter_mut().nth()` on a slice. Calling `.get_mut()` is both faster and more readable
-   --> $DIR/methods.rs:413:26
+   --> $DIR/methods.rs:417:26
     |
-413 |         let bad_slice = &some_vec[..].iter_mut().nth(3);
+417 |         let bad_slice = &some_vec[..].iter_mut().nth(3);
     |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error: called `.iter_mut().nth()` on a VecDeque. Calling `.get_mut()` is both faster and more readable
-   --> $DIR/methods.rs:416:29
+   --> $DIR/methods.rs:420:29
     |
-416 |         let bad_vec_deque = some_vec_deque.iter_mut().nth(3);
+420 |         let bad_vec_deque = some_vec_deque.iter_mut().nth(3);
     |                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error: called `skip(x).next()` on an iterator. This is more succinctly expressed by calling `nth(x)`
-   --> $DIR/methods.rs:428:13
+   --> $DIR/methods.rs:432:13
     |
-428 |     let _ = some_vec.iter().skip(42).next();
+432 |     let _ = some_vec.iter().skip(42).next();
     |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |
     = note: `-D iter-skip-next` implied by `-D warnings`
 
 error: called `skip(x).next()` on an iterator. This is more succinctly expressed by calling `nth(x)`
-   --> $DIR/methods.rs:429:13
+   --> $DIR/methods.rs:433:13
     |
-429 |     let _ = some_vec.iter().cycle().skip(42).next();
+433 |     let _ = some_vec.iter().cycle().skip(42).next();
     |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error: called `skip(x).next()` on an iterator. This is more succinctly expressed by calling `nth(x)`
-   --> $DIR/methods.rs:430:13
+   --> $DIR/methods.rs:434:13
     |
-430 |     let _ = (1..10).skip(10).next();
+434 |     let _ = (1..10).skip(10).next();
     |             ^^^^^^^^^^^^^^^^^^^^^^^
 
 error: called `skip(x).next()` on an iterator. This is more succinctly expressed by calling `nth(x)`
-   --> $DIR/methods.rs:431:14
+   --> $DIR/methods.rs:435:14
     |
-431 |     let _ = &some_vec[..].iter().skip(3).next();
+435 |     let _ = &some_vec[..].iter().skip(3).next();
     |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error: used unwrap() on an Option value. If you don't want to handle the None case gracefully, consider using expect() to provide a better panic message
-   --> $DIR/methods.rs:440:13
+   --> $DIR/methods.rs:444:13
     |
-440 |     let _ = opt.unwrap();
+444 |     let _ = opt.unwrap();
     |             ^^^^^^^^^^^^
     |
     = note: `-D option-unwrap-used` implied by `-D warnings`