-
Notifications
You must be signed in to change notification settings - Fork 12.1k
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. |
@simensgreen We very likely won't ever do that. See #113875 for more context. That issue is assigned to me since I plan on adding a paragraph to the Reference documenting this languages/types guarantee but I still haven't gotten around to do that. |
Very excited about this nearing stabilization! |
Maybe create attribute It may as well take associated types: #[impl_for_uninhabited(!, Item=u32, Sentinel=0)]
trait T { ... } |
I believe any non- |
This doesn't seem any more useful than just writing the implementation by hand. |
I don’t think opt-in derived impls for |
It could be a fair bit less code than manually implementing each method for a trait with a several methods. But the attribute suggested here could just be a proc macro. |
Not backward-compatibly if it implements things out-of-the-box for eligible types. However I'd rather have this sooner and use an attribute in the future. |
@nikomatsakis could you update the OP to reflect #35121 (comment)? (Edit: the below is an unrelated thing that I linked to the wrong url) |
Hey, I notice that all the issues mentioned at blockers have been closed, do you think this can be stabilized? Or are there some undocumented blockers rn? |
The second issue was actually closed in favor of this issue. In other words, the actual problem wasn't fixed yet, but it wasn't seen as worthwhile to have a issue separate from this one tracking the problem. |
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 |
Tracking issue for rust-lang/rfcs#1216, which promotes
!
to a type.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: