]> git.proxmox.com Git - rustc.git/blame - src/test/run-pass/regions-early-bound-lifetime-in-assoc-fn.rs
Imported Upstream version 1.0.0~beta
[rustc.git] / src / test / run-pass / regions-early-bound-lifetime-in-assoc-fn.rs
CommitLineData
1a4d82fc
JJ
1// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2// file at the top-level directory of this distribution and at
3// http://rust-lang.org/COPYRIGHT.
4//
5// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8// option. This file may not be copied, modified, or distributed
9// except according to those terms.
10
11// Test that we are able to compile calls to associated fns like
12// `decode()` where the bound on the `Self` parameter references a
13// lifetime parameter of the trait. This example indicates why trait
14// lifetime parameters must be early bound in the type of the
15// associated item.
16
c34b1796
AL
17// pretty-expanded FIXME #23616
18
85aaf69f
SL
19use std::marker;
20
1a4d82fc
JJ
21pub enum Value<'v> {
22 A(&'v str),
23 B,
24}
25
26pub trait Decoder<'v> {
27 fn read(&mut self) -> Value<'v>;
28}
29
85aaf69f 30pub trait Decodable<'v, D: Decoder<'v>>
c34b1796 31 : marker::PhantomFn<(), &'v isize>
85aaf69f 32{
1a4d82fc
JJ
33 fn decode(d: &mut D) -> Self;
34}
35
36impl<'v, D: Decoder<'v>> Decodable<'v, D> for () {
37 fn decode(d: &mut D) -> () {
38 match d.read() {
39 Value::A(..) => (),
40 Value::B => Decodable::decode(d),
41 }
42 }
43}
44
45pub fn main() { }