3397: UI test cleanup: Extract expect_fun_call tests r=matthiaskrgr a=phansch

Note that the new stderr file does not include a `shadow-unrelated`
error, because the new UI test file does not use `#![warn(clippy::all)]`

cc #2038 

3398: UI test cleanup: Extract match_overlapping_arm tests r=matthiaskrgr a=phansch

cc #2038

Co-authored-by: Philipp Hansch <dev@phansch.net>
This commit is contained in:
bors[bot] 2018-11-02 07:34:38 +00:00
commit ae137d526c
8 changed files with 384 additions and 368 deletions

View File

@ -0,0 +1,69 @@
// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![warn(clippy::expect_fun_call)]
#![allow(clippy::useless_format)]
/// Checks implementation of the `EXPECT_FUN_CALL` lint
fn expect_fun_call() {
struct Foo;
impl Foo {
fn new() -> Self { Foo }
fn expect(&self, msg: &str) {
panic!("{}", msg)
}
}
let with_some = Some("value");
with_some.expect("error");
let with_none: Option<i32> = None;
with_none.expect("error");
let error_code = 123_i32;
let with_none_and_format: Option<i32> = None;
with_none_and_format.expect(&format!("Error {}: fake error", error_code));
let with_none_and_as_str: Option<i32> = None;
with_none_and_as_str.expect(format!("Error {}: fake error", error_code).as_str());
let with_ok: Result<(), ()> = Ok(());
with_ok.expect("error");
let with_err: Result<(), ()> = Err(());
with_err.expect("error");
let error_code = 123_i32;
let with_err_and_format: Result<(), ()> = Err(());
with_err_and_format.expect(&format!("Error {}: fake error", error_code));
let with_err_and_as_str: Result<(), ()> = Err(());
with_err_and_as_str.expect(format!("Error {}: fake error", error_code).as_str());
let with_dummy_type = Foo::new();
with_dummy_type.expect("another test string");
let with_dummy_type_and_format = Foo::new();
with_dummy_type_and_format.expect(&format!("Error {}: fake error", error_code));
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);
Some("foo").expect({ &format!("error") });
Some("foo").expect(format!("error").as_ref());
}
fn main() {}

View File

@ -0,0 +1,40 @@
error: use of `expect` followed by a function call
--> $DIR/expect_fun_call.rs:34:26
|
34 | with_none_and_format.expect(&format!("Error {}: fake error", error_code));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("Error {}: fake error", error_code))`
|
= note: `-D clippy::expect-fun-call` implied by `-D warnings`
error: use of `expect` followed by a function call
--> $DIR/expect_fun_call.rs:37:26
|
37 | with_none_and_as_str.expect(format!("Error {}: fake error", error_code).as_str());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("Error {}: fake error", error_code))`
error: use of `expect` followed by a function call
--> $DIR/expect_fun_call.rs:47:25
|
47 | with_err_and_format.expect(&format!("Error {}: fake error", error_code));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|_| panic!("Error {}: fake error", error_code))`
error: use of `expect` followed by a function call
--> $DIR/expect_fun_call.rs:50:25
|
50 | with_err_and_as_str.expect(format!("Error {}: fake error", error_code).as_str());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|_| panic!("Error {}: fake error", error_code))`
error: use of `expect` followed by a function call
--> $DIR/expect_fun_call.rs:65:17
|
65 | Some("foo").expect({ &format!("error") });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { let msg = { &format!("error") }; panic!(msg) }))`
error: use of `expect` followed by a function call
--> $DIR/expect_fun_call.rs:66:17
|
66 | Some("foo").expect(format!("error").as_ref());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("error"))`
error: aborting due to 6 previous errors

View File

@ -0,0 +1,75 @@
// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(exclusive_range_pattern)]
#![warn(clippy::match_overlapping_arm)]
#![allow(clippy::redundant_pattern_matching)]
/// Tests for match_overlapping_arm
fn overlapping() {
const FOO : u64 = 2;
match 42 {
0 ... 10 => println!("0 ... 10"),
0 ... 11 => println!("0 ... 11"),
_ => (),
}
match 42 {
0 ... 5 => println!("0 ... 5"),
6 ... 7 => println!("6 ... 7"),
FOO ... 11 => println!("0 ... 11"),
_ => (),
}
match 42 {
2 => println!("2"),
0 ... 5 => println!("0 ... 5"),
_ => (),
}
match 42 {
2 => println!("2"),
0 ... 2 => println!("0 ... 2"),
_ => (),
}
match 42 {
0 ... 10 => println!("0 ... 10"),
11 ... 50 => println!("11 ... 50"),
_ => (),
}
match 42 {
2 => println!("2"),
0 .. 2 => println!("0 .. 2"),
_ => (),
}
match 42 {
0 .. 10 => println!("0 .. 10"),
10 .. 50 => println!("10 .. 50"),
_ => (),
}
match 42 {
0 .. 11 => println!("0 .. 11"),
0 ... 11 => println!("0 ... 11"),
_ => (),
}
if let None = Some(42) {
// nothing
} else if let None = Some(42) {
// another nothing :-)
}
}
fn main() {}

