]> git.proxmox.com Git - rustc.git/blob - src/test/ui/nll/issue-32382-index-assoc-type-with-lifetime.rs
New upstream version 1.38.0+dfsg1
[rustc.git] / src / test / ui / nll / issue-32382-index-assoc-type-with-lifetime.rs
1 // build-pass (FIXME(62277): could be check-pass?)
2
3 // rust-lang/rust#32382: Borrow checker used to complain about
4 // `foobar_3` in the `impl` below, presumably due to some interaction
5 // between the use of a lifetime in the associated type and the use of
6 // the overloaded operator[]. This regression test ensures that we do
7 // not resume complaining about it in the future.
8
9
10 use std::marker::PhantomData;
11 use std::ops::Index;
12
13 pub trait Context: Clone {
14 type Container: ?Sized;
15 fn foobar_1( container: &Self::Container ) -> &str;
16 fn foobar_2( container: &Self::Container ) -> &str;
17 fn foobar_3( container: &Self::Container ) -> &str;
18 }
19
20 #[derive(Clone)]
21 struct Foobar<'a> {
22 phantom: PhantomData<&'a ()>
23 }
24
25 impl<'a> Context for Foobar<'a> {
26 type Container = [&'a str];
27
28 fn foobar_1<'r>( container: &'r [&'a str] ) -> &'r str {
29 container[0]
30 }
31
32 fn foobar_2<'r>( container: &'r Self::Container ) -> &'r str {
33 container.index( 0 )
34 }
35
36 fn foobar_3<'r>( container: &'r Self::Container ) -> &'r str {
37 container[0]
38 }
39 }
40
41 fn main() { }