Skip to content

Commit

Permalink
Auto merge of #137348 - compiler-errors:span-trim, r=estebank
Browse files Browse the repository at this point in the history
More sophisticated span trimming for suggestions

Previously #136958 only cared about prefixes or suffixes. Now it detects more cases where a suggestion is "sandwiched" by unchanged code on the left or the right. Would be cool if we could detect several insertions, like `ACE` going to `ABCDE`, extracting `B` and `D`, but that seems unwieldy.

r? `@estebank`
  • Loading branch information
bors committed Feb 21, 2025
2 parents 49082f9 + a04e819 commit a666d6a
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 145 deletions.
12 changes: 6 additions & 6 deletions tests/ui/async_yields_async.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ LL | | };
= help: to override `-D warnings` add `#[allow(clippy::async_yields_async)]`
help: consider awaiting this value
|
LL ~ async {
LL + 3
LL + }.await
LL | async {
LL | 3
LL ~ }.await
|

error: an async construct yields a type which is itself awaitable
Expand Down Expand Up @@ -46,9 +46,9 @@ LL | | };
|
help: consider awaiting this value
|
LL ~ async {
LL + 3
LL + }.await
LL | async {
LL | 3
LL ~ }.await
|

error: an async construct yields a type which is itself awaitable
Expand Down
5 changes: 2 additions & 3 deletions tests/ui/borrow_deref_ref_unfixable.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ LL + let x: &str = s;
|
help: if you would like to deref, try using `&**`
|
LL - let x: &str = &*s;
LL + let x: &str = &**s;
|
LL | let x: &str = &**s;
| +

error: aborting due to 1 previous error

85 changes: 34 additions & 51 deletions tests/ui/fn_to_numeric_cast_any.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ LL | let _ = foo as i8;
= help: to override `-D warnings` add `#[allow(clippy::fn_to_numeric_cast_any)]`
help: did you mean to invoke the function?
|
LL - let _ = foo as i8;
LL + let _ = foo() as i8;
|
LL | let _ = foo() as i8;
| ++

error: casting function pointer `foo` to `i16`
--> tests/ui/fn_to_numeric_cast_any.rs:26:13
Expand All @@ -20,9 +19,8 @@ LL | let _ = foo as i16;
|
help: did you mean to invoke the function?
|
LL - let _ = foo as i16;
LL + let _ = foo() as i16;
|
LL | let _ = foo() as i16;
| ++

error: casting function pointer `foo` to `i32`
--> tests/ui/fn_to_numeric_cast_any.rs:28:13
Expand All @@ -32,9 +30,8 @@ LL | let _ = foo as i32;
|
help: did you mean to invoke the function?
|
LL - let _ = foo as i32;
LL + let _ = foo() as i32;
|
LL | let _ = foo() as i32;
| ++

error: casting function pointer `foo` to `i64`
--> tests/ui/fn_to_numeric_cast_any.rs:30:13
Expand All @@ -44,9 +41,8 @@ LL | let _ = foo as i64;
|
help: did you mean to invoke the function?
|
LL - let _ = foo as i64;
LL + let _ = foo() as i64;
|
LL | let _ = foo() as i64;
| ++

error: casting function pointer `foo` to `i128`
--> tests/ui/fn_to_numeric_cast_any.rs:32:13
Expand All @@ -56,9 +52,8 @@ LL | let _ = foo as i128;
|
help: did you mean to invoke the function?
|
LL - let _ = foo as i128;
LL + let _ = foo() as i128;
|
LL | let _ = foo() as i128;
| ++

error: casting function pointer `foo` to `isize`
--> tests/ui/fn_to_numeric_cast_any.rs:34:13
Expand All @@ -68,9 +63,8 @@ LL | let _ = foo as isize;
|
help: did you mean to invoke the function?
|
LL - let _ = foo as isize;
LL + let _ = foo() as isize;
|
LL | let _ = foo() as isize;
| ++

