Skip to content

Commit

Permalink
On long E0277 primary span label, move it to a help
Browse files Browse the repository at this point in the history
Long span labels don't read well.
  • Loading branch information
estebank committed Oct 25, 2024
1 parent 0687f0d commit d6485d0
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,11 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
}
} else if let Some(custom_explanation) = safe_transmute_explanation {
err.span_label(span, custom_explanation);
} else if explanation.len() > self.tcx.sess.diagnostic_width() {
// Really long types don't look good as span labels, instead move it
// to a `help`.
err.span_label(span, "unsatisfied trait bound");
err.help(explanation);
} else {
err.span_label(span, explanation);
}
Expand Down
3 changes: 2 additions & 1 deletion tests/ui/async-await/async-closures/not-clone-closure.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ error[E0277]: the trait bound `NotClonableUpvar: Clone` is not satisfied in `{as
--> $DIR/not-clone-closure.rs:32:15
|
LL | not_clone.clone();
| ^^^^^ within `{async closure@$DIR/not-clone-closure.rs:29:21: 29:34}`, the trait `Clone` is not implemented for `NotClonableUpvar`
| ^^^^^ unsatisfied trait bound
|
= help: within `{async closure@$DIR/not-clone-closure.rs:29:21: 29:34}`, the trait `Clone` is not implemented for `NotClonableUpvar`
note: required because it's used within this closure
--> $DIR/not-clone-closure.rs:29:21
|
Expand Down
3 changes: 2 additions & 1 deletion tests/ui/async-await/coroutine-not-future.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ error[E0277]: the trait bound `{async block@$DIR/coroutine-not-future.rs:39:21:
--> $DIR/coroutine-not-future.rs:39:21
|
LL | takes_coroutine(async {});
| --------------- ^^^^^^^^ the trait `Coroutine<_>` is not implemented for `{async block@$DIR/coroutine-not-future.rs:39:21: 39:26}`
| --------------- ^^^^^^^^ unsatisfied trait bound
| |
| required by a bound introduced by this call
|
= help: the trait `Coroutine<_>` is not implemented for `{async block@$DIR/coroutine-not-future.rs:39:21: 39:26}`
note: required by a bound in `takes_coroutine`
--> $DIR/coroutine-not-future.rs:19:39
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ error[E0277]: `{closure@$DIR/const_param_ty_bad.rs:8:11: 8:13}` can't be used as
--> $DIR/const_param_ty_bad.rs:8:11
|
LL | check(|| {});
| ----- ^^^^^ the trait `UnsizedConstParamTy` is not implemented for closure `{closure@$DIR/const_param_ty_bad.rs:8:11: 8:13}`
| ----- ^^^^^ unsatisfied trait bound
| |
| required by a bound introduced by this call
|
= help: the trait `UnsizedConstParamTy` is not implemented for closure `{closure@$DIR/const_param_ty_bad.rs:8:11: 8:13}`
note: required by a bound in `check`
--> $DIR/const_param_ty_bad.rs:4:18
|
Expand Down
9 changes: 6 additions & 3 deletions tests/ui/coroutine/clone-impl.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ LL | move || {
| ------- within this `{coroutine@$DIR/clone-impl.rs:43:5: 43:12}`
...
LL | check_copy(&gen_clone_0);
| ^^^^^^^^^^^^^^^^^^^^^^^^ within `{coroutine@$DIR/clone-impl.rs:43:5: 43:12}`, the trait `Copy` is not implemented for `Vec<char>`
| ^^^^^^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound
|
= help: within `{coroutine@$DIR/clone-impl.rs:43:5: 43:12}`, the trait `Copy` is not implemented for `Vec<char>`
note: coroutine does not implement `Copy` as this value is used across a yield
--> $DIR/clone-impl.rs:45:9
|
Expand Down Expand Up @@ -67,8 +68,9 @@ LL | move || {
| ------- within this `{coroutine@$DIR/clone-impl.rs:58:5: 58:12}`
...
LL | check_copy(&gen_clone_1);
| ^^^^^^^^^^^^^^^^^^^^^^^^ within `{coroutine@$DIR/clone-impl.rs:58:5: 58:12}`, the trait `Copy` is not implemented for `Vec<char>`
| ^^^^^^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound
|
= help: within `{coroutine@$DIR/clone-impl.rs:58:5: 58:12}`, the trait `Copy` is not implemented for `Vec<char>`
note: coroutine does not implement `Copy` as this value is used across a yield
--> $DIR/clone-impl.rs:64:9
|
Expand Down Expand Up @@ -115,8 +117,9 @@ LL | move || {
| ------- within this `{coroutine@$DIR/clone-impl.rs:79:5: 79:12}`
...
LL | check_clone(&gen_non_clone);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ within `{coroutine@$DIR/clone-impl.rs:79:5: 79:12}`, the trait `Clone` is not implemented for `NonClone`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound
|
= help: within `{coroutine@$DIR/clone-impl.rs:79:5: 79:12}`, the trait `Clone` is not implemented for `NonClone`
note: captured value does not implement `Clone`
--> $DIR/clone-impl.rs:81:14
|
Expand Down
3 changes: 2 additions & 1 deletion tests/ui/coroutine/issue-105084.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ LL | || {
| -- within this `{coroutine@$DIR/issue-105084.rs:15:5: 15:7}`
...
LL | let mut h = copy(g);
| ^^^^^^^ within `{coroutine@$DIR/issue-105084.rs:15:5: 15:7}`, the trait `Copy` is not implemented for `Box<(i32, ())>`
| ^^^^^^^ unsatisfied trait bound
|
= help: within `{coroutine@$DIR/issue-105084.rs:15:5: 15:7}`, the trait `Copy` is not implemented for `Box<(i32, ())>`
note: coroutine does not implement `Copy` as this value is used across a yield
--> $DIR/issue-105084.rs:22:22
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ error[E0277]: the trait bound `{closure@$DIR/fn-ctor-passed-as-arg-where-it-shou
--> $DIR/fn-ctor-passed-as-arg-where-it-should-have-been-called.rs:19:9
|
LL | bar(closure);
| --- ^^^^^^^ 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}`
| --- ^^^^^^^ unsatisfied trait bound
| |
| required by a bound introduced by this call
|
= 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}`
note: required by a bound in `bar`
--> $DIR/fn-ctor-passed-as-arg-where-it-should-have-been-called.rs:14:16
|
Expand Down
3 changes: 2 additions & 1 deletion tests/ui/suggestions/issue-84973-blacklist.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ error[E0277]: `{static coroutine@$DIR/issue-84973-blacklist.rs:17:26: 17:35}` ca
--> $DIR/issue-84973-blacklist.rs:17:26
|
LL | f_unpin(#[coroutine] static || { yield; });
| ------- ^^^^^^^^^^^^^^^^^^^^ the trait `Unpin` is not implemented for `{static coroutine@$DIR/issue-84973-blacklist.rs:17:26: 17:35}`
| ------- ^^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound
| |
| required by a bound introduced by this call
|
= help: the trait `Unpin` is not implemented for `{static coroutine@$DIR/issue-84973-blacklist.rs:17:26: 17:35}`
= note: consider using the `pin!` macro
consider using `Box::pin` if you need to access the pinned value outside of the current scope
note: required by a bound in `f_unpin`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ error[E0277]: the trait bound `{closure@$DIR/bare-fn-no-impl-fn-ptr-99875.rs:14:
--> $DIR/bare-fn-no-impl-fn-ptr-99875.rs:14:11
|
LL | takes(|_: Argument| -> Return { todo!() });
| ----- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for closure `{closure@$DIR/bare-fn-no-impl-fn-ptr-99875.rs:14:11: 14:34}`
| ----- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound
| |
| required by a bound introduced by this call
|
= help: the trait `Trait` is not implemented for closure `{closure@$DIR/bare-fn-no-impl-fn-ptr-99875.rs:14:11: 14:34}`
= help: the trait `Trait` is implemented for fn pointer `fn(Argument) -> Return`
note: required by a bound in `takes`
--> $DIR/bare-fn-no-impl-fn-ptr-99875.rs:9:18
Expand Down
3 changes: 2 additions & 1 deletion tests/ui/transmutability/assoc-bound.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ error[E0277]: the trait bound `<T as A>::AssocA: TransmuteFrom<(), Assume { alig
--> $DIR/assoc-bound.rs:16:19
|
LL | type AssocB = T::AssocA;
| ^^^^^^^^^ the trait `TransmuteFrom<(), Assume { alignment: false, lifetimes: false, safety: false, validity: false }>` is not implemented for `<T as A>::AssocA`
| ^^^^^^^^^ unsatisfied trait bound
|
= help: the trait `TransmuteFrom<(), Assume { alignment: false, lifetimes: false, safety: false, validity: false }>` is not implemented for `<T as A>::AssocA`
note: required by a bound in `B::AssocB`
--> $DIR/assoc-bound.rs:9:18
|
Expand Down
3 changes: 2 additions & 1 deletion tests/ui/where-clauses/higher-ranked-fn-type.verbose.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ error[E0277]: the trait bound `for<Region(BrNamed(DefId(0:6 ~ higher_ranked_fn_t
--> $DIR/higher-ranked-fn-type.rs:20:5
|
LL | called()
| ^^^^^^^^ 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") ())`
| ^^^^^^^^ unsatisfied trait bound
|
= 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") ())`
help: this trait has no implementations, consider adding one
--> $DIR/higher-ranked-fn-type.rs:6:1
|
Expand Down

0 comments on commit d6485d0

Please sign in to comment.