diff options
| author | bors <bors@rust-lang.org> | 2019-11-18 00:05:38 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-11-18 00:05:38 +0000 |
| commit | 361791bb5fdd714bdc39f8af835f6468dd18331d (patch) | |
| tree | 6eeebf53b94743a431cb0b901f6c14c7a7093948 /src/test | |
| parent | 0f0c640e0ee5a9ad365e78e3c62239b3d65b7045 (diff) | |
| parent | 2fe8371268b36193fa4dc8461341db90f4ec96b9 (diff) | |
Auto merge of #65456 - estebank:trait-bound-borrow, r=matthewjasper
Suggest borrowing when it would satisfy an unmet trait bound When there are multiple implementors for the same trait that is present in an unmet binding, modify the E0277 error to refer to the parent obligation and verify whether borrowing the argument being passed in would satisfy the unmet bound. If it would, suggest it. Fix #56368.
Diffstat (limited to 'src/test')
8 files changed, 34 insertions, 17 deletions
diff --git a/src/test/ui/derives/deriving-copyclone.rs b/src/test/ui/derives/deriving-copyclone.rs index 4565412bff7..06b3157a77a 100644 --- a/src/test/ui/derives/deriving-copyclone.rs +++ b/src/test/ui/derives/deriving-copyclone.rs @@ -28,10 +28,10 @@ fn main() { is_clone(B { a: 1, b: 2 }); // B<C> cannot be copied or cloned - is_copy(B { a: 1, b: C }); //~ERROR Copy - is_clone(B { a: 1, b: C }); //~ERROR Clone + is_copy(B { a: 1, b: C }); //~ ERROR Copy + is_clone(B { a: 1, b: C }); //~ ERROR Clone // B<D> can be cloned but not copied - is_copy(B { a: 1, b: D }); //~ERROR Copy + is_copy(B { a: 1, b: D }); //~ ERROR Copy is_clone(B { a: 1, b: D }); } diff --git a/src/test/ui/derives/deriving-copyclone.stderr b/src/test/ui/derives/deriving-copyclone.stderr index 4cca14ae089..e23d48ca630 100644 --- a/src/test/ui/derives/deriving-copyclone.stderr +++ b/src/test/ui/derives/deriving-copyclone.stderr @@ -5,7 +5,10 @@ LL | fn is_copy<T: Copy>(_: T) {} | ------- ---- required by this bound in `is_copy` ... LL | is_copy(B { a: 1, b: C }); - | ^^^^^^^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `C` + | ^^^^^^^^^^^^^^^^ + | | + | expected an implementor of trait `std::marker::Copy` + | help: consider borrowing here: `&B { a: 1, b: C }` | = note: required because of the requirements on the impl of `std::marker::Copy` for `B<C>` @@ -16,7 +19,10 @@ LL | fn is_clone<T: Clone>(_: T) {} | -------- ----- required by this bound in `is_clone` ... LL | is_clone(B { a: 1, b: C }); - | ^^^^^^^^^^^^^^^^ the trait `std::clone::Clone` is not implemented for `C` + | ^^^^^^^^^^^^^^^^ + | | + | expected an implementor of trait `std::clone::Clone` + | help: consider borrowing here: `&B { a: 1, b: C }` | = note: required because of the requirements on the impl of `std::clone::Clone` for `B<C>` @@ -27,7 +33,10 @@ LL | fn is_copy<T: Copy>(_: T) {} | ------- ---- required by this bound in `is_copy` ... LL | is_copy(B { a: 1, b: D }); - | ^^^^^^^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `D` + | ^^^^^^^^^^^^^^^^ + | | + | expected an implementor of trait `std::marker::Copy` + | help: consider borrowing here: `&B { a: 1, b: D }` | = note: required because of the requirements on the impl of `std::marker::Copy` for `B<D>` diff --git a/src/test/ui/kindck/kindck-impl-type-params-2.rs b/src/test/ui/kindck/kindck-impl-type-params-2.rs index ac9cc1a08f3..d5fcc68a759 100644 --- a/src/test/ui/kindck/kindck-impl-type-params-2.rs +++ b/src/test/ui/kindck/kindck-impl-type-params-2.rs @@ -11,5 +11,5 @@ fn take_param<T:Foo>(foo: &T) { } fn main() { let x: Box<_> = box 3; take_param(&x); - //~^ ERROR `std::boxed::Box<{integer}>: std::marker::Copy` is not satisfied + //~^ ERROR the trait bound `std::boxed::Box<{integer}>: Foo` is not satisfied } diff --git a/src/test/ui/kindck/kindck-impl-type-params-2.stderr b/src/test/ui/kindck/kindck-impl-type-params-2.stderr index 8e989113244..318b7b0f10a 100644 --- a/src/test/ui/kindck/kindck-impl-type-params-2.stderr +++ b/src/test/ui/kindck/kindck-impl-type-params-2.stderr @@ -1,4 +1,4 @@ -error[E0277]: the trait bound `std::boxed::Box<{integer}>: std::marker::Copy` is not satisfied +error[E0277]: the trait bound `std::boxed::Box<{integer}>: Foo` is not satisfied --> $DIR/kindck-impl-type-params-2.rs:13:16 | LL | fn take_param<T:Foo>(foo: &T) { } diff --git a/src/test/ui/kindck/kindck-inherited-copy-bound.curr.stderr b/src/test/ui/kindck/kindck-inherited-copy-bound.curr.stderr index a93f4686496..da1a7a7520e 100644 --- a/src/test/ui/kindck/kindck-inherited-copy-bound.curr.stderr +++ b/src/test/ui/kindck/kindck-inherited-copy-bound.curr.stderr @@ -1,4 +1,4 @@ -error[E0277]: the trait bound `std::boxed::Box<{integer}>: std::marker::Copy` is not satisfied +error[E0277]: the trait bound `std::boxed::Box<{integer}>: Foo` is not satisfied --> $DIR/kindck-inherited-copy-bound.rs:21:16 | LL | fn take_param<T:Foo>(foo: &T) { } diff --git a/src/test/ui/kindck/kindck-inherited-copy-bound.object_safe_for_dispatch.stderr b/src/test/ui/kindck/kindck-inherited-copy-bound.object_safe_for_dispatch.stderr index 7c67c5f9e95..f272f829ba6 100644 --- a/src/test/ui/kindck/kindck-inherited-copy-bound.object_safe_for_dispatch.stderr +++ b/src/test/ui/kindck/kindck-inherited-copy-bound.object_safe_for_dispatch.stderr @@ -1,4 +1,4 @@ -error[E0277]: the trait bound `std::boxed::Box<{integer}>: std::marker::Copy` is not satisfied +error[E0277]: the trait bound `std::boxed::Box<{integer}>: Foo` is not satisfied --> $DIR/kindck-inherited-copy-bound.rs:21:16 | LL | fn take_param<T:Foo>(foo: &T) { } diff --git a/src/test/ui/suggestions/issue-62843.stderr b/src/test/ui/suggestions/issue-62843.stderr index b5801e9162f..3b7f85c5668 100644 --- a/src/test/ui/suggestions/issue-62843.stderr +++ b/src/test/ui/suggestions/issue-62843.stderr @@ -2,10 +2,12 @@ error[E0277]: expected a `std::ops::FnMut<(char,)>` closure, found `std::string: --> $DIR/issue-62843.rs:4:32 | LL | println!("{:?}", line.find(pattern)); - | ^^^^^^^ expected an `FnMut<(char,)>` closure, found `std::string::String` + | ^^^^^^^ + | | + | expected an implementor of trait `std::str::pattern::Pattern<'_>` + | help: consider borrowing here: `&pattern` | - = help: the trait `std::ops::FnMut<(char,)>` is not implemented for `std::string::String` - = note: borrowing the `std::string::String` might fix the problem + = note: the trait bound `std::string::String: std::str::pattern::Pattern<'_>` is not satisfied = note: required because of the requirements on the impl of `std::str::pattern::Pattern<'_>` for `std::string::String` error: aborting due to previous error diff --git a/src/test/ui/traits/traits-negative-impls.stderr b/src/test/ui/traits/traits-negative-impls.stderr index 22b6d2a0c4e..599bbfe2225 100644 --- a/src/test/ui/traits/traits-negative-impls.stderr +++ b/src/test/ui/traits/traits-negative-impls.stderr @@ -50,9 +50,12 @@ LL | fn is_send<T: Send>(_: T) {} | ------- ---- required by this bound in `is_send` ... LL | is_send(Box::new(TestType)); - | ^^^^^^^^^^^^^^^^^^ `dummy2::TestType` cannot be sent between threads safely + | ^^^^^^^^^^^^^^^^^^ + | | + | expected an implementor of trait `std::marker::Send` + | help: consider borrowing here: `&Box::new(TestType)` | - = help: the trait `std::marker::Send` is not implemented for `dummy2::TestType` + = note: the trait bound `dummy2::TestType: std::marker::Send` is not satisfied = note: required because of the requirements on the impl of `std::marker::Send` for `std::ptr::Unique<dummy2::TestType>` = note: required because it appears within the type `std::boxed::Box<dummy2::TestType>` @@ -77,9 +80,12 @@ LL | fn is_sync<T: Sync>(_: T) {} | ------- ---- required by this bound in `is_sync` ... LL | is_sync(Outer2(TestType)); - | ^^^^^^^^^^^^^^^^ `main::TestType` cannot be sent between threads safely + | ^^^^^^^^^^^^^^^^ + | | + | expected an implementor of trait `std::marker::Sync` + | help: consider borrowing here: `&Outer2(TestType)` | - = help: the trait `std::marker::Send` is not implemented for `main::TestType` + = note: the trait bound `main::TestType: std::marker::Sync` is not satisfied = note: required because of the requirements on the impl of `std::marker::Sync` for `Outer2<main::TestType>` error: aborting due to 7 previous errors |
