Skip to content

tokio::select! never return pattern #8199

@yuan-y-chang

Description

@yuan-y-chang

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Sometimes we have a never-returning future Future<Output = !>, or Future<Output = std::convert::Infallible> in stable Rust. Like sync_a2b:

tokio::select! {
    () = sync_a2b => unreachable!(),
    () = sync_b2a => unreachable!(),
    () = main_loop => (),
}

BTW, sync_a2b is coercion to () not ! since placed in select!.
But one day, if this future change the return type to (), since unreachable!() is runtime behavior, it won't be detected by the compiler.

The nightly never_pattern is not stable, so we don't have

tokio::select! {
    ! = sync_a2b => unreachable!(),
    ! = sync_b2a => unreachable!(),
    () = main_loop => (),
}

Also, the stable never ! assertion is match $expr {}, which is not a pattern syntax. This verbose syntax also works:

tokio::select! {
    never = sync_a2b => match never {},
    never = sync_b2a => match never {},
    () = main_loop => (),
}

Describe the solution you'd like
A clear and concise description of what you want to happen.

Since the never pattern had a long way to go, an explicit pattern may be helpful to indicate "always pending futures" in the select branch.

tokio::select! {
    ! = sync_a2b;
    ! = sync_b2a;
    () = main_loop => (),
}

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

I don't know much about the macro design of tokio::select!, if => is required:

tokio::select! {
    ! = sync_a2b => unreachable!(),
    ! = sync_b2a => unreachable!(),
    () = main_loop => (),
}

Also compatible with the future syntax.

Additional context
Add any other context or screenshots about the feature request here.

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-tokioArea: The main tokio crateC-feature-requestCategory: A feature request.M-macrosModule: macros in the main Tokio crate

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions