Skip to content

Tracking Issue for never type fallback change #148922

@WaffleLapkin

Description

@WaffleLapkin

This is a tracking issue for the never type fallback change.

Summary

Stabilization of the never type (aka !) requires (or required, depending on when you read this) a breaking change to how inference works with it.

This issue is tracking said change and is used to refer to it in compiler diagnostics.

Effect on your code

In rare cases code that used to compile won't anymore. It is always possible to make code compile again by annotating types more explicitly.

See migration section in the edition guide.

Never type fallback

Never type fallback is an implementation detail of how Rust compiler handles "never to any" coercions. Specifically, at every coercion site if rustc sees a value of type !, it inserts a never to any coercion to an new inference variable.

In some cases the resulting type of the inference variable can't be inferred from the surrounding code. To prevent errors in such cases, rustc sets such inference variables (i.e. ones that come from never to any coercions and can't be inferred otherwise) to a "fallback".

The change

Due to historic reasons the fallback type used to be (). That caused confusing behavior and other problems, as such we are changing the fallback to !.

However, that can break code which depended on fallback type being (). In such cases you can explicitly set the type to (), as to not even trigger the fallback at all.

Timeline

  • Rust 1.85.0 the never type fallback was switched to ! on edition 2024 only (see edition guide)
  • TBD never type fallback is switched to ! on all editions (required for the never type stabilization)

About tracking issues

Tracking issues are used to record the overall progress of implementation.
They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.
Discussion comments will get marked as off-topic or deleted.
Repeated discussions on the tracking issue may lead to the tracking issue getting locked.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCF-never_type`#![feature(never_type)]`T-langRelevant to the language teamT-typesRelevant to the types team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions