Implement AsMut<T> and AsRef<T> for !. - #161253
Conversation
|
As use std::convert::Infallible;
struct S;
impl AsRef<S> for Infallible {
fn as_ref(&self) -> &S {
match *self {}
}
} |
|
@QuineDot Thanks for pointing that out. That means this PR must either be rejected or get a crater run. I think the possible benefit is significant, so I won’t just close it immediately. …unrelatedly, I just noticed that rustbot hasn’t assigned a reviewer at all. r? libs-api |
|
Not sure how to run crater on this one. Do we wait until after the never type stabilization PR is merged? |
|
You could run a crater with a |
|
@kpreid FYI, libs-api isn't a thing any more, so, please r? libs in the future ditto for the T-libs-api tag |
That would be |
|
I’ll rebase this PR after the stabilization PR merges. |
|
(oops, thanks) |
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
Rebased, and the implementations are now marked |
|
Preparing for crater run |
This comment has been minimized.
This comment has been minimized.
Implement `AsMut<T>` and `AsRef<T>` for `!`.
This comment has been minimized.
This comment has been minimized.
This will allow e.g. `&[!]` to satisfy `&[T] where T: AsRef<str>`. It follows the recommendation from the never documentation: > When writing your own traits, `!` should have an `impl` whenever > there is an obvious `impl` which doesn’t `panic!`. -- <https://doc.rust-lang.org/1.97.1/std/primitive.never.html#-and-traits> The test tests/ui/impl-trait/generic-with-implicit-hrtb-without-dyn.rs had to be updated because it depended on this impl not existing. I’ve confirmed that the modified test still functions as a regression test by compiling it in nightly-2022-08-28 and seeing it ICE.
|
Updated |
|
@craterbot check |
|
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
|
r? libs |
|
@craterbot cancel See #162233 |
|
🗑️ Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
View all comments
This will allow e.g.
&[!]to satisfy&[T] where T: AsRef<str>. It follows the recommendation from the never documentation:— https://doc.rust-lang.org/1.97.1/std/primitive.never.html#-and-traits
The test
tests/ui/impl-trait/generic-with-implicit-hrtb-without-dyn.rshad to be updated because it depended on this impl not existing. I’ve confirmed that the modified test still functions as a regression test by compiling it in nightly-2022-08-28 and seeing it ICE.Tracking issue for never: #35121
(This change has no ACP or tracking issue of its own; I assume it is simple enough that T-libs-api can just accept or reject this PR, and the implementation will be stable when
!is stable.)@rustbot label -T-libs +T-libs-api +F-never_type