about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-04-17 19:18:51 +0000
committerbors <bors@rust-lang.org>2019-04-17 19:18:51 +0000
commit3c3d3c1777041200bb7ed7a65b6562d62899778c (patch)
tree1475fc81e1b201e1944a5cc843c89470e8587396
parent8260e9676089363648dfbce072fca562093b4289 (diff)
parentcc3abc4d2786be6d8366eb904b8ea4ac4a3e9f7e (diff)
downloadrust-3c3d3c1777041200bb7ed7a65b6562d62899778c.tar.gz
rust-3c3d3c1777041200bb7ed7a65b6562d62899778c.zip
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 https://github.com/rust-lang/rust/pull/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
-rw-r--r--src/test/ui/unsized-locals/unsized-index.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/test/ui/unsized-locals/unsized-index.rs b/src/test/ui/unsized-locals/unsized-index.rs
new file mode 100644
index 00000000000..2e6bd82bda3
--- /dev/null
+++ b/src/test/ui/unsized-locals/unsized-index.rs
@@ -0,0 +1,23 @@
+// compile-pass
+
+// `std::ops::Index` has an `: ?Sized` bound on the `Idx` type param. This is
+// an accidental left-over from the times when it `Index` was by-reference.
+// Tightening the bound now could be a breaking change. Although no crater
+// regression were observed (https://github.com/rust-lang/rust/pull/59527),
+// let's be conservative and just add a test for this.
+#![feature(unsized_locals)]
+
+use std::ops;
+
+pub struct A;
+
+impl ops::Index<str> for A {
+    type Output = ();
+    fn index(&self, _: str) -> &Self::Output { panic!() }
+}
+
+impl ops::IndexMut<str> for A {
+    fn index_mut(&mut self, _: str) -> &mut Self::Output { panic!() }
+}
+
+fn main() {}