Skip to content

Commit 15c7234

Browse files
authored
Rollup merge of #113985 - compiler-errors:issue-113951, r=estebank
Use erased self type when autoderefing for trait error suggestion Let's not try to pass something from `skip_binder` into autoderef. Fixes #113951
2 parents 60a5d2d + d1380a1 commit 15c7234

File tree

3 files changed

+52
-7
lines changed

3 files changed

+52
-7
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -777,18 +777,14 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
777777
real_trait_pred = parent_trait_pred;
778778
}
779779

780-
let real_ty = real_trait_pred.self_ty();
781780
// We `erase_late_bound_regions` here because `make_subregion` does not handle
782781
// `ReLateBound`, and we don't particularly care about the regions.
783-
if !self.can_eq(
784-
obligation.param_env,
785-
self.tcx.erase_late_bound_regions(real_ty),
786-
arg_ty,
787-
) {
782+
let real_ty = self.tcx.erase_late_bound_regions(real_trait_pred.self_ty());
783+
if !self.can_eq(obligation.param_env, real_ty, arg_ty) {
788784
continue;
789785
}
790786

791-
if let ty::Ref(region, base_ty, mutbl) = *real_ty.skip_binder().kind() {
787+
if let ty::Ref(region, base_ty, mutbl) = *real_ty.kind() {
792788
let autoderef = (self.autoderef_steps)(base_ty);
793789
if let Some(steps) =
794790
autoderef.into_iter().enumerate().find_map(|(steps, (ty, obligations))| {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// issue:113951
2+
3+
trait Foo<'x, T> {}
4+
5+
trait RefFoo<T> {
6+
fn ref_foo(&self);
7+
}
8+
9+
impl<T> RefFoo<T> for T
10+
where
11+
for<'a> &'a mut Vec<&'a u32>: Foo<'static, T>,
12+
{
13+
fn ref_foo(&self) {}
14+
}
15+
16+
fn coerce_lifetime2() {
17+
<i32 as RefFoo<i32>>::ref_foo(unknown);
18+
//~^ ERROR cannot find value `unknown` in this scope
19+
//~| ERROR the trait bound `for<'a> &'a mut Vec<&'a u32>: Foo<'static, i32>` is not satisfied
20+
}
21+
22+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
error[E0425]: cannot find value `unknown` in this scope
2+
--> $DIR/dont-autoderef-ty-with-escaping-var.rs:17:35
3+
|
4+
LL | <i32 as RefFoo<i32>>::ref_foo(unknown);
5+
| ^^^^^^^ not found in this scope
6+
7+
error[E0277]: the trait bound `for<'a> &'a mut Vec<&'a u32>: Foo<'static, i32>` is not satisfied
8+
--> $DIR/dont-autoderef-ty-with-escaping-var.rs:17:35
9+
|
10+
LL | <i32 as RefFoo<i32>>::ref_foo(unknown);
11+
| ----------------------------- ^^^^^^^ the trait `for<'a> Foo<'static, i32>` is not implemented for `&'a mut Vec<&'a u32>`
12+
| |
13+
| required by a bound introduced by this call
14+
|
15+
note: required for `i32` to implement `RefFoo<i32>`
16+
--> $DIR/dont-autoderef-ty-with-escaping-var.rs:9:9
17+
|
18+
LL | impl<T> RefFoo<T> for T
19+
| ^^^^^^^^^ ^
20+
LL | where
21+
LL | for<'a> &'a mut Vec<&'a u32>: Foo<'static, T>,
22+
| --------------- unsatisfied trait bound introduced here
23+
24+
error: aborting due to 2 previous errors
25+
26+
Some errors have detailed explanations: E0277, E0425.
27+
For more information about an error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)