1 // run-pass
2 #![allow(unused_imports)]
3 // Test that we are able to compile calls to associated fns like
4 // `decode()` where the bound on the `Self` parameter references a
5 // lifetime parameter of the trait. This example indicates why trait
6 // lifetime parameters must be early bound in the type of the
7 // associated item.
8 
9 // pretty-expanded FIXME #23616
10 
11 use std::marker;
12 
13 pub enum Value<'v> {
14     A(&'v str),
15     B,
16 }
17 
18 pub trait Decoder<'v> {
read(&mut self) -> Value<'v>19     fn read(&mut self) -> Value<'v>;
20 }
21 
22 pub trait Decodable<'v, D: Decoder<'v>> {
decode(d: &mut D) -> Self23     fn decode(d: &mut D) -> Self;
24 }
25 
26 impl<'v, D: Decoder<'v>> Decodable<'v, D> for () {
decode(d: &mut D) -> ()27     fn decode(d: &mut D) -> () {
28         match d.read() {
29             Value::A(..) => (),
30             Value::B => Decodable::decode(d),
31         }
32     }
33 }
34 
main()35 pub fn main() { }
36