Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
2 tasks
oli-obk opened this issue Apr 29, 2022 · 2 comments · Fixed by #96727
Closed
2 tasks

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

oli-obk opened this issue Apr 29, 2022 · 2 comments · Fixed by #96727
Assignees
Labels
F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]`

Comments

@oli-obk
Copy link
Contributor

oli-obk commented Apr 29, 2022

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() }
@oli-obk oli-obk self-assigned this Apr 29, 2022
@oli-obk oli-obk added F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` I-needs-decision Issue: In need of a decision. labels Apr 29, 2022
@oli-obk
Copy link
Contributor Author

oli-obk commented May 5, 2022

At present

#![feature(type_alias_impl_trait)]

type Foo = impl for<'a> FnOnce(&'a str) -> usize;
type Bar = impl FnOnce(&'static str) -> usize;

// these two work
fn foo() -> Foo { if true { |s| s.len() } else { panic!() } }
fn bar() -> Bar { if true { |s| s.len() } else { panic!() } }

// these two don't work
fn foo2() -> impl for<'a> FnOnce(&'a str) -> usize { if true { |s| s.len() } else { panic!() } }
fn bar2() -> impl FnOnce(&'static str) -> usize { if true { |s| s.len() } else { panic!() } }

@oli-obk
Copy link
Contributor Author

oli-obk commented May 5, 2022

cc @lcnr

@oli-obk oli-obk removed the I-needs-decision Issue: In need of a decision. label May 12, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jun 29, 2022
Make TAIT behave exactly like RPIT

fixes rust-lang#96552

This makes type-alias-impl-trait behave like return-position-impl-trait. Unfortunately it also causes some cases to stop compiling due to "needing type annotations" and makes panicking cause fallback for the hidden type to `()`.

All of these are addressable, but we should probably address them for RPIT and TAIT together

r? `@lcnr`
@bors bors closed this as completed in 48170d5 Jun 30, 2022
@oli-obk oli-obk moved this from Todo to Done in type alias impl trait stabilization Sep 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]`
Development

Successfully merging a pull request may close this issue.

1 participant