Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Never type (!) initiative #1

Open
nikomatsakis opened this issue Feb 1, 2022 · 2 comments
Open

Never type (!) initiative #1

nikomatsakis opened this issue Feb 1, 2022 · 2 comments

Comments

@nikomatsakis
Copy link

nikomatsakis commented Feb 1, 2022

Metadata
Name Type alias impl Trait initiative
Owner @Mark-Simulacrum
Liaison @nikomatsakis
Other issues rust-lang/lang-team#60

Purpose

Defining and stabilizing the ! type, or ways to represent "impossible values".

@thomaseizinger
Copy link

Nit: The Name field in the metadata table seems to be stale and says "Type alias impl Trait initiative".

@richard-uk1
Copy link

richard-uk1 commented Mar 20, 2022

Just wanna prefix my comment by saying I'm really interested to see the never type land. Apologies if the comment isn't helpful.

IIUC from reading the comments from the previous threads, the issue is that if you write some code like

let v = ();
mem::transmute(v);

or something similar then the previous inference of mem::transmute<(), ()> changes to mem::transmute<(), !>, which means an optimizer assume the function is never called and potentially deletes the code and anything else that depends on it.

Would it be possible to just error when choosing between () and ! changes (or could change) the soundness of the code. The message could say "type inference could choose () or ! here, but picking ! incorrectly could lead to undefined behavior. Please provide explicit types".

EDIT: Or maybe it's not possible in general to say whether changing ! to () affects soundness, I'm not enough of a PL expert to say. As a programmer/user of rustc, I would not mind at all if my code stopped compiling across an epoch with a message saying "please annotate some more types".

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Status: Development
Development

No branches or pull requests

4 participants