1
Fork 0

Handle Self in paths too

This commit is contained in:
Michael Goulet 2023-08-25 18:28:34 +00:00
parent 055452864e
commit 13e8b13e15
12 changed files with 54 additions and 22 deletions

View file

@ -165,6 +165,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
{ {
return true; return true;
} }
// Handle `Self` param specifically, since it's separated in
// the method call representation
if self_param_to_point_at.is_some() {
error.obligation.cause.span = receiver
.span
.find_ancestor_in_same_ctxt(error.obligation.cause.span)
.unwrap_or(receiver.span);
return true;
}
} }
hir::ExprKind::Struct(qpath, fields, ..) => { hir::ExprKind::Struct(qpath, fields, ..) => {
if let Res::Def(DefKind::Struct | DefKind::Variant, variant_def_id) = if let Res::Def(DefKind::Struct | DefKind::Variant, variant_def_id) =
@ -214,7 +223,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
qpath: &hir::QPath<'tcx>, qpath: &hir::QPath<'tcx>,
) -> bool { ) -> bool {
match qpath { match qpath {
hir::QPath::Resolved(_, path) => { hir::QPath::Resolved(self_ty, path) => {
for segment in path.segments.iter().rev() { for segment in path.segments.iter().rev() {
if let Res::Def(kind, def_id) = segment.res if let Res::Def(kind, def_id) = segment.res
&& !matches!(kind, DefKind::Mod | DefKind::ForeignMod) && !matches!(kind, DefKind::Mod | DefKind::ForeignMod)
@ -223,11 +232,34 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return true; return true;
} }
} }
// Handle `Self` param specifically, since it's separated in
// the path representation
if let Some(self_ty) = self_ty
&& let ty::GenericArgKind::Type(ty) = param.unpack()
&& ty == self.tcx.types.self_param
{
error.obligation.cause.span = self_ty
.span
.find_ancestor_in_same_ctxt(error.obligation.cause.span)
.unwrap_or(self_ty.span);
return true;
}
} }
hir::QPath::TypeRelative(_, segment) => { hir::QPath::TypeRelative(self_ty, segment) => {
if self.point_at_generic_if_possible(error, def_id, param, segment) { if self.point_at_generic_if_possible(error, def_id, param, segment) {
return true; return true;
} }
// Handle `Self` param specifically, since it's separated in
// the path representation
if let ty::GenericArgKind::Type(ty) = param.unpack()
&& ty == self.tcx.types.self_param
{
error.obligation.cause.span = self_ty
.span
.find_ancestor_in_same_ctxt(error.obligation.cause.span)
.unwrap_or(self_ty.span);
return true;
}
} }
_ => {} _ => {}
} }

View file

@ -1,8 +1,8 @@
error[E0277]: the trait bound `i32: Foo` is not satisfied error[E0277]: the trait bound `i32: Foo` is not satisfied
--> $DIR/associated-const-array-len.rs:5:16 --> $DIR/associated-const-array-len.rs:5:17
| |
LL | const X: [i32; <i32 as Foo>::ID] = [0, 1, 2]; LL | const X: [i32; <i32 as Foo>::ID] = [0, 1, 2];
| ^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `i32` | ^^^ the trait `Foo` is not implemented for `i32`
error: aborting due to previous error error: aborting due to previous error

View file

@ -1,8 +1,8 @@
error[E0271]: type mismatch resolving `<() as Array>::Element == &()` error[E0271]: type mismatch resolving `<() as Array>::Element == &()`
--> $DIR/issue-44153.rs:18:5 --> $DIR/issue-44153.rs:18:6
| |
LL | <() as Visit>::visit(); LL | <() as Visit>::visit();
| ^^^^^^^^^^^^^^^^^^^^ type mismatch resolving `<() as Array>::Element == &()` | ^^ type mismatch resolving `<() as Array>::Element == &()`
| |
note: expected this to be `&()` note: expected this to be `&()`
--> $DIR/issue-44153.rs:10:20 --> $DIR/issue-44153.rs:10:20

View file

