Blame SOURCES/rust-pr61085-fix-ICE-with-incorrect-turbofish.patch

ec855a
From 476732995c2f5dc08e20eb8f9f03c628a48f5f41 Mon Sep 17 00:00:00 2001
ec855a
From: Oliver Scherer <github35764891676564198441@oli-obk.de>
ec855a
Date: Thu, 23 May 2019 17:05:48 +0200
ec855a
Subject: [PATCH 1/3] WIP
ec855a
ec855a
---
ec855a
 src/librustc_typeck/check/mod.rs | 22 +++++++++++-----------
ec855a
 src/test/run-pass/issue-60989.rs |  4 ++++
ec855a
 2 files changed, 15 insertions(+), 11 deletions(-)
ec855a
 create mode 100644 src/test/run-pass/issue-60989.rs
ec855a
ec855a
diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs
ec855a
index 313ed19b945d..088729f12b1e 100644
ec855a
--- a/src/librustc_typeck/check/mod.rs
ec855a
+++ b/src/librustc_typeck/check/mod.rs
ec855a
@@ -5396,17 +5396,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
ec855a
 
ec855a
         let tcx = self.tcx;
ec855a
 
ec855a
-        match def {
ec855a
-            Def::Local(nid) | Def::Upvar(nid, ..) => {
ec855a
-                let hid = self.tcx.hir().node_to_hir_id(nid);
ec855a
-                let ty = self.local_ty(span, hid).decl_ty;
ec855a
-                let ty = self.normalize_associated_types_in(span, &ty;;
ec855a
-                self.write_ty(hir_id, ty);
ec855a
-                return (ty, def);
ec855a
-            }
ec855a
-            _ => {}
ec855a
-        }
ec855a
-
ec855a
         let (def, def_id, ty) = self.rewrite_self_ctor(def, span);
ec855a
         let path_segs = AstConv::def_ids_for_path_segments(self, segments, self_ty, def);
ec855a
 
ec855a
@@ -5469,6 +5458,17 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
ec855a
             user_self_ty = None;
ec855a
         }
ec855a
 
ec855a
+        match def {
ec855a
+            Def::Local(nid) | Def::Upvar(nid, ..) => {
ec855a
+                let hid = self.tcx.hir().node_to_hir_id(nid);
ec855a
+                let ty = self.local_ty(span, hid).decl_ty;
ec855a
+                let ty = self.normalize_associated_types_in(span, &ty;;
ec855a
+                self.write_ty(hir_id, ty);
ec855a
+                return (ty, def);
ec855a
+            }
ec855a
+            _ => {}
ec855a
+        }
ec855a
+
ec855a
         // Now we have to compare the types that the user *actually*
ec855a
         // provided against the types that were *expected*. If the user
ec855a
         // did not provide any types, then we want to substitute inference
ec855a
diff --git a/src/test/run-pass/issue-60989.rs b/src/test/run-pass/issue-60989.rs
ec855a
new file mode 100644
ec855a
index 000000000000..efaa74da3baa
ec855a
--- /dev/null
ec855a
+++ b/src/test/run-pass/issue-60989.rs
ec855a
@@ -0,0 +1,4 @@
ec855a
+fn main() {
ec855a
+    let c1 = ();
ec855a
+    c1::<()>;
ec855a
+}
ec855a
-- 
ec855a
2.21.0
ec855a
ec855a
ec855a
From 97f204e6ae43bfe0fed64221d709a194bef728a4 Mon Sep 17 00:00:00 2001
ec855a
From: Oliver Scherer <github35764891676564198441@oli-obk.de>
ec855a
Date: Thu, 23 May 2019 17:21:32 +0200
ec855a
Subject: [PATCH 2/3] Make regression test a compile-fail test
ec855a
ec855a
---
ec855a
 src/test/{run-pass => compile-fail}/issue-60989.rs | 0
ec855a
 1 file changed, 0 insertions(+), 0 deletions(-)
ec855a
 rename src/test/{run-pass => compile-fail}/issue-60989.rs (100%)
ec855a
ec855a
diff --git a/src/test/run-pass/issue-60989.rs b/src/test/compile-fail/issue-60989.rs
ec855a
similarity index 100%
ec855a
rename from src/test/run-pass/issue-60989.rs
ec855a
rename to src/test/compile-fail/issue-60989.rs
ec855a
-- 
ec855a
2.21.0
ec855a
ec855a
ec855a
From 6e81f8205a6d47648d086d26e96bf05e962e3715 Mon Sep 17 00:00:00 2001
ec855a
From: Eduard-Mihai Burtescu <edy.burt@gmail.com>
ec855a
Date: Thu, 23 May 2019 19:23:00 +0300
ec855a
Subject: [PATCH 3/3] rustc_typeck: don't produce a `DefId` or `Ty` from
ec855a
 `rewrite_self_ctor`, only a `Def`.
ec855a
ec855a
---
ec855a
 src/librustc_typeck/check/mod.rs     | 30 ++++++++++++++++++----------
ec855a
 src/test/compile-fail/issue-60989.rs |  4 ----
ec855a
 src/test/ui/issue-60989.rs           | 18 +++++++++++++++++
ec855a
 src/test/ui/issue-60989.stderr       | 15 ++++++++++++++
ec855a
 4 files changed, 52 insertions(+), 15 deletions(-)
ec855a
 delete mode 100644 src/test/compile-fail/issue-60989.rs
ec855a
 create mode 100644 src/test/ui/issue-60989.rs
ec855a
 create mode 100644 src/test/ui/issue-60989.stderr
ec855a
ec855a
diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs
ec855a
index 088729f12b1e..b6adcdbf35e9 100644
ec855a
--- a/src/librustc_typeck/check/mod.rs
ec855a
+++ b/src/librustc_typeck/check/mod.rs
ec855a
@@ -5330,7 +5330,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
ec855a
     }
