about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2019-11-13 16:06:28 -0800
committerEsteban Küber <esteban@kuber.com.ar>2019-11-17 14:40:41 -0800
commit578bc438b0cd17cab59df335063d1b273ef22ddb (patch)
tree3c0070fea3e9b40bbdc61dd9fb68a8e215f177a3
parent5c5b8afd80e6fa1d24632153cb2257c686041d41 (diff)
downloadrust-578bc438b0cd17cab59df335063d1b273ef22ddb.tar.gz
rust-578bc438b0cd17cab59df335063d1b273ef22ddb.zip
Do not ICE on trait aliases with missing obligations
-rw-r--r--src/librustc_typeck/astconv.rs11
-rw-r--r--src/test/ui/issues/issue-65673.rs12
-rw-r--r--src/test/ui/issues/issue-65673.stderr17
3 files changed, 37 insertions, 3 deletions
diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs
index c3bd916b9ce..46559422b03 100644
--- a/src/librustc_typeck/astconv.rs
+++ b/src/librustc_typeck/astconv.rs
@@ -1226,10 +1226,15 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
 
     /// Transform a `PolyTraitRef` into a `PolyExistentialTraitRef` by
     /// removing the dummy `Self` type (`trait_object_dummy_self`).
-    fn trait_ref_to_existential(&self, trait_ref: ty::TraitRef<'tcx>)
-                                -> ty::ExistentialTraitRef<'tcx> {
+    fn trait_ref_to_existential(
+        &self,
+        trait_ref: ty::TraitRef<'tcx>,
+    ) -> ty::ExistentialTraitRef<'tcx> {
         if trait_ref.self_ty() != self.tcx().types.trait_object_dummy_self {
-            bug!("trait_ref_to_existential called on {:?} with non-dummy Self", trait_ref);
+            self.tcx().sess.delay_span_bug(DUMMY_SP, &format!(
+                "trait_ref_to_existential called on {:?} with non-dummy Self",
+                trait_ref,
+            ));
         }
         ty::ExistentialTraitRef::erase_self_ty(self.tcx(), trait_ref)
     }
diff --git a/src/test/ui/issues/issue-65673.rs b/src/test/ui/issues/issue-65673.rs
new file mode 100644
index 00000000000..ea1d70194b1
--- /dev/null
+++ b/src/test/ui/issues/issue-65673.rs
@@ -0,0 +1,12 @@
+#![feature(trait_alias)]
+trait Trait {}
+trait WithType {
+    type Ctx;
+}
+trait Alias<T> = where T: Trait;
+
+impl<T> WithType for T {
+    type Ctx = dyn Alias<T>;
+//~^ ERROR the size for values of type `(dyn Trait + 'static)` cannot be known at compilation time
+}
+fn main() {}
diff --git a/src/test/ui/issues/issue-65673.stderr b/src/test/ui/issues/issue-65673.stderr
new file mode 100644
index 00000000000..a556e35b6a9
--- /dev/null
+++ b/src/test/ui/issues/issue-65673.stderr
@@ -0,0 +1,17 @@
+error[E0277]: the size for values of type `(dyn Trait + 'static)` cannot be known at compilation time
+  --> $DIR/issue-65673.rs:9:5
+   |
+LL |     type Ctx;
+   |          --- associated type defined here
+...
+LL | impl<T> WithType for T {
+   | ---------------------- in this `impl` item
+LL |     type Ctx = dyn Alias<T>;
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+   |
+   = help: the trait `std::marker::Sized` is not implemented for `(dyn Trait + 'static)`
+   = note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.