Make Diag::multipart_suggestions always verbose

This commit is contained in:
Esteban Küber
2025-07-10 17:21:59 +00:00
parent 7dfc3e9af4
commit 0674eca2f0
24 changed files with 187 additions and 110 deletions

View File

@@ -1165,7 +1165,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
self.push_suggestion(CodeSuggestion {
substitutions,
msg: self.subdiagnostic_message_to_diagnostic_message(msg),
style: SuggestionStyle::ShowCode,
style: SuggestionStyle::ShowAlways,
applicability,
});
self

View File

@@ -2,10 +2,8 @@ error[E0277]: the trait bound `B<C>: Copy` is not satisfied
--> $DIR/deriving-copyclone.rs:31:26
|
LL | is_copy(B { a: 1, b: C });
| ------- ^
| | |
| | the trait `Copy` is not implemented for `B<C>`
| | help: consider borrowing here: `&`
| ------- ^ the trait `Copy` is not implemented for `B<C>`
| |
| required by a bound introduced by this call
|
note: required for `B<C>` to implement `Copy`
@@ -18,15 +16,17 @@ note: required by a bound in `is_copy`
|
LL | fn is_copy<T: Copy>(_: T) {}
| ^^^^ required by this bound in `is_copy`
help: consider borrowing here
|
LL | is_copy(B { a: 1, b: &C });
| +
error[E0277]: the trait bound `B<C>: Clone` is not satisfied
--> $DIR/deriving-copyclone.rs:32:27
|
LL | is_clone(B { a: 1, b: C });
| -------- ^
| | |
| | the trait `Clone` is not implemented for `B<C>`
| | help: consider borrowing here: `&`
| -------- ^ the trait `Clone` is not implemented for `B<C>`
| |
| required by a bound introduced by this call
|
note: required for `B<C>` to implement `Clone`
@@ -39,15 +39,17 @@ note: required by a bound in `is_clone`
|
LL | fn is_clone<T: Clone>(_: T) {}
| ^^^^^ required by this bound in `is_clone`
help: consider borrowing here
|
LL | is_clone(B { a: 1, b: &C });
| +
error[E0277]: the trait bound `B<D>: Copy` is not satisfied
--> $DIR/deriving-copyclone.rs:35:26
|
LL | is_copy(B { a: 1, b: D });
| ------- ^
| | |
| | the trait `Copy` is not implemented for `B<D>`
| | help: consider borrowing here: `&`
| ------- ^ the trait `Copy` is not implemented for `B<D>`
| |
| required by a bound introduced by this call
|
note: required for `B<D>` to implement `Copy`
@@ -60,6 +62,10 @@ note: required by a bound in `is_copy`
|
LL | fn is_copy<T: Copy>(_: T) {}
| ^^^^ required by this bound in `is_copy`
help: consider borrowing here
|
LL | is_copy(B { a: 1, b: &D });
| +
error: aborting due to 3 previous errors

View File

@@ -2,13 +2,14 @@ error[E0277]: `dyn Iterator<Item = &'a mut u8>` is not an iterator
--> $DIR/issue-20605.rs:6:17
|
LL | for item in *things { *item = 0 }
| -^^^^^^
| |
| the trait `IntoIterator` is not implemented for `dyn Iterator<Item = &'a mut u8>`
| help: consider mutably borrowing here: `&mut`
| ^^^^^^^ the trait `IntoIterator` is not implemented for `dyn Iterator<Item = &'a mut u8>`
|
= note: the trait bound `dyn Iterator<Item = &'a mut u8>: IntoIterator` is not satisfied
= note: required for `dyn Iterator<Item = &'a mut u8>` to implement `IntoIterator`
help: consider mutably borrowing here
|
LL | for item in &mut *things { *item = 0 }
| ++++
error: aborting due to 1 previous error

View File