@ -71,10 +71,10 @@ LL | let x: () = foo::<'static>();
| ++ | ++
error[E0277]: the size for values of type `str` cannot be known at compilation time error[E0277]: the size for values of type `str` cannot be known at compilation time
--> $DIR/substs-ppaux.rs:49:5 --> $DIR/substs-ppaux.rs:49:6
| |
LL | <str as Foo<u8>>::bar; LL | <str as Foo<u8>>::bar;
| ^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | ^^^ doesn't have a size known at compile-time
| |
= help: the trait `Sized` is not implemented for `str` = help: the trait `Sized` is not implemented for `str`
note: required for `str` to implement `Foo<'_, '_, u8>` note: required for `str` to implement `Foo<'_, '_, u8>`

View file

@ -71,10 +71,10 @@ LL | let x: () = foo::<'static>();
| ++ | ++
error[E0277]: the size for values of type `str` cannot be known at compilation time error[E0277]: the size for values of type `str` cannot be known at compilation time
--> $DIR/substs-ppaux.rs:49:5 --> $DIR/substs-ppaux.rs:49:6
| |
LL | <str as Foo<u8>>::bar; LL | <str as Foo<u8>>::bar;
| ^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | ^^^ doesn't have a size known at compile-time
| |
= help: the trait `Sized` is not implemented for `str` = help: the trait `Sized` is not implemented for `str`
note: required for `str` to implement `Foo<'?0, '?1, u8>` note: required for `str` to implement `Foo<'?0, '?1, u8>`

View file

@ -1,8 +1,8 @@
error[E0277]: the trait bound `[Adt; std::mem::size_of::<Self::Assoc>()]: Foo` is not satisfied error[E0277]: the trait bound `[Adt; std::mem::size_of::<Self::Assoc>()]: Foo` is not satisfied
--> $DIR/dont-evaluate-array-len-on-err-1.rs:15:9 --> $DIR/dont-evaluate-array-len-on-err-1.rs:15:10
| |
LL | <[Adt; std::mem::size_of::<Self::Assoc>()] as Foo>::bar() LL | <[Adt; std::mem::size_of::<Self::Assoc>()] as Foo>::bar()
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `[Adt; std::mem::size_of::<Self::Assoc>()]` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `[Adt; std::mem::size_of::<Self::Assoc>()]`
error: aborting due to previous error error: aborting due to previous error

View file

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

View file

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

View file

@ -1,8 +1,8 @@
error[E0277]: the trait bound `u32: ~const Plus` is not satisfied error[E0277]: the trait bound `u32: ~const Plus` is not satisfied
--> $DIR/call-const-trait-method-fail.rs:25:7 --> $DIR/call-const-trait-method-fail.rs:25:5
| |
LL | a.plus(b) LL | a.plus(b)
| ^^^^ the trait `Plus` is not implemented for `u32` | ^ the trait `Plus` is not implemented for `u32`
| |
= help: the trait `Plus` is implemented for `u32` = help: the trait `Plus` is implemented for `u32`

View file

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

View file

@ -2,7 +2,7 @@ error[E0277]: the trait bound `T: Bar` is not satisfied
--> $DIR/trait-where-clause.rs:14:5 --> $DIR/trait-where-clause.rs:14:5
| |
LL | T::b(); LL | T::b();
| ^^^^ the trait `Bar` is not implemented for `T` | ^ the trait `Bar` is not implemented for `T`
| |
note: required by a bound in `Foo::b` note: required by a bound in `Foo::b`
--> $DIR/trait-where-clause.rs:8:24 --> $DIR/trait-where-clause.rs:8:24

View file

@ -1,8 +1,8 @@
error[E0277]: the trait bound `[(); 0]: Foo` is not satisfied error[E0277]: the trait bound `[(); 0]: Foo` is not satisfied
--> $DIR/unevaluated_fixed_size_array_len.rs:12:5 --> $DIR/unevaluated_fixed_size_array_len.rs:12:6
| |
LL | <[(); 0] as Foo>::foo() LL | <[(); 0] as Foo>::foo()
| ^^^^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `[(); 0]` | ^^^^^^^ the trait `Foo` is not implemented for `[(); 0]`
| |
= help: the trait `Foo` is implemented for `[(); 1]` = help: the trait `Foo` is implemented for `[(); 1]`