Skip to content

Commit 2059f1a

Browse files
committed
---
yaml --- r: 273142 b: refs/heads/beta c: 1077ff2 h: refs/heads/master
1 parent 01374c3 commit 2059f1a

16 files changed

+571
-20
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ refs/tags/0.9: 36870b185fc5f5486636d4515f0e22677493f225
2323
refs/tags/0.10: ac33f2b15782272ae348dbd7b14b8257b2148b5a
2424
refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
2525
refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
26-
refs/heads/beta: 7e42a780161e757ddd7d20925691a861f9d86725
26+
refs/heads/beta: 1077ff2deca4c80f27596905119a84564fe9813f
2727
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
2828
refs/heads/tmp: e06d2ad9fcd5027bcaac5b08fc9aa39a49d0ecd3
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f

branches/beta/src/test/auxiliary/go_trait.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ pub fn go_once<G:GoOnce>(this: G, arg: isize) {
3737
impl<G> GoMut for G
3838
where G : Go
3939
{
40-
fn go_mut(&mut self, arg: isize) {
40+
default fn go_mut(&mut self, arg: isize) {
4141
go(&*self, arg)
4242
}
4343
}
4444

4545
impl<G> GoOnce for G
4646
where G : GoMut
4747
{
48-
fn go_once(mut self, arg: isize) {
48+
default fn go_once(mut self, arg: isize) {
4949
go_mut(&mut self, arg)
5050
}
5151
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// Copyright 2015 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+
pub trait Foo {
12+
fn foo(&self) -> &'static str;
13+
}
14+
15+
impl<T> Foo for T {
16+
default fn foo(&self) -> &'static str {
17+
"generic"
18+
}
19+
}
20+
21+
impl<T: Clone> Foo for T {
22+
default fn foo(&self) -> &'static str {
23+
"generic Clone"
24+
}
25+
}
26+
27+
impl<T, U> Foo for (T, U) where T: Clone, U: Clone {
28+
default fn foo(&self) -> &'static str {
29+
"generic pair"
30+
}
31+
}
32+
33+
impl<T: Clone> Foo for (T, T) {
34+
default fn foo(&self) -> &'static str {
35+
"generic uniform pair"
36+
}
37+
}
38+
39+
impl Foo for (u8, u32) {
40+
default fn foo(&self) -> &'static str {
41+
"(u8, u32)"
42+
}
43+
}
44+
45+
impl Foo for (u8, u8) {
46+
default fn foo(&self) -> &'static str {
47+
"(u8, u8)"
48+
}
49+
}
50+
51+
impl<T: Clone> Foo for Vec<T> {
52+
default fn foo(&self) -> &'static str {
53+
"generic Vec"
54+
}
55+
}
56+
57+
impl Foo for Vec<i32> {
58+
fn foo(&self) -> &'static str {
59+
"Vec<i32>"
60+
}
61+
}
62+
63+
impl Foo for String {
64+
fn foo(&self) -> &'static str {
65+
"String"
66+
}
67+
}
68+
69+
impl Foo for i32 {
70+
fn foo(&self) -> &'static str {
71+
"i32"
72+
}
73+
}
74+
75+
pub trait MyMarker {}
76+
impl<T: Clone + MyMarker> Foo for T {
77+
default fn foo(&self) -> &'static str {
78+
"generic Clone + MyMarker"
79+
}
80+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright 2015 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+
12+
#![feature(specialization)]
13+
14+
// First, test only use of explicit `default` items:
15+
16+
pub trait Foo {
17+
fn foo(&self) -> bool;
18+
}
19+
20+
impl<T> Foo for T {
21+
default fn foo(&self) -> bool { false }
22+
}
23+
24+
impl Foo for i32 {}
25+
26+
impl Foo for i64 {
27+
fn foo(&self) -> bool { true }
28+
}
29+
30+
// Next, test mixture of explicit `default` and provided methods:
31+
32+
pub trait Bar {
33+
fn bar(&self) -> i32 { 0 }
34+
}
35+
36+
impl<T> Bar for T {} // use the provided method
37+
38+
impl Bar for i32 {
39+
fn bar(&self) -> i32 { 1 }
40+
}
41+
impl<'a> Bar for &'a str {}
42+
43+
impl<T> Bar for Vec<T> {
44+
default fn bar(&self) -> i32 { 2 }
45+
}
46+
impl Bar for Vec<i32> {}
47+
impl Bar for Vec<i64> {
48+
fn bar(&self) -> i32 { 3 }
49+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2015 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 you cannot *directly* dispatch on lifetime requirements
12+
13+
trait MyTrait {}
14+
15+
impl<T> MyTrait for T {}
16+
impl<T: 'static> MyTrait for T {} //~ ERROR E0119
17+
18+
fn main() {}

branches/beta/src/test/compile-fail/coherence-overlap-messages.rs

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,18 @@ impl<U> Foo for U {}
1515

1616
trait Bar {}
1717

18-
impl<T> Bar for T {} //~ ERROR conflicting implementations of trait `Bar` for type `u8`:
19-
impl Bar for u8 {}
18+
impl<T> Bar for (T, u8) {} //~ ERROR conflicting implementations of trait `Bar` for type `(u8, u8)`:
19+
impl<T> Bar for (u8, T) {}
2020

2121
trait Baz<T> {}
2222

23-
impl<T, U> Baz<U> for T {} //~ ERROR conflicting implementations of trait `Baz<_>` for type `u8`:
23+
impl<T> Baz<u8> for T {} //~ ERROR conflicting implementations of trait `Baz<u8>` for type `u8`:
2424
impl<T> Baz<T> for u8 {}
2525

26-
trait Quux<T> {}
26+
trait Quux<U, V> {}
2727

28-
impl<T, U> Quux<U> for T {} //~ ERROR conflicting implementations of trait `Quux<_>`:
29-
impl<T> Quux<T> for T {}
30-
31-
trait Qaar<T> {}
32-
33-
impl<T, U> Qaar<U> for T {} //~ ERROR conflicting implementations of trait `Qaar<u8>`:
34-
impl<T> Qaar<u8> for T {}
35-
36-
trait Qaax<T> {}
37-
38-
impl<T, U> Qaax<U> for T {}
39-
//~^ ERROR conflicting implementations of trait `Qaax<u8>` for type `u32`:
40-
impl Qaax<u8> for u32 {}
28+
impl<T, U, V> Quux<U, V> for T {} //~ ERROR conflicting implementations of trait `Quux<_, _>`:
29+
impl<T, U> Quux<U, U> for T {}
30+
impl<T, V> Quux<T, V> for T {}
4131

4232
fn main() {}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2015 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+
#![feature(optin_builtin_traits)]
12+
13+
struct TestType<T>(T);
14+
15+
unsafe impl<T> Send for TestType<T> {}
16+
impl !Send for TestType<u8> {}
17+
18+
fn assert_send<T: Send>() {}
19+
20+
fn main() {
21+
assert_send::<TestType<()>>();
22+
assert_send::<TestType<u8>>(); //~ ERROR
23+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2015 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+
#![feature(optin_builtin_traits)]
12+
13+
trait MyTrait {}
14+
15+
struct TestType<T>(::std::marker::PhantomData<T>);
16+
17+
unsafe impl<T: Clone> Send for TestType<T> {}
18+
impl<T: MyTrait> !Send for TestType<T> {} //~ ERROR E0119
19+
20+
fn main() {}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2015 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+
trait Foo {}
12+
impl<T: Clone> Foo for T {}
13+
impl<T> Foo for Vec<T> {} //~ ERROR E0119
14+
15+
trait Bar {}
16+
impl<T> Bar for (T, u8) {}
17+
impl<T> Bar for (u8, T) {} //~ ERROR E0119
18+
19+
trait Baz<U> {}
20+
impl<T> Baz<T> for u8 {}
21+
impl<T> Baz<u8> for T {} //~ ERROR E0119
22+
23+
fn main() {}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2014 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+
// aux-build:go_trait.rs
12+
13+
extern crate go_trait;
14+
15+
use go_trait::{Go,GoMut};
16+
use std::fmt::Debug;
17+
use std::default::Default;
18+
19+
struct MyThingy;
20+
21+
impl Go for MyThingy {
22+
fn go(&self, arg: isize) { }
23+
}
24+
25+
impl GoMut for MyThingy {
26+
fn go_mut(&mut self, arg: isize) { }
27+
}
28+
29+
fn main() { }
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2015 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+
trait Foo {
12+
fn mk() -> Self;
13+
}
14+
15+
impl<T: Default> Foo for T {
16+
default fn mk() -> T {
17+
T::default()
18+
}
19+
}
20+
21+
impl Foo for Vec<u8> {
22+
fn mk() -> Vec<u8> {
23+
vec![0]
24+
}
25+
}
26+
27+
fn main() {
28+
let v1: Vec<i32> = Foo::mk();
29+
let v2: Vec<u8> = Foo::mk();
30+
31+
assert!(v1.len() == 0);
32+
assert!(v2.len() == 1);
33+
}

0 commit comments

Comments
 (0)