Skip to content

Commit 13e8b13

Browse files
Handle Self in paths too
1 parent 0554528 commit 13e8b13

12 files changed

+54
-22
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs

+34-2
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
165165
{
166166
return true;
167167
}
168+
// Handle `Self` param specifically, since it's separated in
169+
// the method call representation
170+
if self_param_to_point_at.is_some() {
171+
error.obligation.cause.span = receiver
172+
.span
173+
.find_ancestor_in_same_ctxt(error.obligation.cause.span)
174+
.unwrap_or(receiver.span);
175+
return true;
176+
}
168177
}
169178
hir::ExprKind::Struct(qpath, fields, ..) => {
170179
if let Res::Def(DefKind::Struct | DefKind::Variant, variant_def_id) =
@@ -214,7 +223,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
214223
qpath: &hir::QPath<'tcx>,
215224
) -> bool {
216225
match qpath {
217-
hir::QPath::Resolved(_, path) => {
226+
hir::QPath::Resolved(self_ty, path) => {
218227
for segment in path.segments.iter().rev() {
219228
if let Res::Def(kind, def_id) = segment.res
220229
&& !matches!(kind, DefKind::Mod | DefKind::ForeignMod)
@@ -223,11 +232,34 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
223232
return true;
224233
}
225234
}
235+
// Handle `Self` param specifically, since it's separated in
236+
// the path representation
237+
if let Some(self_ty) = self_ty
238+
&& let ty::GenericArgKind::Type(ty) = param.unpack()
239+
&& ty == self.tcx.types.self_param
240+
{
241+
error.obligation.cause.span = self_ty
242+
.span
243+
.find_ancestor_in_same_ctxt(error.obligation.cause.span)
244+
.unwrap_or(self_ty.span);
245+
return true;
246+
}
226247
}
227-
hir::QPath::TypeRelative(_, segment) => {
248+
hir::QPath::TypeRelative(self_ty, segment) => {
228249
if self.point_at_generic_if_possible(error, def_id, param, segment) {
229250
return true;
230251
}
252+
// Handle `Self` param specifically, since it's separated in
253+
// the path representation
254+
if let ty::GenericArgKind::Type(ty) = param.unpack()
255+
&& ty == self.tcx.types.self_param
256+
{
257+
error.obligation.cause.span = self_ty
258+
.span
259+
.find_ancestor_in_same_ctxt(error.obligation.cause.span)
260+
.unwrap_or(self_ty.span);
261+
return true;
262+
}
231263
}
232264
_ => {}
233265
}

tests/ui/associated-consts/associated-const-array-len.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0277]: the trait bound `i32: Foo` is not satisfied
2-
--> $DIR/associated-const-array-len.rs:5:16
2+
--> $DIR/associated-const-array-len.rs:5:17
33
|
44
LL | const X: [i32; <i32 as Foo>::ID] = [0, 1, 2];
5-
| ^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `i32`
5+
| ^^^ the trait `Foo` is not implemented for `i32`
66

77
error: aborting due to previous error
88

tests/ui/associated-types/issue-44153.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0271]: type mismatch resolving `<() as Array>::Element == &()`
2-
--> $DIR/issue-44153.rs:18:5
2+
--> $DIR/issue-44153.rs:18:6
33
|
44
LL | <() as Visit>::visit();
5-
| ^^^^^^^^^^^^^^^^^^^^ type mismatch resolving `<() as Array>::Element == &()`
5+
| ^^ type mismatch resolving `<() as Array>::Element == &()`
66
|
77
note: expected this to be `&()`
88
--> $DIR/issue-44153.rs:10:20

tests/ui/associated-types/substs-ppaux.normal.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ LL | let x: () = foo::<'static>();
7171
| ++
7272

7373
error[E0277]: the size for values of type `str` cannot be known at compilation time
74-
--> $DIR/substs-ppaux.rs:49:5
74+
--> $DIR/substs-ppaux.rs:49:6
7575
|
7676
LL | <str as Foo<u8>>::bar;
77-
| ^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
77+
| ^^^ doesn't have a size known at compile-time
7878
|
7979
= help: the trait `Sized` is not implemented for `str`
8080
note: required for `str` to implement `Foo<'_, '_, u8>`

tests/ui/associated-types/substs-ppaux.verbose.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ LL | let x: () = foo::<'static>();
7171
| ++
7272

