Skip to content

Commit 2caa2a7

Browse files
authored
Unrolled build for #142045
Rollup merge of #142045 - estebank:obligation-cause-code-suggestion, r=compiler-errors Make obligation cause code suggestions verbose ``` error[E0277]: `()` is not a future --> $DIR/unnecessary-await.rs:28:10 | LL | e!().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]: 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` | = 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]; | +++++++ + ``` Part of #141973
2 parents 1dc9ae6 + ac980ca commit 2caa2a7

File tree

11 files changed

+80
-57
lines changed

11 files changed

+80
-57
lines changed

compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,7 +1411,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
14111411
}
14121412
}
14131413

1414-
err.span_suggestion(
1414+
err.span_suggestion_verbose(
14151415
obligation.cause.span.shrink_to_lo(),
14161416
format!(
14171417
"consider borrowing the value, since `&{self_ty}` can be coerced into `{target_ty}`"
@@ -1574,7 +1574,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
15741574
.span_extend_while_whitespace(expr_span)
15751575
.shrink_to_hi()
15761576
.to(await_expr.span.shrink_to_hi());
1577-
err.span_suggestion(
1577+
err.span_suggestion_verbose(
15781578
removal_span,
15791579
"remove the `.await`",
15801580
"",
@@ -2126,7 +2126,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
21262126
));
21272127

21282128
if !assoc_item.is_impl_trait_in_trait() {
2129-
err.span_suggestion(
2129+
err.span_suggestion_verbose(
21302130
span,
21312131
"use the fully qualified path to an implementation",
21322132
format!(
@@ -2924,12 +2924,14 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
29242924
);
29252925
let sm = tcx.sess.source_map();
29262926
if matches!(is_constable, IsConstable::Fn | IsConstable::Ctor)
2927-
&& let Ok(snip) = sm.span_to_snippet(elt_span)
2927+
&& let Ok(_) = sm.span_to_snippet(elt_span)
29282928
{
2929-
err.span_suggestion(
2930-
elt_span,
2929+
err.multipart_suggestion(
29312930
"create an inline `const` block",
2932-
format!("const {{ {snip} }}"),
2931+
vec![
2932+
(elt_span.shrink_to_lo(), "const { ".to_string()),
2933+
(elt_span.shrink_to_hi(), " }".to_string()),
2934+
],
29332935
Applicability::MachineApplicable,
29342936
);
29352937
} else {
@@ -3127,13 +3129,13 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
31273129
}
31283130
}
31293131
err.help("change the field's type to have a statically known size");
3130-
err.span_suggestion(
3132+
err.span_suggestion_verbose(
31313133
span.shrink_to_lo(),
31323134
"borrowed types always have a statically known size",
31333135
"&",
31343136
Applicability::MachineApplicable,
31353137
);
3136-
err.multipart_suggestion(
3138+
err.multipart_suggestion_verbose(
31373139
"the `Box` type always has a statically known size and allocates its contents \
31383140
in the heap",
31393141
vec![

tests/ui/async-await/debug-ice-attempted-to-add-with-overflow.stderr

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ error[E0277]: `[usize; usize::MAX]` is not a future
22
--> $DIR/debug-ice-attempted-to-add-with-overflow.rs:8:37
33
|
44
LL | [0usize; 0xffff_ffff_ffff_ffff].await;
5-
| -^^^^^
6-
| ||
7-
| |`[usize; usize::MAX]` is not a future
8-
| help: remove the `.await`
5+
| ^^^^^ `[usize; usize::MAX]` is not a future
96
|
107
= help: the trait `Future` is not implemented for `[usize; usize::MAX]`
118
= note: [usize; usize::MAX] must be a future or must implement `IntoFuture` to be awaited
129
= note: required for `[usize; usize::MAX]` to implement `IntoFuture`
10+
help: remove the `.await`
11+
|
12+
LL - [0usize; 0xffff_ffff_ffff_ffff].await;
13+
LL + [0usize; 0xffff_ffff_ffff_ffff];
14+
|
1315

1416
error[E0752]: `main` function is not allowed to be `async`
1517
--> $DIR/debug-ice-attempted-to-add-with-overflow.rs:6:1

tests/ui/async-await/drop-track-bad-field-in-fru.stderr

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ error[E0277]: `Option<_>` is not a future
1010
--> $DIR/drop-track-bad-field-in-fru.rs:6:46
1111
|
1212
LL | None { value: (), ..Default::default() }.await;
13-
| -^^^^^
14-
| ||
15-
| |`Option<_>` is not a future
16-
| help: remove the `.await`
13+
| ^^^^^ `Option<_>` is not a future
1714
|
1815
= help: the trait `Future` is not implemented for `Option<_>`
1916
= note: Option<_> must be a future or must implement `IntoFuture` to be awaited
2017
= note: required for `Option<_>` to implement `IntoFuture`
18+
help: remove the `.await`
19+
|
20+
LL - None { value: (), ..Default::default() }.await;
21+
LL + None { value: (), ..Default::default() };
22+
|
2123

2224
error: aborting due to 2 previous errors
2325

tests/ui/async-await/issue-101715.stderr

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ error[E0277]: `()` is not a future
22
--> $DIR/issue-101715.rs:11:10
33
|
44
LL | .await
5-
| -^^^^^
6-
| ||
7-
| |`()` is not a future
8-
| help: remove the `.await`
5+
| ^^^^^ `()` is not a future
96
|
107
= help: the trait `Future` is not implemented for `()`
118
= note: () must be a future or must implement `IntoFuture` to be awaited
129
= note: required for `()` to implement `IntoFuture`
10+
help: remove the `.await`
11+
|
12+
LL - .await
13+
|
1314

1415
error: aborting due to 1 previous error
1516

tests/ui/async-await/unnecessary-await.stderr

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,16 @@ error[E0277]: `()` is not a future
2323
--> $DIR/unnecessary-await.rs:28:10
2424
|
2525
LL | e!().await;
26-
| -^^^^^
27-
| ||
28-
| |`()` is not a future
29-
| help: remove the `.await`
26+
| ^^^^^ `()` is not a future
3027
|
3128
= help: the trait `Future` is not implemented for `()`
3229
= note: () must be a future or must implement `IntoFuture` to be awaited
3330
= note: required for `()` to implement `IntoFuture`
31+
help: remove the `.await`
32+
|
33+
LL - e!().await;
34+
LL + e!();
35+
|
3436

3537
error[E0277]: `()` is not a future
3638
--> $DIR/unnecessary-await.rs:22:15
@@ -53,14 +55,16 @@ error[E0277]: `()` is not a future
5355
--> $DIR/unnecessary-await.rs:36:20
5456
|
5557
LL | for x in [] {}.await
56-
| -^^^^^
57-
| ||
58-
| |`()` is not a future
59-
| help: remove the `.await`
58+
| ^^^^^ `()` is not a future
6059
|
6160
= help: the trait `Future` is not implemented for `()`
6261
= note: () must be a future or must implement `IntoFuture` to be awaited
6362
= note: required for `()` to implement `IntoFuture`
63+
help: remove the `.await`
64+
|
65+
LL - for x in [] {}.await
66+
LL + for x in [] {}
67+
|
6468

6569
error: aborting due to 4 previous errors
6670

tests/ui/consts/const-blocks/fn-call-in-non-const.stderr

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ LL | struct Bar;
1313
|
1414
help: create an inline `const` block
1515
|
16-
LL - let _: [Option<Bar>; 2] = [no_copy(); 2];
17-
LL + let _: [Option<Bar>; 2] = [const { no_copy() }; 2];
18-
|
16+
LL | let _: [Option<Bar>; 2] = [const { no_copy() }; 2];
17+
| +++++++ +
1918

2019
error: aborting due to 1 previous error
2120

tests/ui/consts/const-blocks/trait-error.stderr

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@ error[E0277]: the trait bound `String: Copy` is not satisfied
22
--> $DIR/trait-error.rs:5:6
33
|
44
LL | [Foo(String::new()); 4];
5-
| ^^^^^^^^^^^^^^^^^^
6-
| |
7-
| the trait `Copy` is not implemented for `String`
8-
| help: create an inline `const` block: `const { Foo(String::new()) }`
5+
| ^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String`
96
|
107
note: required for `Foo<String>` to implement `Copy`
118
--> $DIR/trait-error.rs:1:10
129
|
1310
LL | #[derive(Copy, Clone)]
1411
| ^^^^ unsatisfied trait bound introduced in this `derive` macro
1512
= note: the `Copy` trait is required because this value will be copied for each element of the array
13+
help: create an inline `const` block
14+
|
15+
LL | [const { Foo(String::new()) }; 4];
16+
| +++++++ +
1617

1718
error: aborting due to 1 previous error
1819

tests/ui/consts/const-fn-in-vec.stderr

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,39 @@ error[E0277]: the trait bound `String: Copy` is not satisfied
22
--> $DIR/const-fn-in-vec.rs:1:47
33
|
44
LL | static _MAYBE_STRINGS: [Option<String>; 5] = [None; 5];
5-
| ^^^^
6-
| |
7-
| the trait `Copy` is not implemented for `String`
8-
| help: create an inline `const` block: `const { None }`
5+
| ^^^^ the trait `Copy` is not implemented for `String`
96
|
107
= note: required for `Option<String>` to implement `Copy`
118
= note: the `Copy` trait is required because this value will be copied for each element of the array
9+
help: create an inline `const` block
10+
|
11+
LL | static _MAYBE_STRINGS: [Option<String>; 5] = [const { None }; 5];
12+
| +++++++ +
1213

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

2426
error[E0277]: the trait bound `String: Copy` is not satisfied
2527
--> $DIR/const-fn-in-vec.rs:12:48
2628
|
2729
LL | let _maybe_strings: [Option<String>; 5] = [None; 5];
28-
| ^^^^
29-
| |
30-
| the trait `Copy` is not implemented for `String`
31-
| help: create an inline `const` block: `const { None }`
30+
| ^^^^ the trait `Copy` is not implemented for `String`
3231
|
3332
= note: required for `Option<String>` to implement `Copy`
3433
= note: the `Copy` trait is required because this value will be copied for each element of the array
34+
help: create an inline `const` block
35+
|
36+
LL | let _maybe_strings: [Option<String>; 5] = [const { None }; 5];
37+
| +++++++ +
3538

3639
error: aborting due to 3 previous errors
3740

tests/ui/coroutine/unresolved-ct-var.stderr

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@ error[E0277]: `[(); _]` is not a future
22
--> $DIR/unresolved-ct-var.rs:6:45
33
|
44
LL | let s = std::array::from_fn(|_| ()).await;
5-
| ----------------------------^^^^^
6-
| | ||
7-
| | |`[(); _]` is not a future
8-
| | help: remove the `.await`
5+
| --------------------------- ^^^^^ `[(); _]` is not a future
6+
| |
97
| this call returns `[(); _]`
108
|
119
= help: the trait `Future` is not implemented for `[(); _]`
1210
= note: [(); _] must be a future or must implement `IntoFuture` to be awaited
1311
= note: required for `[(); _]` to implement `IntoFuture`
12+
help: remove the `.await`
13+
|
14+
LL - let s = std::array::from_fn(|_| ()).await;
15+
LL + let s = std::array::from_fn(|_| ());
16+
|
1417

1518
error: aborting due to 1 previous error
1619

tests/ui/repeat-expr/copy-check-when-count-inferred-later.stderr

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ error[E0277]: the trait bound `String: Copy` is not satisfied
22
--> $DIR/copy-check-when-count-inferred-later.rs:8:14
33
|
44
LL | let a = [String::new(); _];
5-
| ^^^^^^^^^^^^^
6-
| |
7-
| the trait `Copy` is not implemented for `String`
8-
| help: create an inline `const` block: `const { String::new() }`
5+
| ^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String`
96
|
107
= note: the `Copy` trait is required because this value will be copied for each element of the array
8+
help: create an inline `const` block
9+
|
10+
LL | let a = [const { String::new() }; _];
11+
| +++++++ +
1112

1213
error: aborting due to 1 previous error
1314

tests/ui/type-alias-impl-trait/constrain_in_projection2.next.stderr

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0283]: type annotations needed: cannot satisfy `Foo: Trait<Bar>`
22
--> $DIR/constrain_in_projection2.rs:28:14
33
|
44
LL | let x = <Foo as Trait<Bar>>::Assoc::default();
5-
| ^^^ help: use the fully qualified path to an implementation: `<Type as Trait>::Assoc`
5+
| ^^^
66
|
77
note: multiple `impl`s satisfying `Foo: Trait<Bar>` found
88
--> $DIR/constrain_in_projection2.rs:18:1
@@ -13,6 +13,11 @@ LL | impl Trait<()> for Foo {
1313
LL | impl Trait<u32> for Foo {
1414
| ^^^^^^^^^^^^^^^^^^^^^^^
1515
= note: associated types cannot be accessed directly on a `trait`, they can only be accessed through a specific `impl`
16+
help: use the fully qualified path to an implementation
17+
|
18+
LL - let x = <Foo as Trait<Bar>>::Assoc::default();
19+
LL + let x = <<Type as Trait>::Assoc as Trait<Bar>>::Assoc::default();
20+
|
1621

1722
error: aborting due to 1 previous error
1823

0 commit comments

Comments
 (0)