Rollup merge of #65192 - estebank:restrict-bound, r=matthewjasper

Use structured suggestion for restricting bounds

When a trait bound is not met and restricting a type parameter would
make the restriction hold, use a structured suggestion pointing at an
appropriate place (type param in param list or `where` clause).

Account for opaque parameters where instead of suggesting extending
the `where` clause, we suggest appending the new restriction:
`fn foo(impl Trait + UnmetTrait)`. Fix #64565, fix #41817, fix #24354,
cc #26026, cc #37808, cc #24159, fix #37138, fix #24354, cc #20671.
This commit is contained in:
Mazdak Farrokhzad 2019-10-19 16:00:51 +02:00 committed by GitHub
commit 7e4ff91403
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
102 changed files with 847 additions and 243 deletions

View file

@ -7,13 +7,13 @@ LL | trait From<Src> {
LL | / fn to<Dst>(
LL | | self
LL | | ) -> <Dst as From<Self>>::Result where Dst: From<Self> {
| | - help: consider further restricting `Self`: `, Self: std::marker::Sized`
LL | | From::from(self)
LL | | }
| |_____^ doesn't have a size known at compile-time
|
= help: the trait `std::marker::Sized` is not implemented for `Self`
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
= help: consider adding a `where Self: std::marker::Sized` bound
error: aborting due to previous error

View file

@ -5,9 +5,9 @@ LL | pub struct Foo<T: Bound>(T);
| ---------------------------- required by `Foo`
...
LL | impl<T> Trait2 for Foo<T> {}
| ^^^^^^ the trait `Bound` is not implemented for `T`
|
= help: consider adding a `where T: Bound` bound
| - ^^^^^^ the trait `Bound` is not implemented for `T`
| |
| help: consider restricting this bound: `T: Bound`
error: aborting due to previous error

View file

@ -1,11 +1,12 @@
error[E0277]: `<P as Process<'_>>::Item` is not an iterator
--> $DIR/issue-22872.rs:20:40
|
LL | fn push_process<P>(process: P) where P: Process<'static> {
| - help: consider further restricting the associated type: `, <P as Process<'_>>::Item: std::iter::Iterator`
LL | let _: Box<dyn for<'b> Wrap<'b>> = Box::new(Wrapper(process));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ `<P as Process<'_>>::Item` is not an iterator
|
= help: the trait `std::iter::Iterator` is not implemented for `<P as Process<'_>>::Item`
= help: consider adding a `where <P as Process<'_>>::Item: std::iter::Iterator` bound
= note: required because of the requirements on the impl of `for<'b> Wrap<'b>` for `Wrapper<P>`
= note: required for the cast to the object type `dyn for<'b> Wrap<'b>`

View file

@ -1,12 +1,13 @@
error[E0277]: the size for values of type `T` cannot be known at compilation time
--> $DIR/issue-27060-2.rs:3:5
|
LL | pub struct Bad<T: ?Sized> {
| -- help: consider further restricting this bound: `T: std::marker::Sized +`
LL | data: T,
| ^^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `std::marker::Sized` is not implemented for `T`
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
= help: consider adding a `where T: std::marker::Sized` bound
= note: the last field of a packed struct may only have a dynamically sized type if it does not need drop to be run
error: aborting due to previous error

View file

@ -2,11 +2,12 @@ error[E0277]: the size for values of type `Self` cannot be known at compilation
--> $DIR/issue-27078.rs:5:12
|
LL | fn foo(self) -> &'static i32 {
| ^^^^ doesn't have a size known at compile-time
| ^^^^ - help: consider further restricting `Self`: `where Self: std::marker::Sized`
| |
| doesn't have a size known at compile-time
|
= help: the trait `std::marker::Sized` is not implemented for `Self`
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
= help: consider adding a `where Self: std::marker::Sized` bound
= note: all local variables must have a statically known size
= help: unsized locals are gated as an unstable feature

View file

@ -4,7 +4,6 @@ error[E0277]: the trait bound `<Col as Expression>::SqlType: NotNull` is not sat
LL | #[derive(Debug, Copy, Clone)]
| ^^^^ the trait `NotNull` is not implemented for `<Col as Expression>::SqlType`
|
= help: consider adding a `where <Col as Expression>::SqlType: NotNull` bound
= note: required because of the requirements on the impl of `IntoNullable` for `<Col as Expression>::SqlType`
error: aborting due to previous error

View file

@ -2,11 +2,12 @@ error[E0277]: the size for values of type `<Self as std::ops::Deref>::Target` ca
--> $DIR/issue-42312.rs:4:29
|
LL | fn baz(_: Self::Target) where Self: Deref {}
| ^ doesn't have a size known at compile-time
| ^ - help: consider further restricting the associated type: `, <Self as std::ops::Deref>::Target: std::marker::Sized`
| |
| doesn't have a size known at compile-time
|
= help: the trait `std::marker::Sized` is not implemented for `<Self as std::ops::Deref>::Target`
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
= help: consider adding a `where <Self as std::ops::Deref>::Target: std::marker::Sized` bound
= note: all function arguments must have a statically known size
= help: unsized locals are gated as an unstable feature

View file

@ -2,9 +2,9 @@ error[E0277]: the trait bound `T: std::marker::Copy` is not satisfied
--> $DIR/issue-43784-associated-type.rs:13:9
|
LL | impl<T> Complete for T {
| ^^^^^^^^ the trait `std::marker::Copy` is not implemented for `T`
|
= help: consider adding a `where T: std::marker::Copy` bound
| - ^^^^^^^^ the trait `std::marker::Copy` is not implemented for `T`
| |
| help: consider restricting this bound: `T: std::marker::Copy`
error: aborting due to previous error

View file

@ -2,9 +2,9 @@ error[E0277]: the trait bound `T: std::marker::Copy` is not satisfied
--> $DIR/issue-43784-supertrait.rs:8:9
|
LL | impl<T> Complete for T {}
| ^^^^^^^^ the trait `std::marker::Copy` is not implemented for `T`
|
= help: consider adding a `where T: std::marker::Copy` bound
| - ^^^^^^^^ the trait `std::marker::Copy` is not implemented for `T`
| |
| help: consider restricting this bound: `T: std::marker::Copy`
error: aborting due to previous error