Skip to content

Commit d6485d0

Browse files
committed
On long E0277 primary span label, move it to a help
Long span labels don't read well.
1 parent 0687f0d commit d6485d0

File tree

11 files changed

+29
-12
lines changed

11 files changed

+29
-12
lines changed

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

+5
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,11 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
328328
}
329329
} else if let Some(custom_explanation) = safe_transmute_explanation {
330330
err.span_label(span, custom_explanation);
331+
} else if explanation.len() > self.tcx.sess.diagnostic_width() {
332+
// Really long types don't look good as span labels, instead move it
333+
// to a `help`.
334+
err.span_label(span, "unsatisfied trait bound");
335+
err.help(explanation);
331336
} else {
332337
err.span_label(span, explanation);
333338
}

tests/ui/async-await/async-closures/not-clone-closure.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ error[E0277]: the trait bound `NotClonableUpvar: Clone` is not satisfied in `{as
22
--> $DIR/not-clone-closure.rs:32:15
33
|
44
LL | not_clone.clone();
5-
| ^^^^^ within `{async closure@$DIR/not-clone-closure.rs:29:21: 29:34}`, the trait `Clone` is not implemented for `NotClonableUpvar`
5+
| ^^^^^ unsatisfied trait bound
66
|
7+
= help: within `{async closure@$DIR/not-clone-closure.rs:29:21: 29:34}`, the trait `Clone` is not implemented for `NotClonableUpvar`
78
note: required because it's used within this closure
89
--> $DIR/not-clone-closure.rs:29:21
910
|

tests/ui/async-await/coroutine-not-future.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ error[E0277]: the trait bound `{async block@$DIR/coroutine-not-future.rs:39:21:
3030
--> $DIR/coroutine-not-future.rs:39:21
3131
|
3232
LL | takes_coroutine(async {});
33-
| --------------- ^^^^^^^^ the trait `Coroutine<_>` is not implemented for `{async block@$DIR/coroutine-not-future.rs:39:21: 39:26}`
33+
| --------------- ^^^^^^^^ unsatisfied trait bound
3434
| |
3535
| required by a bound introduced by this call
3636
|
37+
= help: the trait `Coroutine<_>` is not implemented for `{async block@$DIR/coroutine-not-future.rs:39:21: 39:26}`
3738
note: required by a bound in `takes_coroutine`
3839
--> $DIR/coroutine-not-future.rs:19:39
3940
|

tests/ui/const-generics/adt_const_params/const_param_ty_bad.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ error[E0277]: `{closure@$DIR/const_param_ty_bad.rs:8:11: 8:13}` can't be used as
2020
--> $DIR/const_param_ty_bad.rs:8:11
2121
|
2222
LL | check(|| {});
23-
| ----- ^^^^^ the trait `UnsizedConstParamTy` is not implemented for closure `{closure@$DIR/const_param_ty_bad.rs:8:11: 8:13}`
23+
| ----- ^^^^^ unsatisfied trait bound
2424
| |
2525
| required by a bound introduced by this call
2626
|
27+
= help: the trait `UnsizedConstParamTy` is not implemented for closure `{closure@$DIR/const_param_ty_bad.rs:8:11: 8:13}`
2728
note: required by a bound in `check`
2829
--> $DIR/const_param_ty_bad.rs:4:18
2930
|

tests/ui/coroutine/clone-impl.stderr

+6-3
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ LL | move || {
2525
| ------- within this `{coroutine@$DIR/clone-impl.rs:43:5: 43:12}`
2626
...
2727
LL | check_copy(&gen_clone_0);
28-
| ^^^^^^^^^^^^^^^^^^^^^^^^ within `{coroutine@$DIR/clone-impl.rs:43:5: 43:12}`, the trait `Copy` is not implemented for `Vec<char>`
28+
| ^^^^^^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound
2929
|
30+
= help: within `{coroutine@$DIR/clone-impl.rs:43:5: 43:12}`, the trait `Copy` is not implemented for `Vec<char>`
3031
note: coroutine does not implement `Copy` as this value is used across a yield
3132
--> $DIR/clone-impl.rs:45:9
3233
|
@@ -67,8 +68,9 @@ LL | move || {
6768
| ------- within this `{coroutine@$DIR/clone-impl.rs:58:5: 58:12}`
6869
...
6970
LL | check_copy(&gen_clone_1);
70-
| ^^^^^^^^^^^^^^^^^^^^^^^^ within `{coroutine@$DIR/clone-impl.rs:58:5: 58:12}`, the trait `Copy` is not implemented for `Vec<char>`
71+
| ^^^^^^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound
7172
|
73+
= help: within `{coroutine@$DIR/clone-impl.rs:58:5: 58:12}`, the trait `Copy` is not implemented for `Vec<char>`
7274
note: coroutine does not implement `Copy` as this value is used across a yield
7375
--> $DIR/clone-impl.rs:64:9
7476
|
@@ -115,8 +117,9 @@ LL | move || {
115117
| ------- within this `{coroutine@$DIR/clone-impl.rs:79:5: 79:12}`
116118
...
117119
LL | check_clone(&gen_non_clone);
118-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ within `{coroutine@$DIR/clone-impl.rs:79:5: 79:12}`, the trait `Clone` is not implemented for `NonClone`
120+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound
119121
|
122+
= help: within `{coroutine@$DIR/clone-impl.rs:79:5: 79:12}`, the trait `Clone` is not implemented for `NonClone`
120123
note: captured value does not implement `Clone`
121124
--> $DIR/clone-impl.rs:81:14
122125
|

tests/ui/coroutine/issue-105084.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ LL | || {
2929
| -- within this `{coroutine@$DIR/issue-105084.rs:15:5: 15:7}`
3030
...
3131
LL | let mut h = copy(g);
32-
| ^^^^^^^ within `{coroutine@$DIR/issue-105084.rs:15:5: 15:7}`, the trait `Copy` is not implemented for `Box<(i32, ())>`
32+
| ^^^^^^^ unsatisfied trait bound
3333
|
34+
= help: within `{coroutine@$DIR/issue-105084.rs:15:5: 15:7}`, the trait `Copy` is not implemented for `Box<(i32, ())>`
3435
note: coroutine does not implement `Copy` as this value is used across a yield
3536
--> $DIR/issue-105084.rs:22:22
3637
|

tests/ui/suggestions/fn-ctor-passed-as-arg-where-it-should-have-been-called.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ error[E0277]: the trait bound `{closure@$DIR/fn-ctor-passed-as-arg-where-it-shou
2020
--> $DIR/fn-ctor-passed-as-arg-where-it-should-have-been-called.rs:19:9
2121
|
2222
LL | bar(closure);
23-
| --- ^^^^^^^ the trait `T` is not implemented for closure `{closure@$DIR/fn-ctor-passed-as-arg-where-it-should-have-been-called.rs:18:19: 18:21}`
23+
| --- ^^^^^^^ unsatisfied trait bound
2424
| |
2525
| required by a bound introduced by this call
2626
|
27+
= help: the trait `T` is not implemented for closure `{closure@$DIR/fn-ctor-passed-as-arg-where-it-should-have-been-called.rs:18:19: 18:21}`
2728
note: required by a bound in `bar`
2829
--> $DIR/fn-ctor-passed-as-arg-where-it-should-have-been-called.rs:14:16
2930
|

tests/ui/suggestions/issue-84973-blacklist.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ error[E0277]: `{static coroutine@$DIR/issue-84973-blacklist.rs:17:26: 17:35}` ca
4040
--> $DIR/issue-84973-blacklist.rs:17:26
4141
|
4242
LL | f_unpin(#[coroutine] static || { yield; });
43-
| ------- ^^^^^^^^^^^^^^^^^^^^ the trait `Unpin` is not implemented for `{static coroutine@$DIR/issue-84973-blacklist.rs:17:26: 17:35}`
43+
| ------- ^^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound
4444
| |
4545
| required by a bound introduced by this call
4646
|
47+
= help: the trait `Unpin` is not implemented for `{static coroutine@$DIR/issue-84973-blacklist.rs:17:26: 17:35}`
4748
= note: consider using the `pin!` macro
4849
consider using `Box::pin` if you need to access the pinned value outside of the current scope
4950
note: required by a bound in `f_unpin`

tests/ui/traits/fn-pointer/bare-fn-no-impl-fn-ptr-99875.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ error[E0277]: the trait bound `{closure@$DIR/bare-fn-no-impl-fn-ptr-99875.rs:14:
2020
--> $DIR/bare-fn-no-impl-fn-ptr-99875.rs:14:11
2121
|
2222
LL | takes(|_: Argument| -> Return { todo!() });
23-
| ----- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for closure `{closure@$DIR/bare-fn-no-impl-fn-ptr-99875.rs:14:11: 14:34}`
23+
| ----- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound
2424
| |
2525
| required by a bound introduced by this call
2626
|
27+
= help: the trait `Trait` is not implemented for closure `{closure@$DIR/bare-fn-no-impl-fn-ptr-99875.rs:14:11: 14:34}`
2728
= help: the trait `Trait` is implemented for fn pointer `fn(Argument) -> Return`
2829
note: required by a bound in `takes`
2930
--> $DIR/bare-fn-no-impl-fn-ptr-99875.rs:9:18

tests/ui/transmutability/assoc-bound.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ error[E0277]: the trait bound `<T as A>::AssocA: TransmuteFrom<(), Assume { alig
22
--> $DIR/assoc-bound.rs:16:19
33
|
44
LL | type AssocB = T::AssocA;
5-
| ^^^^^^^^^ the trait `TransmuteFrom<(), Assume { alignment: false, lifetimes: false, safety: false, validity: false }>` is not implemented for `<T as A>::AssocA`
5+
| ^^^^^^^^^ unsatisfied trait bound
66
|
7+
= help: the trait `TransmuteFrom<(), Assume { alignment: false, lifetimes: false, safety: false, validity: false }>` is not implemented for `<T as A>::AssocA`
78
note: required by a bound in `B::AssocB`
89
--> $DIR/assoc-bound.rs:9:18
910
|

tests/ui/where-clauses/higher-ranked-fn-type.verbose.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ error[E0277]: the trait bound `for<Region(BrNamed(DefId(0:6 ~ higher_ranked_fn_t
22
--> $DIR/higher-ranked-fn-type.rs:20:5
33
|
44
LL | called()
5-
| ^^^^^^^^ the trait `for<Region(BrNamed(DefId(0:6 ~ higher_ranked_fn_type[9e51]::called::'b), 'b))> Foo` is not implemented for `fn(&'^1_0.Named(DefId(0:6 ~ higher_ranked_fn_type[9e51]::called::'b), "'b") ())`
5+
| ^^^^^^^^ unsatisfied trait bound
66
|
7+
= help: the trait `for<Region(BrNamed(DefId(0:6 ~ higher_ranked_fn_type[9e51]::called::'b), 'b))> Foo` is not implemented for `fn(&'^1_0.Named(DefId(0:6 ~ higher_ranked_fn_type[9e51]::called::'b), "'b") ())`
78
help: this trait has no implementations, consider adding one
89
--> $DIR/higher-ranked-fn-type.rs:6:1
910
|

0 commit comments

Comments
 (0)