7373
error[E0277]: the size for values of type `str` cannot be known at compilation time
74-
--> $DIR/substs-ppaux.rs:49:5
74+
--> $DIR/substs-ppaux.rs:49:6
7575
|
7676
LL | <str as Foo<u8>>::bar;
77-
| ^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
77+
| ^^^ doesn't have a size known at compile-time
7878
|
7979
= help: the trait `Sized` is not implemented for `str`
8080
note: required for `str` to implement `Foo<'?0, '?1, u8>`

tests/ui/const-generics/dont-evaluate-array-len-on-err-1.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0277]: the trait bound `[Adt; std::mem::size_of::<Self::Assoc>()]: Foo` is not satisfied
2-
--> $DIR/dont-evaluate-array-len-on-err-1.rs:15:9
2+
--> $DIR/dont-evaluate-array-len-on-err-1.rs:15:10
33
|
44
LL | <[Adt; std::mem::size_of::<Self::Assoc>()] as Foo>::bar()
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `[Adt; std::mem::size_of::<Self::Assoc>()]`
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `[Adt; std::mem::size_of::<Self::Assoc>()]`
66

77
error: aborting due to previous error
88

tests/ui/consts/missing-larger-array-impl.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0277]: the trait bound `[X; 35]: Default` is not satisfied
2-
--> $DIR/missing-larger-array-impl.rs:7:5
2+
--> $DIR/missing-larger-array-impl.rs:7:6
33
|
44
LL | <[X; 35] as Default>::default();
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Default` is not implemented for `[X; 35]`
5+
| ^^^^^^^ the trait `Default` is not implemented for `[X; 35]`
66
|
77
= help: the following other types implement trait `Default`:
88
[T; 0]

tests/ui/issues/issue-39970.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0271]: type mismatch resolving `<() as Array<'a>>::Element == ()`
2-
--> $DIR/issue-39970.rs:19:5
2+
--> $DIR/issue-39970.rs:19:6
33
|
44
LL | <() as Visit>::visit();
5-
| ^^^^^^^^^^^^^^^^^^^^ type mismatch resolving `<() as Array<'a>>::Element == ()`
5+
| ^^ type mismatch resolving `<() as Array<'a>>::Element == ()`
66
|
77
note: expected this to be `()`
88
--> $DIR/issue-39970.rs:10:20

tests/ui/rfcs/rfc-2632-const-trait-impl/call-const-trait-method-fail.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0277]: the trait bound `u32: ~const Plus` is not satisfied
2-
--> $DIR/call-const-trait-method-fail.rs:25:7
2+
--> $DIR/call-const-trait-method-fail.rs:25:5
33
|
44
LL | a.plus(b)
5-
| ^^^^ the trait `Plus` is not implemented for `u32`
5+
| ^ the trait `Plus` is not implemented for `u32`
66
|
77
= help: the trait `Plus` is implemented for `u32`
88

tests/ui/rfcs/rfc-2632-const-trait-impl/trait-where-clause-const.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0277]: the trait bound `T: ~const Bar` is not satisfied
22
--> $DIR/trait-where-clause-const.rs:21:5
33
|
44
LL | T::b();
5-
| ^^^^ the trait `Bar` is not implemented for `T`
5+
| ^ the trait `Bar` is not implemented for `T`
66
|
77
note: required by a bound in `Foo::b`
88
--> $DIR/trait-where-clause-const.rs:15:24

tests/ui/rfcs/rfc-2632-const-trait-impl/trait-where-clause.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0277]: the trait bound `T: Bar` is not satisfied
22
--> $DIR/trait-where-clause.rs:14:5
33
|
44
LL | T::b();
5-
| ^^^^ the trait `Bar` is not implemented for `T`
5+
| ^ the trait `Bar` is not implemented for `T`
66
|
77
note: required by a bound in `Foo::b`
88
--> $DIR/trait-where-clause.rs:8:24

tests/ui/unevaluated_fixed_size_array_len.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0277]: the trait bound `[(); 0]: Foo` is not satisfied
2-
--> $DIR/unevaluated_fixed_size_array_len.rs:12:5
2+
--> $DIR/unevaluated_fixed_size_array_len.rs:12:6
33
|
44
LL | <[(); 0] as Foo>::foo()
5-
| ^^^^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `[(); 0]`
5+
| ^^^^^^^ the trait `Foo` is not implemented for `[(); 0]`
66
|
77
= help: the trait `Foo` is implemented for `[(); 1]`
88

0 commit comments

Comments
 (0)