Skip to content

Commit 594655b

Browse files
committed
Regression test for #32382.
1 parent 088fc73 commit 594655b

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#![feature(nll)]
2+
// compile-pass
3+
4+
// rust-lang/rust#32382: Borrow checker used to complain about
5+
// `foobar_3` in the `impl` below, presumably due to some interaction
6+
// between the use of a lifetime in the associated type and the use of
7+
// the overloaded operator[]. This regression test ensures that we do
8+
// not resume complaining about it in the future.
9+
10+
11+
use std::marker::PhantomData;
12+
use std::ops::Index;
13+
14+
pub trait Context: Clone {
15+
type Container: ?Sized;
16+
fn foobar_1( container: &Self::Container ) -> &str;
17+
fn foobar_2( container: &Self::Container ) -> &str;
18+
fn foobar_3( container: &Self::Container ) -> &str;
19+
}
20+
21+
#[derive(Clone)]
22+
struct Foobar<'a> {
23+
phantom: PhantomData<&'a ()>
24+
}
25+
26+
impl<'a> Context for Foobar<'a> {
27+
type Container = [&'a str];
28+
29+
fn foobar_1<'r>( container: &'r [&'a str] ) -> &'r str {
30+
container[0]
31+
}
32+
33+
fn foobar_2<'r>( container: &'r Self::Container ) -> &'r str {
34+
container.index( 0 )
35+
}
36+
37+
fn foobar_3<'r>( container: &'r Self::Container ) -> &'r str {
38+
container[0]
39+
}
40+
}
41+
42+
fn main() { }

0 commit comments

Comments
 (0)