Skip to content

Never type fallback #10

Open
Open
@oli-obk

Description

@oli-obk

Right now

trait T {}
impl T for () {}

fn should_ret_unit() -> impl T {
    panic!()
}

compiles successfully, but

trait T {}
impl T for () {}

fn rec() -> impl T {
    rec()
}

does not, even though

trait T {}
impl T for () {}

fn rec() -> ! {
    rec()
}

does with the never_type feature gate.

I think we should "just make it work" (it's actually less special casing in the compiler to make it work than to make it error).

Similarly, with type alias impl trait, when we have

trait T {}
impl T for i32 {}

type U = impl T;

fn foo() -> U {
    panic!()
}
fn bar() -> U {
    42
}

it should just compile, as foo never produces any problematic value.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions