summaryrefslogtreecommitdiffstats
path: root/tests/ui/regions/regions-early-bound-lifetime-in-assoc-fn.rs
blob: fe50a7dd1be330e6d5ffdafac8f7f2beb9bb576f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// run-pass
#![allow(unused_imports)]
// Test that we are able to compile calls to associated fns like
// `decode()` where the bound on the `Self` parameter references a
// lifetime parameter of the trait. This example indicates why trait
// lifetime parameters must be early bound in the type of the
// associated item.

// pretty-expanded FIXME #23616

use std::marker;

pub enum Value<'v> {
    A(&'v str),
    B,
}

pub trait Decoder<'v> {
    fn read(&mut self) -> Value<'v>;
}

pub trait Decodable<'v, D: Decoder<'v>> {
    fn decode(d: &mut D) -> Self;
}

impl<'v, D: Decoder<'v>> Decodable<'v, D> for () {
    fn decode(d: &mut D) -> () {
        match d.read() {
            Value::A(..) => (),
            Value::B => Decodable::decode(d),
        }
    }
}

pub fn main() { }