diff options
9 files changed, 72 insertions, 40 deletions
diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs index 35a3ae3ebf7..182e69d2aae 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs @@ -1669,6 +1669,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if let ty::GenericArgKind::Type(ty) = arg.unpack() && let ty::Param(param_ty) = ty.kind() && self.tcx.parent(generics.type_param(param_ty, self.tcx).def_id) != def_id + && param_ty.name != rustc_span::symbol::kw::SelfUpper + { + Some(arg) + } else { + None + } + }) + }); + let mut self_param_to_point_at = predicate_substs.types().find_map(|ty| { + ty.walk().find_map(|arg| { + if let ty::GenericArgKind::Type(ty) = arg.unpack() + && let ty::Param(param_ty) = ty.kind() + && param_ty.name == rustc_span::symbol::kw::SelfUpper { Some(arg) } else { @@ -1681,6 +1694,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // to print a relevant error. if let traits::FulfillmentErrorCode::CodeAmbiguity = error.code { fallback_param_to_point_at = None; + self_param_to_point_at = None; param_to_point_at = self.find_ambiguous_parameter_in(def_id, error.root_obligation.predicate); } @@ -1704,6 +1718,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { return; } + if let Some(self_param_to_point_at) = self_param_to_point_at + && self.point_at_args_if_possible(error, def_id, self_param_to_point_at, *call_hir_id, callee.span, args) + { + return; + } + if let hir::QPath::Resolved(_, path) = qpath && let Some(param_to_point_at) = param_to_point_at && let Some(segment) = path.segments.last() @@ -1733,6 +1753,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { return; } + if let Some(self_param_to_point_at) = self_param_to_point_at + && self.point_at_args_if_possible(error, def_id, self_param_to_point_at, hir_id, segment.ident.span, args) + { + return; + } + if let Some(param_to_point_at) = param_to_point_at && self.point_at_generics_if_possible(error, def_id, param_to_point_at, segment) { diff --git a/src/test/ui/did_you_mean/issue-21659-show-relevant-trait-impls-1.stderr b/src/test/ui/did_you_mean/issue-21659-show-relevant-trait-impls-1.stderr index f2f8d84ad3b..b69fcd5d32a 100644 --- a/src/test/ui/did_you_mean/issue-21659-show-relevant-trait-impls-1.stderr +++ b/src/test/ui/did_you_mean/issue-21659-show-relevant-trait-impls-1.stderr @@ -1,10 +1,10 @@ error[E0277]: the trait bound `Bar: Foo<usize>` is not satisfied - --> $DIR/issue-21659-show-relevant-trait-impls-1.rs:24:5 + --> $DIR/issue-21659-show-relevant-trait-impls-1.rs:24:12 | LL | f1.foo(1usize); - | ^^ --- required by a bound introduced by this call - | | - | the trait `Foo<usize>` is not implemented for `Bar` + | --- ^^^^^^ the trait `Foo<usize>` is not implemented for `Bar` + | | + | required by a bound introduced by this call | = help: the following other types implement trait `Foo<A>`: <Bar as Foo<i32>> diff --git a/src/test/ui/did_you_mean/issue-21659-show-relevant-trait-impls-2.stderr b/src/test/ui/did_you_mean/issue-21659-show-relevant-trait-impls-2.stderr index b0c41e2fae1..5e0e4a0115a 100644 --- a/src/test/ui/did_you_mean/issue-21659-show-relevant-trait-impls-2.stderr +++ b/src/test/ui/did_you_mean/issue-21659-show-relevant-trait-impls-2.stderr @@ -1,10 +1,10 @@ error[E0277]: the trait bound `Bar: Foo<usize>` is not satisfied - --> $DIR/issue-21659-show-relevant-trait-impls-2.rs:28:5 + --> $DIR/issue-21659-show-relevant-trait-impls-2.rs:28:12 | LL | f1.foo(1usize); - | ^^ --- required by a bound introduced by this call - | | - | the trait `Foo<usize>` is not implemented for `Bar` + | --- ^^^^^^ the trait `Foo<usize>` is not implemented for `Bar` + | | + | required by a bound introduced by this call | = help: the following other types implement trait `Foo<A>`: <Bar as Foo<i16>> diff --git a/src/test/ui/never_type/never-value-fallback-issue-66757.nofallback.stderr b/src/test/ui/never_type/never-value-fallback-issue-66757.nofallback.stderr index e2045591390..06e902bca70 100644 --- a/src/test/ui/never_type/never-value-fallback-issue-66757.nofallback.stderr +++ b/src/test/ui/never_type/never-value-fallback-issue-66757.nofallback.stderr @@ -1,8 +1,10 @@ error[E0277]: the trait bound `E: From<()>` is not satisfied - --> $DIR/never-value-fallback-issue-66757.rs:28:5 + --> $DIR/never-value-fallback-issue-66757.rs:28:26 | LL | <E as From<_>>::from(never); - | ^^^^^^^^^^^^^^^^^^^^ the trait `From<()>` is not implemented for `E` + | -------------------- ^^^^^ the trait `From<()>` is not implemented for `E` + | | + | required by a bound introduced by this call | = help: the trait `From<!>` is implemented for `E` diff --git a/src/test/ui/on-unimplemented/multiple-impls.stderr b/src/test/ui/on-unimplemented/multiple-impls.stderr index ad0cebb3736..8b94c8545ff 100644 --- a/src/test/ui/on-unimplemented/multiple-impls.stderr +++ b/src/test/ui/on-unimplemented/multiple-impls.stderr @@ -1,8 +1,8 @@ error[E0277]: the trait bound `[i32]: Index<u32>` is not satisfied - --> $DIR/multiple-impls.rs:33:18 + --> $DIR/multiple-impls.rs:33:33 | LL | Index::index(&[] as &[i32], 2u32); - | ------------ ^^^^^^^^^^^^^ trait message + | ------------ ^^^^ trait message | | | required by a bound introduced by this call | @@ -23,10 +23,10 @@ LL | Index::index(&[] as &[i32], 2u32); <[i32] as Index<Foo<usize>>> error[E0277]: the trait bound `[i32]: Index<Foo<u32>>` is not satisfied - --> $DIR/multiple-impls.rs:35:18 + --> $DIR/multiple-impls.rs:35:33 | LL | Index::index(&[] as &[i32], Foo(2u32)); - | ------------ ^^^^^^^^^^^^^ on impl for Foo + | ------------ ^^^^^^^^^ on impl for Foo | | | required by a bound introduced by this call | @@ -47,10 +47,10 @@ LL | Index::index(&[] as &[i32], Foo(2u32)); <[i32] as Index<Foo<usize>>> error[E0277]: the trait bound `[i32]: Index<Bar<u32>>` is not satisfied - --> $DIR/multiple-impls.rs:37:18 + --> $DIR/multiple-impls.rs:37:33 | LL | Index::index(&[] as &[i32], Bar(2u32)); - | ------------ ^^^^^^^^^^^^^ on impl for Bar + | ------------ ^^^^^^^^^ on impl for Bar | | | required by a bound introduced by this call | diff --git a/src/test/ui/on-unimplemented/on-impl.stderr b/src/test/ui/on-unimplemented/on-impl.stderr index 769a3d77a57..46902ad30a5 100644 --- a/src/test/ui/on-unimplemented/on-impl.stderr +++ b/src/test/ui/on-unimplemented/on-impl.stderr @@ -1,8 +1,8 @@ error[E0277]: the trait bound `[i32]: Index<u32>` is not satisfied - --> $DIR/on-impl.rs:22:25 + --> $DIR/on-impl.rs:22:47 | LL | Index::<u32>::index(&[1, 2, 3] as &[i32], 2u32); - | ------------------- ^^^^^^^^^^^^^^^^^^^^ a usize is required to index into a slice + | ------------------- ^^^^ a usize is required to index into a slice | | | required by a bound introduced by this call | diff --git a/src/test/ui/traits/inheritance/repeated-supertrait-ambig.stderr b/src/test/ui/traits/inheritance/repeated-supertrait-ambig.stderr index 6ef9ee81a9b..656e0d0bf26 100644 --- a/src/test/ui/traits/inheritance/repeated-supertrait-ambig.stderr +++ b/src/test/ui/traits/inheritance/repeated-supertrait-ambig.stderr @@ -1,22 +1,22 @@ error[E0277]: the trait bound `dyn CompareToInts: CompareTo<i32>` is not satisfied - --> $DIR/repeated-supertrait-ambig.rs:26:5 + --> $DIR/repeated-supertrait-ambig.rs:26:15 | LL | c.same_as(22) - | ^ ------- required by a bound introduced by this call - | | - | the trait `CompareTo<i32>` is not implemented for `dyn CompareToInts` + | ------- ^^ the trait `CompareTo<i32>` is not implemented for `dyn CompareToInts` + | | + | required by a bound introduced by this call | = help: the following other types implement trait `CompareTo<T>`: <i64 as CompareTo<i64>> <i64 as CompareTo<u64>> error[E0277]: the trait bound `C: CompareTo<i32>` is not satisfied - --> $DIR/repeated-supertrait-ambig.rs:30:5 + --> $DIR/repeated-supertrait-ambig.rs:30:15 | LL | c.same_as(22) - | ^ ------- required by a bound introduced by this call - | | - | the trait `CompareTo<i32>` is not implemented for `C` + | ------- ^^ the trait `CompareTo<i32>` is not implemented for `C` + | | + | required by a bound introduced by this call | help: consider further restricting this bound | @@ -24,10 +24,10 @@ LL | fn with_trait<C:CompareToInts + CompareTo<i32>>(c: &C) -> bool { | ++++++++++++++++ error[E0277]: the trait bound `dyn CompareToInts: CompareTo<i32>` is not satisfied - --> $DIR/repeated-supertrait-ambig.rs:34:34 + --> $DIR/repeated-supertrait-ambig.rs:34:37 | LL | <dyn CompareToInts>::same_as(c, 22) - | ---------------------------- ^ the trait `CompareTo<i32>` is not implemented for `dyn CompareToInts` + | ---------------------------- ^^ the trait `CompareTo<i32>` is not implemented for `dyn CompareToInts` | | | required by a bound introduced by this call | @@ -36,10 +36,10 @@ LL | <dyn CompareToInts>::same_as(c, 22) <i64 as CompareTo<u64>> error[E0277]: the trait bound `C: CompareTo<i32>` is not satisfied - --> $DIR/repeated-supertrait-ambig.rs:38:24 + --> $DIR/repeated-supertrait-ambig.rs:38:27 | LL | CompareTo::same_as(c, 22) - | ------------------ ^ the trait `CompareTo<i32>` is not implemented for `C` + | ------------------ ^^ the trait `CompareTo<i32>` is not implemented for `C` | | | required by a bound introduced by this call | @@ -49,12 +49,12 @@ LL | fn with_ufcs2<C:CompareToInts + CompareTo<i32>>(c: &C) -> bool { | ++++++++++++++++ error[E0277]: the trait bound `i64: CompareTo<i32>` is not satisfied - --> $DIR/repeated-supertrait-ambig.rs:42:16 + --> $DIR/repeated-supertrait-ambig.rs:42:31 | LL | assert_eq!(22_i64.same_as(22), true); - | ^^^^^^ ------- required by a bound introduced by this call - | | - | the trait `CompareTo<i32>` is not implemented for `i64` + | ------- ^^ the trait `CompareTo<i32>` is not implemented for `i64` + | | + | required by a bound introduced by this call | = help: the following other types implement trait `CompareTo<T>`: <i64 as CompareTo<i64>> diff --git a/src/test/ui/type/type-params-in-different-spaces-2.stderr b/src/test/ui/type/type-params-in-different-spaces-2.stderr index 53610985f31..220b3929c88 100644 --- a/src/test/ui/type/type-params-in-different-spaces-2.stderr +++ b/src/test/ui/type/type-params-in-different-spaces-2.stderr @@ -1,8 +1,10 @@ error[E0277]: the trait bound `Self: Tr<U>` is not satisfied - --> $DIR/type-params-in-different-spaces-2.rs:10:9 + --> $DIR/type-params-in-different-spaces-2.rs:10:16 | LL | Tr::op(u) - | ^^^^^^ the trait `Tr<U>` is not implemented for `Self` + | ------ ^ the trait `Tr<U>` is not implemented for `Self` + | | + | required by a bound introduced by this call | help: consider further restricting `Self` | @@ -10,10 +12,12 @@ LL | fn test<U>(u: U) -> Self where Self: Tr<U> { | +++++++++++++++++ error[E0277]: the trait bound `Self: Tr<U>` is not satisfied - --> $DIR/type-params-in-different-spaces-2.rs:16:9 + --> $DIR/type-params-in-different-spaces-2.rs:16:16 | LL | Tr::op(u) - | ^^^^^^ the trait `Tr<U>` is not implemented for `Self` + | ------ ^ the trait `Tr<U>` is not implemented for `Self` + | | + | required by a bound introduced by this call | help: consider further restricting `Self` | diff --git a/src/test/ui/ufcs/ufcs-qpath-self-mismatch.stderr b/src/test/ui/ufcs/ufcs-qpath-self-mismatch.stderr index 4f721f987ae..f08c81bc1e9 100644 --- a/src/test/ui/ufcs/ufcs-qpath-self-mismatch.stderr +++ b/src/test/ui/ufcs/ufcs-qpath-self-mismatch.stderr @@ -1,8 +1,8 @@ error[E0277]: cannot add `u32` to `i32` - --> $DIR/ufcs-qpath-self-mismatch.rs:4:28 + --> $DIR/ufcs-qpath-self-mismatch.rs:4:31 | LL | <i32 as Add<u32>>::add(1, 2); - | ---------------------- ^ no implementation for `i32 + u32` + | ---------------------- ^ no implementation for `i32 + u32` | | | required by a bound introduced by this call | |
