Skip to content

Commit 3a1aa3c

Browse files
Do not favor projection type when pointing out arg causing fulfillment error
1 parent c9cb19d commit 3a1aa3c

File tree

5 files changed

+32
-14
lines changed

5 files changed

+32
-14
lines changed

compiler/rustc_typeck/src/check/fn_ctxt/checks.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1742,7 +1742,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17421742
.inputs()
17431743
.iter()
17441744
.enumerate()
1745-
.filter(|(_, ty)| ty.walk().any(|arg| arg == param_to_point_at))
1745+
.filter(|(_, ty)| {
1746+
let mut walk = ty.walk();
1747+
while let Some(arg) = walk.next() {
1748+
if arg == param_to_point_at {
1749+
return true;
1750+
} else if let ty::GenericArgKind::Type(ty) = arg.unpack()
1751+
&& let ty::Projection(..) = ty.kind()
1752+
{
1753+
// This logic may seem a bit strange, but typically when
1754+
// we have a projection type in a function signature, the
1755+
// argument that's being passed into that signature is
1756+
// not actually constraining that projection in a meaningful
1757+
// way. So we skip it, and see improvements in some UI tests
1758+
// due to it.
1759+
walk.skip_current_subtree();
1760+
}
1761+
}
1762+
false
1763+
})
17461764
.collect();
17471765

17481766
if let [(idx, _)] = args_referencing_param.as_slice()

src/test/ui/associated-types/associated-types-path-2.stderr

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ LL | f1(2i32, 4u32);
1717
| ~~~
1818

1919
error[E0277]: the trait bound `u32: Foo` is not satisfied
20-
--> $DIR/associated-types-path-2.rs:29:5
20+
--> $DIR/associated-types-path-2.rs:29:8
2121
|
2222
LL | f1(2u32, 4u32);
23-
| ^^ the trait `Foo` is not implemented for `u32`
23+
| -- ^^^^ the trait `Foo` is not implemented for `u32`
24+
| |
25+
| required by a bound introduced by this call
2426
|
2527
= help: the trait `Foo` is implemented for `i32`
2628
note: required by a bound in `f1`
@@ -38,10 +40,12 @@ LL | f1(2u32, 4u32);
3840
= help: the trait `Foo` is implemented for `i32`
3941

4042
error[E0277]: the trait bound `u32: Foo` is not satisfied
41-
--> $DIR/associated-types-path-2.rs:35:5
43+
--> $DIR/associated-types-path-2.rs:35:8
4244
|
4345
LL | f1(2u32, 4i32);
44-
| ^^ the trait `Foo` is not implemented for `u32`
46+
| -- ^^^^ the trait `Foo` is not implemented for `u32`
47+
| |
48+
| required by a bound introduced by this call
4549
|
4650
= help: the trait `Foo` is implemented for `i32`
4751
note: required by a bound in `f1`

src/test/ui/associated-types/issue-27675-unchecked-bounds.stderr

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
error[E0277]: the trait bound `T: Copy` is not satisfied
2-
--> $DIR/issue-27675-unchecked-bounds.rs:15:31
2+
--> $DIR/issue-27675-unchecked-bounds.rs:15:12
33
|
44
LL | copy::<dyn Setup<From=T>>(t)
5-
| ------------------------- ^ the trait `Copy` is not implemented for `T`
6-
| |
7-
| required by a bound introduced by this call
5+
| ^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `T`
86
|
97
note: required by a bound in `copy`
108
--> $DIR/issue-27675-unchecked-bounds.rs:10:12

src/test/ui/issues/issue-69683.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ error[E0283]: type annotations needed
1414
--> $DIR/issue-69683.rs:30:10
1515
|
1616
LL | 0u16.foo(b);
17-
| ^^^ - type must be known at this point
17+
| ^^^
1818
|
1919
note: multiple `impl`s satisfying `u8: Element<_>` found
2020
--> $DIR/issue-69683.rs:5:1

src/test/ui/traits/object/enforce-supertrait-projection.stderr

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
error[E0271]: type mismatch resolving `<dyn Trait<B = B, A = A> as SuperTrait>::A == B`
2-
--> $DIR/enforce-supertrait-projection.rs:9:42
2+
--> $DIR/enforce-supertrait-projection.rs:9:17
33
|
44
LL | fn transmute<A, B>(x: A) -> B {
55
| - - expected type parameter
66
| |
77
| found type parameter
88
LL | foo::<A, B, dyn Trait<A = A, B = B>>(x)
9-
| ------------------------------------ ^ expected type parameter `B`, found type parameter `A`
10-
| |
11-
| required by a bound introduced by this call
9+
| ^^^^^^^^^^^^^^^^^^^^^^^ expected type parameter `B`, found type parameter `A`
1210
|
1311
= note: expected type parameter `B`
1412
found type parameter `A`

0 commit comments

Comments
 (0)