@@ -2,13 +2,14 @@ error[E0277]: `dyn Iterator<Item = &'a mut u8>` is not an iterator
--> $DIR/issue-20605.rs:6:17
|
LL | for item in *things { *item = 0 }
| -^^^^^^
| |
| the trait `IntoIterator` is not implemented for `dyn Iterator<Item = &'a mut u8>`
| help: consider mutably borrowing here: `&mut`
| ^^^^^^^ the trait `IntoIterator` is not implemented for `dyn Iterator<Item = &'a mut u8>`
|
= note: the trait bound `dyn Iterator<Item = &'a mut u8>: IntoIterator` is not satisfied
= note: required for `dyn Iterator<Item = &'a mut u8>` to implement `IntoIterator`
help: consider mutably borrowing here
|
LL | for item in &mut *things { *item = 0 }
| ++++
error: aborting due to 1 previous error

View File

@@ -4,9 +4,12 @@ error[E0308]: mismatched types
LL | async fn woopsie_async(&self) -> String {
| ------ expected `String` because of return type
LL | 42
| ^^- help: try using a conversion method: `.to_string()`
| |
| expected `String`, found integer
| ^^ expected `String`, found integer
|
help: try using a conversion method
|
LL | 42.to_string()
| ++++++++++++
error: aborting due to 1 previous error

View File

@@ -2,9 +2,8 @@ error[E0308]: mismatched types
--> $DIR/deref-suggestion.rs:8:9
|
LL | foo(s);
| --- ^- help: try using a conversion method: `.to_string()`
| | |
| | expected `String`, found `&String`
| --- ^ expected `String`, found `&String`
| |
| arguments to this function are incorrect
|
note: function defined here
@@ -12,6 +11,10 @@ note: function defined here
|
LL | fn foo(_: String) {}
| ^^^ ---------
help: try using a conversion method
|
LL | foo(s.to_string());
| ++++++++++++
error[E0308]: mismatched types
--> $DIR/deref-suggestion.rs:14:10

View File

@@ -38,9 +38,12 @@ error[E0308]: mismatched types
--> $DIR/typo-in-repeat-expr-issue-80173.rs:32:29
|
LL | let e = [String::new(), 10];
| ^^- help: try using a conversion method: `.to_string()`
| |
| expected `String`, found integer
| ^^ expected `String`, found integer
|
help: try using a conversion method
|
LL | let e = [String::new(), 10.to_string()];
| ++++++++++++
error[E0308]: mismatched types
--> $DIR/typo-in-repeat-expr-issue-80173.rs:36:19

View File

@@ -2,9 +2,12 @@ error[E0308]: mismatched types
--> $DIR/bad-const-type.rs:1:20
|
LL | static i: String = 10;
| ^^- help: try using a conversion method: `.to_string()`
| |
| expected `String`, found integer
| ^^ expected `String`, found integer
|
help: try using a conversion method
|
LL | static i: String = 10.to_string();
| ++++++++++++
error: aborting due to 1 previous error

View File

@@ -21,10 +21,8 @@ error[E0277]: the trait bound `S: Trait` is not satisfied
--> $DIR/imm-ref-trait-object-literal.rs:13:7
|
LL | foo(s);
| --- ^
| | |
| | the trait `Trait` is not implemented for `S`
| | help: consider mutably borrowing here: `&mut`
| --- ^ the trait `Trait` is not implemented for `S`
| |
| required by a bound introduced by this call
|
note: required by a bound in `foo`
@@ -32,6 +30,10 @@ note: required by a bound in `foo`
|
LL | fn foo<X: Trait>(_: X) {}
| ^^^^^ required by this bound in `foo`
help: consider mutably borrowing here
|
LL | foo(&mut s);
| ++++
error: aborting due to 2 previous errors

View File

@@ -18,15 +18,17 @@ error[E0277]: the trait bound `String: Pattern` is not satisfied
--> $DIR/issue-104961.rs:9:19
|
LL | x.starts_with("hi".to_string())
| ----------- -^^^^^^^^^^^^^^^
| | |
| | the trait `Pattern` is not implemented for `String`
| | help: consider borrowing here: `&`
| ----------- ^^^^^^^^^^^^^^^^ the trait `Pattern` is not implemented for `String`
| |
| required by a bound introduced by this call
|
= note: required for `String` to implement `Pattern`
note: required by a bound in `core::str::<impl str>::starts_with`
--> $SRC_DIR/core/src/str/mod.rs:LL:COL
help: consider borrowing here
|
LL | x.starts_with(&"hi".to_string())
| +
error: aborting due to 2 previous errors

View File

@@ -13,10 +13,13 @@ error[E0308]: mismatched types
--> $DIR/issue-52820.rs:13:17
|
LL | brains: guts.clone(),
| ^^^^^-----^^
| | |
| | help: try using a conversion method: `to_string`
| expected `String`, found `&str`
| ^^^^^^^^^^^^ expected `String`, found `&str`
|
help: try using a conversion method
|
LL - brains: guts.clone(),
LL + brains: guts.to_string(),
|
error: aborting due to 2 previous errors

View File

@@ -2,24 +2,31 @@ error[E0308]: mismatched types
--> $DIR/issue-53692.rs:7:33
|
LL | let items_clone: Vec<i32> = ref_items.clone();
| -------- ^^^^^^^^^^-----^^
| | | |
| | | help: try using a conversion method: `to_vec`
| | expected `Vec<i32>`, found `&[i32]`
| -------- ^^^^^^^^^^^^^^^^^ expected `Vec<i32>`, found `&[i32]`
| |
| expected due to this
|
= note: expected struct `Vec<i32>`
found reference `&[i32]`
help: try using a conversion method
|
LL - let items_clone: Vec<i32> = ref_items.clone();
LL + let items_clone: Vec<i32> = ref_items.to_vec();
|
error[E0308]: mismatched types
--> $DIR/issue-53692.rs:14:26
|
LL | let string: String = s.clone();
| ------ ^^-----^^
| | | |
| | | help: try using a conversion method: `to_string`
| | expected `String`, found `&str`
| ------ ^^^^^^^^^ expected `String`, found `&str`
| |
| expected due to this
|
help: try using a conversion method
|
LL - let string: String = s.clone();
LL + let string: String = s.to_string();
|
error: aborting due to 2 previous errors

View File

@@ -28,10 +28,14 @@ error[E0308]: mismatched types
--> $DIR/issue-59819.rs:34:21
|
LL | let g: String = f;
| ------ ^- help: try using a conversion method: `.to_string()`
| | |
| | expected `String`, found `Bar`
| ------ ^ expected `String`, found `Bar`
| |
| expected due to this
|
help: try using a conversion method
|
LL | let g: String = f.to_string();
| ++++++++++++
error: aborting due to 3 previous errors

View File

@@ -2,15 +2,17 @@ error[E0277]: the trait bound `String: Pattern` is not satisfied
--> $DIR/issue-62843.rs:4:32
|
LL | println!("{:?}", line.find(pattern));
| ---- -^^^^^^
| | |
| | the trait `Pattern` is not implemented for `String`
| | help: consider borrowing here: `&`
| ---- ^^^^^^^ the trait `Pattern` is not implemented for `String`
| |
| required by a bound introduced by this call
|
= note: required for `String` to implement `Pattern`
note: required by a bound in `core::str::<impl str>::find`
--> $SRC_DIR/core/src/str/mod.rs:LL:COL
help: consider borrowing here
|
LL | println!("{:?}", line.find(&pattern));
| +
error: aborting due to 1 previous error

View File

@@ -6,11 +6,14 @@ LL | | "A".to_string()
| | --------------- expected because of this
LL | | } else {
LL | | "B"
| | ^^^- help: try using a conversion method: `.to_string()`
| | |
| | expected `String`, found `&str`
| | ^^^ expected `String`, found `&str`
LL | | };
| |_____- `if` and `else` have incompatible types
|
help: try using a conversion method
|
LL | "B".to_string()
| ++++++++++++
error: aborting due to 1 previous error

