Skip to content

Commit

Permalink
Also do it for generics
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Aug 14, 2022
1 parent 16b33cc commit 54edf18
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 27 deletions.
37 changes: 20 additions & 17 deletions compiler/rustc_typeck/src/check/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1756,25 +1756,28 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if let hir::ExprKind::Call(path, _) = &call_expr.kind {
if let hir::ExprKind::Path(hir::QPath::Resolved(_, path)) = &path.kind {
for error in errors {
if let ty::PredicateKind::Trait(predicate) =
error.obligation.predicate.kind().skip_binder()
let self_ty = match error.obligation.predicate.kind().skip_binder() {
ty::PredicateKind::Trait(predicate) => predicate.self_ty(),
ty::PredicateKind::Projection(predicate) => {
predicate.projection_ty.self_ty()
}
_ => continue,
};
// If any of the type arguments in this path segment caused the
// `FulfillmentError`, point at its span (#61860).
for arg in path
.segments
.iter()
.filter_map(|seg| seg.args.as_ref())
.flat_map(|a| a.args.iter())
{
// If any of the type arguments in this path segment caused the
// `FulfillmentError`, point at its span (#61860).
for arg in path
.segments
.iter()
.filter_map(|seg| seg.args.as_ref())
.flat_map(|a| a.args.iter())
if let hir::GenericArg::Type(hir_ty) = &arg
&& let Some(ty) =
self.typeck_results.borrow().node_type_opt(hir_ty.hir_id)
&& self.resolve_vars_if_possible(ty) == self_ty
{
if let hir::GenericArg::Type(hir_ty) = &arg
&& let Some(ty) =
self.typeck_results.borrow().node_type_opt(hir_ty.hir_id)
&& self.resolve_vars_if_possible(ty) == predicate.self_ty()
{
error.obligation.cause.span = hir_ty.span;
break;
}
error.obligation.cause.span = hir_ty.span;
break;
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/associated-types/associated-types-eq-hr.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0271]: type mismatch resolving `for<'x> <UintStruct as TheTrait<&'x isize>>::A == &'x isize`
--> $DIR/associated-types-eq-hr.rs:87:5
--> $DIR/associated-types-eq-hr.rs:87:11
|
LL | foo::<UintStruct>();
| ^^^^^^^^^^^^^^^^^ type mismatch resolving `for<'x> <UintStruct as TheTrait<&'x isize>>::A == &'x isize`
| ^^^^^^^^^^ type mismatch resolving `for<'x> <UintStruct as TheTrait<&'x isize>>::A == &'x isize`
|
note: expected this to be `&isize`
--> $DIR/associated-types-eq-hr.rs:26:14
Expand All @@ -21,10 +21,10 @@ LL | T: for<'x> TheTrait<&'x isize, A = &'x isize>,
| ^^^^^^^^^^^^^ required by this bound in `foo`

error[E0271]: type mismatch resolving `for<'x> <IntStruct as TheTrait<&'x isize>>::A == &'x usize`
--> $DIR/associated-types-eq-hr.rs:91:5
--> $DIR/associated-types-eq-hr.rs:91:11
|
LL | bar::<IntStruct>();
| ^^^^^^^^^^^^^^^^ type mismatch resolving `for<'x> <IntStruct as TheTrait<&'x isize>>::A == &'x usize`
| ^^^^^^^^^ type mismatch resolving `for<'x> <IntStruct as TheTrait<&'x isize>>::A == &'x usize`
|
note: expected this to be `&usize`
--> $DIR/associated-types-eq-hr.rs:14:14
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
error[E0271]: type mismatch resolving `<dyn Trait<B = B, A = A> as SuperTrait>::A == B`
--> $DIR/enforce-supertrait-projection.rs:9:5
--> $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`
| ^^^^^^^^^^^^^^^^^^^^^^^ expected type parameter `B`, found type parameter `A`
|
= note: expected type parameter `B`
found type parameter `A`
Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/traits/pointee-tail-is-generic-errors.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0271]: type mismatch resolving `<T as Pointee>::Metadata == ()`
--> $DIR/pointee-tail-is-generic-errors.rs:13:5
--> $DIR/pointee-tail-is-generic-errors.rs:13:15
|
LL | is_thin::<T>();
| ^^^^^^^^^^^^ expected `()`, found associated type
| ^ expected `()`, found associated type
|
= note: expected unit type `()`
found associated type `<T as Pointee>::Metadata`
Expand All @@ -15,13 +15,13 @@ LL | fn is_thin<T: std::ptr::Pointee<Metadata = ()> + ?Sized>() {}
| ^^^^^^^^^^^^^ required by this bound in `is_thin`

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

0 comments on commit 54edf18

Please sign in to comment.