From 16b33cc1e32d1814d961d97a6e76defc079316d2 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 13 Aug 2022 07:09:08 +0000 Subject: [PATCH 1/2] Point to argument if it's self type of unsatisfied projection predicate --- .../rustc_typeck/src/check/fn_ctxt/checks.rs | 13 +-- ...nding-to-type-defined-in-supertrait.stderr | 12 ++- .../associated-types-eq-3.stderr | 10 ++- .../associated-types-issue-20346.stderr | 6 +- ...ated-types-multiple-types-one-trait.stderr | 12 ++- .../ui/associated-types/issue-87261.stderr | 84 ++++++++++++------- src/test/ui/error-codes/E0271.stderr | 6 +- .../issue-74684-2.stderr | 6 +- .../issue-62203-hrtb-ice.rs | 2 +- .../issue-62203-hrtb-ice.stderr | 21 +++-- .../intrinsics/const-eval-select-bad.stderr | 6 +- .../check-trait-object-bounds-5.stderr | 6 +- .../check-trait-object-bounds-6.stderr | 6 +- 13 files changed, 125 insertions(+), 65 deletions(-) diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs index a7df5320296..1f2dfc30ae0 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs @@ -1660,12 +1660,13 @@ fn unpeel_to_top<'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_); diff --git a/src/test/ui/associated-types/associated-types-binding-to-type-defined-in-supertrait.stderr b/src/test/ui/associated-types/associated-types-binding-to-type-defined-in-supertrait.stderr index 0cccc6b38a3..a777e064f1a 100644 --- a/src/test/ui/associated-types/associated-types-binding-to-type-defined-in-supertrait.stderr +++ b/src/test/ui/associated-types/associated-types-binding-to-type-defined-in-supertrait.stderr @@ -1,8 +1,10 @@ error[E0271]: type mismatch resolving `::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 `::Color == Blue` + | -------- ^^^^^^ type mismatch resolving `::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 @@ -16,10 +18,12 @@ LL | fn blue_car>(c: C) { | ^^^^^^^^^^ required by this bound in `blue_car` error[E0271]: type mismatch resolving `::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 `::Color == Black` + | --------- ^^^^^^ type mismatch resolving `::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 diff --git a/src/test/ui/associated-types/associated-types-eq-3.stderr b/src/test/ui/associated-types/associated-types-eq-3.stderr index bed63a5e6df..19750fe1f33 100644 --- a/src/test/ui/associated-types/associated-types-eq-3.stderr +++ b/src/test/ui/associated-types/associated-types-eq-3.stderr @@ -14,10 +14,12 @@ LL | fn foo2>(x: I) { | +++++++++ error[E0271]: type mismatch resolving `::A == Bar` - --> $DIR/associated-types-eq-3.rs:38:5 + --> $DIR/associated-types-eq-3.rs:38:10 | LL | foo1(a); - | ^^^^ type mismatch resolving `::A == Bar` + | ---- ^ type mismatch resolving `::A == Bar` + | | + | required by a bound introduced by this call | note: expected this to be `Bar` --> $DIR/associated-types-eq-3.rs:12:14 @@ -34,7 +36,9 @@ error[E0271]: type mismatch resolving `::A == Bar` --> $DIR/associated-types-eq-3.rs:40:9 | LL | baz(&a); - | ^^ type mismatch resolving `::A == Bar` + | --- ^^ type mismatch resolving `::A == Bar` + | | + | required by a bound introduced by this call | note: expected this to be `Bar` --> $DIR/associated-types-eq-3.rs:12:14 diff --git a/src/test/ui/associated-types/associated-types-issue-20346.stderr b/src/test/ui/associated-types/associated-types-issue-20346.stderr index a67cf99283c..b1708b96e52 100644 --- a/src/test/ui/associated-types/associated-types-issue-20346.stderr +++ b/src/test/ui/associated-types/associated-types-issue-20346.stderr @@ -1,11 +1,13 @@ error[E0271]: type mismatch resolving ` as Iterator>::Item == Option` - --> $DIR/associated-types-issue-20346.rs:34:5 + --> $DIR/associated-types-issue-20346.rs:34:36 | LL | fn test_adapter>>(it: I) { | - this type parameter ... LL | is_iterator_of::, _>(&adapter); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type mismatch resolving ` as Iterator>::Item == Option` + | ------------------------------ ^^^^^^^^ type mismatch resolving ` as Iterator>::Item == Option` + | | + | required by a bound introduced by this call | note: expected this to be `Option` --> $DIR/associated-types-issue-20346.rs:23:17 diff --git a/src/test/ui/associated-types/associated-types-multiple-types-one-trait.stderr b/src/test/ui/associated-types/associated-types-multiple-types-one-trait.stderr index 922cf88a049..89cdba524be 100644 --- a/src/test/ui/associated-types/associated-types-multiple-types-one-trait.stderr +++ b/src/test/ui/associated-types/associated-types-multiple-types-one-trait.stderr @@ -1,8 +1,10 @@ error[E0271]: type mismatch resolving `::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 `::Y` @@ -17,10 +19,12 @@ LL | fn have_x_want_y>(t: &T) | +++++++++ error[E0271]: type mismatch resolving `::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 `::X` diff --git a/src/test/ui/associated-types/issue-87261.stderr b/src/test/ui/associated-types/issue-87261.stderr index 8db4a49da3c..f24423dd106 100644 --- a/src/test/ui/associated-types/issue-87261.stderr +++ b/src/test/ui/associated-types/issue-87261.stderr @@ -1,8 +1,10 @@ error[E0271]: type mismatch resolving `::Associated == ()` - --> $DIR/issue-87261.rs:56:5 + --> $DIR/issue-87261.rs:56:19 | LL | accepts_trait(a); - | ^^^^^^^^^^^^^ expected `()`, found associated type + | ------------- ^ expected `()`, found associated type + | | + | required by a bound introduced by this call | = note: expected unit type `()` found associated type `::Associated` @@ -17,10 +19,12 @@ LL | A: Trait + 'static, | +++++++++++++++++ error[E0271]: type mismatch resolving `::Associated == ()` - --> $DIR/issue-87261.rs:59:5 + --> $DIR/issue-87261.rs:59:19 | LL | accepts_trait(b); - | ^^^^^^^^^^^^^ expected `()`, found associated type + | ------------- ^ expected `()`, found associated type + | | + | required by a bound introduced by this call | = note: expected unit type `()` found associated type `::Associated` @@ -33,10 +37,12 @@ LL | fn accepts_trait>(_: T) {} | ^^^^^^^^^^^^^^^ required by this bound in `accepts_trait` error[E0271]: type mismatch resolving `::Associated == ()` - --> $DIR/issue-87261.rs:62:5 + --> $DIR/issue-87261.rs:62:19 | LL | accepts_trait(c); - | ^^^^^^^^^^^^^ expected `()`, found associated type + | ------------- ^ expected `()`, found associated type + | | + | required by a bound introduced by this call | = note: expected unit type `()` found associated type `::Associated` @@ -51,10 +57,12 @@ LL | C: Trait + Foo, | +++++++++++++++++ error[E0271]: type mismatch resolving `::Associated == ()` - --> $DIR/issue-87261.rs:65:5 + --> $DIR/issue-87261.rs:65:19 | LL | accepts_trait(d); - | ^^^^^^^^^^^^^ expected `()`, found associated type + | ------------- ^ expected `()`, found associated type + | | + | required by a bound introduced by this call | = note: expected unit type `()` found associated type `::Associated` @@ -67,10 +75,12 @@ LL | fn accepts_trait>(_: T) {} | ^^^^^^^^^^^^^^^ required by this bound in `accepts_trait` error[E0271]: type mismatch resolving `>::Associated == ()` - --> $DIR/issue-87261.rs:68:5 + --> $DIR/issue-87261.rs:68:27 | LL | accepts_generic_trait(e); - | ^^^^^^^^^^^^^^^^^^^^^ expected `()`, found associated type + | --------------------- ^ expected `()`, found associated type + | | + | required by a bound introduced by this call | = note: expected unit type `()` found associated type `>::Associated` @@ -85,10 +95,12 @@ LL | E: GenericTrait<(), Associated = ()> + 'static, | +++++++++++++++++ error[E0271]: type mismatch resolving `>::Associated == ()` - --> $DIR/issue-87261.rs:71:5 + --> $DIR/issue-87261.rs:71:27 | LL | accepts_generic_trait(f); - | ^^^^^^^^^^^^^^^^^^^^^ expected `()`, found associated type + | --------------------- ^ expected `()`, found associated type + | | + | required by a bound introduced by this call | = note: expected unit type `()` found associated type `>::Associated` @@ -103,10 +115,12 @@ LL | F: GenericTrait<(), Associated = ()> + Foo, | +++++++++++++++++ error[E0271]: type mismatch resolving `>::Associated == ()` - --> $DIR/issue-87261.rs:74:5 + --> $DIR/issue-87261.rs:74:27 | LL | accepts_generic_trait(g); - | ^^^^^^^^^^^^^^^^^^^^^ expected `()`, found associated type + | --------------------- ^ expected `()`, found associated type + | | + | required by a bound introduced by this call | = note: expected unit type `()` found associated type `>::Associated` @@ -119,13 +133,15 @@ LL | fn accepts_generic_trait>(_: T) {} | ^^^^^^^^^^^^^^^ required by this bound in `accepts_generic_trait` error[E0271]: type mismatch resolving `::Associated == ()` - --> $DIR/issue-87261.rs:79:5 + --> $DIR/issue-87261.rs:79:19 | LL | fn returns_opaque() -> impl Trait + 'static { | -------------------- the found opaque type ... LL | accepts_trait(returns_opaque()); - | ^^^^^^^^^^^^^ expected `()`, found associated type + | ------------- ^^^^^^^^^^^^^^^^ expected `()`, found associated type + | | + | required by a bound introduced by this call | = note: expected unit type `()` found associated type `::Associated` @@ -140,13 +156,15 @@ LL | fn returns_opaque() -> impl Trait + 'static { | +++++++++++++++++ error[E0271]: type mismatch resolving `::Associated == ()` - --> $DIR/issue-87261.rs:82:5 + --> $DIR/issue-87261.rs:82:19 | LL | fn returns_opaque_derived() -> impl DerivedTrait + 'static { | --------------------------- the found opaque type ... LL | accepts_trait(returns_opaque_derived()); - | ^^^^^^^^^^^^^ expected `()`, found associated type + | ------------- ^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found associated type + | | + | required by a bound introduced by this call | = note: expected unit type `()` found associated type `::Associated` @@ -161,13 +179,15 @@ LL | fn returns_opaque_derived() -> impl DerivedTrait + 'static | +++++++++++++++++ error[E0271]: type mismatch resolving `::Associated == ()` - --> $DIR/issue-87261.rs:85:5 + --> $DIR/issue-87261.rs:85:19 | LL | fn returns_opaque_foo() -> impl Trait + Foo { | ---------------- the found opaque type ... LL | accepts_trait(returns_opaque_foo()); - | ^^^^^^^^^^^^^ expected `()`, found associated type + | ------------- ^^^^^^^^^^^^^^^^^^^^ expected `()`, found associated type + | | + | required by a bound introduced by this call | = note: expected unit type `()` found associated type `::Associated` @@ -182,13 +202,15 @@ LL | fn returns_opaque_foo() -> impl Trait + Foo { | +++++++++++++++++ error[E0271]: type mismatch resolving `::Associated == ()` - --> $DIR/issue-87261.rs:88:5 + --> $DIR/issue-87261.rs:88:19 | LL | fn returns_opaque_derived_foo() -> impl DerivedTrait + Foo { | ----------------------- the found opaque type ... LL | accepts_trait(returns_opaque_derived_foo()); - | ^^^^^^^^^^^^^ expected `()`, found associated type + | ------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found associated type + | | + | required by a bound introduced by this call | = note: expected unit type `()` found associated type `::Associated` @@ -201,13 +223,15 @@ LL | fn accepts_trait>(_: T) {} | ^^^^^^^^^^^^^^^ required by this bound in `accepts_trait` error[E0271]: type mismatch resolving ` as GenericTrait<()>>::Associated == ()` - --> $DIR/issue-87261.rs:91:5 + --> $DIR/issue-87261.rs:91:27 | LL | fn returns_opaque_generic() -> impl GenericTrait<()> + 'static { | ------------------------------- the found opaque type ... LL | accepts_generic_trait(returns_opaque_generic()); - | ^^^^^^^^^^^^^^^^^^^^^ expected `()`, found associated type + | --------------------- ^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found associated type + | | + | required by a bound introduced by this call | = note: expected unit type `()` found associated type ` as GenericTrait<()>>::Associated` @@ -222,13 +246,15 @@ LL | fn returns_opaque_generic() -> impl GenericTrait<(), Associated = ()> + 'st | +++++++++++++++++ error[E0271]: type mismatch resolving ` + Foo as GenericTrait<()>>::Associated == ()` - --> $DIR/issue-87261.rs:94:5 + --> $DIR/issue-87261.rs:94:27 | LL | fn returns_opaque_generic_foo() -> impl GenericTrait<()> + Foo { | --------------------------- the found opaque type ... LL | accepts_generic_trait(returns_opaque_generic_foo()); - | ^^^^^^^^^^^^^^^^^^^^^ expected `()`, found associated type + | --------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found associated type + | | + | required by a bound introduced by this call | = note: expected unit type `()` found associated type ` + Foo as GenericTrait<()>>::Associated` @@ -243,13 +269,15 @@ LL | fn returns_opaque_generic_foo() -> impl GenericTrait<(), Associated = ()> + | +++++++++++++++++ error[E0271]: type mismatch resolving ` + GenericTrait as GenericTrait<()>>::Associated == ()` - --> $DIR/issue-87261.rs:97:5 + --> $DIR/issue-87261.rs:97:27 | LL | fn returns_opaque_generic_duplicate() -> impl GenericTrait<()> + GenericTrait { | ---------------------------------------- the found opaque type ... LL | accepts_generic_trait(returns_opaque_generic_duplicate()); - | ^^^^^^^^^^^^^^^^^^^^^ expected `()`, found associated type + | --------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found associated type + | | + | required by a bound introduced by this call | = note: expected unit type `()` found associated type ` + GenericTrait as GenericTrait<()>>::Associated` diff --git a/src/test/ui/error-codes/E0271.stderr b/src/test/ui/error-codes/E0271.stderr index 9c9c7237d71..1e2f4383459 100644 --- a/src/test/ui/error-codes/E0271.stderr +++ b/src/test/ui/error-codes/E0271.stderr @@ -1,8 +1,10 @@ error[E0271]: type mismatch resolving `::AssociatedType == u32` - --> $DIR/E0271.rs:10:5 + --> $DIR/E0271.rs:10:9 | LL | foo(3_i8); - | ^^^ type mismatch resolving `::AssociatedType == u32` + | --- ^^^^ type mismatch resolving `::AssociatedType == u32` + | | + | required by a bound introduced by this call | note: expected this to be `u32` --> $DIR/E0271.rs:7:43 diff --git a/src/test/ui/generic-associated-types/issue-74684-2.stderr b/src/test/ui/generic-associated-types/issue-74684-2.stderr index f0e03e73f0b..7c2935d32bf 100644 --- a/src/test/ui/generic-associated-types/issue-74684-2.stderr +++ b/src/test/ui/generic-associated-types/issue-74684-2.stderr @@ -1,8 +1,10 @@ error[E0271]: type mismatch resolving `<{integer} as Fun>::F<'_> == [u8]` - --> $DIR/issue-74684-2.rs:23:5 + --> $DIR/issue-74684-2.rs:23:9 | LL | bug(Box::new(x)); - | ^^^ type mismatch resolving `<{integer} as Fun>::F<'_> == [u8]` + | --- ^^^^^^^^^^^ type mismatch resolving `<{integer} as Fun>::F<'_> == [u8]` + | | + | required by a bound introduced by this call | note: expected this to be `[u8]` --> $DIR/issue-74684-2.rs:10:18 diff --git a/src/test/ui/higher-rank-trait-bounds/issue-62203-hrtb-ice.rs b/src/test/ui/higher-rank-trait-bounds/issue-62203-hrtb-ice.rs index ae21dbce011..e70f6fc3430 100644 --- a/src/test/ui/higher-rank-trait-bounds/issue-62203-hrtb-ice.rs +++ b/src/test/ui/higher-rank-trait-bounds/issue-62203-hrtb-ice.rs @@ -36,9 +36,9 @@ trait Ty<'a> { fn main() { let v = Unit2.m( - //~^ ERROR type mismatch L { //~^ ERROR to be a closure that returns `Unit3`, but it returns `Unit4` + //~| ERROR type mismatch f: |x| { drop(x); Unit4 diff --git a/src/test/ui/higher-rank-trait-bounds/issue-62203-hrtb-ice.stderr b/src/test/ui/higher-rank-trait-bounds/issue-62203-hrtb-ice.stderr index 8365fd0c79e..51017ffbd41 100644 --- a/src/test/ui/higher-rank-trait-bounds/issue-62203-hrtb-ice.stderr +++ b/src/test/ui/higher-rank-trait-bounds/issue-62203-hrtb-ice.stderr @@ -1,8 +1,16 @@ error[E0271]: type mismatch resolving `for<'r> as T0<'r, (&'r u8,)>>::O == <_ as Ty<'r>>::V` - --> $DIR/issue-62203-hrtb-ice.rs:38:19 + --> $DIR/issue-62203-hrtb-ice.rs:39:9 | -LL | let v = Unit2.m( - | ^ type mismatch resolving `for<'r> as T0<'r, (&'r u8,)>>::O == <_ as Ty<'r>>::V` +LL | let v = Unit2.m( + | - required by a bound introduced by this call +LL | / L { +LL | | +LL | | +LL | | f: |x| { +... | +LL | | }, +LL | | }, + | |_________^ type mismatch resolving `for<'r> as T0<'r, (&'r u8,)>>::O == <_ as Ty<'r>>::V` | note: expected this to be `<_ as Ty<'_>>::V` --> $DIR/issue-62203-hrtb-ice.rs:21:14 @@ -23,16 +31,15 @@ LL | F: for<'r> T0<'r, (>::V,), O = >::V>, | ^^^^^^^^^^^^^^^^^^^^ required by this bound in `T1::m` error[E0271]: expected `[closure@$DIR/issue-62203-hrtb-ice.rs:42:16: 42:19]` to be a closure that returns `Unit3`, but it returns `Unit4` - --> $DIR/issue-62203-hrtb-ice.rs:40:9 + --> $DIR/issue-62203-hrtb-ice.rs:39:9 | LL | let v = Unit2.m( | - required by a bound introduced by this call -LL | LL | / L { LL | | +LL | | LL | | f: |x| { -LL | | drop(x); -LL | | Unit4 +... | LL | | }, LL | | }, | |_________^ expected struct `Unit3`, found struct `Unit4` diff --git a/src/test/ui/intrinsics/const-eval-select-bad.stderr b/src/test/ui/intrinsics/const-eval-select-bad.stderr index e7b7e4a4a91..1a761ad5441 100644 --- a/src/test/ui/intrinsics/const-eval-select-bad.stderr +++ b/src/test/ui/intrinsics/const-eval-select-bad.stderr @@ -52,10 +52,12 @@ LL | G: FnOnce + ~const Destruct, | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `const_eval_select` error[E0271]: expected `fn(i32) -> bool {bar}` to be a fn item that returns `i32`, but it returns `bool` - --> $DIR/const-eval-select-bad.rs:29:5 + --> $DIR/const-eval-select-bad.rs:29:34 | LL | const_eval_select((1,), foo, bar); - | ^^^^^^^^^^^^^^^^^ expected `i32`, found `bool` + | ----------------- ^^^ expected `i32`, found `bool` + | | + | required by a bound introduced by this call | note: required by a bound in `const_eval_select` --> $SRC_DIR/core/src/intrinsics.rs:LL:COL diff --git a/src/test/ui/traits/associated_type_bound/check-trait-object-bounds-5.stderr b/src/test/ui/traits/associated_type_bound/check-trait-object-bounds-5.stderr index 4251c1a1ed6..00fdb375346 100644 --- a/src/test/ui/traits/associated_type_bound/check-trait-object-bounds-5.stderr +++ b/src/test/ui/traits/associated_type_bound/check-trait-object-bounds-5.stderr @@ -1,8 +1,10 @@ error[E0271]: type mismatch resolving `::T == i64` - --> $DIR/check-trait-object-bounds-5.rs:23:5 + --> $DIR/check-trait-object-bounds-5.rs:23:12 | LL | is_obj(x) - | ^^^^^^ type mismatch resolving `::T == i64` + | ------ ^ type mismatch resolving `::T == i64` + | | + | required by a bound introduced by this call | note: expected this to be `i64` --> $DIR/check-trait-object-bounds-5.rs:9:14 diff --git a/src/test/ui/traits/associated_type_bound/check-trait-object-bounds-6.stderr b/src/test/ui/traits/associated_type_bound/check-trait-object-bounds-6.stderr index 5b23a513eea..9b0975e5ed3 100644 --- a/src/test/ui/traits/associated_type_bound/check-trait-object-bounds-6.stderr +++ b/src/test/ui/traits/associated_type_bound/check-trait-object-bounds-6.stderr @@ -1,8 +1,10 @@ error[E0271]: type mismatch resolving `::T == i64` - --> $DIR/check-trait-object-bounds-6.rs:20:5 + --> $DIR/check-trait-object-bounds-6.rs:20:12 | LL | is_obj(x) - | ^^^^^^ type mismatch resolving `::T == i64` + | ------ ^ type mismatch resolving `::T == i64` + | | + | required by a bound introduced by this call | note: expected this to be `i64` --> $DIR/check-trait-object-bounds-6.rs:9:14 From 54edf1863e120f9b2f3bf1a3f2b5040e9c8ca476 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 13 Aug 2022 07:14:54 +0000 Subject: [PATCH 2/2] Also do it for generics --- .../rustc_typeck/src/check/fn_ctxt/checks.rs | 37 ++++++++++--------- .../associated-types-eq-hr.stderr | 8 ++-- .../enforce-supertrait-projection.stderr | 4 +- .../pointee-tail-is-generic-errors.stderr | 8 ++-- 4 files changed, 30 insertions(+), 27 deletions(-) diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs index 1f2dfc30ae0..bdb7c90aca3 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs @@ -1756,25 +1756,28 @@ fn point_at_type_arg_instead_of_call_if_possible( 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; } } } diff --git a/src/test/ui/associated-types/associated-types-eq-hr.stderr b/src/test/ui/associated-types/associated-types-eq-hr.stderr index b306ae273e8..6cff403b318 100644 --- a/src/test/ui/associated-types/associated-types-eq-hr.stderr +++ b/src/test/ui/associated-types/associated-types-eq-hr.stderr @@ -1,8 +1,8 @@ error[E0271]: type mismatch resolving `for<'x> >::A == &'x isize` - --> $DIR/associated-types-eq-hr.rs:87:5 + --> $DIR/associated-types-eq-hr.rs:87:11 | LL | foo::(); - | ^^^^^^^^^^^^^^^^^ type mismatch resolving `for<'x> >::A == &'x isize` + | ^^^^^^^^^^ type mismatch resolving `for<'x> >::A == &'x isize` | note: expected this to be `&isize` --> $DIR/associated-types-eq-hr.rs:26:14 @@ -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> >::A == &'x usize` - --> $DIR/associated-types-eq-hr.rs:91:5 + --> $DIR/associated-types-eq-hr.rs:91:11 | LL | bar::(); - | ^^^^^^^^^^^^^^^^ type mismatch resolving `for<'x> >::A == &'x usize` + | ^^^^^^^^^ type mismatch resolving `for<'x> >::A == &'x usize` | note: expected this to be `&usize` --> $DIR/associated-types-eq-hr.rs:14:14 diff --git a/src/test/ui/traits/object/enforce-supertrait-projection.stderr b/src/test/ui/traits/object/enforce-supertrait-projection.stderr index eab42ca568a..cbf09386654 100644 --- a/src/test/ui/traits/object/enforce-supertrait-projection.stderr +++ b/src/test/ui/traits/object/enforce-supertrait-projection.stderr @@ -1,12 +1,12 @@ error[E0271]: type mismatch resolving ` as SuperTrait>::A == B` - --> $DIR/enforce-supertrait-projection.rs:9:5 + --> $DIR/enforce-supertrait-projection.rs:9:17 | LL | fn transmute(x: A) -> B { | - - expected type parameter | | | found type parameter LL | foo::>(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` diff --git a/src/test/ui/traits/pointee-tail-is-generic-errors.stderr b/src/test/ui/traits/pointee-tail-is-generic-errors.stderr index 8456f84562f..0c3d7060dd7 100644 --- a/src/test/ui/traits/pointee-tail-is-generic-errors.stderr +++ b/src/test/ui/traits/pointee-tail-is-generic-errors.stderr @@ -1,8 +1,8 @@ error[E0271]: type mismatch resolving `::Metadata == ()` - --> $DIR/pointee-tail-is-generic-errors.rs:13:5 + --> $DIR/pointee-tail-is-generic-errors.rs:13:15 | LL | is_thin::(); - | ^^^^^^^^^^^^ expected `()`, found associated type + | ^ expected `()`, found associated type | = note: expected unit type `()` found associated type `::Metadata` @@ -15,13 +15,13 @@ LL | fn is_thin + ?Sized>() {} | ^^^^^^^^^^^^^ required by this bound in `is_thin` error[E0271]: type mismatch resolving `::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::(); - | ^^^^^^^^^^^^^^^^^ expected `()`, found associated type + | ^^^^^^ expected `()`, found associated type | = note: expected unit type `()` found associated type `::Metadata`