commit
073fd5beab
6 changed files with 50 additions and 18 deletions
17
src/test/auxiliary/traitimpl.rs
Normal file
17
src/test/auxiliary/traitimpl.rs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
// Copyright 2014 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.
|
||||
|
||||
// Test inherant trait impls work cross-crait.
|
||||
|
||||
pub trait Bar<'a> for ?Sized : 'a {}
|
||||
|
||||
impl<'a> Bar<'a> {
|
||||
pub fn bar(&self) {}
|
||||
}
|
||||
|
|
@ -10,6 +10,10 @@
|
|||
|
||||
// Test calling methods on an impl for a bare trait.
|
||||
|
||||
// aux-build:traitimpl.rs
|
||||
extern crate traitimpl;
|
||||
use traitimpl::Bar;
|
||||
|
||||
static mut COUNT: uint = 1;
|
||||
|
||||
trait T {}
|
||||
|
|
@ -25,6 +29,9 @@ impl<'a> T+'a {
|
|||
|
||||
impl T for int {}
|
||||
|
||||
struct Foo;
|
||||
impl<'a> Bar<'a> for Foo {}
|
||||
|
||||
fn main() {
|
||||
let x: &T = &42i;
|
||||
|
||||
|
|
@ -33,4 +40,8 @@ fn main() {
|
|||
T::bar();
|
||||
|
||||
unsafe { assert!(COUNT == 12); }
|
||||
|
||||
// Cross-crait case
|
||||
let x: &Bar = &Foo;
|
||||
x.bar();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue