Skip to content

Commit 45738e8

Browse files
committed
Increase verbosity of bound restriction suggestions
- Make the bound restriction suggestion `span_suggestion_verbose`. - Fix whitespace typo.
1 parent 545320a commit 45738e8

32 files changed

+215
-123
lines changed

src/librustc_trait_selection/traits/error_reporting/suggestions.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ fn predicate_constraint(generics: &hir::Generics<'_>, pred: String) -> (Span, St
156156
(
157157
generics.where_clause.span_for_predicates_or_empty_place().shrink_to_hi(),
158158
format!(
159-
"{} {} ",
159+
"{} {}",
160160
if !generics.where_clause.predicates.is_empty() { "," } else { " where" },
161161
pred,
162162
),
@@ -263,7 +263,7 @@ fn suggest_restriction(
263263
);
264264
} else {
265265
// Trivial case: `T` needs an extra bound: `T: Bound`.
266-
let (sp, sugg) = match super_traits {
266+
let (sp, suggestion) = match super_traits {
267267
None => {
268268
predicate_constraint(generics, trait_ref.without_const().to_predicate().to_string())
269269
}
@@ -279,8 +279,12 @@ fn suggest_restriction(
279279
},
280280
};
281281

282-
let appl = Applicability::MachineApplicable;
283-
err.span_suggestion(sp, &format!("consider further restricting {}", msg), sugg, appl);
282+
err.span_suggestion_verbose(
283+
sp,
284+
&format!("consider further restricting {}", msg),
285+
suggestion,
286+
Applicability::MachineApplicable,
287+
);
284288
}
285289
}
286290

src/test/ui/associated-type-bounds/bad-bounds-on-assoc-in-trait.stderr

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ error[E0277]: `<<T as Case1>::C as std::iter::Iterator>::Item` is not an iterato
1616
--> $DIR/bad-bounds-on-assoc-in-trait.rs:36:20
1717
|
1818
LL | fn assume_case1<T: Case1>() {
19-
| ^^^^^ - help: consider further restricting the associated type: `where <<T as Case1>::C as std::iter::Iterator>::Item: std::iter::Iterator`
20-
| |
21-
| `<<T as Case1>::C as std::iter::Iterator>::Item` is not an iterator
19+
| ^^^^^ `<<T as Case1>::C as std::iter::Iterator>::Item` is not an iterator
2220
|
2321
= help: the trait `std::iter::Iterator` is not implemented for `<<T as Case1>::C as std::iter::Iterator>::Item`
22+
help: consider further restricting the associated type
23+
|
24+
LL | fn assume_case1<T: Case1>() where <<T as Case1>::C as std::iter::Iterator>::Item: std::iter::Iterator {
25+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2426

2527
error[E0277]: `<<T as Case1>::C as std::iter::Iterator>::Item` cannot be sent between threads safely
2628
--> $DIR/bad-bounds-on-assoc-in-trait.rs:36:20
@@ -32,11 +34,13 @@ LL | Send + Iterator<Item:
3234
| ---- required by this bound in `Case1`
3335
...
3436
LL | fn assume_case1<T: Case1>() {
35-
| ^^^^^ - help: consider further restricting the associated type: `where <<T as Case1>::C as std::iter::Iterator>::Item: std::marker::Send`
36-
| |
37-
| `<<T as Case1>::C as std::iter::Iterator>::Item` cannot be sent between threads safely
37+
| ^^^^^ `<<T as Case1>::C as std::iter::Iterator>::Item` cannot be sent between threads safely
3838
|
3939
= help: the trait `std::marker::Send` is not implemented for `<<T as Case1>::C as std::iter::Iterator>::Item`
40+
help: consider further restricting the associated type
41+
|
42+
LL | fn assume_case1<T: Case1>() where <<T as Case1>::C as std::iter::Iterator>::Item: std::marker::Send {
43+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4044

4145
error[E0277]: `<<T as Case1>::C as std::iter::Iterator>::Item` cannot be shared between threads safely
4246
--> $DIR/bad-bounds-on-assoc-in-trait.rs:36:20
@@ -48,11 +52,13 @@ LL | > + Sync>;
4852
| ---- required by this bound in `Case1`
4953
...
5054
LL | fn assume_case1<T: Case1>() {
51-
| ^^^^^ - help: consider further restricting the associated type: `where <<T as Case1>::C as std::iter::Iterator>::Item: std::marker::Sync`
52-
| |
53-
| `<<T as Case1>::C as std::iter::Iterator>::Item` cannot be shared between threads safely
55+
| ^^^^^ `<<T as Case1>::C as std::iter::Iterator>::Item` cannot be shared between threads safely
5456
|
5557
= help: the trait `std::marker::Sync` is not implemented for `<<T as Case1>::C as std::iter::Iterator>::Item`
58+
help: consider further restricting the associated type
59+
|
60+
LL | fn assume_case1<T: Case1>() where <<T as Case1>::C as std::iter::Iterator>::Item: std::marker::Sync {
61+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5662

5763
error[E0277]: `<_ as Lam<&'a u8>>::App` doesn't implement `std::fmt::Debug`
5864
--> $DIR/bad-bounds-on-assoc-in-trait.rs:36:20

src/test/ui/associated-types/associated-types-bound-failure.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub trait GetToInt
1414
}
1515

1616
fn foo<G>(g: G) -> isize
17-
where G : GetToInt, <G as GetToInt>::R: ToInt
17+
where G : GetToInt, <G as GetToInt>::R: ToInt
1818
{
1919
ToInt::to_int(&g.get()) //~ ERROR E0277
2020
}

src/test/ui/associated-types/associated-types-bound-failure.stderr

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ error[E0277]: the trait bound `<G as GetToInt>::R: ToInt` is not satisfied
44
LL | fn to_int(&self) -> isize;
55
| -------------------------- required by `ToInt::to_int`
66
...
7-
LL | where G : GetToInt
8-
| - help: consider further restricting the associated type: `, <G as GetToInt>::R: ToInt`
9-
LL | {
107
LL | ToInt::to_int(&g.get())
118
| ^^^^^^^^ the trait `ToInt` is not implemented for `<G as GetToInt>::R`
9+
|
10+
help: consider further restricting the associated type
11+
|
12+
LL | where G : GetToInt, <G as GetToInt>::R: ToInt
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1214

1315
error: aborting due to previous error
1416

src/test/ui/associated-types/associated-types-for-unimpl-trait.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ trait Get {
77
}
88

99
trait Other {
10-
fn uhoh<U:Get>(&self, foo: U, bar: <Self as Get>::Value) where Self: Get {}
10+
fn uhoh<U:Get>(&self, foo: U, bar: <Self as Get>::Value) where Self: Get {}
1111
//~^ ERROR the trait bound `Self: Get` is not satisfied
1212
}
1313

src/test/ui/associated-types/associated-types-for-unimpl-trait.stderr

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ error[E0277]: the trait bound `Self: Get` is not satisfied
22
--> $DIR/associated-types-for-unimpl-trait.rs:10:5
33
|
44
LL | fn uhoh<U:Get>(&self, foo: U, bar: <Self as Get>::Value) {}
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-^^
6-
| | |
7-
| | help: consider further restricting `Self`: `where Self: Get`
8-
| the trait `Get` is not implemented for `Self`
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Get` is not implemented for `Self`
6+
|
7+
help: consider further restricting `Self`
8+
|
9+
LL | fn uhoh<U:Get>(&self, foo: U, bar: <Self as Get>::Value) where Self: Get {}
10+
| ^^^^^^^^^^^^^^^
911

1012
error: aborting due to previous error
1113

src/test/ui/associated-types/associated-types-no-suitable-supertrait-2.stderr

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ error[E0277]: the trait bound `Self: Get` is not satisfied
22
--> $DIR/associated-types-no-suitable-supertrait-2.rs:17:5
33
|
44
LL | fn uhoh<U:Get>(&self, foo: U, bar: <Self as Get>::Value) {}
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-^^
6-
| | |
7-
| | help: consider further restricting `Self`: `where Self: Get`
8-
| the trait `Get` is not implemented for `Self`
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Get` is not implemented for `Self`
6+
|
7+
help: consider further restricting `Self`
8+
|
9+
LL | fn uhoh<U:Get>(&self, foo: U, bar: <Self as Get>::Value) where Self: Get {}
10+
| ^^^^^^^^^^^^^^^
911

1012
error: aborting due to previous error
1113

src/test/ui/associated-types/associated-types-no-suitable-supertrait.stderr

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ error[E0277]: the trait bound `Self: Get` is not satisfied
22
--> $DIR/associated-types-no-suitable-supertrait.rs:17:5
33
|
44
LL | fn uhoh<U:Get>(&self, foo: U, bar: <Self as Get>::Value) {}
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-^^
6-
| | |
7-
| | help: consider further restricting `Self`: `where Self: Get`
8-
| the trait `Get` is not implemented for `Self`
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Get` is not implemented for `Self`
6+
|
7+
help: consider further restricting `Self`
8+
|
9+
LL | fn uhoh<U:Get>(&self, foo: U, bar: <Self as Get>::Value) where Self: Get {}
10+
| ^^^^^^^^^^^^^^^
911

1012
error[E0277]: the trait bound `(T, U): Get` is not satisfied
1113
--> $DIR/associated-types-no-suitable-supertrait.rs:22:5

src/test/ui/associated-types/associated-types-projection-to-unrelated-trait-in-method-without-default.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ trait Get {
77
}
88

99
trait Other {
10-
fn okay<U:Get>(&self, foo: U, bar: <Self as Get>::Value) where Self: Get ;
10+
fn okay<U:Get>(&self, foo: U, bar: <Self as Get>::Value) where Self: Get;
1111
//~^ ERROR E0277
1212
}
1313

src/test/ui/associated-types/associated-types-projection-to-unrelated-trait-in-method-without-default.stderr

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ error[E0277]: the trait bound `Self: Get` is not satisfied
22
--> $DIR/associated-types-projection-to-unrelated-trait-in-method-without-default.rs:10:5
33
|
44
LL | fn okay<U:Get>(&self, foo: U, bar: <Self as Get>::Value);
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
6-
| | |
7-
| | help: consider further restricting `Self`: `where Self: Get`
8-
| the trait `Get` is not implemented for `Self`
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Get` is not implemented for `Self`
6+
|
7+
help: consider further restricting `Self`
8+
|
9+
LL | fn okay<U:Get>(&self, foo: U, bar: <Self as Get>::Value) where Self: Get;
10+
| ^^^^^^^^^^^^^^^
911

1012
error: aborting due to previous error
1113

0 commit comments

Comments
 (0)