Skip to content

Commit 54edf18

Browse files
Also do it for generics
1 parent 16b33cc commit 54edf18

File tree

4 files changed

+30
-27
lines changed

4 files changed

+30
-27
lines changed

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

+20-17
Original file line numberDiff line numberDiff line change
@@ -1756,25 +1756,28 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17561756
if let hir::ExprKind::Call(path, _) = &call_expr.kind {
17571757
if let hir::ExprKind::Path(hir::QPath::Resolved(_, path)) = &path.kind {
17581758
for error in errors {
1759-
if let ty::PredicateKind::Trait(predicate) =
1760-
error.obligation.predicate.kind().skip_binder()
1759+
let self_ty = match error.obligation.predicate.kind().skip_binder() {
1760+
ty::PredicateKind::Trait(predicate) => predicate.self_ty(),
1761+
ty::PredicateKind::Projection(predicate) => {
1762+
predicate.projection_ty.self_ty()
1763+
}
1764+
_ => continue,
1765+
};
1766+
// If any of the type arguments in this path segment caused the
1767+
// `FulfillmentError`, point at its span (#61860).
1768+
for arg in path
1769+
.segments
1770+
.iter()
1771+
.filter_map(|seg| seg.args.as_ref())
1772+
.flat_map(|a| a.args.iter())
17611773
{
1762-
// If any of the type arguments in this path segment caused the
1763-
// `FulfillmentError`, point at its span (#61860).
1764-
for arg in path
1765-
.segments
1766-
.iter()
1767-
.filter_map(|seg| seg.args.as_ref())
1768-
.flat_map(|a| a.args.iter())
1774+
if let hir::GenericArg::Type(hir_ty) = &arg
1775+
&& let Some(ty) =
1776+
self.typeck_results.borrow().node_type_opt(hir_ty.hir_id)
1777+
&& self.resolve_vars_if_possible(ty) == self_ty
17691778
{
1770-
if let hir::GenericArg::Type(hir_ty) = &arg
1771-
&& let Some(ty) =
1772-
self.typeck_results.borrow().node_type_opt(hir_ty.hir_id)
1773-
&& self.resolve_vars_if_possible(ty) == predicate.self_ty()
1774-
{
1775-
error.obligation.cause.span = hir_ty.span;
1776-
break;
1777-
}
1779+
error.obligation.cause.span = hir_ty.span;
1780+
break;
17781781
}
17791782
}
17801783
}

src/test/ui/associated-types/associated-types-eq-hr.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0271]: type mismatch resolving `for<'x> <UintStruct as TheTrait<&'x isize>>::A == &'x isize`
2-
--> $DIR/associated-types-eq-hr.rs:87:5
2+
--> $DIR/associated-types-eq-hr.rs:87:11
33
|
44
LL | foo::<UintStruct>();
5-
| ^^^^^^^^^^^^^^^^^ type mismatch resolving `for<'x> <UintStruct as TheTrait<&'x isize>>::A == &'x isize`
5+
| ^^^^^^^^^^ type mismatch resolving `for<'x> <UintStruct as TheTrait<&'x isize>>::A == &'x isize`
66
|
77
note: expected this to be `&isize`
88
--> $DIR/associated-types-eq-hr.rs:26:14
@@ -21,10 +21,10 @@ LL | T: for<'x> TheTrait<&'x isize, A = &'x isize>,
2121
| ^^^^^^^^^^^^^ required by this bound in `foo`
2222

2323
error[E0271]: type mismatch resolving `for<'x> <IntStruct as TheTrait<&'x isize>>::A == &'x usize`
24-
--> $DIR/associated-types-eq-hr.rs:91:5
24+
--> $DIR/associated-types-eq-hr.rs:91:11
2525
|
2626
LL | bar::<IntStruct>();
27-
| ^^^^^^^^^^^^^^^^ type mismatch resolving `for<'x> <IntStruct as TheTrait<&'x isize>>::A == &'x usize`
27+
| ^^^^^^^^^ type mismatch resolving `for<'x> <IntStruct as TheTrait<&'x isize>>::A == &'x usize`
2828
|
2929
note: expected this to be `&usize`
3030
--> $DIR/associated-types-eq-hr.rs:14:14

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +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:5
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`
9+
| ^^^^^^^^^^^^^^^^^^^^^^^ expected type parameter `B`, found type parameter `A`
1010
|
1111
= note: expected type parameter `B`
1212
found type parameter `A`

src/test/ui/traits/pointee-tail-is-generic-errors.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0271]: type mismatch resolving `<T as Pointee>::Metadata == ()`
2-
--> $DIR/pointee-tail-is-generic-errors.rs:13:5
2+
--> $DIR/pointee-tail-is-generic-errors.rs:13:15
33
|
44
LL | is_thin::<T>();
5-
| ^^^^^^^^^^^^ expected `()`, found associated type
5+
| ^ expected `()`, found associated type
66
|
77
= note: expected unit type `()`
88
found associated type `<T as Pointee>::Metadata`
@@ -15,13 +15,13 @@ LL | fn is_thin<T: std::ptr::Pointee<Metadata = ()> + ?Sized>() {}
1515
| ^^^^^^^^^^^^^ required by this bound in `is_thin`
1616

1717
error[E0271]: type mismatch resolving `<Opaque as Pointee>::Metadata == ()`
18-
--> $DIR/pointee-tail-is-generic-errors.rs:16:5
18+
--> $DIR/pointee-tail-is-generic-errors.rs:16:15
1919
|
2020
LL | type Opaque = impl std::fmt::Debug + ?Sized;
2121
| ----------------------------- the found opaque type
2222
...
2323
LL | is_thin::<Opaque>();
24-
| ^^^^^^^^^^^^^^^^^ expected `()`, found associated type
24+
| ^^^^^^ expected `()`, found associated type
2525
|
2626
= note: expected unit type `()`
2727
found associated type `<Opaque as Pointee>::Metadata`

0 commit comments

Comments
 (0)