ec855a
 
ec855a
     // Rewrite `SelfCtor` to `Ctor`
ec855a
-    pub fn rewrite_self_ctor(&self, def: Def, span: Span) -> (Def, DefId, Ty<'tcx>) {
ec855a
+    pub fn rewrite_self_ctor(&self, def: Def, span: Span) -> Def {
ec855a
         let tcx = self.tcx;
ec855a
         if let Def::SelfCtor(impl_def_id) = def {
ec855a
             let ty = self.impl_self_ty(span, impl_def_id).ty;
ec855a
@@ -5340,8 +5340,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
ec855a
                 Some(adt_def) if adt_def.has_ctor() => {
ec855a
                     let variant = adt_def.non_enum_variant();
ec855a
                     let ctor_def_id = variant.ctor_def_id.unwrap();
ec855a
-                    let def = Def::Ctor(ctor_def_id, CtorOf::Struct, variant.ctor_kind);
ec855a
-                    (def, ctor_def_id, tcx.type_of(ctor_def_id))
ec855a
+                    Def::Ctor(ctor_def_id, CtorOf::Struct, variant.ctor_kind)
ec855a
                 }
ec855a
                 _ => {
ec855a
                     let mut err = tcx.sess.struct_span_err(span,
ec855a
@@ -5364,16 +5363,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
ec855a
                     }
ec855a
                     err.emit();
ec855a
 
ec855a
-                    (def, impl_def_id, tcx.types.err)
ec855a
+                    def
ec855a
                 }
ec855a
             }
ec855a
         } else {
ec855a
-            let def_id = def.def_id();
ec855a
-
ec855a
-            // The things we are substituting into the type should not contain
ec855a
-            // escaping late-bound regions, and nor should the base type scheme.
ec855a
-            let ty = tcx.type_of(def_id);
ec855a
-            (def, def_id, ty)
ec855a
+            def
ec855a
         }
ec855a
     }
ec855a
 
ec855a
@@ -5396,7 +5390,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
ec855a
 
ec855a
         let tcx = self.tcx;
ec855a
 