error: casting function pointer `foo` to `u8`
--> tests/ui/fn_to_numeric_cast_any.rs:37:13
Expand All @@ -80,9 +74,8 @@ LL | let _ = foo as u8;
|
help: did you mean to invoke the function?
|
LL - let _ = foo as u8;
LL + let _ = foo() as u8;
|
LL | let _ = foo() as u8;
| ++

error: casting function pointer `foo` to `u16`
--> tests/ui/fn_to_numeric_cast_any.rs:39:13
Expand All @@ -92,9 +85,8 @@ LL | let _ = foo as u16;
|
help: did you mean to invoke the function?
|
LL - let _ = foo as u16;
LL + let _ = foo() as u16;
|
LL | let _ = foo() as u16;
| ++

error: casting function pointer `foo` to `u32`
--> tests/ui/fn_to_numeric_cast_any.rs:41:13
Expand All @@ -104,9 +96,8 @@ LL | let _ = foo as u32;
|
help: did you mean to invoke the function?
|
LL - let _ = foo as u32;
LL + let _ = foo() as u32;
|
LL | let _ = foo() as u32;
| ++

error: casting function pointer `foo` to `u64`
--> tests/ui/fn_to_numeric_cast_any.rs:43:13
Expand All @@ -116,9 +107,8 @@ LL | let _ = foo as u64;
|
help: did you mean to invoke the function?
|
LL - let _ = foo as u64;
LL + let _ = foo() as u64;
|
LL | let _ = foo() as u64;
| ++

error: casting function pointer `foo` to `u128`
--> tests/ui/fn_to_numeric_cast_any.rs:45:13
Expand All @@ -128,9 +118,8 @@ LL | let _ = foo as u128;
|
help: did you mean to invoke the function?
|
LL - let _ = foo as u128;
LL + let _ = foo() as u128;
|
LL | let _ = foo() as u128;
| ++

error: casting function pointer `foo` to `usize`
--> tests/ui/fn_to_numeric_cast_any.rs:47:13
Expand All @@ -140,9 +129,8 @@ LL | let _ = foo as usize;
|
help: did you mean to invoke the function?
|
LL - let _ = foo as usize;
LL + let _ = foo() as usize;
|
LL | let _ = foo() as usize;
| ++

error: casting function pointer `Struct::static_method` to `usize`
--> tests/ui/fn_to_numeric_cast_any.rs:52:13
Expand All @@ -152,9 +140,8 @@ LL | let _ = Struct::static_method as usize;
|
help: did you mean to invoke the function?
|
LL - let _ = Struct::static_method as usize;
LL + let _ = Struct::static_method() as usize;
|
LL | let _ = Struct::static_method() as usize;
| ++

error: casting function pointer `f` to `usize`
--> tests/ui/fn_to_numeric_cast_any.rs:57:5
Expand All @@ -164,9 +151,8 @@ LL | f as usize
|
help: did you mean to invoke the function?
|
LL - f as usize
LL + f() as usize
|
LL | f() as usize
| ++

error: casting function pointer `T::static_method` to `usize`
--> tests/ui/fn_to_numeric_cast_any.rs:62:5
Expand All @@ -176,9 +162,8 @@ LL | T::static_method as usize
|
help: did you mean to invoke the function?
|
LL - T::static_method as usize
LL + T::static_method() as usize
|
LL | T::static_method() as usize
| ++

error: casting function pointer `(clos as fn(u32) -> u32)` to `usize`
--> tests/ui/fn_to_numeric_cast_any.rs:69:13
Expand All @@ -188,9 +173,8 @@ LL | let _ = (clos as fn(u32) -> u32) as usize;
|
help: did you mean to invoke the function?
|
LL - let _ = (clos as fn(u32) -> u32) as usize;
LL + let _ = (clos as fn(u32) -> u32)() as usize;
|
LL | let _ = (clos as fn(u32) -> u32)() as usize;
| ++

error: casting function pointer `foo` to `*const ()`
--> tests/ui/fn_to_numeric_cast_any.rs:74:13
Expand All @@ -200,9 +184,8 @@ LL | let _ = foo as *const ();
|
help: did you mean to invoke the function?
|
LL - let _ = foo as *const ();
LL + let _ = foo() as *const ();
|
LL | let _ = foo() as *const ();
| ++