View File

@ -0,0 +1,63 @@
error: some ranges overlap
--> $DIR/match_overlapping_arm.rs:20:9
|
20 | 0 ... 10 => println!("0 ... 10"),
| ^^^^^^^^
|
= note: `-D clippy::match-overlapping-arm` implied by `-D warnings`
note: overlaps with this
--> $DIR/match_overlapping_arm.rs:21:9
|
21 | 0 ... 11 => println!("0 ... 11"),
| ^^^^^^^^
error: some ranges overlap
--> $DIR/match_overlapping_arm.rs:26:9
|
26 | 0 ... 5 => println!("0 ... 5"),
| ^^^^^^^
|
note: overlaps with this
--> $DIR/match_overlapping_arm.rs:28:9
|
28 | FOO ... 11 => println!("0 ... 11"),
| ^^^^^^^^^^
error: some ranges overlap
--> $DIR/match_overlapping_arm.rs:34:9
|
34 | 0 ... 5 => println!("0 ... 5"),
| ^^^^^^^
|
note: overlaps with this
--> $DIR/match_overlapping_arm.rs:33:9
|
33 | 2 => println!("2"),
| ^
error: some ranges overlap
--> $DIR/match_overlapping_arm.rs:40:9
|
40 | 0 ... 2 => println!("0 ... 2"),
| ^^^^^^^
|
note: overlaps with this
--> $DIR/match_overlapping_arm.rs:39:9
|
39 | 2 => println!("2"),
| ^
error: some ranges overlap
--> $DIR/match_overlapping_arm.rs:63:9
|
63 | 0 .. 11 => println!("0 .. 11"),
| ^^^^^^^
|
note: overlaps with this
--> $DIR/match_overlapping_arm.rs:64:9
|
64 | 0 ... 11 => println!("0 ... 11"),
| ^^^^^^^^
error: aborting due to 5 previous errors

View File

