From 8c46c498d9a575576d8d8106269cb549830ccf30 Mon Sep 17 00:00:00 2001 From: Matthias Kaak Date: Thu, 10 Oct 2024 08:05:41 +0000 Subject: [PATCH] Improved wording of or_fun_call lint Signed-off-by: Matthias Kaak --- clippy_lints/src/methods/expect_fun_call.rs | 4 +-- clippy_lints/src/methods/or_fun_call.rs | 2 +- tests/ui/expect_fun_call.stderr | 30 ++++++++-------- tests/ui/or_fun_call.fixed | 10 +++--- tests/ui/or_fun_call.rs | 10 +++--- tests/ui/or_fun_call.stderr | 40 ++++++++++----------- tests/ui/unwrap_or.fixed | 4 +-- tests/ui/unwrap_or.rs | 4 +-- tests/ui/unwrap_or.stderr | 4 +-- 9 files changed, 54 insertions(+), 54 deletions(-) diff --git a/clippy_lints/src/methods/expect_fun_call.rs b/clippy_lints/src/methods/expect_fun_call.rs index 2922086522c2..c288dbdabe96 100644 --- a/clippy_lints/src/methods/expect_fun_call.rs +++ b/clippy_lints/src/methods/expect_fun_call.rs @@ -143,7 +143,7 @@ pub(super) fn check<'tcx>( cx, EXPECT_FUN_CALL, span_replace_word, - format!("use of `{name}` followed by a function call"), + format!("function call inside of `{name}`"), "try", format!("unwrap_or_else({closure_args} panic!({sugg}))"), applicability, @@ -161,7 +161,7 @@ pub(super) fn check<'tcx>( cx, EXPECT_FUN_CALL, span_replace_word, - format!("use of `{name}` followed by a function call"), + format!("function call inside of `{name}`"), "try", format!("unwrap_or_else({closure_args} {{ panic!(\"{{}}\", {arg_root_snippet}) }})"), applicability, diff --git a/clippy_lints/src/methods/or_fun_call.rs b/clippy_lints/src/methods/or_fun_call.rs index b971f60d4169..9f456c5c5991 100644 --- a/clippy_lints/src/methods/or_fun_call.rs +++ b/clippy_lints/src/methods/or_fun_call.rs @@ -183,7 +183,7 @@ pub(super) fn check<'tcx>( cx, OR_FUN_CALL, span_replace_word, - format!("use of `{name}` followed by a function call"), + format!("function call inside of `{name}`"), "try", format!("{name}_{suffix}({sugg})"), app, diff --git a/tests/ui/expect_fun_call.stderr b/tests/ui/expect_fun_call.stderr index bae853ac5c19..050c039f834d 100644 --- a/tests/ui/expect_fun_call.stderr +++ b/tests/ui/expect_fun_call.stderr @@ -1,4 +1,4 @@ -error: use of `expect` followed by a function call +error: function call inside of `expect` --> tests/ui/expect_fun_call.rs:35:26 | LL | with_none_and_format.expect(&format!("Error {}: fake error", error_code)); @@ -7,85 +7,85 @@ LL | with_none_and_format.expect(&format!("Error {}: fake error", error_code = note: `-D clippy::expect-fun-call` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::expect_fun_call)]` -error: use of `expect` followed by a function call +error: function call inside of `expect` --> tests/ui/expect_fun_call.rs:38:26 | LL | with_none_and_as_str.expect(format!("Error {}: fake error", error_code).as_str()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("Error {}: fake error", error_code))` -error: use of `expect` followed by a function call +error: function call inside of `expect` --> tests/ui/expect_fun_call.rs:41:37 | LL | with_none_and_format_with_macro.expect(format!("Error {}: fake error", one!()).as_str()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("Error {}: fake error", one!()))` -error: use of `expect` followed by a function call +error: function call inside of `expect` --> tests/ui/expect_fun_call.rs:51:25 | LL | with_err_and_format.expect(&format!("Error {}: fake error", error_code)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|_| panic!("Error {}: fake error", error_code))` -error: use of `expect` followed by a function call +error: function call inside of `expect` --> tests/ui/expect_fun_call.rs:54:25 | LL | with_err_and_as_str.expect(format!("Error {}: fake error", error_code).as_str()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|_| panic!("Error {}: fake error", error_code))` -error: use of `expect` followed by a function call +error: function call inside of `expect` --> tests/ui/expect_fun_call.rs:66:17 | LL | Some("foo").expect(format!("{} {}", 1, 2).as_ref()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("{} {}", 1, 2))` -error: use of `expect` followed by a function call +error: function call inside of `expect` --> tests/ui/expect_fun_call.rs:87:21 | LL | Some("foo").expect(&get_string()); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| { panic!("{}", get_string()) })` -error: use of `expect` followed by a function call +error: function call inside of `expect` --> tests/ui/expect_fun_call.rs:88:21 | LL | Some("foo").expect(get_string().as_ref()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| { panic!("{}", get_string()) })` -error: use of `expect` followed by a function call +error: function call inside of `expect` --> tests/ui/expect_fun_call.rs:89:21 | LL | Some("foo").expect(get_string().as_str()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| { panic!("{}", get_string()) })` -error: use of `expect` followed by a function call +error: function call inside of `expect` --> tests/ui/expect_fun_call.rs:91:21 | LL | Some("foo").expect(get_static_str()); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| { panic!("{}", get_static_str()) })` -error: use of `expect` followed by a function call +error: function call inside of `expect` --> tests/ui/expect_fun_call.rs:92:21 | LL | Some("foo").expect(get_non_static_str(&0)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| { panic!("{}", get_non_static_str(&0).to_string()) })` -error: use of `expect` followed by a function call +error: function call inside of `expect` --> tests/ui/expect_fun_call.rs:96:16 | LL | Some(true).expect(&format!("key {}, {}", 1, 2)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("key {}, {}", 1, 2))` -error: use of `expect` followed by a function call +error: function call inside of `expect` --> tests/ui/expect_fun_call.rs:102:17 | LL | opt_ref.expect(&format!("{:?}", opt_ref)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("{:?}", opt_ref))` -error: use of `expect` followed by a function call +error: function call inside of `expect` --> tests/ui/expect_fun_call.rs:106:20 | LL | format_capture.expect(&format!("{error_code}")); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("{error_code}"))` -error: use of `expect` followed by a function call +error: function call inside of `expect` --> tests/ui/expect_fun_call.rs:109:30 | LL | format_capture_and_value.expect(&format!("{error_code}, {}", 1)); diff --git a/tests/ui/or_fun_call.fixed b/tests/ui/or_fun_call.fixed index 7452eb776888..625d654dd396 100644 --- a/tests/ui/or_fun_call.fixed +++ b/tests/ui/or_fun_call.fixed @@ -341,18 +341,18 @@ fn fn_call_in_nested_expr() { } let opt: Option = Some(1); - //~v ERROR: use of `unwrap_or` followed by a function call + //~v ERROR: function call inside of `unwrap_or` let _ = opt.unwrap_or_else(f); // suggest `.unwrap_or_else(f)` // - //~v ERROR: use of `unwrap_or` followed by a function call + //~v ERROR: function call inside of `unwrap_or` let _ = opt.unwrap_or_else(|| f() + 1); // suggest `.unwrap_or_else(|| f() + 1)` // - //~v ERROR: use of `unwrap_or` followed by a function call + //~v ERROR: function call inside of `unwrap_or` let _ = opt.unwrap_or_else(|| { let x = f(); x + 1 }); - //~v ERROR: use of `map_or` followed by a function call + //~v ERROR: function call inside of `map_or` let _ = opt.map_or_else(|| f() + 1, |v| v); // suggest `.map_or_else(|| f() + 1, |v| v)` // //~v ERROR: use of `unwrap_or` to construct default value @@ -361,7 +361,7 @@ fn fn_call_in_nested_expr() { let opt_foo = Some(Foo { val: String::from("123"), }); - //~v ERROR: use of `unwrap_or` followed by a function call + //~v ERROR: function call inside of `unwrap_or` let _ = opt_foo.unwrap_or_else(|| Foo { val: String::default() }); } diff --git a/tests/ui/or_fun_call.rs b/tests/ui/or_fun_call.rs index cd6f7bb20701..5b7d8faec7bf 100644 --- a/tests/ui/or_fun_call.rs +++ b/tests/ui/or_fun_call.rs @@ -341,18 +341,18 @@ fn fn_call_in_nested_expr() { } let opt: Option = Some(1); - //~v ERROR: use of `unwrap_or` followed by a function call + //~v ERROR: function call inside of `unwrap_or` let _ = opt.unwrap_or({ f() }); // suggest `.unwrap_or_else(f)` // - //~v ERROR: use of `unwrap_or` followed by a function call + //~v ERROR: function call inside of `unwrap_or` let _ = opt.unwrap_or(f() + 1); // suggest `.unwrap_or_else(|| f() + 1)` // - //~v ERROR: use of `unwrap_or` followed by a function call + //~v ERROR: function call inside of `unwrap_or` let _ = opt.unwrap_or({ let x = f(); x + 1 }); - //~v ERROR: use of `map_or` followed by a function call + //~v ERROR: function call inside of `map_or` let _ = opt.map_or(f() + 1, |v| v); // suggest `.map_or_else(|| f() + 1, |v| v)` // //~v ERROR: use of `unwrap_or` to construct default value @@ -361,7 +361,7 @@ fn fn_call_in_nested_expr() { let opt_foo = Some(Foo { val: String::from("123"), }); - //~v ERROR: use of `unwrap_or` followed by a function call + //~v ERROR: function call inside of `unwrap_or` let _ = opt_foo.unwrap_or(Foo { val: String::default() }); } diff --git a/tests/ui/or_fun_call.stderr b/tests/ui/or_fun_call.stderr index 06f804fb41e8..9f90a830a211 100644 --- a/tests/ui/or_fun_call.stderr +++ b/tests/ui/or_fun_call.stderr @@ -1,4 +1,4 @@ -error: use of `unwrap_or` followed by a function call +error: function call inside of `unwrap_or` --> tests/ui/or_fun_call.rs:52:22 | LL | with_constructor.unwrap_or(make()); @@ -16,19 +16,19 @@ LL | with_new.unwrap_or(Vec::new()); = note: `-D clippy::unwrap-or-default` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::unwrap_or_default)]` -error: use of `unwrap_or` followed by a function call +error: function call inside of `unwrap_or` --> tests/ui/or_fun_call.rs:58:21 | LL | with_const_args.unwrap_or(Vec::with_capacity(12)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| Vec::with_capacity(12))` -error: use of `unwrap_or` followed by a function call +error: function call inside of `unwrap_or` --> tests/ui/or_fun_call.rs:61:14 | LL | with_err.unwrap_or(make()); | ^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|_| make())` -error: use of `unwrap_or` followed by a function call +error: function call inside of `unwrap_or` --> tests/ui/or_fun_call.rs:64:19 | LL | with_err_args.unwrap_or(Vec::with_capacity(12)); @@ -46,7 +46,7 @@ error: use of `unwrap_or` to construct default value LL | with_default_type.unwrap_or(u64::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` -error: use of `unwrap_or` followed by a function call +error: function call inside of `unwrap_or` --> tests/ui/or_fun_call.rs:73:18 | LL | self_default.unwrap_or(::default()); @@ -64,7 +64,7 @@ error: use of `unwrap_or` to construct default value LL | with_vec.unwrap_or(vec![]); | ^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` -error: use of `unwrap_or` followed by a function call +error: function call inside of `unwrap_or` --> tests/ui/or_fun_call.rs:82:21 | LL | without_default.unwrap_or(Foo::new()); @@ -100,55 +100,55 @@ error: use of `unwrap_or` to construct default value LL | let _ = stringy.unwrap_or(String::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` -error: use of `ok_or` followed by a function call +error: function call inside of `ok_or` --> tests/ui/or_fun_call.rs:101:17 | LL | let _ = opt.ok_or(format!("{} world.", hello)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `ok_or_else(|| format!("{} world.", hello))` -error: use of `unwrap_or` followed by a function call +error: function call inside of `unwrap_or` --> tests/ui/or_fun_call.rs:105:21 | LL | let _ = Some(1).unwrap_or(map[&1]); | ^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| map[&1])` -error: use of `unwrap_or` followed by a function call +error: function call inside of `unwrap_or` --> tests/ui/or_fun_call.rs:107:21 | LL | let _ = Some(1).unwrap_or(map[&1]); | ^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| map[&1])` -error: use of `or` followed by a function call +error: function call inside of `or` --> tests/ui/or_fun_call.rs:131:35 | LL | let _ = Some("a".to_string()).or(Some("b".to_string())); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `or_else(|| Some("b".to_string()))` -error: use of `unwrap_or` followed by a function call +error: function call inside of `unwrap_or` --> tests/ui/or_fun_call.rs:170:14 | LL | None.unwrap_or(ptr_to_ref(s)); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| ptr_to_ref(s))` -error: use of `unwrap_or` followed by a function call +error: function call inside of `unwrap_or` --> tests/ui/or_fun_call.rs:176:14 | LL | None.unwrap_or(unsafe { ptr_to_ref(s) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| unsafe { ptr_to_ref(s) })` -error: use of `unwrap_or` followed by a function call +error: function call inside of `unwrap_or` --> tests/ui/or_fun_call.rs:178:14 | LL | None.unwrap_or( unsafe { ptr_to_ref(s) } ); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| unsafe { ptr_to_ref(s) })` -error: use of `map_or` followed by a function call +error: function call inside of `map_or` --> tests/ui/or_fun_call.rs:253:25 | LL | let _ = Some(4).map_or(g(), |v| v); | ^^^^^^^^^^^^^^^^^^ help: try: `map_or_else(g, |v| v)` -error: use of `map_or` followed by a function call +error: function call inside of `map_or` --> tests/ui/or_fun_call.rs:254:25 | LL | let _ = Some(4).map_or(g(), f); @@ -196,19 +196,19 @@ error: use of `unwrap_or_else` to construct default value LL | let _ = stringy.unwrap_or_else(String::new); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` -error: use of `unwrap_or` followed by a function call +error: function call inside of `unwrap_or` --> tests/ui/or_fun_call.rs:345:17 | LL | let _ = opt.unwrap_or({ f() }); // suggest `.unwrap_or_else(f)` | ^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(f)` -error: use of `unwrap_or` followed by a function call +error: function call inside of `unwrap_or` --> tests/ui/or_fun_call.rs:348:17 | LL | let _ = opt.unwrap_or(f() + 1); // suggest `.unwrap_or_else(|| f() + 1)` | ^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| f() + 1)` -error: use of `unwrap_or` followed by a function call +error: function call inside of `unwrap_or` --> tests/ui/or_fun_call.rs:351:17 | LL | let _ = opt.unwrap_or({ @@ -226,7 +226,7 @@ LL + x + 1 LL ~ }); | -error: use of `map_or` followed by a function call +error: function call inside of `map_or` --> tests/ui/or_fun_call.rs:356:17 | LL | let _ = opt.map_or(f() + 1, |v| v); // suggest `.map_or_else(|| f() + 1, |v| v)` @@ -238,7 +238,7 @@ error: use of `unwrap_or` to construct default value LL | let _ = opt.unwrap_or({ i32::default() }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` -error: use of `unwrap_or` followed by a function call +error: function call inside of `unwrap_or` --> tests/ui/or_fun_call.rs:365:21 | LL | let _ = opt_foo.unwrap_or(Foo { val: String::default() }); diff --git a/tests/ui/unwrap_or.fixed b/tests/ui/unwrap_or.fixed index e1a47fc7bd94..62bc1966da6f 100644 --- a/tests/ui/unwrap_or.fixed +++ b/tests/ui/unwrap_or.fixed @@ -3,11 +3,11 @@ fn main() { let s = Some(String::from("test string")).unwrap_or_else(|| "Fail".to_string()).len(); - //~^ ERROR: use of `unwrap_or` followed by a function call + //~^ ERROR: function call inside of `unwrap_or` //~| NOTE: `-D clippy::or-fun-call` implied by `-D warnings` } fn new_lines() { let s = Some(String::from("test string")).unwrap_or_else(|| "Fail".to_string()).len(); - //~^ ERROR: use of `unwrap_or` followed by a function call + //~^ ERROR: function call inside of `unwrap_or` } diff --git a/tests/ui/unwrap_or.rs b/tests/ui/unwrap_or.rs index 914bfb939b88..e8e4b6b7168f 100644 --- a/tests/ui/unwrap_or.rs +++ b/tests/ui/unwrap_or.rs @@ -3,11 +3,11 @@ fn main() { let s = Some(String::from("test string")).unwrap_or("Fail".to_string()).len(); - //~^ ERROR: use of `unwrap_or` followed by a function call + //~^ ERROR: function call inside of `unwrap_or` //~| NOTE: `-D clippy::or-fun-call` implied by `-D warnings` } fn new_lines() { let s = Some(String::from("test string")).unwrap_or("Fail".to_string()).len(); - //~^ ERROR: use of `unwrap_or` followed by a function call + //~^ ERROR: function call inside of `unwrap_or` } diff --git a/tests/ui/unwrap_or.stderr b/tests/ui/unwrap_or.stderr index 6aa0b9df29b9..b712f8cf693d 100644 --- a/tests/ui/unwrap_or.stderr +++ b/tests/ui/unwrap_or.stderr @@ -1,4 +1,4 @@ -error: use of `unwrap_or` followed by a function call +error: function call inside of `unwrap_or` --> tests/ui/unwrap_or.rs:5:47 | LL | let s = Some(String::from("test string")).unwrap_or("Fail".to_string()).len(); @@ -7,7 +7,7 @@ LL | let s = Some(String::from("test string")).unwrap_or("Fail".to_string()) = note: `-D clippy::or-fun-call` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::or_fun_call)]` -error: use of `unwrap_or` followed by a function call +error: function call inside of `unwrap_or` --> tests/ui/unwrap_or.rs:11:47 | LL | let s = Some(String::from("test string")).unwrap_or("Fail".to_string()).len();