Document why Range*<&T> as RangeBounds<T>
impls are not T: ?Sized
, and give an alternative.
#144167
+42
−0
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.
Range*<&T> as RangeBounds<T>
impls have been tried to be relaxed toT: ?Sized
at least twice:I also was just about to make another PR to do it again until I
./x.py test library/alloc
and rediscovered the type inference regression, then searched around and found the previous PRs. Hence this PR instead so hopefully that doesn't keep happening 😛.These impls cannot be relaxed for two reasons:
impl RangeBounds<MyUnsizedType> for std::ops::Range<&MyUnsizedType>
is allowed after the coherence rebalance (playground link), and relaxing these impls would conflict with that downstream impl.This PR adds doc-comments explaining that not having
T: ?Sized
is intentional1, and gives an explicit alternative:(Bound<&T>, Bound<&T>)
.Technically, the impls for the unstable new
std::range
types could be relaxed, as they are still unstable so the change would not be breaking, but having them be different in this regard seems worse (and the non-iterableRangeTo/RangeToInclusive
range types are shared between the "new" and "old" so cannot be changed anyway), and then the type inference regression would pop up in whatever edition the new range types stabilize in.The "see <link> for discussion of those issues" is intentionally left as a non-doc comment just for whoever may try to relax these impls again in the future, but if it is preferred to have the link in the docs I can add that.
Closes #107196 (as wontfix)
CC #64027
Footnotes
"intentional" is maybe a bit of strong wording, should it instead say something like "was stabilized without it and it would be breaking to change it now"? ↩