Do not favor projection type when pointing out arg causing fulfillment error

This commit is contained in:
Michael Goulet 2022-08-16 23:37:56 +00:00
parent c9cb19d26e
commit 3a1aa3c76e
5 changed files with 32 additions and 14 deletions

View File

@ -1742,7 +1742,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.inputs()
.iter()
.enumerate()
.filter(|(_, ty)| ty.walk().any(|arg| arg == param_to_point_at))
.filter(|(_, ty)| {
let mut walk = ty.walk();
while let Some(arg) = walk.next() {
if arg == param_to_point_at {
return true;
} else if let ty::GenericArgKind::Type(ty) = arg.unpack()
&& let ty::Projection(..) = ty.kind()
{
// This logic may seem a bit strange, but typically when
// we have a projection type in a function signature, the
// argument that's being passed into that signature is
// not actually constraining that projection in a meaningful
// way. So we skip it, and see improvements in some UI tests
// due to it.
walk.skip_current_subtree();
}
}
false
})
.collect();
if let [(idx, _)] = args_referencing_param.as_slice()

View File

@ -17,10 +17,12 @@ LL | f1(2i32, 4u32);
| ~~~
error[E0277]: the trait bound `u32: Foo` is not satisfied
--> $DIR/associated-types-path-2.rs:29:5
--> $DIR/associated-types-path-2.rs:29:8
|
LL | f1(2u32, 4u32);
| ^^ the trait `Foo` is not implemented for `u32`
| -- ^^^^ the trait `Foo` is not implemented for `u32`
| |
| required by a bound introduced by this call
|
= help: the trait `Foo` is implemented for `i32`
note: required by a bound in `f1`
@ -38,10 +40,12 @@ LL | f1(2u32, 4u32);
= help: the trait `Foo` is implemented for `i32`
error[E0277]: the trait bound `u32: Foo` is not satisfied
--> $DIR/associated-types-path-2.rs:35:5
--> $DIR/associated-types-path-2.rs:35:8
|
LL | f1(2u32, 4i32);
| ^^ the trait `Foo` is not implemented for `u32`
| -- ^^^^ the trait `Foo` is not implemented for `u32`
| |
| required by a bound introduced by this call
|
= help: the trait `Foo` is implemented for `i32`
note: required by a bound in `f1`

View File

@ -1,10 +1,8 @@
error[E0277]: the trait bound `T: Copy` is not satisfied
--> $DIR/issue-27675-unchecked-bounds.rs:15:31
--> $DIR/issue-27675-unchecked-bounds.rs:15:12
|
LL | copy::<dyn Setup<From=T>>(t)
| ------------------------- ^ the trait `Copy` is not implemented for `T`
| |
| required by a bound introduced by this call
| ^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `T`
|
note: required by a bound in `copy`
--> $DIR/issue-27675-unchecked-bounds.rs:10:12

View File

@ -14,7 +14,7 @@ error[E0283]: type annotations needed
--> $DIR/issue-69683.rs:30:10
|
LL | 0u16.foo(b);
| ^^^ - type must be known at this point
| ^^^
|
note: multiple `impl`s satisfying `u8: Element<_>` found
--> $DIR/issue-69683.rs:5:1

View File

@ -1,14 +1,12 @@
error[E0271]: type mismatch resolving `<dyn Trait<B = B, A = A> as SuperTrait>::A == B`
--> $DIR/enforce-supertrait-projection.rs:9:42
--> $DIR/enforce-supertrait-projection.rs:9:17
|
LL | fn transmute<A, B>(x: A) -> B {
| - - expected type parameter
| |
| found type parameter
LL | foo::<A, B, dyn Trait<A = A, B = B>>(x)
| ------------------------------------ ^ expected type parameter `B`, found type parameter `A`
| |
| required by a bound introduced by this call
| ^^^^^^^^^^^^^^^^^^^^^^^ expected type parameter `B`, found type parameter `A`
|
= note: expected type parameter `B`
found type parameter `A`