View File

@@ -2,10 +2,8 @@ error[E0277]: the trait bound `i32: Tr` is not satisfied
--> $DIR/issue-84973-2.rs:11:9
|
LL | foo(a);
| --- ^
| | |
| | the trait `Tr` is not implemented for `i32`
| | help: consider mutably borrowing here: `&mut`
| --- ^ the trait `Tr` is not implemented for `i32`
| |
| required by a bound introduced by this call
|
note: required by a bound in `foo`
@@ -13,6 +11,10 @@ note: required by a bound in `foo`
|
LL | fn foo<T: Tr>(i: T) {}
| ^^ required by this bound in `foo`
help: consider mutably borrowing here
|
LL | foo(&mut a);
| ++++
error: aborting due to 1 previous error

View File

@@ -17,10 +17,8 @@ error[E0277]: the trait bound `f32: Tr` is not satisfied
--> $DIR/issue-84973-negative.rs:11:9
|
LL | bar(b);
| --- ^
| | |
| | the trait `Tr` is not implemented for `f32`
| | help: consider borrowing here: `&`
| --- ^ the trait `Tr` is not implemented for `f32`
| |
| required by a bound introduced by this call
|
note: required by a bound in `bar`
@@ -28,6 +26,10 @@ note: required by a bound in `bar`
|
LL | fn bar<T: Tr>(t: T) {}
| ^^ required by this bound in `bar`
help: consider borrowing here
|
LL | bar(&b);
| +
error: aborting due to 2 previous errors

