Skip to content

Commit c45e560

Browse files
committed
Arbitrary self types v2: add Deref test.
This case (found in IndexVec/IndexSlice within rustc_index) causes unusual problems for deshadowing algorithms which we might want to add in the Arbitrary Self Types v2 additions.
1 parent 226df07 commit c45e560

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

tests/ui/self/conflicting_inner.rs

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//@ run-pass
2+
//@ revisions: default feature
3+
#![cfg_attr(feature, feature(arbitrary_self_types))]
4+
5+
// This test aims to be like the IndexVec within rustc, and conflicts
6+
// over its into_iter().
7+
8+
#[allow(dead_code)]
9+
trait Foo {
10+
fn foo(self) -> usize;
11+
}
12+
13+
struct IndexVec<T>(T);
14+
15+
impl<T> std::ops::Deref for IndexVec<T> {
16+
type Target = T;
17+
18+
fn deref(&self) -> &Self::Target {
19+
&self.0
20+
}
21+
}
22+
23+
impl<'a, T> Foo for &'a IndexVec<T> {
24+
fn foo(self) -> usize {
25+
2
26+
}
27+
}
28+
29+
impl<T> IndexVec<T> {
30+
fn foo(self) -> usize {
31+
1
32+
}
33+
}
34+
35+
fn main() {
36+
let ivec = IndexVec(0usize);
37+
assert_eq!(ivec.foo(), 1);
38+
}

0 commit comments

Comments
 (0)