-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Tracking issue for promoting !
to a type (RFC 1216)
#35121
Comments
Huzzah! There's a WIP implementation of this here: https://github.com/canndrew/rust/tree/bang_type_coerced It's current status is: it builds with old-trans and is usable but has a couple of failing tests. Some tests fail due to a bug that causes code like My current roadmap is:
Is there anything that needs to be added to this list? Is it just going to be me working on this? And should this branch be moved onto the main repository? |
@eddyb, @arielb1, @anyone_else: Thoughts on this approach? I'm pretty much up to this stage (sans a couple of failing tests that I'm (very slowly) trying to fix). |
Shouldn't This kind of code is fairly common:
I'd expect
But this is only possible if |
@tomaka There's RFC about it: rust-lang/rfcs#1637 The problem is that if |
Then special-case |
@tomaka As for |
But yes, it might be nice if |
When exactly do we default diverging type variables to
But the first error I get is " I'd like to have a clear idea of exactly why we have this defaulting behaviour and when it's supposed to get invoked. |
That's a very good idea in my opinion. Same for |
The trait Balls: Default {}
impl Balls for () {}
struct Flah;
impl Flah {
fn flah<T: Balls>(&self) -> T {
Default::default()
}
}
fn doit(cond: bool) {
let _ = if cond {
Flah.flah()
} else {
return
};
}
fn main() {
let _ = doit(true);
} Only the type variable created by |
Define "specified". :) The answer is that certain operations, which are not afaik written down anywhere outside the code, require that the type is known at that point. The most common case is field access ( If you make it all the way to the end of the fn, then we run all pending trait selection operations until a steady state is reached. This is the point where defaults (e.g., i32, etc) are applied. This last part is described in the RFC talking about user-specified default type parameters (though that RFC in general needs work). |
Boy, that's an old bug! But yes I'd say my #36038 is a dupe of that (I thought I'd seen it somewhere before). I don't think |
Is it planned for #![feature(never_type)]
fn main() {
let result: Result<_, !> = Ok(1);
match result {
// ^^^^^^ pattern `Err(_)` not covered
Ok(i) => println!("{}", i),
}
} |
@tikue yes, it's one of the bugs listed above. |
Im not quite grasping what the problem is, and there didn’t seem to be an example in the original issue, is there perhaps a concrete example somewhere? |
|
I might also cross-link this to #64715, which should at least be partially unblocked by the stabilization of Once impl From<Infallible> for AtomicLookupError {
fn from(_: Infallible) -> Self {
unreachable!()
}
} |
@TheLostLambda the most recent update I've heard from T-types is that making an |
What issues are holding this up right now? All the issues about bugs seem to be closed now, what do we still need to do? One use case for this would be when you have multiple fallible try_into conversions but when one of them may not actually be fallible. In that case, the error type for the infallible conversions is Infallible and the fallible ones are something else, so it doesn't work. |
I just realized that I never posted an update here, oops. For the last couple of months I was working on moving the never type forward. In collaboration with the language team we found & agreed on the path towards stabilizing the never type (you can read meeting notes for meeting 1 and meeting 2). The main problem is that we really want to change "never type fallback", but it is a breaking change. Moreover, it can make code which compiled fine, into code that has UB. I found a way to lint against most/all of such cases and it was implemented in #123939. The first step of our plan is tracked in #123748 -- we want to change fallback on the next edition, so that code written for it is never broken. At a later date we'll make the switch for all editions, and then we'll be able to stabilize |
Thanks for the update.
That sounds quite scary. Can you elaborate on it? (From the lint PR it seems it only affects |
Hi, stumble into a case that the never type appears to be the solution for me but the never documentation does not mention that use case, so would it be a proper case for it ? pub trait FuncTrait: Fn() {}
fn foo::<Func : FuncTrait>( func: Option<Func>) {}
// and at use site:
foo( None ); // <-- cannot satisfy `_: FuncTrait`
foo::<!>( None ); // I think would work, but I am running stable, and never doc mention it is only for return types, so ? Unless there is a different way to have rust figured the type is not be constructed and does not need to be known ? |
I think it would work? You can use the never say never crate to hack the real ! into existence on stable, just to verify if it works, just as a heads up, it’s not on stable for a reason. |
@bp-galopin You can use the enum std::convert::Infallible for the same purpose right now. Keep in mind that you have to implement FuncTrait for Infallible first, but IIRC that would be the case for ! as well as of right now. |
Could I get some updates from this? |
The plan, as FCPed here, is to:
Rust 2024 is expected to be released in Q1 2025. We're not sure how long step 3 will take after that. See the draft edition guide chapter for further background here: https://doc.rust-lang.org/nightly/edition-guide/rust-2024/never-type-fallback.html |
Checked, faster than expected |
I have some questions regarding 3).
This is a breaking change isn't it? It looks like it could also produce unsoundness in
Why does it have to wait until widespread 2024 adoption?
How can the fallback change without stabilizing in the first place? And why can't it be stabilized with edition 2024 release? |
Yes, it is a breaking change. Yes it can produce unsoundness in unsafe code, however note that we have a lint such unsoundness which is also reported in deps. No, it does not break Rust's stability guarantees, technically Rust permits inference changes (still, this is not something to take lightly, we are trying to take all imaginable precautions to make sure it's as light change as it can be).
We can just do it. Not sure what to add here.
Language team fears the sudden change will break too many things, as planned, we are providing a grace period for everyone affected to patch their code, while making e2024 have the semantics we want from the start.
If you want to learn more, please read recording of T-lang design meeting about the never type, and then a second discussion of some details. |
@WaffleLapkin Thanks for explaining! In particular, the design meeting recording convinced me this is likely the least bad option. I'm just not sure if the lint is 100% reliable since if it isn't it can be a huge problem. |
This comment was marked as off-topic.
This comment was marked as off-topic.
@Seidko, and others who are interested in reporting bugs: Please open a separate bug if you think there is a bug with the never type implementation. This tracking issue does not say it since it likely precedes its inclusion in other tracking issues, but
|
Tracking issue for rust-lang/rfcs#1216, which promotes
!
to a type.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.
Pending issues to resolve
()
without fallback, never type introduces regressions #67225never_type
(!
) #65992Interesting events and links
!
type #35162!
in Rust 1.41.0 #65355The text was updated successfully, but these errors were encountered: