Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In suggest_missing_return_type, erase late bound regions after normalizing #88846

Merged
merged 1 commit into from
Sep 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
debug!("suggest_missing_return_type: return type {:?}", ty);
debug!("suggest_missing_return_type: expected type {:?}", ty);
let bound_vars = self.tcx.late_bound_vars(fn_id);
let ty = self.tcx.erase_late_bound_regions(Binder::bind_with_vars(ty, bound_vars));
let ty = Binder::bind_with_vars(ty, bound_vars);
let ty = self.normalize_associated_types_in(sp, ty);
let ty = self.tcx.erase_late_bound_regions(ty);
if self.can_coerce(expected, ty) {
err.span_label(sp, format!("expected `{}` because of return type", expected));
return true;
Expand Down
19 changes: 19 additions & 0 deletions src/test/ui/generic-associated-types/issue-88360.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#![feature(generic_associated_types)]

trait GatTrait {
type Gat<'a>;

fn test(&self) -> Self::Gat<'_>;
}

trait SuperTrait<T>
where
for<'a> Self: GatTrait<Gat<'a> = &'a T>,
{
fn copy(&self) -> Self::Gat<'_> where T: Copy {
*self.test()
//~^ mismatched types
}
}

fn main() {}
20 changes: 20 additions & 0 deletions src/test/ui/generic-associated-types/issue-88360.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
error[E0308]: mismatched types
--> $DIR/issue-88360.rs:14:9
|
LL | trait SuperTrait<T>
| - this type parameter
...
LL | fn copy(&self) -> Self::Gat<'_> where T: Copy {
| ------------- expected `&T` because of return type
LL | *self.test()
| ^^^^^^^^^^^^
| |
| expected `&T`, found type parameter `T`
| help: consider borrowing here: `&*self.test()`
|
= note: expected reference `&T`
found type parameter `T`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.