View File

@@ -2,10 +2,8 @@ error[E0277]: the trait bound `Fancy: SomeTrait` is not satisfied
--> $DIR/issue-84973.rs:6:24
|
LL | let o = Other::new(f);
| ---------- ^
| | |
| | the trait `SomeTrait` is not implemented for `Fancy`
| | help: consider borrowing here: `&`
| ---------- ^ the trait `SomeTrait` is not implemented for `Fancy`
| |
| required by a bound introduced by this call
|
note: required by a bound in `Other::<'a, G>::new`
@@ -16,6 +14,10 @@ LL | G: SomeTrait,
LL | {
LL | pub fn new(g: G) -> Self {
| --- required by a bound in this associated function
help: consider borrowing here
|
LL | let o = Other::new(&f);
| +
error: aborting due to 1 previous error

View File

@@ -5,9 +5,12 @@ LL | fn get_name() -> String {
| ------ expected `String` because of return type
...
LL | your_name.trim()
| ^^^^^^^^^^^^^^^^- help: try using a conversion method: `.to_string()`
| |
| expected `String`, found `&str`
| ^^^^^^^^^^^^^^^^ expected `String`, found `&str`
|
help: try using a conversion method
|
LL | your_name.trim().to_string()
| ++++++++++++
error: aborting due to 1 previous error

View File

@@ -2,19 +2,23 @@ error[E0277]: the trait bound `&mut usize: Default` is not satisfied
--> $DIR/suggest-adding-reference-to-trait-assoc-item.rs:13:9
|
LL | foo(Default::default());
| -^^^^^^^^^^^^^^^^^
| |
| the trait `Default` is not implemented for `&mut usize`
| help: consider mutably borrowing here: `&mut`
| ^^^^^^^^^^^^^^^^^^ the trait `Default` is not implemented for `&mut usize`
|
help: consider mutably borrowing here
|
LL | foo(&mut Default::default());
| ++++
error[E0277]: the trait bound `&usize: Default` is not satisfied
--> $DIR/suggest-adding-reference-to-trait-assoc-item.rs:14:9
|
LL | bar(Default::default());
| -^^^^^^^^^^^^^^^^^
| |
| the trait `Default` is not implemented for `&usize`
| help: consider borrowing here: `&`
| ^^^^^^^^^^^^^^^^^^ the trait `Default` is not implemented for `&usize`
|
help: consider borrowing here
|
LL | bar(&Default::default());
| +
error: aborting due to 2 previous errors

View File

@@ -22,10 +22,8 @@ error[E0277]: the trait bound `B: Trait` is not satisfied
--> $DIR/suggest-imm-mut-trait-implementations.rs:21:9
|
LL | foo(b);
| --- ^
| | |
| | the trait `Trait` is not implemented for `B`
| | help: consider borrowing here: `&`
| --- ^ the trait `Trait` is not implemented for `B`
| |
| required by a bound introduced by this call
|
note: required by a bound in `foo`
@@ -33,15 +31,17 @@ note: required by a bound in `foo`
|
LL | fn foo<X: Trait>(_: X) {}
| ^^^^^ required by this bound in `foo`
help: consider borrowing here
|
LL | foo(&b);
| +
error[E0277]: the trait bound `C: Trait` is not satisfied
--> $DIR/suggest-imm-mut-trait-implementations.rs:22:9
|
LL | foo(c);
| --- ^
| | |
| | the trait `Trait` is not implemented for `C`
| | help: consider mutably borrowing here: `&mut`
| --- ^ the trait `Trait` is not implemented for `C`
| |
| required by a bound introduced by this call
|
note: required by a bound in `foo`
@@ -49,6 +49,10 @@ note: required by a bound in `foo`
|
LL | fn foo<X: Trait>(_: X) {}
| ^^^^^ required by this bound in `foo`
help: consider mutably borrowing here
|
LL | foo(&mut c);
| ++++
error: aborting due to 3 previous errors

View File

@@ -2,9 +2,12 @@ error[E0308]: mismatched types
--> $DIR/switched-expectations.rs:3:30
|
LL | let ref string: String = var;
| ^^^- help: try using a conversion method: `.to_string()`
| |
| expected `String`, found `i32`
| ^^^ expected `String`, found `i32`
|
help: try using a conversion method
|
LL | let ref string: String = var.to_string();
| ++++++++++++
error: aborting due to 1 previous error

View File

@@ -61,10 +61,8 @@ error[E0277]: `dummy2::TestType` cannot be sent between threads safely
--> $DIR/negated-auto-traits-error.rs:48:13
|
LL | is_send(Box::new(TestType));
| ------- -^^^^^^^^^^^^^^^^^
| | |
| | the trait `Send` is not implemented for `Unique<dummy2::TestType>`
| | help: consider borrowing here: `&`
| ------- ^^^^^^^^^^^^^^^^^^ the trait `Send` is not implemented for `Unique<dummy2::TestType>`
| |
| required by a bound introduced by this call
|
= note: the trait bound `Unique<dummy2::TestType>: Send` is not satisfied
@@ -76,6 +74,10 @@ note: required by a bound in `is_send`
|
LL | fn is_send<T: Send>(_: T) {}
| ^^^^ required by this bound in `is_send`
help: consider borrowing here
|
LL | is_send(&Box::new(TestType));
| +
error[E0277]: `dummy3::TestType` cannot be sent between threads safely
--> $DIR/negated-auto-traits-error.rs:56:13

View File

@@ -2,28 +2,40 @@ error[E0308]: mismatched types
--> $DIR/conversion-methods.rs:5:41
|
LL | let _tis_an_instants_play: String = "'Tis a fond Ambush—";
| ------ ^^^^^^^^^^^^^^^^^^^^^- help: try using a conversion method: `.to_string()`
| | |
| | expected `String`, found `&str`
| ------ ^^^^^^^^^^^^^^^^^^^^^ expected `String`, found `&str`
| |
| expected due to this
|
help: try using a conversion method
|
LL | let _tis_an_instants_play: String = "'Tis a fond Ambush—".to_string();
| ++++++++++++
error[E0308]: mismatched types
--> $DIR/conversion-methods.rs:6:40
|
LL | let _just_to_make_bliss: PathBuf = Path::new("/ern/her/own/surprise");
| ------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- help: try using a conversion method: `.to_path_buf()`
| | |
| | expected `PathBuf`, found `&Path`
| ------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `PathBuf`, found `&Path`
| |
| expected due to this
|
help: try using a conversion method
|
LL | let _just_to_make_bliss: PathBuf = Path::new("/ern/her/own/surprise").to_path_buf();
| ++++++++++++++
error[E0308]: mismatched types
--> $DIR/conversion-methods.rs:9:40
|
LL | let _but_should_the_play: String = 2; // Perhaps surprisingly, we suggest .to_string() here
| ------ ^- help: try using a conversion method: `.to_string()`
| | |
| | expected `String`, found integer
| ------ ^ expected `String`, found integer
| |
| expected due to this
|
help: try using a conversion method
|
LL | let _but_should_the_play: String = 2.to_string(); // Perhaps surprisingly, we suggest .to_string() here
| ++++++++++++
error[E0308]: mismatched types
--> $DIR/conversion-methods.rs:12:47