Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Only prevent TAITs from defining each other, RPIT and async are fine,…
… they only ever have one defining site, and it is ordered correctly around expected and actual type in type comparisons
  • Loading branch information
oli-obk committed Feb 2, 2022
1 parent 7f608eb commit be153f0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 21 deletions.
9 changes: 8 additions & 1 deletion compiler/rustc_infer/src/infer/opaque_types.rs
Expand Up @@ -82,7 +82,14 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
let process = |a: Ty<'tcx>, b: Ty<'tcx>| match *a.kind() {
ty::Opaque(def_id, substs) => {
if let ty::Opaque(did2, _) = *b.kind() {
if self.opaque_type_origin(did2, cause.span).is_some() {
// We could accept this, but there are various ways to handle this situation, and we don't
// want to make a decision on it right now. Likely this case is so super rare anyway, that
// no one encounters it in practice.
// It does occur however in `fn fut() -> impl Future<Output = i32> { async { 42 } }`,
// where it is of no concern, so we only check for TAITs.
if let Some(OpaqueTyOrigin::TyAlias) =
self.opaque_type_origin(did2, cause.span)
{
self.tcx
.sess
.struct_span_err(
Expand Down
3 changes: 2 additions & 1 deletion src/test/ui/impl-trait/example-calendar.rs
@@ -1,3 +1,4 @@
// run-pass
// ignore-compare-mode-chalk

#![feature(fn_traits,
Expand Down Expand Up @@ -589,7 +590,7 @@ fn test_format_month() {
fn format_months(it: impl Iterator<Item = impl DateIterator>)
-> impl Iterator<Item=impl Iterator<Item=String>>
{
it.map(format_month) //~ ERROR opaque type's hidden type cannot be another opaque type
it.map(format_month)
}

/// Takes an iterator of iterators of strings; the sub-iterators are consumed
Expand Down
19 changes: 0 additions & 19 deletions src/test/ui/impl-trait/example-calendar.stderr

This file was deleted.

0 comments on commit be153f0

Please sign in to comment.