Skip to content

Commit 3c3d3c1

Browse files
committed
Auto merge of #59527 - matklad:sized-index, r=Centril
Add test checking that Index<T: ?Sized> works I've noticed that we have an `Idx: ?Sized` bound on the **index** in the `Index`, which seems strange given that we accept index by value. My guess is that it was meant to be removed in #23601, but was overlooked. If I remove this bound, `./x.py src/libstd/ src/libcore/` passes, which means at least that this is not covered by test. I think there's three things we can do here: * run crater with the bound removed to check if there are any regressions, and merge this, to be consistent with other operator traits * run crater, get regressions, write a test for this with a note that "hey, we tried to fix it, its unfixable" * decide, in the light of by-value DSTs, that this is a feature rather than a bug, and add a test cc @rust-lang/libs EDIT: the forth alternative is that there exist a genuine reason why this is the case, but I failed to see it :D
2 parents 8260e96 + cc3abc4 commit 3c3d3c1

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// compile-pass
2+
3+
// `std::ops::Index` has an `: ?Sized` bound on the `Idx` type param. This is
4+
// an accidental left-over from the times when it `Index` was by-reference.
5+
// Tightening the bound now could be a breaking change. Although no crater
6+
// regression were observed (https://github.com/rust-lang/rust/pull/59527),
7+
// let's be conservative and just add a test for this.
8+
#![feature(unsized_locals)]
9+
10+
use std::ops;
11+
12+
pub struct A;
13+
14+
impl ops::Index<str> for A {
15+
type Output = ();
16+
fn index(&self, _: str) -> &Self::Output { panic!() }
17+
}
18+
19+
impl ops::IndexMut<str> for A {
20+
fn index_mut(&mut self, _: str) -> &mut Self::Output { panic!() }
21+
}
22+
23+
fn main() {}

0 commit comments

Comments
 (0)