Skip to content

Commit 77f4143

Browse files
committed
Auto merge of #88846 - jackh726:issue-88360, r=nikomatsakis
In suggest_missing_return_type, erase late bound regions after normalizing Fixes #88360 There might be some hardening that could be done to not error or avoid erroring with LUBing `ReErased` with `ReEmpty`, but this was the most simple fix for this particular case. r? `@nikomatsakis`
2 parents 5fd6f3b + 1ed18f5 commit 77f4143

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
484484
debug!("suggest_missing_return_type: return type {:?}", ty);
485485
debug!("suggest_missing_return_type: expected type {:?}", ty);
486486
let bound_vars = self.tcx.late_bound_vars(fn_id);
487-
let ty = self.tcx.erase_late_bound_regions(Binder::bind_with_vars(ty, bound_vars));
487+
let ty = Binder::bind_with_vars(ty, bound_vars);
488488
let ty = self.normalize_associated_types_in(sp, ty);
489+
let ty = self.tcx.erase_late_bound_regions(ty);
489490
if self.can_coerce(expected, ty) {
490491
err.span_label(sp, format!("expected `{}` because of return type", expected));
491492
return true;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#![feature(generic_associated_types)]
2+
3+
trait GatTrait {
4+
type Gat<'a>;
5+
6+
fn test(&self) -> Self::Gat<'_>;
7+
}
8+
9+
trait SuperTrait<T>
10+
where
11+
for<'a> Self: GatTrait<Gat<'a> = &'a T>,
12+
{
13+
fn copy(&self) -> Self::Gat<'_> where T: Copy {
14+
*self.test()
15+
//~^ mismatched types
16+
}
17+
}
18+
19+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/issue-88360.rs:14:9
3+
|
4+
LL | trait SuperTrait<T>
5+
| - this type parameter
6+
...
7+
LL | fn copy(&self) -> Self::Gat<'_> where T: Copy {
8+
| ------------- expected `&T` because of return type
9+
LL | *self.test()
10+
| ^^^^^^^^^^^^
11+
| |
12+
| expected `&T`, found type parameter `T`
13+
| help: consider borrowing here: `&*self.test()`
14+
|
15+
= note: expected reference `&T`
16+
found type parameter `T`
17+
18+
error: aborting due to previous error
19+
20+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)