ec855a
-        let (def, def_id, ty) = self.rewrite_self_ctor(def, span);
ec855a
+        let def = self.rewrite_self_ctor(def, span);
ec855a
         let path_segs = AstConv::def_ids_for_path_segments(self, segments, self_ty, def);
ec855a
 
ec855a
         let mut user_self_ty = None;
ec855a
@@ -5501,6 +5495,20 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
ec855a
             tcx.generics_of(*def_id).has_self
ec855a
         }).unwrap_or(false);
ec855a
 
ec855a
+        let (def_id, ty) = if let Def::SelfCtor(impl_def_id) = def {
ec855a
+            // NOTE(eddyb) an error has already been emitted by `rewrite_self_ctor`,
ec855a
+            // avoid using the wrong type here. This isn't in `rewrite_self_ctor`
ec855a
+            // itself because that runs too early (see #60989).
ec855a
+            (impl_def_id, tcx.types.err)
ec855a
+        } else {
ec855a
+            let def_id = def.def_id();
ec855a
+
ec855a
+            // The things we are substituting into the type should not contain
ec855a
+            // escaping late-bound regions, and nor should the base type scheme.
ec855a
+            let ty = tcx.type_of(def_id);
ec855a
+            (def_id, ty)
ec855a
+        };
ec855a
+
ec855a
         let substs = AstConv::create_substs_for_generic_args(
ec855a
             tcx,
ec855a
             def_id,
ec855a
diff --git a/src/test/compile-fail/issue-60989.rs b/src/test/compile-fail/issue-60989.rs
ec855a
deleted file mode 100644
ec855a
index efaa74da3baa..000000000000
ec855a
--- a/src/test/compile-fail/issue-60989.rs
ec855a
+++ /dev/null
ec855a
@@ -1,4 +0,0 @@
ec855a
-fn main() {
ec855a
-    let c1 = ();
ec855a
-    c1::<()>;
ec855a
-}
ec855a
diff --git a/src/test/ui/issue-60989.rs b/src/test/ui/issue-60989.rs
ec855a
new file mode 100644
ec855a
index 000000000000..930e98bedce8
ec855a
--- /dev/null
ec855a
+++ b/src/test/ui/issue-60989.rs
ec855a
@@ -0,0 +1,18 @@
ec855a
+struct A {}
ec855a
+struct B {}
ec855a
+
ec855a
+impl From for B {
ec855a
+    fn from(a: A) -> B {
ec855a
+        B{}
ec855a
+    }
ec855a
+}
ec855a
+
ec855a
+fn main() {
ec855a
+    let c1 = ();
ec855a
+    c1::<()>;
ec855a
+    //~^ ERROR type arguments are not allowed for this type
ec855a
+
ec855a
+    let c1 = A {};
ec855a
+    c1::<Into<B>>;
ec855a
+    //~^ ERROR type arguments are not allowed for this type
ec855a
+}
ec855a
diff --git a/src/test/ui/issue-60989.stderr b/src/test/ui/issue-60989.stderr
ec855a
new file mode 100644
ec855a
index 000000000000..55a0b9626df7
ec855a
--- /dev/null
ec855a
+++ b/src/test/ui/issue-60989.stderr
ec855a
@@ -0,0 +1,15 @@
ec855a
+error[E0109]: type arguments are not allowed for this type
ec855a
+  --> $DIR/issue-60989.rs:12:10
ec855a
+   |
ec855a
+LL |     c1::<()>;
ec855a
+   |          ^^ type argument not allowed
ec855a
+
ec855a
+error[E0109]: type arguments are not allowed for this type
ec855a
+  --> $DIR/issue-60989.rs:16:10
ec855a
+   |
ec855a
+LL |     c1::<Into<B>>;
ec855a
+   |          ^^^^^^^ type argument not allowed
ec855a
+
ec855a
+error: aborting due to 2 previous errors
ec855a
+
ec855a
+For more information about this error, try `rustc --explain E0109`.
ec855a
-- 
ec855a
2.21.0
ec855a