Skip to content

Commit 477814a

Browse files
committed
Document (internally) that Range*<&T> as RangeBounds<T> impls are intentionally not T: ?Sized, and document (publically) an alternative.
1 parent 29a5872 commit 477814a

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

library/core/src/ops/range.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,12 @@ impl<'a, T: ?Sized + 'a> RangeBounds<T> for (Bound<&'a T>, Bound<&'a T>) {
11411141
}
11421142
}
11431143

1144+
// This impl intentionally does not have `T: ?Sized`;
1145+
// see https://github.com/rust-lang/rust/pull/61584 for discussion of why.
1146+
//
1147+
/// If you need to use this implementation where `T` is unsized,
1148+
/// consider using the `RangeBounds` impl for a 2-tuple of [`Bound<&T>`][Bound],
1149+
/// i.e. replace `start..` with `(Bound::Included(start), Bound::Unbounded)`.
11441150
#[stable(feature = "collections_range", since = "1.28.0")]
11451151
impl<T> RangeBounds<T> for RangeFrom<&T> {
11461152
fn start_bound(&self) -> Bound<&T> {
@@ -1151,6 +1157,12 @@ impl<T> RangeBounds<T> for RangeFrom<&T> {
11511157
}
11521158
}
11531159

1160+
// This impl intentionally does not have `T: ?Sized`;
1161+
// see https://github.com/rust-lang/rust/pull/61584 for discussion of why.
1162+
//
1163+
/// If you need to use this implementation where `T` is unsized,
1164+
/// consider using the `RangeBounds` impl for a 2-tuple of [`Bound<&T>`][Bound],
1165+
/// i.e. replace `..end` with `(Bound::Unbounded, Bound::Excluded(end))`.
11541166
#[stable(feature = "collections_range", since = "1.28.0")]
11551167
impl<T> RangeBounds<T> for RangeTo<&T> {
11561168
fn start_bound(&self) -> Bound<&T> {
@@ -1161,6 +1173,12 @@ impl<T> RangeBounds<T> for RangeTo<&T> {
11611173
}
11621174
}
11631175

1176+
// This impl intentionally does not have `T: ?Sized`;
1177+
// see https://github.com/rust-lang/rust/pull/61584 for discussion of why.
1178+
//
1179+
/// If you need to use this implementation where `T` is unsized,
1180+
/// consider using the `RangeBounds` impl for a 2-tuple of [`Bound<&T>`][Bound],
1181+
/// i.e. replace `start..end` with `(Bound::Included(start), Bound::Excluded(end))`.
11641182
#[stable(feature = "collections_range", since = "1.28.0")]
11651183
impl<T> RangeBounds<T> for Range<&T> {
11661184
fn start_bound(&self) -> Bound<&T> {
@@ -1171,6 +1189,12 @@ impl<T> RangeBounds<T> for Range<&T> {
11711189
}
11721190
}
11731191

1192+
// This impl intentionally does not have `T: ?Sized`;
1193+
// see https://github.com/rust-lang/rust/pull/61584 for discussion of why.
1194+
//
1195+
/// If you need to use this implementation where `T` is unsized,
1196+
/// consider using the `RangeBounds` impl for a 2-tuple of [`Bound<&T>`][Bound],
1197+
/// i.e. replace `start..=end` with `(Bound::Included(start), Bound::Included(end))`.
11741198
#[stable(feature = "collections_range", since = "1.28.0")]
11751199
impl<T> RangeBounds<T> for RangeInclusive<&T> {
11761200
fn start_bound(&self) -> Bound<&T> {
@@ -1181,6 +1205,12 @@ impl<T> RangeBounds<T> for RangeInclusive<&T> {
11811205
}
11821206
}
11831207

1208+
// This impl intentionally does not have `T: ?Sized`;
1209+
// see https://github.com/rust-lang/rust/pull/61584 for discussion of why.
1210+
//
1211+
/// If you need to use this implementation where `T` is unsized,
1212+
/// consider using the `RangeBounds` impl for a 2-tuple of [`Bound<&T>`][Bound],
1213+
/// i.e. replace `..=end` with `(Bound::Unbounded, Bound::Included(end))`.
11841214
#[stable(feature = "collections_range", since = "1.28.0")]
11851215
impl<T> RangeBounds<T> for RangeToInclusive<&T> {
11861216
fn start_bound(&self) -> Bound<&T> {

library/core/src/range.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,12 @@ impl<T> RangeBounds<T> for Range<T> {
167167
}
168168
}
169169

170+
// This impl intentionally does not have `T: ?Sized`;
171+
// see https://github.com/rust-lang/rust/pull/61584 for discussion of why.
172+
//
173+
/// If you need to use this implementation where `T` is unsized,
174+
/// consider using the `RangeBounds` impl for a 2-tuple of [`Bound<&T>`][Bound],
175+
/// i.e. replace `start..end` with `(Bound::Included(start), Bound::Excluded(end))`.
170176
#[unstable(feature = "new_range_api", issue = "125687")]
171177
impl<T> RangeBounds<T> for Range<&T> {
172178
fn start_bound(&self) -> Bound<&T> {
@@ -346,6 +352,12 @@ impl<T> RangeBounds<T> for RangeInclusive<T> {
346352
}
347353
}
348354

355+
// This impl intentionally does not have `T: ?Sized`;
356+
// see https://github.com/rust-lang/rust/pull/61584 for discussion of why.
357+
//
358+
/// If you need to use this implementation where `T` is unsized,
359+
/// consider using the `RangeBounds` impl for a 2-tuple of [`Bound<&T>`][Bound],
360+
/// i.e. replace `start..=end` with `(Bound::Included(start), Bound::Included(end))`.
349361
#[unstable(feature = "new_range_api", issue = "125687")]
350362
impl<T> RangeBounds<T> for RangeInclusive<&T> {
351363
fn start_bound(&self) -> Bound<&T> {
@@ -491,6 +503,12 @@ impl<T> RangeBounds<T> for RangeFrom<T> {
491503
}
492504
}
493505

506+
// This impl intentionally does not have `T: ?Sized`;
507+
// see https://github.com/rust-lang/rust/pull/61584 for discussion of why.
508+
//
509+
/// If you need to use this implementation where `T` is unsized,
510+
/// consider using the `RangeBounds` impl for a 2-tuple of [`Bound<&T>`][Bound],
511+
/// i.e. replace `start..` with `(Bound::Included(start), Bound::Unbounded)`.
494512
#[unstable(feature = "new_range_api", issue = "125687")]
495513
impl<T> RangeBounds<T> for RangeFrom<&T> {
496514
fn start_bound(&self) -> Bound<&T> {

0 commit comments

Comments
 (0)