Add tests for assoc type issues that have been fixed
Closes #17732 Closes #18819 Closes #19479 Closes #19631 Closes #19632 Closes #19850 Closes #19883 Closes #20005 Closes #20009 Closes #20389
This commit is contained in:
parent
c594959cdf
commit
182db6e7f8
15
src/test/auxiliary/issue_20389.rs
Normal file
15
src/test/auxiliary/issue_20389.rs
Normal file
@ -0,0 +1,15 @@
|
||||
// Copyright 2015 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.
|
||||
|
||||
#![feature(associated_types)]
|
||||
|
||||
pub trait T {
|
||||
type C;
|
||||
}
|
29
src/test/compile-fail/issue-18819.rs
Normal file
29
src/test/compile-fail/issue-18819.rs
Normal file
@ -0,0 +1,29 @@
|
||||
// Copyright 2015 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.
|
||||
|
||||
#![feature(associated_types)]
|
||||
|
||||
trait Foo {
|
||||
type Item;
|
||||
}
|
||||
|
||||
struct X;
|
||||
|
||||
impl Foo for X {
|
||||
type Item = bool;
|
||||
}
|
||||
|
||||
fn print_x(_: &Foo, extra: &str) {
|
||||
println!("{}", extra);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
print_x(X); //~error this function takes 2 parameters but 1 parameter was supplied
|
||||
}
|
27
src/test/compile-fail/issue-19883.rs
Normal file
27
src/test/compile-fail/issue-19883.rs
Normal file
@ -0,0 +1,27 @@
|
||||
// Copyright 2015 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.
|
||||
|
||||
#![feature(associated_types)]
|
||||
|
||||
trait From<Src> {
|
||||
type Output;
|
||||
|
||||
fn from(src: Src) -> <Self as From<Src>>::Output;
|
||||
}
|
||||
|
||||
trait To {
|
||||
// This is a typo, the return type should be `<Dst as From<Self>>::Output`
|
||||
fn to<Dst: From<Self>>(self) -> <Dst as From<Self>>::Dst {
|
||||
//~ error: the trait `core::kinds::Sized` is not implemented
|
||||
From::from(self)
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
25
src/test/compile-fail/issue-20005.rs
Normal file
25
src/test/compile-fail/issue-20005.rs
Normal file
@ -0,0 +1,25 @@
|
||||
// Copyright 2015 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.
|
||||
|
||||
#![feature(associated_types)]
|
||||
|
||||
trait From<Src> {
|
||||
type Result;
|
||||
|
||||
fn from(src: Src) -> Self::Result;
|
||||
}
|
||||
|
||||
trait To {
|
||||
fn to<Dst>(self) -> <Dst as From<Self>>::Result where Dst: From<Self> {
|
||||
From::from(self) //~error: type annotations required
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
18
src/test/run-pass/issue-17732.rs
Normal file
18
src/test/run-pass/issue-17732.rs
Normal file
@ -0,0 +1,18 @@
|
||||
// Copyright 2015 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.
|
||||
|
||||
#![feature(associated_types)]
|
||||
trait Person {
|
||||
type string;
|
||||
}
|
||||
|
||||
struct Someone<P: Person>;
|
||||
|
||||
fn main() {}
|
23
src/test/run-pass/issue-19479.rs
Normal file
23
src/test/run-pass/issue-19479.rs
Normal file
@ -0,0 +1,23 @@
|
||||
// Copyright 2015 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.
|
||||
|
||||
#![feature(associated_types)]
|
||||
trait Base {}
|
||||
trait AssocA {
|
||||
type X: Base;
|
||||
}
|
||||
trait AssocB {
|
||||
type Y: Base;
|
||||
}
|
||||
impl<T: AssocA> AssocB for T {
|
||||
type Y = <T as AssocA>::X;
|
||||
}
|
||||
|
||||
fn main() {}
|
23
src/test/run-pass/issue-19631.rs
Normal file
23
src/test/run-pass/issue-19631.rs
Normal file
@ -0,0 +1,23 @@
|
||||
// Copyright 2015 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.
|
||||
|
||||
#![feature(associated_types)]
|
||||
|
||||
trait PoolManager {
|
||||
type C;
|
||||
}
|
||||
|
||||
struct InnerPool<M> {
|
||||
manager: M,
|
||||
}
|
||||
|
||||
impl<M> InnerPool<M> where M: PoolManager {}
|
||||
|
||||
fn main() {}
|
21
src/test/run-pass/issue-19632.rs
Normal file
21
src/test/run-pass/issue-19632.rs
Normal file
@ -0,0 +1,21 @@
|
||||
// Copyright 2015 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.
|
||||
|
||||
#![feature(associated_types)]
|
||||
|
||||
trait PoolManager {
|
||||
type C;
|
||||
}
|
||||
|
||||
struct InnerPool<M: PoolManager> {
|
||||
manager: M,
|
||||
}
|
||||
|
||||
fn main() {}
|
30
src/test/run-pass/issue-19850.rs
Normal file
30
src/test/run-pass/issue-19850.rs
Normal file
@ -0,0 +1,30 @@
|
||||
// Copyright 2015 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 that `<Type as Trait>::Output` and `Self::Output` are accepted as type annotations in let
|
||||
// bindings
|
||||
|
||||
#![feature(associated_types)]
|
||||
|
||||
trait Int {
|
||||
fn one() -> Self;
|
||||
fn leading_zeros(self) -> uint;
|
||||
}
|
||||
|
||||
trait Foo {
|
||||
type T : Int;
|
||||
|
||||
fn test(&self) {
|
||||
let r: <Self as Foo>::T = Int::one();
|
||||
let r: Self::T = Int::one();
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
22
src/test/run-pass/issue-20009.rs
Normal file
22
src/test/run-pass/issue-20009.rs
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright 2015 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.
|
||||
|
||||
// Check that associated types are `Sized`
|
||||
|
||||
#![feature(associated_types)]
|
||||
|
||||
trait Trait {
|
||||
type Output;
|
||||
|
||||
fn is_sized(&self) -> Self::Output;
|
||||
fn wasnt_sized(&self) -> Self::Output { loop {} }
|
||||
}
|
||||
|
||||
fn main() {}
|
22
src/test/run-pass/issue-20389.rs
Normal file
22
src/test/run-pass/issue-20389.rs
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright 2015 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_20389.rs
|
||||
|
||||
#![feature(associated_types)]
|
||||
extern crate issue_20389;
|
||||
|
||||
struct Foo;
|
||||
|
||||
impl issue_20389::T for Foo {
|
||||
type C = ();
|
||||
}
|
||||
|
||||
fn main() {}
|
Loading…
Reference in New Issue
Block a user