error: aborting due to 17 previous errors

15 changes: 6 additions & 9 deletions tests/ui/implicit_hasher.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,8 @@ LL | pub fn map(map: &mut HashMap<i32, i32>) {}
|
help: add a type parameter for `BuildHasher`
|
LL - pub fn map(map: &mut HashMap<i32, i32>) {}
LL + pub fn map<S: ::std::hash::BuildHasher>(map: &mut HashMap<i32, i32, S>) {}
|
LL | pub fn map<S: ::std::hash::BuildHasher>(map: &mut HashMap<i32, i32, S>) {}
| +++++++++++++++++++++++++++++ +++

error: parameter of type `HashSet` should be generalized over different hashers
--> tests/ui/implicit_hasher.rs:70:22
Expand All @@ -90,9 +89,8 @@ LL | pub fn set(set: &mut HashSet<i32>) {}
|
help: add a type parameter for `BuildHasher`
|
LL - pub fn set(set: &mut HashSet<i32>) {}
LL + pub fn set<S: ::std::hash::BuildHasher>(set: &mut HashSet<i32, S>) {}
|
LL | pub fn set<S: ::std::hash::BuildHasher>(set: &mut HashSet<i32, S>) {}
| +++++++++++++++++++++++++++++ +++

error: impl for `HashMap` should be generalized over different hashers
--> tests/ui/implicit_hasher.rs:76:43
Expand All @@ -116,9 +114,8 @@ LL | pub async fn election_vote(_data: HashMap<i32, i32>) {}
|
help: add a type parameter for `BuildHasher`
|
LL - pub async fn election_vote(_data: HashMap<i32, i32>) {}
LL + pub async fn election_vote<S: ::std::hash::BuildHasher>(_data: HashMap<i32, i32, S>) {}
|
LL | pub async fn election_vote<S: ::std::hash::BuildHasher>(_data: HashMap<i32, i32, S>) {}
| +++++++++++++++++++++++++++++ +++

error: aborting due to 9 previous errors

14 changes: 6 additions & 8 deletions tests/ui/implicit_return.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ LL | true
help: add `return` as shown
|
LL | return true
|
| ++++++

error: missing `return` statement
--> tests/ui/implicit_return.rs:19:15
Expand Down Expand Up @@ -122,7 +122,7 @@ LL | format!("test {}", "test")
help: add `return` as shown
|
LL | return format!("test {}", "test")
|
| ++++++

error: missing `return` statement
--> tests/ui/implicit_return.rs:90:5
Expand All @@ -133,7 +133,7 @@ LL | m!(true, false)
help: add `return` as shown
|
LL | return m!(true, false)
|
| ++++++

error: missing `return` statement
--> tests/ui/implicit_return.rs:96:13
Expand Down Expand Up @@ -169,10 +169,8 @@ LL | | }
|
help: add `return` as shown
|
LL ~ return loop {
LL + m!(true);
LL + }
|
LL | return loop {
| ++++++

error: missing `return` statement
--> tests/ui/implicit_return.rs:130:5
Expand All @@ -183,7 +181,7 @@ LL | true
help: add `return` as shown
|
LL | return true
|
| ++++++

error: aborting due to 16 previous errors

5 changes: 2 additions & 3 deletions tests/ui/literals.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,8 @@ LL + let fail8 = 123;
|
help: if you mean to use an octal constant, use `0o`
|
LL - let fail8 = 0123;
LL + let fail8 = 0o123;
|
LL | let fail8 = 0o123;
| +

error: integer type suffix should not be separated by an underscore
--> tests/ui/literals.rs:48:16
Expand Down
8 changes: 3 additions & 5 deletions tests/ui/manual_flatten.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,9 @@ LL | | }
| |_________^
help: try
|
LL ~ for n in vec![
LL +
LL + Some(1),
LL + Some(2),
LL + Some(3)
LL | for n in vec![
...
LL | Some(3)
LL ~ ].iter().flatten() {
|

Expand Down
Loading

0 comments on commit a666d6a

Please sign in to comment.