@ -74,65 +74,6 @@ fn ref_pats() {
}
}
fn overlapping() {
const FOO : u64 = 2;
match 42 {
0 ... 10 => println!("0 ... 10"),
0 ... 11 => println!("0 ... 11"),
_ => (),
}
match 42 {
0 ... 5 => println!("0 ... 5"),
6 ... 7 => println!("6 ... 7"),
FOO ... 11 => println!("0 ... 11"),
_ => (),
}
match 42 {
2 => println!("2"),
0 ... 5 => println!("0 ... 5"),
_ => (),
}
match 42 {
2 => println!("2"),
0 ... 2 => println!("0 ... 2"),
_ => (),
}
match 42 {
0 ... 10 => println!("0 ... 10"),
11 ... 50 => println!("11 ... 50"),
_ => (),
}
match 42 {
2 => println!("2"),
0 .. 2 => println!("0 .. 2"),
_ => (),
}
match 42 {
0 .. 10 => println!("0 .. 10"),
10 .. 50 => println!("10 .. 50"),
_ => (),
}
match 42 {
0 .. 11 => println!("0 .. 11"),
0 ... 11 => println!("0 ... 11"),
_ => (),
}
if let None = Some(42) {
// nothing
} else if let None = Some(42) {
// another nothing :-)
}
}
fn match_wild_err_arm() {
let x: Result<i32, &str> = Ok(3);

View File

@ -88,276 +88,215 @@ help: try
72 | if let None = b {
| ^^^^ ^
error: some ranges overlap
--> $DIR/matches.rs:81:9
error: Err(_) will match all errors, maybe not a good idea
--> $DIR/matches.rs:83:9
|
81 | 0 ... 10 => println!("0 ... 10"),
| ^^^^^^^^
83 | Err(_) => panic!("err")
| ^^^^^^
|
= note: `-D clippy::match-overlapping-arm` implied by `-D warnings`
note: overlaps with this
--> $DIR/matches.rs:82:9
|
82 | 0 ... 11 => println!("0 ... 11"),
| ^^^^^^^^
= note: `-D clippy::match-wild-err-arm` implied by `-D warnings`
= note: to remove this warning, match each error separately or use unreachable macro
error: some ranges overlap
--> $DIR/matches.rs:87:9
error: this `match` has identical arm bodies
--> $DIR/matches.rs:82:18
|
87 | 0 ... 5 => println!("0 ... 5"),
| ^^^^^^^
82 | Ok(_) => println!("ok"),
| ^^^^^^^^^^^^^^
|
note: overlaps with this
= note: `-D clippy::match-same-arms` implied by `-D warnings`
note: same as this
--> $DIR/matches.rs:81:18
|
81 | Ok(3) => println!("ok"),
| ^^^^^^^^^^^^^^
note: consider refactoring into `Ok(3) | Ok(_)`
--> $DIR/matches.rs:81:18
|
81 | Ok(3) => println!("ok"),
| ^^^^^^^^^^^^^^
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error: Err(_) will match all errors, maybe not a good idea
--> $DIR/matches.rs:89:9
|
89 | FOO ... 11 => println!("0 ... 11"),
| ^^^^^^^^^^
89 | Err(_) => {panic!()}
| ^^^^^^
|
= note: to remove this warning, match each error separately or use unreachable macro
error: some ranges overlap
error: this `match` has identical arm bodies
--> $DIR/matches.rs:88:18
|
88 | Ok(_) => println!("ok"),
| ^^^^^^^^^^^^^^
|
note: same as this
--> $DIR/matches.rs:87:18
|
87 | Ok(3) => println!("ok"),
| ^^^^^^^^^^^^^^
note: consider refactoring into `Ok(3) | Ok(_)`
--> $DIR/matches.rs:87:18
|
87 | Ok(3) => println!("ok"),
| ^^^^^^^^^^^^^^
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error: Err(_) will match all errors, maybe not a good idea
--> $DIR/matches.rs:95:9
|
95 | 0 ... 5 => println!("0 ... 5"),
| ^^^^^^^
95 | Err(_) => {panic!();}
| ^^^^^^
|
note: overlaps with this
--> $DIR/matches.rs:94:9
= note: to remove this warning, match each error separately or use unreachable macro
error: this `match` has identical arm bodies
--> $DIR/matches.rs:94:18
|
94 | Ok(_) => println!("ok"),
| ^^^^^^^^^^^^^^
|
94 | 2 => println!("2"),
| ^
error: some ranges overlap
--> $DIR/matches.rs:101:9
|
101 | 0 ... 2 => println!("0 ... 2"),
| ^^^^^^^
|
note: overlaps with this
--> $DIR/matches.rs:100:9
|
100 | 2 => println!("2"),
| ^
error: some ranges overlap
--> $DIR/matches.rs:124:9
|
124 | 0 .. 11 => println!("0 .. 11"),
| ^^^^^^^
|
note: overlaps with this
--> $DIR/matches.rs:125:9
|
125 | 0 ... 11 => println!("0 ... 11"),
| ^^^^^^^^
error: Err(_) will match all errors, maybe not a good idea
--> $DIR/matches.rs:142:9
|
142 | Err(_) => panic!("err")
| ^^^^^^
|
= note: `-D clippy::match-wild-err-arm` implied by `-D warnings`
= note: to remove this warning, match each error separately or use unreachable macro
error: this `match` has identical arm bodies
--> $DIR/matches.rs:141:18
|
141 | Ok(_) => println!("ok"),
| ^^^^^^^^^^^^^^
|
= note: `-D clippy::match-same-arms` implied by `-D warnings`
note: same as this
--> $DIR/matches.rs:140:18
|
140 | Ok(3) => println!("ok"),
| ^^^^^^^^^^^^^^
--> $DIR/matches.rs:93:18
|
93 | Ok(3) => println!("ok"),
| ^^^^^^^^^^^^^^
note: consider refactoring into `Ok(3) | Ok(_)`
--> $DIR/matches.rs:140:18
|
140 | Ok(3) => println!("ok"),
| ^^^^^^^^^^^^^^
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error: Err(_) will match all errors, maybe not a good idea
--> $DIR/matches.rs:148:9
|
148 | Err(_) => {panic!()}
| ^^^^^^
|
= note: to remove this warning, match each error separately or use unreachable macro
--> $DIR/matches.rs:93:18
|
93 | Ok(3) => println!("ok"),
| ^^^^^^^^^^^^^^
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error: this `match` has identical arm bodies
--> $DIR/matches.rs:147:18
--> $DIR/matches.rs:101:18
|
147 | Ok(_) => println!("ok"),
101 | Ok(_) => println!("ok"),
| ^^^^^^^^^^^^^^
|
note: same as this
--> $DIR/matches.rs:146:18
--> $DIR/matches.rs:100:18
|
146 | Ok(3) => println!("ok"),
100 | Ok(3) => println!("ok"),
| ^^^^^^^^^^^^^^
note: consider refactoring into `Ok(3) | Ok(_)`
--> $DIR/matches.rs:146:18
--> $DIR/matches.rs:100:18
|
146 | Ok(3) => println!("ok"),
| ^^^^^^^^^^^^^^
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error: Err(_) will match all errors, maybe not a good idea
--> $DIR/matches.rs:154:9
|
154 | Err(_) => {panic!();}
| ^^^^^^
|
= note: to remove this warning, match each error separately or use unreachable macro
error: this `match` has identical arm bodies
--> $DIR/matches.rs:153:18
|
153 | Ok(_) => println!("ok"),
| ^^^^^^^^^^^^^^
|
note: same as this
--> $DIR/matches.rs:152:18
|
152 | Ok(3) => println!("ok"),
| ^^^^^^^^^^^^^^
note: consider refactoring into `Ok(3) | Ok(_)`
--> $DIR/matches.rs:152:18
|
152 | Ok(3) => println!("ok"),
100 | Ok(3) => println!("ok"),
| ^^^^^^^^^^^^^^
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error: this `match` has identical arm bodies
--> $DIR/matches.rs:160:18
--> $DIR/matches.rs:108:18
|
160 | Ok(_) => println!("ok"),
108 | Ok(_) => println!("ok"),
| ^^^^^^^^^^^^^^
|
note: same as this
--> $DIR/matches.rs:159:18
--> $DIR/matches.rs:107:18
|
159 | Ok(3) => println!("ok"),
107 | Ok(3) => println!("ok"),
| ^^^^^^^^^^^^^^
note: consider refactoring into `Ok(3) | Ok(_)`
--> $DIR/matches.rs:159:18
--> $DIR/matches.rs:107:18
|
159 | Ok(3) => println!("ok"),
107 | Ok(3) => println!("ok"),
| ^^^^^^^^^^^^^^
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error: this `match` has identical arm bodies
--> $DIR/matches.rs:167:18
--> $DIR/matches.rs:114:18
|
167 | Ok(_) => println!("ok"),
114 | Ok(_) => println!("ok"),
| ^^^^^^^^^^^^^^
|
note: same as this
--> $DIR/matches.rs:166:18
--> $DIR/matches.rs:113:18
|
166 | Ok(3) => println!("ok"),
113 | Ok(3) => println!("ok"),
| ^^^^^^^^^^^^^^
note: consider refactoring into `Ok(3) | Ok(_)`
--> $DIR/matches.rs:166:18
--> $DIR/matches.rs:113:18
|
166 | Ok(3) => println!("ok"),
113 | Ok(3) => println!("ok"),
| ^^^^^^^^^^^^^^
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error: this `match` has identical arm bodies
--> $DIR/matches.rs:173:18
--> $DIR/matches.rs:120:18
|
173 | Ok(_) => println!("ok"),
120 | Ok(_) => println!("ok"),
| ^^^^^^^^^^^^^^
|
note: same as this
--> $DIR/matches.rs:172:18
--> $DIR/matches.rs:119:18
|
172 | Ok(3) => println!("ok"),
119 | Ok(3) => println!("ok"),
| ^^^^^^^^^^^^^^
note: consider refactoring into `Ok(3) | Ok(_)`
--> $DIR/matches.rs:172:18
--> $DIR/matches.rs:119:18
|
172 | Ok(3) => println!("ok"),
119 | Ok(3) => println!("ok"),
| ^^^^^^^^^^^^^^
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error: this `match` has identical arm bodies
--> $DIR/matches.rs:179:18
--> $DIR/matches.rs:141:29
|
179 | Ok(_) => println!("ok"),
| ^^^^^^^^^^^^^^
|
note: same as this
--> $DIR/matches.rs:178:18
|
178 | Ok(3) => println!("ok"),
| ^^^^^^^^^^^^^^
note: consider refactoring into `Ok(3) | Ok(_)`
--> $DIR/matches.rs:178:18
|
178 | Ok(3) => println!("ok"),
| ^^^^^^^^^^^^^^
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error: this `match` has identical arm bodies
--> $DIR/matches.rs:200:29
|
200 | (Ok(_), Some(x)) => println!("ok {}", x),
141 | (Ok(_), Some(x)) => println!("ok {}", x),
| ^^^^^^^^^^^^^^^^^^^^
|
note: same as this
--> $DIR/matches.rs:199:29
--> $DIR/matches.rs:140:29
|
199 | (Ok(x), Some(_)) => println!("ok {}", x),
140 | (Ok(x), Some(_)) => println!("ok {}", x),
| ^^^^^^^^^^^^^^^^^^^^
note: consider refactoring into `(Ok(x), Some(_)) | (Ok(_), Some(x))`
--> $DIR/matches.rs:199:29
--> $DIR/matches.rs:140:29
|
199 | (Ok(x), Some(_)) => println!("ok {}", x),
140 | (Ok(x), Some(_)) => println!("ok {}", x),
| ^^^^^^^^^^^^^^^^^^^^
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error: this `match` has identical arm bodies
--> $DIR/matches.rs:215:18
--> $DIR/matches.rs:156:18
|
215 | Ok(_) => println!("ok"),
156 | Ok(_) => println!("ok"),
| ^^^^^^^^^^^^^^
|
note: same as this
--> $DIR/matches.rs:214:18
--> $DIR/matches.rs:155:18
|
214 | Ok(3) => println!("ok"),
155 | Ok(3) => println!("ok"),
| ^^^^^^^^^^^^^^
note: consider refactoring into `Ok(3) | Ok(_)`
--> $DIR/matches.rs:214:18
--> $DIR/matches.rs:155:18
|
214 | Ok(3) => println!("ok"),
155 | Ok(3) => println!("ok"),
| ^^^^^^^^^^^^^^
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error: use as_ref() instead
--> $DIR/matches.rs:222:33
--> $DIR/matches.rs:163:33
|
222 | let borrowed: Option<&()> = match owned {
163 | let borrowed: Option<&()> = match owned {
| _________________________________^
223 | | None => None,
224 | | Some(ref v) => Some(v),
225 | | };
164 | | None => None,
165 | | Some(ref v) => Some(v),
166 | | };
| |_____^ help: try this: `owned.as_ref()`
|
= note: `-D clippy::match-as-ref` implied by `-D warnings`
error: use as_mut() instead
--> $DIR/matches.rs:228:39
--> $DIR/matches.rs:169:39
|
228 | let borrow_mut: Option<&mut ()> = match mut_owned {
169 | let borrow_mut: Option<&mut ()> = match mut_owned {
| _______________________________________^
229 | | None => None,
230 | | Some(ref mut v) => Some(v),
231 | | };
170 | | None => None,
171 | | Some(ref mut v) => Some(v),
172 | | };
| |_____^ help: try this: `mut_owned.as_mut()`
error: aborting due to 26 previous errors
error: aborting due to 21 previous errors

View File

@ -353,61 +353,6 @@ fn or_fun_call() {
let _ = stringy.unwrap_or("".to_owned());
}
/// Checks implementation of the `EXPECT_FUN_CALL` lint
fn expect_fun_call() {
struct Foo;
impl Foo {
fn new() -> Self { Foo }
fn expect(&self, msg: &str) {
panic!("{}", msg)
}
}
let with_some = Some("value");
with_some.expect("error");
let with_none: Option<i32> = None;
with_none.expect("error");
let error_code = 123_i32;
let with_none_and_format: Option<i32> = None;
with_none_and_format.expect(&format!("Error {}: fake error", error_code));
let with_none_and_as_str: Option<i32> = None;
with_none_and_as_str.expect(format!("Error {}: fake error", error_code).as_str());
let with_ok: Result<(), ()> = Ok(());
with_ok.expect("error");
let with_err: Result<(), ()> = Err(());
with_err.expect("error");
let error_code = 123_i32;
let with_err_and_format: Result<(), ()> = Err(());
with_err_and_format.expect(&format!("Error {}: fake error", error_code));
let with_err_and_as_str: Result<(), ()> = Err(());
with_err_and_as_str.expect(format!("Error {}: fake error", error_code).as_str());
let with_dummy_type = Foo::new();
with_dummy_type.expect("another test string");
let with_dummy_type_and_format = Foo::new();
with_dummy_type_and_format.expect(&format!("Error {}: fake error", error_code));
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);
Some("foo").expect({ &format!("error") });
Some("foo").expect(format!("error").as_ref());
}
/// Checks implementation of `ITER_NTH` lint
fn iter_nth() {
let mut some_vec = vec![0, 1, 2, 3];

View File

@ -323,139 +323,83 @@ error: use of `unwrap_or` followed by a function call
353 | let _ = stringy.unwrap_or("".to_owned());
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| "".to_owned())`
error: `error_code` is shadowed by `123_i32`
--> $DIR/methods.rs:387:9
|
387 | let error_code = 123_i32;
| ^^^^^^^^^^
|
= note: `-D clippy::shadow-unrelated` implied by `-D warnings`
note: initialization happens here
--> $DIR/methods.rs:387:22
|
387 | let error_code = 123_i32;
| ^^^^^^^
note: previous binding is here
--> $DIR/methods.rs:374:9
|
374 | let error_code = 123_i32;
| ^^^^^^^^^^
error: use of `expect` followed by a function call
--> $DIR/methods.rs:376:26
|
376 | with_none_and_format.expect(&format!("Error {}: fake error", error_code));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("Error {}: fake error", error_code))`
|
= note: `-D clippy::expect-fun-call` implied by `-D warnings`
error: use of `expect` followed by a function call
--> $DIR/methods.rs:379:26
|
379 | with_none_and_as_str.expect(format!("Error {}: fake error", error_code).as_str());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("Error {}: fake error", error_code))`
error: use of `expect` followed by a function call
--> $DIR/methods.rs:389:25
|
389 | with_err_and_format.expect(&format!("Error {}: fake error", error_code));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|_| panic!("Error {}: fake error", error_code))`
error: use of `expect` followed by a function call
--> $DIR/methods.rs:392:25
|
392 | with_err_and_as_str.expect(format!("Error {}: fake error", error_code).as_str());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|_| panic!("Error {}: fake error", error_code))`
error: use of `expect` followed by a function call
--> $DIR/methods.rs:407:17
|
407 | Some("foo").expect({ &format!("error") });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { let msg = { &format!("error") }; panic!(msg) }))`
error: use of `expect` followed by a function call
--> $DIR/methods.rs:408:17
|
408 | Some("foo").expect(format!("error").as_ref());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("error"))`
error: called `.iter().nth()` on a Vec. Calling `.get()` is both faster and more readable
--> $DIR/methods.rs:419:23
--> $DIR/methods.rs:364:23
|
419 | let bad_vec = some_vec.iter().nth(3);
364 | let bad_vec = some_vec.iter().nth(3);
| ^^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::iter-nth` implied by `-D warnings`
error: called `.iter().nth()` on a slice. Calling `.get()` is both faster and more readable
--> $DIR/methods.rs:420:26
--> $DIR/methods.rs:365:26
|
420 | let bad_slice = &some_vec[..].iter().nth(3);
365 | 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:421:31
--> $DIR/methods.rs:366:31
|
421 | let bad_boxed_slice = boxed_slice.iter().nth(3);
366 | 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:422:29
--> $DIR/methods.rs:367:29
|
422 | let bad_vec_deque = some_vec_deque.iter().nth(3);
367 | 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:427:23
--> $DIR/methods.rs:372:23
|
427 | let bad_vec = some_vec.iter_mut().nth(3);
372 | 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:430:26
--> $DIR/methods.rs:375:26
|
430 | let bad_slice = &some_vec[..].iter_mut().nth(3);
375 | 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:433:29
--> $DIR/methods.rs:378:29
|
433 | let bad_vec_deque = some_vec_deque.iter_mut().nth(3);
378 | 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:445:13
--> $DIR/methods.rs:390:13
|
445 | let _ = some_vec.iter().skip(42).next();
390 | let _ = some_vec.iter().skip(42).next();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::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:446:13
--> $DIR/methods.rs:391:13
|
446 | let _ = some_vec.iter().cycle().skip(42).next();
391 | 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:447:13
--> $DIR/methods.rs:392:13
|
447 | let _ = (1..10).skip(10).next();
392 | 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:448:14
--> $DIR/methods.rs:393:14
|
448 | let _ = &some_vec[..].iter().skip(3).next();
393 | 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:457:13
--> $DIR/methods.rs:402:13
|
457 | let _ = opt.unwrap();
402 | let _ = opt.unwrap();
| ^^^^^^^^^^^^
|
= note: `-D clippy::option-unwrap-used` implied by `-D warnings`
error: aborting due to 57 previous errors
error: aborting due to 50 previous errors