Skip to content

Experiment: try out removing opaque types from typeck expectations #96552

Closed
@oli-obk

Description

@oli-obk

a721052 made type-alias-impl-trait different from return-position-impl-trait.

type Foo = impl std::fmt::Debug;

fn foo(b: bool) -> Foo {
    if b {
        vec![42_i32]
    } else {
        std::iter::empty().collect()
        //~^ ERROR `Foo` cannot be built from an iterator over elements of type `_`
    }
}

does not compile while the equivalent return-position-impl-trait program compiles:

fn foo(b: bool) -> impl std::fmt::Debug{
    if b {
        vec![42_i32]
    } else {
        std::iter::empty().collect()
    }
}

We should figure out what we actually want here and whether we can go even further and just remove opaque types from Expectation entirely. Things to try:

  • fn foo() -> for<'a> impl FnOnce(&'a str) -> usize { |s| s.len() }
  • fn foo() -> impl FnOnce(&'static str) -> usize { |s| s.len() }

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions