-
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
Box::new(!) doesn't coerce to Box<Error>
successfully
#49593
Comments
@nikomatsakis, @dtolnay and I discussed this at the Rust all hands, and our preliminary opinion was that we should roll back the stabilization of As far as the error itself, this is happening because inference works backwards from the return type to assume that use std::error::Error;
fn foo(x: !) -> Box<Error> {
Box::new(x)
}
We discussed the possibility of disabling inference where it would produce unsized argument types, but this would interact poorly with future changes to remove the |
Is it possible to make the I really hope we can find a solution similar to this, in time for 1.26 |
I talked to @nikomatsakis as well and looking at the example again it's plausible we could try unsizing coercion before the |
I opened #49691 to track specifically the rollback part. |
I'm removing the regression tag since this is not a regression, and we have #49691 to track that part. This issue should be added to the various spreadsheets tracking Rust 2018 progress though. |
Starting at #35121 (comment) is some discussion of |
Is keeping things as-is and introducing the coercion properly later on gonna cause some sort of pain or backcompat issues? |
Removing from milestone now that ! is destabilized |
I am wondering if there is an explanation somewhere as to why functions that take Similarly for any branches that involve creation or matching of never values, I suppose... |
At the codegen (LLVM backend) level, the "presence" of an uninhabited value makes the code unreachable and I assume that no code is generated. But in my opinion it’s much less obvious that we should skip type-checking. |
Has there been any progress on this issue in the last months? |
This PR causes unsized coercions to not be disabled by `$0: Unsize<dyn Object>` coercion obligations when we have an `$0: Sized` obligation somewhere. Note that `X: Unsize<dyn Object>` obligations can't fail *as obligations* if `X: Sized` holds, so this still maintains some version of monotonicity (I think that an unsized coercion can't be converted to no coercion by unifying type variables). Fixes rust-lang#49593 (unblocking never_type).
trigger unsized coercions keyed on Sized bounds This PR causes unsized coercions to not be disabled by `$0: Unsize<dyn Object>` coercion obligations when we have an `$0: Sized` obligation somewhere. This should be mostly backwards-compatible, because in these cases not doing the unsize coercion should have caused the `$0: Sized` obligation to fail. Note that `X: Unsize<dyn Object>` obligations can't fail *as obligations* if `X: Sized` holds, so this still maintains some version of monotonicity (I think that an unsized coercion can't be converted to no coercion by unifying type variables). Fixes #49593 (unblocking never_type). r? @eddyb cc @nikomatsakis
trigger unsized coercions keyed on Sized bounds This PR causes unsized coercions to not be disabled by `$0: Unsize<dyn Object>` coercion obligations when we have an `$0: Sized` obligation somewhere. This should be mostly backwards-compatible, because in these cases not doing the unsize coercion should have caused the `$0: Sized` obligation to fail. Note that `X: Unsize<dyn Object>` obligations can't fail *as obligations* if `X: Sized` holds, so this still maintains some version of monotonicity (I think that an unsized coercion can't be converted to no coercion by unifying type variables). Fixes #49593 (unblocking never_type). r? @eddyb cc @nikomatsakis
Does this mean |
Confirmed that the code below now compiles on #![feature(never_type)]
pub fn foo(x: !) -> Box<std::error::Error> {
Box::new(x)
} |
Discovered in #49039 the recent stabilization of
!
unfortunately has some hazards related to coercion on the libs side of things. We discussed this at the work week and decided that we can't land PRs like #49039 which would also mean that the libs team wouldn't be able to actually recommend using!
as an error type (bummer!)This is intended to be a tracking issue for sorting this out. I'm tagging it as a regression to mainly keep track of it, but it's not strictly speaking a regression.
cc @rust-lang/libs
cc @rust-lang/lang
The text was updated successfully, but these errors were encountered: