Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Point to generic or arg if it's the self type of unsatisfied projection predicate #100483

Merged
merged 2 commits into from
Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 27 additions & 23 deletions compiler/rustc_typeck/src/check/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1660,12 +1660,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
ObligationCauseCode::ImplDerivedObligation(code) => {
code.derived.parent_trait_pred.self_ty().skip_binder().into()
}
_ if let ty::PredicateKind::Trait(predicate) =
error.obligation.predicate.kind().skip_binder() =>
{
predicate.self_ty().into()
}
_ => continue,
_ => match error.obligation.predicate.kind().skip_binder() {
ty::PredicateKind::Trait(predicate) => predicate.self_ty().into(),
ty::PredicateKind::Projection(predicate) => {
predicate.projection_ty.self_ty().into()
}
_ => continue,
},
};
let self_ = self.resolve_vars_if_possible(self_);
let ty_matches_self = |ty: Ty<'tcx>| ty.walk().any(|arg| arg == self_);
Expand Down Expand Up @@ -1755,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
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
error[E0271]: type mismatch resolving `<ModelT as Vehicle>::Color == Blue`
--> $DIR/associated-types-binding-to-type-defined-in-supertrait.rs:31:10
--> $DIR/associated-types-binding-to-type-defined-in-supertrait.rs:31:19
|
LL | fn b() { blue_car(ModelT); }
| ^^^^^^^^ type mismatch resolving `<ModelT as Vehicle>::Color == Blue`
| -------- ^^^^^^ type mismatch resolving `<ModelT as Vehicle>::Color == Blue`
| |
| required by a bound introduced by this call
|
note: expected this to be `Blue`
--> $DIR/associated-types-binding-to-type-defined-in-supertrait.rs:16:40
Expand All @@ -16,10 +18,12 @@ LL | fn blue_car<C:Car<Color=Blue>>(c: C) {
| ^^^^^^^^^^ required by this bound in `blue_car`

error[E0271]: type mismatch resolving `<ModelU as Vehicle>::Color == Black`
--> $DIR/associated-types-binding-to-type-defined-in-supertrait.rs:32:10
--> $DIR/associated-types-binding-to-type-defined-in-supertrait.rs:32:20
|
LL | fn c() { black_car(ModelU); }
| ^^^^^^^^^ type mismatch resolving `<ModelU as Vehicle>::Color == Black`
| --------- ^^^^^^ type mismatch resolving `<ModelU as Vehicle>::Color == Black`
| |
| required by a bound introduced by this call
|
note: expected this to be `Black`
--> $DIR/associated-types-binding-to-type-defined-in-supertrait.rs:21:40
Expand Down
10 changes: 7 additions & 3 deletions src/test/ui/associated-types/associated-types-eq-3.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ LL | fn foo2<I: Foo<A = Bar>>(x: I) {
| +++++++++

error[E0271]: type mismatch resolving `<isize as Foo>::A == Bar`
--> $DIR/associated-types-eq-3.rs:38:5
--> $DIR/associated-types-eq-3.rs:38:10
|
LL | foo1(a);
| ^^^^ type mismatch resolving `<isize as Foo>::A == Bar`
| ---- ^ type mismatch resolving `<isize as Foo>::A == Bar`
| |
| required by a bound introduced by this call
|
note: expected this to be `Bar`
--> $DIR/associated-types-eq-3.rs:12:14
Expand All @@ -34,7 +36,9 @@ error[E0271]: type mismatch resolving `<isize as Foo>::A == Bar`
--> $DIR/associated-types-eq-3.rs:40:9
|
LL | baz(&a);
| ^^ type mismatch resolving `<isize as Foo>::A == Bar`
| --- ^^ type mismatch resolving `<isize as Foo>::A == Bar`
| |
| required by a bound introduced by this call
|
note: expected this to be `Bar`
--> $DIR/associated-types-eq-3.rs:12:14
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,11 +1,13 @@
error[E0271]: type mismatch resolving `<Adapter<I> as Iterator>::Item == Option<T>`
--> $DIR/associated-types-issue-20346.rs:34:5
--> $DIR/associated-types-issue-20346.rs:34:36
|
LL | fn test_adapter<T, I: Iterator<Item=Option<T>>>(it: I) {
| - this type parameter
...
LL | is_iterator_of::<Option<T>, _>(&adapter);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type mismatch resolving `<Adapter<I> as Iterator>::Item == Option<T>`
| ------------------------------ ^^^^^^^^ type mismatch resolving `<Adapter<I> as Iterator>::Item == Option<T>`
| |
| required by a bound introduced by this call
|
note: expected this to be `Option<T>`
--> $DIR/associated-types-issue-20346.rs:23:17
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
error[E0271]: type mismatch resolving `<T as Foo>::Y == i32`
--> $DIR/associated-types-multiple-types-one-trait.rs:13:5
--> $DIR/associated-types-multiple-types-one-trait.rs:13:12
|
LL | want_y(t);
| ^^^^^^ expected `i32`, found associated type
| ------ ^ expected `i32`, found associated type
| |
| required by a bound introduced by this call
|
= note: expected type `i32`
found associated type `<T as Foo>::Y`
Expand All @@ -17,10 +19,12 @@ LL | fn have_x_want_y<T:Foo<X=u32, Y = i32>>(t: &T)
| +++++++++

error[E0271]: type mismatch resolving `<T as Foo>::X == u32`
--> $DIR/associated-types-multiple-types-one-trait.rs:18:5
--> $DIR/associated-types-multiple-types-one-trait.rs:18:12
|
LL | want_x(t);
| ^^^^^^ expected `u32`, found associated type
| ------ ^ expected `u32`, found associated type
| |
| required by a bound introduced by this call
|
= note: expected type `u32`
found associated type `<T as Foo>::X`
Expand Down
Loading