Repository navigation
Implement AsMut<T> and AsRef<T> for !. - #161253
Merged
Merged
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
A class of use case for these impls is:
T: AsRef<SomeOtherType>,Ts, because it takesOption<T>or&[T]or any other input that can be empty or never-called, yet still do things with other inputs,in which case providing
T = !is slightly better than the alternative of providing an inhabited placeholder type, because it ensures that the generic code is compiled with knowledge of the fact that that there will never be anyTs, even if the specific code that cares about whether there are anyTs doesn’t get inlined into the call site that doesn’t provide anyTs.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