issue-3447.rs 888 字节
Newer Older
1 2 3 4 5 6 7 8 9 10
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

11 12 13 14 15
static S: &'static str = "str";

struct list<T> {
    element: T,
    next: Option<@mut list<T>>
T
Tim Chevalier 已提交
16 17
}

18 19
impl<T:'static> list<T> {
    pub fn addEnd(&mut self, element: T) {
T
Tim Chevalier 已提交
20 21
        let newList = list {
            element: element,
22
            next: None
T
Tim Chevalier 已提交
23 24
        };

25
        self.next = Some(@mut newList);
T
Tim Chevalier 已提交
26 27 28
    }
}

29
pub fn main() {
30
    let ls = list {
31
        element: S,
32
        next: None
T
Tim Chevalier 已提交
33
    };
34
    println(ls.element);
T
Tim Chevalier 已提交
35
}