Skip to content

Commit e3fa2d5

Browse files
committed
tolerate existential types whose concrete expansion is not known
1 parent a2a019a commit e3fa2d5

File tree

4 files changed

+53
-8
lines changed

4 files changed

+53
-8
lines changed

src/librustc/infer/anon_types/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
434434
instantiated_ty: Ty<'gcx>,
435435
) -> Ty<'gcx> {
436436
debug!(
437-
"infer_anon_definition_from_instantiation(instantiated_ty={:?})",
438-
instantiated_ty
437+
"infer_anon_definition_from_instantiation(def_id={:?}, instantiated_ty={:?})",
438+
def_id, instantiated_ty
439439
);
440440

441441
let gcx = self.tcx.global_tcx();

src/librustc_typeck/collect.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,24 @@ fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
10471047
ItemExistential(hir::ExistTy { impl_trait_fn: None, .. }) => unimplemented!(),
10481048
// existential types desugared from impl Trait
10491049
ItemExistential(hir::ExistTy { impl_trait_fn: Some(owner), .. }) => {
1050-
tcx.typeck_tables_of(owner).concrete_existential_types[&def_id]
1050+
tcx.typeck_tables_of(owner).concrete_existential_types
1051+
.get(&def_id)
1052+
.cloned()
1053+
.unwrap_or_else(|| {
1054+
// This can occur if some error in the
1055+
// owner fn prevented us from populating
1056+
// the `concrete_existential_types` table.
1057+
tcx.sess.delay_span_bug(
1058+
DUMMY_SP,
1059+
&format!(
1060+
"owner {:?} has no existential type for {:?} in its tables",
1061+
owner,
1062+
def_id,
1063+
),
1064+
);
1065+
1066+
tcx.types.err
1067+
})
10511068
},
10521069
ItemTrait(..) | ItemTraitAlias(..) |
10531070
ItemMod(..) |

src/test/ui/impl_trait_projections.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ fn projection_with_named_trait_is_disallowed(x: impl Iterator)
3434
fn projection_with_named_trait_inside_path_is_disallowed()
3535
-> <::std::ops::Range<impl Debug> as Iterator>::Item
3636
//~^ ERROR `impl Trait` is not allowed in path parameters
37-
{
38-
(1i32..100).next().unwrap()
37+
//~| ERROR trait bound `impl std::fmt::Debug: std::iter::Step` is not satisfied
38+
{ //~ ERROR trait bound `impl std::fmt::Debug: std::iter::Step` is not satisfied
39+
(1i32..100).next().unwrap() //~ ERROR mismatched types
3940
}
4041

4142
fn projection_from_impl_trait_inside_dyn_trait_is_disallowed()

src/test/ui/impl_trait_projections.stderr

+30-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ LL | -> <::std::ops::Range<impl Debug> as Iterator>::Item
1717
| ^^^^^^^^^^
1818

1919
error[E0667]: `impl Trait` is not allowed in path parameters
20-
--> $DIR/impl_trait_projections.rs:42:29
20+
--> $DIR/impl_trait_projections.rs:43:29
2121
|
2222
LL | -> <dyn Iterator<Item = impl Debug> as Iterator>::Item
2323
| ^^^^^^^^^^
@@ -30,7 +30,34 @@ LL | fn projection_is_disallowed(x: impl Iterator) -> <impl Iterator>::Item {
3030
|
3131
= note: specify the type using the syntax `<impl std::iter::Iterator as Trait>::Item`
3232

33-
error: aborting due to 5 previous errors
33+
error[E0277]: the trait bound `impl std::fmt::Debug: std::iter::Step` is not satisfied
34+
--> $DIR/impl_trait_projections.rs:38:1
35+
|
36+
LL | / { //~ ERROR trait bound `impl std::fmt::Debug: std::iter::Step` is not satisfied
37+
LL | | (1i32..100).next().unwrap() //~ ERROR mismatched types
38+
LL | | }
39+
| |_^ the trait `std::iter::Step` is not implemented for `impl std::fmt::Debug`
40+
|
41+
= note: required because of the requirements on the impl of `std::iter::Iterator` for `std::ops::Range<impl std::fmt::Debug>`
42+
43+
error[E0308]: mismatched types
44+
--> $DIR/impl_trait_projections.rs:39:5
45+
|
46+
LL | (1i32..100).next().unwrap() //~ ERROR mismatched types
47+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected anonymized type, found i32
48+
|
49+
= note: expected type `impl std::fmt::Debug`
50+
found type `i32`
51+
52+
error[E0277]: the trait bound `impl std::fmt::Debug: std::iter::Step` is not satisfied
53+
--> $DIR/impl_trait_projections.rs:35:8
54+
|
55+
LL | -> <::std::ops::Range<impl Debug> as Iterator>::Item
56+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::iter::Step` is not implemented for `impl std::fmt::Debug`
57+
|
58+
= note: required because of the requirements on the impl of `std::iter::Iterator` for `std::ops::Range<impl std::fmt::Debug>`
59+
60+
error: aborting due to 8 previous errors
3461

35-
Some errors occurred: E0223, E0667.
62+
Some errors occurred: E0223, E0277, E0308, E0667.
3663
For more information about an error, try `rustc --explain E0223`.

0 commit comments

Comments
 (0)