about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-09-22 04:02:01 +0000
committerbors <bors@rust-lang.org>2021-09-22 04:02:01 +0000
commit77f4143fa26a1434088f532d2ba7ec51e0a392fd (patch)
tree2ac36b864964dec158496187d069dffd96949f1e
parent5fd6f3b16db75f01ffa4e59860e35f1e636590d5 (diff)
parent1ed18f589ec62bf99a4ff541830fbc2bc48ce9f1 (diff)
downloadrust-77f4143fa26a1434088f532d2ba7ec51e0a392fd.tar.gz
rust-77f4143fa26a1434088f532d2ba7ec51e0a392fd.zip
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`
-rw-r--r--compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs3
-rw-r--r--src/test/ui/generic-associated-types/issue-88360.rs19
-rw-r--r--src/test/ui/generic-associated-types/issue-88360.stderr20
3 files changed, 41 insertions, 1 deletions
diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs b/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs
index 0acf1d26e25..da8b863e2db 100644
--- a/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs
+++ b/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs
@@ -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;
diff --git a/src/test/ui/generic-associated-types/issue-88360.rs b/src/test/ui/generic-associated-types/issue-88360.rs
new file mode 100644
index 00000000000..06af3f5ec96
--- /dev/null
+++ b/src/test/ui/generic-associated-types/issue-88360.rs
@@ -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() {}
diff --git a/src/test/ui/generic-associated-types/issue-88360.stderr b/src/test/ui/generic-associated-types/issue-88360.stderr
new file mode 100644
index 00000000000..cfbf3aaa4e6
--- /dev/null
+++ b/src/test/ui/generic-associated-types/issue-88360.stderr
@@ -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`.