]> git.lizzy.rs Git - rust.git/commitdiff
tolerate existential types whose concrete expansion is not known
authorNiko Matsakis <niko@alum.mit.edu>
Thu, 21 Jun 2018 20:21:44 +0000 (16:21 -0400)
committerNiko Matsakis <niko@alum.mit.edu>
Thu, 21 Jun 2018 20:38:35 +0000 (16:38 -0400)
src/librustc/infer/anon_types/mod.rs
src/librustc_typeck/collect.rs
src/test/ui/impl_trait_projections.rs
src/test/ui/impl_trait_projections.stderr

index f068a54ce44479f27a49ce8a1e49d9416f1da2e1..5487da97d5b2a137348e04041e0e11af62ebf484 100644 (file)
@@ -434,8 +434,8 @@ pub fn infer_anon_definition_from_instantiation(
         instantiated_ty: Ty<'gcx>,
     ) -> Ty<'gcx> {
         debug!(
-            "infer_anon_definition_from_instantiation(instantiated_ty={:?})",
-            instantiated_ty
+            "infer_anon_definition_from_instantiation(def_id={:?}, instantiated_ty={:?})",
+            def_id, instantiated_ty
         );
 
         let gcx = self.tcx.global_tcx();
index fe55ca66379957229771e24ebf9d3ece2c1056a4..51727b5b8978aca3f75fb76fd4a5bbd2498a3ab8 100644 (file)
@@ -1047,7 +1047,24 @@ fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
                 ItemExistential(hir::ExistTy { impl_trait_fn: None, .. }) => unimplemented!(),
                 // existential types desugared from impl Trait
                 ItemExistential(hir::ExistTy { impl_trait_fn: Some(owner), .. }) => {
-                    tcx.typeck_tables_of(owner).concrete_existential_types[&def_id]
+                    tcx.typeck_tables_of(owner).concrete_existential_types
+                        .get(&def_id)
+                        .cloned()
+                        .unwrap_or_else(|| {
+                            // This can occur if some error in the
+                            // owner fn prevented us from populating
+                            // the `concrete_existential_types` table.
+                            tcx.sess.delay_span_bug(
+                                DUMMY_SP,
+                                &format!(
+                                    "owner {:?} has no existential type for {:?} in its tables",
+                                    owner,
+                                    def_id,
+                                ),
+                            );
+
+                            tcx.types.err
+                        })
                 },
                 ItemTrait(..) | ItemTraitAlias(..) |
                 ItemMod(..) |
index 57a0040600a255d506e893c997c8b983494b9479..b64caccd98abef8311b646deb96affdb375a3aeb 100644 (file)
@@ -34,8 +34,9 @@ fn projection_with_named_trait_is_disallowed(x: impl Iterator)
 fn projection_with_named_trait_inside_path_is_disallowed()
     -> <::std::ops::Range<impl Debug> as Iterator>::Item
 //~^ ERROR `impl Trait` is not allowed in path parameters
-{
-    (1i32..100).next().unwrap()
+//~| ERROR trait bound `impl std::fmt::Debug: std::iter::Step` is not satisfied
+{ //~ ERROR trait bound `impl std::fmt::Debug: std::iter::Step` is not satisfied
+    (1i32..100).next().unwrap() //~ ERROR mismatched types
 }
 
 fn projection_from_impl_trait_inside_dyn_trait_is_disallowed()
index f6d58984ecef747ae3994640d005c6380d7ae928..b495d4b4b010b82890183f7631cea963eedc3ab4 100644 (file)
@@ -17,7 +17,7 @@ LL |     -> <::std::ops::Range<impl Debug> as Iterator>::Item
    |                           ^^^^^^^^^^
 
 error[E0667]: `impl Trait` is not allowed in path parameters
-  --> $DIR/impl_trait_projections.rs:42:29
+  --> $DIR/impl_trait_projections.rs:43:29
    |
 LL |     -> <dyn Iterator<Item = impl Debug> as Iterator>::Item
    |                             ^^^^^^^^^^
@@ -30,7 +30,34 @@ LL | fn projection_is_disallowed(x: impl Iterator) -> <impl Iterator>::Item {
    |
    = note: specify the type using the syntax `<impl std::iter::Iterator as Trait>::Item`
 
-error: aborting due to 5 previous errors
+error[E0277]: the trait bound `impl std::fmt::Debug: std::iter::Step` is not satisfied
+  --> $DIR/impl_trait_projections.rs:38:1
+   |
+LL | / { //~ ERROR trait bound `impl std::fmt::Debug: std::iter::Step` is not satisfied
+LL | |     (1i32..100).next().unwrap() //~ ERROR mismatched types
+LL | | }
+   | |_^ the trait `std::iter::Step` is not implemented for `impl std::fmt::Debug`
+   |
+   = note: required because of the requirements on the impl of `std::iter::Iterator` for `std::ops::Range<impl std::fmt::Debug>`
+
+error[E0308]: mismatched types
+  --> $DIR/impl_trait_projections.rs:39:5
+   |
+LL |     (1i32..100).next().unwrap() //~ ERROR mismatched types
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected anonymized type, found i32
+   |
+   = note: expected type `impl std::fmt::Debug`
+              found type `i32`
+
+error[E0277]: the trait bound `impl std::fmt::Debug: std::iter::Step` is not satisfied
+  --> $DIR/impl_trait_projections.rs:35:8
+   |
+LL |     -> <::std::ops::Range<impl Debug> as Iterator>::Item
+   |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::iter::Step` is not implemented for `impl std::fmt::Debug`
+   |
+   = note: required because of the requirements on the impl of `std::iter::Iterator` for `std::ops::Range<impl std::fmt::Debug>`
+
+error: aborting due to 8 previous errors
 
-Some errors occurred: E0223, E0667.
+Some errors occurred: E0223, E0277, E0308, E0667.
 For more information about an error, try `rustc --explain E0223`.