Skip to content

Commit

Permalink
Increase verbosity of bound restriction suggestions
Browse files Browse the repository at this point in the history
- Make the bound restriction suggestion `span_suggestion_verbose`.
- Fix whitespace typo.
  • Loading branch information
estebank committed May 12, 2020
1 parent 545320a commit 45738e8
Show file tree
Hide file tree
Showing 32 changed files with 215 additions and 123 deletions.
Expand Up @@ -156,7 +156,7 @@ fn predicate_constraint(generics: &hir::Generics<'_>, pred: String) -> (Span, St
(
generics.where_clause.span_for_predicates_or_empty_place().shrink_to_hi(),
format!(
"{} {} ",
"{} {}",
if !generics.where_clause.predicates.is_empty() { "," } else { " where" },
pred,
),
Expand Down Expand Up @@ -263,7 +263,7 @@ fn suggest_restriction(
);
} else {
// Trivial case: `T` needs an extra bound: `T: Bound`.
let (sp, sugg) = match super_traits {
let (sp, suggestion) = match super_traits {
None => {
predicate_constraint(generics, trait_ref.without_const().to_predicate().to_string())
}
Expand All @@ -279,8 +279,12 @@ fn suggest_restriction(
},
};

let appl = Applicability::MachineApplicable;
err.span_suggestion(sp, &format!("consider further restricting {}", msg), sugg, appl);
err.span_suggestion_verbose(
sp,
&format!("consider further restricting {}", msg),
suggestion,
Applicability::MachineApplicable,
);
}
}

Expand Down
Expand Up @@ -16,11 +16,13 @@ error[E0277]: `<<T as Case1>::C as std::iter::Iterator>::Item` is not an iterato
--> $DIR/bad-bounds-on-assoc-in-trait.rs:36:20
|
LL | fn assume_case1<T: Case1>() {
| ^^^^^ - help: consider further restricting the associated type: `where <<T as Case1>::C as std::iter::Iterator>::Item: std::iter::Iterator`
| |
| `<<T as Case1>::C as std::iter::Iterator>::Item` is not an iterator
| ^^^^^ `<<T as Case1>::C as std::iter::Iterator>::Item` is not an iterator
|
= help: the trait `std::iter::Iterator` is not implemented for `<<T as Case1>::C as std::iter::Iterator>::Item`
help: consider further restricting the associated type
|
LL | fn assume_case1<T: Case1>() where <<T as Case1>::C as std::iter::Iterator>::Item: std::iter::Iterator {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

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

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

error[E0277]: `<_ as Lam<&'a u8>>::App` doesn't implement `std::fmt::Debug`
--> $DIR/bad-bounds-on-assoc-in-trait.rs:36:20
Expand Down
Expand Up @@ -14,7 +14,7 @@ pub trait GetToInt
}

fn foo<G>(g: G) -> isize
where G : GetToInt, <G as GetToInt>::R: ToInt
where G : GetToInt, <G as GetToInt>::R: ToInt
{
ToInt::to_int(&g.get()) //~ ERROR E0277
}
Expand Down
Expand Up @@ -4,11 +4,13 @@ error[E0277]: the trait bound `<G as GetToInt>::R: ToInt` is not satisfied
LL | fn to_int(&self) -> isize;
| -------------------------- required by `ToInt::to_int`
...
LL | where G : GetToInt
| - help: consider further restricting the associated type: `, <G as GetToInt>::R: ToInt`
LL | {
LL | ToInt::to_int(&g.get())
| ^^^^^^^^ the trait `ToInt` is not implemented for `<G as GetToInt>::R`
|
help: consider further restricting the associated type
|
LL | where G : GetToInt, <G as GetToInt>::R: ToInt
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

Expand Down
Expand Up @@ -7,7 +7,7 @@ trait Get {
}

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

Expand Down
Expand Up @@ -2,10 +2,12 @@ error[E0277]: the trait bound `Self: Get` is not satisfied
--> $DIR/associated-types-for-unimpl-trait.rs:10:5
|
LL | fn uhoh<U:Get>(&self, foo: U, bar: <Self as Get>::Value) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-^^
| | |
| | help: consider further restricting `Self`: `where Self: Get`
| the trait `Get` is not implemented for `Self`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Get` is not implemented for `Self`
|
help: consider further restricting `Self`
|
LL | fn uhoh<U:Get>(&self, foo: U, bar: <Self as Get>::Value) where Self: Get {}
| ^^^^^^^^^^^^^^^

error: aborting due to previous error

Expand Down
Expand Up @@ -2,10 +2,12 @@ error[E0277]: the trait bound `Self: Get` is not satisfied
--> $DIR/associated-types-no-suitable-supertrait-2.rs:17:5
|
LL | fn uhoh<U:Get>(&self, foo: U, bar: <Self as Get>::Value) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-^^
| | |
| | help: consider further restricting `Self`: `where Self: Get`
| the trait `Get` is not implemented for `Self`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Get` is not implemented for `Self`
|
help: consider further restricting `Self`
|
LL | fn uhoh<U:Get>(&self, foo: U, bar: <Self as Get>::Value) where Self: Get {}
| ^^^^^^^^^^^^^^^

error: aborting due to previous error

Expand Down
Expand Up @@ -2,10 +2,12 @@ error[E0277]: the trait bound `Self: Get` is not satisfied
--> $DIR/associated-types-no-suitable-supertrait.rs:17:5
|
LL | fn uhoh<U:Get>(&self, foo: U, bar: <Self as Get>::Value) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-^^
| | |
| | help: consider further restricting `Self`: `where Self: Get`
| the trait `Get` is not implemented for `Self`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Get` is not implemented for `Self`
|
help: consider further restricting `Self`
|
LL | fn uhoh<U:Get>(&self, foo: U, bar: <Self as Get>::Value) where Self: Get {}
| ^^^^^^^^^^^^^^^

error[E0277]: the trait bound `(T, U): Get` is not satisfied
--> $DIR/associated-types-no-suitable-supertrait.rs:22:5
Expand Down
Expand Up @@ -7,7 +7,7 @@ trait Get {
}

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

Expand Down
Expand Up @@ -2,10 +2,12 @@ error[E0277]: the trait bound `Self: Get` is not satisfied
--> $DIR/associated-types-projection-to-unrelated-trait-in-method-without-default.rs:10:5
|
LL | fn okay<U:Get>(&self, foo: U, bar: <Self as Get>::Value);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
| | |
| | help: consider further restricting `Self`: `where Self: Get`
| the trait `Get` is not implemented for `Self`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Get` is not implemented for `Self`
|
help: consider further restricting `Self`
|
LL | fn okay<U:Get>(&self, foo: U, bar: <Self as Get>::Value) where Self: Get;
| ^^^^^^^^^^^^^^^

error: aborting due to previous error

Expand Down
Expand Up @@ -6,7 +6,7 @@ trait Get {
fn get(&self) -> <Self as Get>::Value;
}

fn foo<T:Get>(t: T) where <T as Get>::Value: std::marker::Sized {
fn foo<T:Get>(t: T) where <T as Get>::Value: std::marker::Sized {
let x = t.get(); //~ ERROR the size for values of type
}

Expand Down
6 changes: 4 additions & 2 deletions src/test/ui/associated-types/associated-types-unsized.stderr
@@ -1,15 +1,17 @@
error[E0277]: the size for values of type `<T as Get>::Value` cannot be known at compilation time
--> $DIR/associated-types-unsized.rs:10:9
|
LL | fn foo<T:Get>(t: T) {
| - help: consider further restricting the associated type: `where <T as Get>::Value: std::marker::Sized`
LL | let x = t.get();
| ^ doesn't have a size known at compile-time
|
= help: the trait `std::marker::Sized` is not implemented for `<T as Get>::Value`
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
= note: all local variables must have a statically known size
= help: unsized locals are gated as an unstable feature
help: consider further restricting the associated type
|
LL | fn foo<T:Get>(t: T) where <T as Get>::Value: std::marker::Sized {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

Expand Down
16 changes: 10 additions & 6 deletions src/test/ui/associated-types/defaults-suitability.stderr
Expand Up @@ -85,25 +85,29 @@ error[E0277]: the trait bound `<Self as Foo2<T>>::Baz: std::clone::Clone` is not
--> $DIR/defaults-suitability.rs:72:15
|
LL | trait Foo2<T> {
| -------------- help: consider further restricting the associated type: `where <Self as Foo2<T>>::Baz: std::clone::Clone`
| |
| required by `Foo2`
| ------------- required by `Foo2`
LL | type Bar: Clone = Vec<Self::Baz>;
| ^^^^^ the trait `std::clone::Clone` is not implemented for `<Self as Foo2<T>>::Baz`
|
= note: required because of the requirements on the impl of `std::clone::Clone` for `std::vec::Vec<<Self as Foo2<T>>::Baz>`
help: consider further restricting the associated type
|
LL | trait Foo2<T> where <Self as Foo2<T>>::Baz: std::clone::Clone {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0277]: the trait bound `<Self as Foo25<T>>::Baz: std::clone::Clone` is not satisfied
--> $DIR/defaults-suitability.rs:81:15
|
LL | trait Foo25<T: Clone> {
| ---------------------- help: consider further restricting the associated type: `where <Self as Foo25<T>>::Baz: std::clone::Clone`
| |
| required by `Foo25`
| --------------------- required by `Foo25`
LL | type Bar: Clone = Vec<Self::Baz>;
| ^^^^^ the trait `std::clone::Clone` is not implemented for `<Self as Foo25<T>>::Baz`
|
= note: required because of the requirements on the impl of `std::clone::Clone` for `std::vec::Vec<<Self as Foo25<T>>::Baz>`
help: consider further restricting the associated type
|
LL | trait Foo25<T: Clone> where <Self as Foo25<T>>::Baz: std::clone::Clone {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0277]: the trait bound `T: std::clone::Clone` is not satisfied
--> $DIR/defaults-suitability.rs:90:16
Expand Down
34 changes: 22 additions & 12 deletions src/test/ui/associated-types/defaults-unsound-62211-1.stderr
Expand Up @@ -2,50 +2,60 @@ error[E0277]: the trait bound `Self: std::marker::Copy` is not satisfied
--> $DIR/defaults-unsound-62211-1.rs:21:18
|
LL | trait UncheckedCopy: Sized {
| --------------------------- help: consider further restricting `Self`: `+ std::marker::Copy`
| |
| required by `UncheckedCopy`
| -------------------------- required by `UncheckedCopy`
...
LL | type Output: Copy
| ^^^^ the trait `std::marker::Copy` is not implemented for `Self`
|
help: consider further restricting `Self`
|
LL | trait UncheckedCopy: Sized + std::marker::Copy {
| ^^^^^^^^^^^^^^^^^^^

error[E0277]: cannot add-assign `&'static str` to `Self`
--> $DIR/defaults-unsound-62211-1.rs:25:7
|
LL | trait UncheckedCopy: Sized {
| --------------------------- help: consider further restricting `Self`: `+ std::ops::AddAssign<&'static str>`
| |
| required by `UncheckedCopy`
| -------------------------- required by `UncheckedCopy`
...
LL | + AddAssign<&'static str>
| ^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `Self += &'static str`
|
= help: the trait `std::ops::AddAssign<&'static str>` is not implemented for `Self`
help: consider further restricting `Self`
|
LL | trait UncheckedCopy: Sized + std::ops::AddAssign<&'static str> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0277]: the trait bound `Self: std::ops::Deref` is not satisfied
--> $DIR/defaults-unsound-62211-1.rs:23:7
|
LL | trait UncheckedCopy: Sized {
| --------------------------- help: consider further restricting `Self`: `+ std::ops::Deref`
| |
| required by `UncheckedCopy`
| -------------------------- required by `UncheckedCopy`
...
LL | + Deref<Target = str>
| ^^^^^^^^^^^^^^^^^^^ the trait `std::ops::Deref` is not implemented for `Self`
|
help: consider further restricting `Self`
|
LL | trait UncheckedCopy: Sized + std::ops::Deref {
| ^^^^^^^^^^^^^^^^^

error[E0277]: `Self` doesn't implement `std::fmt::Display`
--> $DIR/defaults-unsound-62211-1.rs:28:7
|
LL | trait UncheckedCopy: Sized {
| --------------------------- help: consider further restricting `Self`: `+ std::fmt::Display`
| |
| required by `UncheckedCopy`
| -------------------------- required by `UncheckedCopy`
...
LL | + Display = Self;
| ^^^^^^^ `Self` cannot be formatted with the default formatter
|
= help: the trait `std::fmt::Display` is not implemented for `Self`
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
help: consider further restricting `Self`
|
LL | trait UncheckedCopy: Sized + std::fmt::Display {
| ^^^^^^^^^^^^^^^^^^^

error[E0277]: `T` doesn't implement `std::fmt::Display`
--> $DIR/defaults-unsound-62211-1.rs:41:9
Expand Down

0 comments on commit 45738e8

Please sign in to comment.