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. |
@rustbot labels -I-lang-nominated We discussed this in the triage meeting today, mostly to understand where this might be with respect to the Rust 2024 edition. @compiler-errors is working with @WaffleLapkin on adding a lint to detect the cases of fallback that have made the never type difficult to stabilize. E.g.: if false { panic!() } else { transmute::<_ /* ?0 */>(()) }
// later in fallback: ?0 := ()
// after ! stabilization: ?0 := ! We're excited by this work and hope to see it land. |
Can we let the type #![feature(never_type)]
#![feature(never_type_fallback)]
trait Foo {}
fn foo<T: Foo>(t: T) {}
fn main() {
foo(panic!());
// ^^^^^^^^
// | the trait `Foo` is not implemented for `!`
} Theoretically, this code could not exist due to value of type |
There's at least two cases where we can't do it automatically:
In general, the only things we could write automatically are functions that take an empty type as argument. |
@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. |
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: