Skip to content

Commit

Permalink
Add a test case using associated types cross crate. Fixes rust-lang#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed Dec 30, 2014
1 parent 208d32d commit cdd5ff8
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/test/auxiliary/issue-18048-lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// 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.

#![crate_type="lib"]
#![feature(associated_types)]

pub trait Bar {
type T;

fn get(x: Option<Self>) -> <Self as Bar>::T;
}

impl Bar for int {
type T = uint;

fn get(_: Option<int>) -> uint { 22 }
}
28 changes: 28 additions & 0 deletions src/test/run-pass/issue-18048.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// 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.

// aux-build:issue-18048-lib.rs

// Test that we are able to reference cross-crate traits that employ
// associated types.

#![feature(associated_types)]

extern crate "issue-18048-lib" as bar;

use bar::Bar;

fn foo<B:Bar>(b: B) -> <B as Bar>::T {
Bar::get(None::<B>)
}

fn main() {
println!("{}", foo(3i));
}

0 comments on commit cdd5ff8

Please sign in to comment.