Skip to content

Make obligation cause code suggestions verbose #142045

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1411,7 +1411,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
}
}

err.span_suggestion(
err.span_suggestion_verbose(
obligation.cause.span.shrink_to_lo(),
format!(
"consider borrowing the value, since `&{self_ty}` can be coerced into `{target_ty}`"
Expand Down Expand Up @@ -1574,7 +1574,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
.span_extend_while_whitespace(expr_span)
.shrink_to_hi()
.to(await_expr.span.shrink_to_hi());
err.span_suggestion(
err.span_suggestion_verbose(
removal_span,
"remove the `.await`",
"",
Expand Down Expand Up @@ -2126,7 +2126,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
));

if !assoc_item.is_impl_trait_in_trait() {
err.span_suggestion(
err.span_suggestion_verbose(
span,
"use the fully qualified path to an implementation",
format!(
Expand Down Expand Up @@ -2924,12 +2924,14 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
);
let sm = tcx.sess.source_map();
if matches!(is_constable, IsConstable::Fn | IsConstable::Ctor)
&& let Ok(snip) = sm.span_to_snippet(elt_span)
&& let Ok(_) = sm.span_to_snippet(elt_span)
{
err.span_suggestion(
elt_span,
err.multipart_suggestion(
"create an inline `const` block",
format!("const {{ {snip} }}"),
vec![
(elt_span.shrink_to_lo(), "const { ".to_string()),
(elt_span.shrink_to_hi(), " }".to_string()),
],
Applicability::MachineApplicable,
);
} else {
Expand Down Expand Up @@ -3127,13 +3129,13 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
}
}
err.help("change the field's type to have a statically known size");
err.span_suggestion(
err.span_suggestion_verbose(
span.shrink_to_lo(),
"borrowed types always have a statically known size",
"&",
Applicability::MachineApplicable,
);
err.multipart_suggestion(
err.multipart_suggestion_verbose(
"the `Box` type always has a statically known size and allocates its contents \
in the heap",
vec![
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ error[E0277]: `[usize; usize::MAX]` is not a future
--> $DIR/debug-ice-attempted-to-add-with-overflow.rs:8:37
|
LL | [0usize; 0xffff_ffff_ffff_ffff].await;
| -^^^^^
| ||
| |`[usize; usize::MAX]` is not a future
| help: remove the `.await`
| ^^^^^ `[usize; usize::MAX]` is not a future
|
= help: the trait `Future` is not implemented for `[usize; usize::MAX]`
= note: [usize; usize::MAX] must be a future or must implement `IntoFuture` to be awaited
= note: required for `[usize; usize::MAX]` to implement `IntoFuture`
help: remove the `.await`
|
LL - [0usize; 0xffff_ffff_ffff_ffff].await;
LL + [0usize; 0xffff_ffff_ffff_ffff];
|

error[E0752]: `main` function is not allowed to be `async`
--> $DIR/debug-ice-attempted-to-add-with-overflow.rs:6:1
Expand Down
10 changes: 6 additions & 4 deletions tests/ui/async-await/drop-track-bad-field-in-fru.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ error[E0277]: `Option<_>` is not a future
--> $DIR/drop-track-bad-field-in-fru.rs:6:46
|
LL | None { value: (), ..Default::default() }.await;
| -^^^^^
| ||
| |`Option<_>` is not a future
| help: remove the `.await`
| ^^^^^ `Option<_>` is not a future
|
= help: the trait `Future` is not implemented for `Option<_>`
= note: Option<_> must be a future or must implement `IntoFuture` to be awaited
= note: required for `Option<_>` to implement `IntoFuture`
help: remove the `.await`
|
LL - None { value: (), ..Default::default() }.await;
LL + None { value: (), ..Default::default() };
|

error: aborting due to 2 previous errors

Expand Down
9 changes: 5 additions & 4 deletions tests/ui/async-await/issue-101715.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ error[E0277]: `()` is not a future
--> $DIR/issue-101715.rs:11:10
|
LL | .await
| -^^^^^
| ||
| |`()` is not a future
| help: remove the `.await`
| ^^^^^ `()` is not a future
|
= help: the trait `Future` is not implemented for `()`
= note: () must be a future or must implement `IntoFuture` to be awaited
= note: required for `()` to implement `IntoFuture`
help: remove the `.await`
|
LL - .await
|

error: aborting due to 1 previous error

Expand Down
20 changes: 12 additions & 8 deletions tests/ui/async-await/unnecessary-await.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@ error[E0277]: `()` is not a future
--> $DIR/unnecessary-await.rs:28:10
|
LL | e!().await;
| -^^^^^
| ||
| |`()` is not a future
| help: remove the `.await`
| ^^^^^ `()` is not a future
|
= help: the trait `Future` is not implemented for `()`
= note: () must be a future or must implement `IntoFuture` to be awaited
= note: required for `()` to implement `IntoFuture`
help: remove the `.await`
|
LL - e!().await;
LL + e!();
|

error[E0277]: `()` is not a future
--> $DIR/unnecessary-await.rs:22:15
Expand All @@ -53,14 +55,16 @@ error[E0277]: `()` is not a future
--> $DIR/unnecessary-await.rs:36:20
|
LL | for x in [] {}.await
| -^^^^^
| ||
| |`()` is not a future
| help: remove the `.await`
| ^^^^^ `()` is not a future
|
= help: the trait `Future` is not implemented for `()`
= note: () must be a future or must implement `IntoFuture` to be awaited
= note: required for `()` to implement `IntoFuture`
help: remove the `.await`
|
LL - for x in [] {}.await
LL + for x in [] {}
|

error: aborting due to 4 previous errors

Expand Down
5 changes: 2 additions & 3 deletions tests/ui/consts/const-blocks/fn-call-in-non-const.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ LL | struct Bar;
|
help: create an inline `const` block
|
LL - let _: [Option<Bar>; 2] = [no_copy(); 2];
LL + let _: [Option<Bar>; 2] = [const { no_copy() }; 2];
|
LL | let _: [Option<Bar>; 2] = [const { no_copy() }; 2];
| +++++++ +

error: aborting due to 1 previous error

Expand Down
9 changes: 5 additions & 4 deletions tests/ui/consts/const-blocks/trait-error.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ error[E0277]: the trait bound `String: Copy` is not satisfied
--> $DIR/trait-error.rs:5:6
|
LL | [Foo(String::new()); 4];
| ^^^^^^^^^^^^^^^^^^
| |
| the trait `Copy` is not implemented for `String`
| help: create an inline `const` block: `const { Foo(String::new()) }`
| ^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String`
|
note: required for `Foo<String>` to implement `Copy`
--> $DIR/trait-error.rs:1:10
|
LL | #[derive(Copy, Clone)]
| ^^^^ unsatisfied trait bound introduced in this `derive` macro
= note: the `Copy` trait is required because this value will be copied for each element of the array
help: create an inline `const` block
|
LL | [const { Foo(String::new()) }; 4];
| +++++++ +

error: aborting due to 1 previous error

Expand Down
27 changes: 15 additions & 12 deletions tests/ui/consts/const-fn-in-vec.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,39 @@ error[E0277]: the trait bound `String: Copy` is not satisfied
--> $DIR/const-fn-in-vec.rs:1:47
|
LL | static _MAYBE_STRINGS: [Option<String>; 5] = [None; 5];
| ^^^^
| |
| the trait `Copy` is not implemented for `String`
| help: create an inline `const` block: `const { None }`
| ^^^^ the trait `Copy` is not implemented for `String`
|
= note: required for `Option<String>` to implement `Copy`
= note: the `Copy` trait is required because this value will be copied for each element of the array
help: create an inline `const` block
|
LL | static _MAYBE_STRINGS: [Option<String>; 5] = [const { None }; 5];
| +++++++ +

error[E0277]: the trait bound `String: Copy` is not satisfied
--> $DIR/const-fn-in-vec.rs:7:34
|
LL | let _strings: [String; 5] = [String::new(); 5];
| ^^^^^^^^^^^^^
| |
| the trait `Copy` is not implemented for `String`
| help: create an inline `const` block: `const { String::new() }`
| ^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String`
|
= note: the `Copy` trait is required because this value will be copied for each element of the array
help: create an inline `const` block
|
LL | let _strings: [String; 5] = [const { String::new() }; 5];
| +++++++ +

error[E0277]: the trait bound `String: Copy` is not satisfied
--> $DIR/const-fn-in-vec.rs:12:48
|
LL | let _maybe_strings: [Option<String>; 5] = [None; 5];
| ^^^^
| |
| the trait `Copy` is not implemented for `String`
| help: create an inline `const` block: `const { None }`
| ^^^^ the trait `Copy` is not implemented for `String`
|
= note: required for `Option<String>` to implement `Copy`
= note: the `Copy` trait is required because this value will be copied for each element of the array
help: create an inline `const` block
|
LL | let _maybe_strings: [Option<String>; 5] = [const { None }; 5];
| +++++++ +

error: aborting due to 3 previous errors

Expand Down
11 changes: 7 additions & 4 deletions tests/ui/coroutine/unresolved-ct-var.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ error[E0277]: `[(); _]` is not a future
--> $DIR/unresolved-ct-var.rs:6:45
|
LL | let s = std::array::from_fn(|_| ()).await;
| ----------------------------^^^^^
| | ||
| | |`[(); _]` is not a future
| | help: remove the `.await`
| --------------------------- ^^^^^ `[(); _]` is not a future
| |
| this call returns `[(); _]`
|
= help: the trait `Future` is not implemented for `[(); _]`
= note: [(); _] must be a future or must implement `IntoFuture` to be awaited
= note: required for `[(); _]` to implement `IntoFuture`
help: remove the `.await`
|
LL - let s = std::array::from_fn(|_| ()).await;
LL + let s = std::array::from_fn(|_| ());
|

error: aborting due to 1 previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ error[E0277]: the trait bound `String: Copy` is not satisfied
--> $DIR/copy-check-when-count-inferred-later.rs:8:14
|
LL | let a = [String::new(); _];
| ^^^^^^^^^^^^^
| |
| the trait `Copy` is not implemented for `String`
| help: create an inline `const` block: `const { String::new() }`
| ^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String`
|
= note: the `Copy` trait is required because this value will be copied for each element of the array
help: create an inline `const` block
|
LL | let a = [const { String::new() }; _];
| +++++++ +

error: aborting due to 1 previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0283]: type annotations needed: cannot satisfy `Foo: Trait<Bar>`
--> $DIR/constrain_in_projection2.rs:28:14
|
LL | let x = <Foo as Trait<Bar>>::Assoc::default();
| ^^^ help: use the fully qualified path to an implementation: `<Type as Trait>::Assoc`
| ^^^
|
note: multiple `impl`s satisfying `Foo: Trait<Bar>` found
--> $DIR/constrain_in_projection2.rs:18:1
Expand All @@ -13,6 +13,11 @@ LL | impl Trait<()> for Foo {
LL | impl Trait<u32> for Foo {
| ^^^^^^^^^^^^^^^^^^^^^^^
= note: associated types cannot be accessed directly on a `trait`, they can only be accessed through a specific `impl`
help: use the fully qualified path to an implementation
|
LL - let x = <Foo as Trait<Bar>>::Assoc::default();
LL + let x = <<Type as Trait>::Assoc as Trait<Bar>>::Assoc::default();
|

error: aborting due to 1 previous error

Expand Down
Loading