Skip to content

Commit 972b7e9

Browse files
committed
Document why Range*<&T> as RangeBounds<T> impls are not T: ?Sized, and the alternative.
1 parent ebd8557 commit 972b7e9

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

library/core/src/ops/range.rs

Lines changed: 26 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` due to type inference issues.
1145+
// see https://github.com/rust-lang/rust/pull/61584 for discussion of those issues
1146+
///
1147+
/// If you need to use this impl where `T` is unsized,
1148+
/// consider using the `RangeBounds` impl for a 2-tuple of [`Bound<&T>`][Bound],
1149+
/// e.g. 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,11 @@ impl<T> RangeBounds<T> for RangeFrom<&T> {
11511157
}
11521158
}
11531159

1160+
/// This impl intentionally does not have `T: ?Sized` due to type inference issues.
1161+
///
1162+
/// If you need to use this impl where `T` is unsized,
1163+
/// consider using the `RangeBounds` impl for a 2-tuple of [`Bound<&T>`][Bound],
1164+
/// e.g. replace `..end` with `(Bound::Unbounded, Bound::Excluded(end))`.
11541165
#[stable(feature = "collections_range", since = "1.28.0")]
11551166
impl<T> RangeBounds<T> for RangeTo<&T> {
11561167
fn start_bound(&self) -> Bound<&T> {
@@ -1161,6 +1172,11 @@ impl<T> RangeBounds<T> for RangeTo<&T> {
11611172
}
11621173
}
11631174

1175+
/// This impl intentionally does not have `T: ?Sized` due to type inference issues.
1176+
///
1177+
/// If you need to use this impl where `T` is unsized,
1178+
/// consider using the `RangeBounds` impl for a 2-tuple of [`Bound<&T>`][Bound],
1179+
/// e.g. replace `start..end` with `(Bound::Included(start), Bound::Excluded(end))`.
11641180
#[stable(feature = "collections_range", since = "1.28.0")]
11651181
impl<T> RangeBounds<T> for Range<&T> {
11661182
fn start_bound(&self) -> Bound<&T> {
@@ -1171,6 +1187,11 @@ impl<T> RangeBounds<T> for Range<&T> {
11711187
}
11721188
}
11731189

1190+
/// This impl intentionally does not have `T: ?Sized` due to type inference issues.
1191+
///
1192+
/// If you need to use this impl where `T` is unsized,
1193+
/// consider using the `RangeBounds` impl for a 2-tuple of [`Bound<&T>`][Bound],
1194+
/// e.g. replace `start..=end` with `(Bound::Included(start), Bound::Included(end))`.
11741195
#[stable(feature = "collections_range", since = "1.28.0")]
11751196
impl<T> RangeBounds<T> for RangeInclusive<&T> {
11761197
fn start_bound(&self) -> Bound<&T> {
@@ -1181,6 +1202,11 @@ impl<T> RangeBounds<T> for RangeInclusive<&T> {
11811202
}
11821203
}
11831204

1205+
/// This impl intentionally does not have `T: ?Sized` due to type inference issues.
1206+
///
1207+
/// If you need to use this impl where `T` is unsized,
1208+
/// consider using the `RangeBounds` impl for a 2-tuple of [`Bound<&T>`][Bound],
1209+
/// e.g. replace `..=end` with `(Bound::Unbounded, Bound::Included(end))`.
11841210
#[stable(feature = "collections_range", since = "1.28.0")]
11851211
impl<T> RangeBounds<T> for RangeToInclusive<&T> {
11861212
fn start_bound(&self) -> Bound<&T> {

library/core/src/range.rs

Lines changed: 16 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` due to type inference issues.
171+
// see https://github.com/rust-lang/rust/pull/61584 for discussion of those issues
172+
///
173+
/// If you need to use this impl where `T` is unsized,
174+
/// consider using the `RangeBounds` impl for a 2-tuple of [`Bound<&T>`][Bound],
175+
/// e.g. 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,11 @@ impl<T> RangeBounds<T> for RangeInclusive<T> {
346352
}
347353
}
348354

355+
/// This impl intentionally does not have `T: ?Sized` due to type inference issues.
356+
///
357+
/// If you need to use this impl where `T` is unsized,
358+
/// consider using the `RangeBounds` impl for a 2-tuple of [`Bound<&T>`][Bound],
359+
/// e.g. replace `start..=end` with `(Bound::Included(start), Bound::Included(end))`.
349360
#[unstable(feature = "new_range_api", issue = "125687")]
350361
impl<T> RangeBounds<T> for RangeInclusive<&T> {
351362
fn start_bound(&self) -> Bound<&T> {
@@ -491,6 +502,11 @@ impl<T> RangeBounds<T> for RangeFrom<T> {
491502
}
492503
}
493504

505+
/// This impl intentionally does not have `T: ?Sized` due to type inference issues.
506+
///
507+
/// If you need to use this impl where `T` is unsized,
508+
/// consider using the `RangeBounds` impl for a 2-tuple of [`Bound<&T>`][Bound],
509+
/// e.g. replace `start..` with `(Bound::Included(start), Bound::Unbounded)`.
494510
#[unstable(feature = "new_range_api", issue = "125687")]
495511
impl<T> RangeBounds<T> for RangeFrom<&T> {
496512
fn start_bound(&self) -> Bound<&T> {

0 commit comments

Comments
 (0)