-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for trait object coercion.
- Loading branch information
Showing
5 changed files
with
150 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// 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. | ||
|
||
#[feature(managed_boxes)]; | ||
|
||
struct Struct { | ||
person: &'static str | ||
} | ||
|
||
trait Trait<T> { | ||
fn f(&self, x: T); | ||
} | ||
|
||
impl Trait<&'static str> for Struct { | ||
fn f(&self, x: &'static str) { | ||
println!("Hello, {}!", x); | ||
} | ||
} | ||
|
||
fn main() { | ||
let s: @Trait<int> = @Struct { person: "Fred" }; //~ ERROR expected Trait<int>, but found Trait<&'static str> | ||
//~^ ERROR expected Trait<int>, but found Trait<&'static str> | ||
s.f(1); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2013 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(managed_boxes)]; | ||
|
||
struct Struct { | ||
person: &'static str | ||
} | ||
|
||
trait Trait<T> { | ||
fn f(&self, x: T); | ||
} | ||
|
||
impl Trait<&'static str> for Struct { | ||
fn f(&self, x: &'static str) { | ||
println!("Hello, {}!", x); | ||
} | ||
} | ||
|
||
fn main() { | ||
let person = ~"Fred"; | ||
let person: &str = person; //~ ERROR borrowed value does not live long enough | ||
let s: @Trait<&'static str> = @Struct { person: person }; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2013 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(managed_boxes)]; | ||
|
||
trait Trait<T> { | ||
fn f(&self, x: T); | ||
} | ||
|
||
struct Struct { | ||
x: int, | ||
y: int, | ||
} | ||
|
||
impl Trait<&'static str> for Struct { | ||
fn f(&self, x: &'static str) { | ||
println(~"Hi, " + x + ~"!"); | ||
} | ||
} | ||
fn f(x: @Trait<&'static str>) { | ||
x.f("Sue"); | ||
} | ||
|
||
pub fn main() { | ||
let a = Struct { x: 1, y: 2 }; | ||
let b: @Trait<&'static str> = @a; | ||
b.f("Fred"); | ||
let c: ~Trait<&'static str> = ~a; | ||
c.f("Mary"); | ||
let d: &Trait<&'static str> = &a; | ||
d.f("Joe"); | ||
f(@a); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2013 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(managed_boxes)]; | ||
|
||
trait Trait { | ||
fn f(&self); | ||
} | ||
|
||
struct Struct { | ||
x: int, | ||
y: int, | ||
} | ||
|
||
impl Trait for Struct { | ||
fn f(&self) { | ||
println("Hi!"); | ||
} | ||
} | ||
|
||
fn f(x: @Trait) { | ||
x.f(); | ||
} | ||
|
||
pub fn main() { | ||
let a = Struct { x: 1, y: 2 }; | ||
let b: @Trait = @a; | ||
b.f(); | ||
let c: ~Trait = ~a; | ||
c.f(); | ||
let d: &Trait = &a; | ||
d.f(); | ||
f(@a); | ||
} | ||
|
981c6b1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
saw approval from pcwalton
at luqmana@981c6b1
981c6b1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merging luqmana/rust/trait-object-coercion = 981c6b1 into auto
981c6b1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
luqmana/rust/trait-object-coercion = 981c6b1 merged ok, testing candidate = cea4d138
981c6b1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some tests failed:
failure: http://buildbot.rust-lang.org/builders/auto-win-32-nopt-t/builds/2315
exception: http://buildbot.rust-lang.org/builders/auto-mac-32-opt/builds/3202
exception: http://buildbot.rust-lang.org/builders/auto-mac-32-nopt-c/builds/1045
exception: http://buildbot.rust-lang.org/builders/auto-mac-32-nopt-t/builds/1047
exception: http://buildbot.rust-lang.org/builders/auto-mac-64-opt/builds/3206
exception: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-c/builds/2308
exception: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-t/builds/2310
exception: http://buildbot.rust-lang.org/builders/auto-linux-32-opt/builds/3221
exception: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-c/builds/2310
exception: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-t/builds/2315
exception: http://buildbot.rust-lang.org/builders/auto-linux-64-opt/builds/3223
exception: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-c/builds/2310
exception: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-t/builds/2314
exception: http://buildbot.rust-lang.org/builders/auto-linux-64-x-android/builds/2385
exception: http://buildbot.rust-lang.org/builders/auto-win-32-opt/builds/3209
exception: http://buildbot.rust-lang.org/builders/auto-win-32-nopt-c/builds/2311
exception: http://buildbot.rust-lang.org/builders/auto-bsd-64-opt/builds/2984
981c6b1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
saw approval from pcwalton
at luqmana@981c6b1
981c6b1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merging luqmana/rust/trait-object-coercion = 981c6b1 into auto
981c6b1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
luqmana/rust/trait-object-coercion = 981c6b1 merged ok, testing candidate = c34623d7
981c6b1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some tests failed:
failure: http://buildbot.rust-lang.org/builders/auto-linux-32-opt/builds/3223
exception: http://buildbot.rust-lang.org/builders/auto-mac-32-opt/builds/3204
exception: http://buildbot.rust-lang.org/builders/auto-mac-32-nopt-c/builds/1047
exception: http://buildbot.rust-lang.org/builders/auto-mac-32-nopt-t/builds/1049
exception: http://buildbot.rust-lang.org/builders/auto-mac-64-opt/builds/3208
exception: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-c/builds/2310
exception: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-t/builds/2312
exception: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-c/builds/2312
exception: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-t/builds/2317
exception: http://buildbot.rust-lang.org/builders/auto-linux-64-opt/builds/3225
exception: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-c/builds/2312
exception: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-t/builds/2316
exception: http://buildbot.rust-lang.org/builders/auto-linux-64-x-android/builds/2387
exception: http://buildbot.rust-lang.org/builders/auto-win-32-opt/builds/3211
exception: http://buildbot.rust-lang.org/builders/auto-win-32-nopt-c/builds/2313
exception: http://buildbot.rust-lang.org/builders/auto-win-32-nopt-t/builds/2317
exception: http://buildbot.rust-lang.org/builders/auto-bsd-64-opt/builds/2986
981c6b1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
saw approval from pcwalton
at luqmana@981c6b1
981c6b1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merging luqmana/rust/trait-object-coercion = 981c6b1 into auto
981c6b1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
luqmana/rust/trait-object-coercion = 981c6b1 merged ok, testing candidate = 1a9c8cc
981c6b1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all tests pass:
success: http://buildbot.rust-lang.org/builders/auto-mac-32-opt/builds/3206
success: http://buildbot.rust-lang.org/builders/auto-mac-32-nopt-c/builds/1049
success: http://buildbot.rust-lang.org/builders/auto-mac-32-nopt-t/builds/1051
success: http://buildbot.rust-lang.org/builders/auto-mac-64-opt/builds/3210
success: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-c/builds/2312
success: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-t/builds/2314
success: http://buildbot.rust-lang.org/builders/auto-linux-32-opt/builds/3225
success: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-c/builds/2314
success: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-t/builds/2319
success: http://buildbot.rust-lang.org/builders/auto-linux-64-opt/builds/3227
success: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-c/builds/2314
success: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-t/builds/2318
success: http://buildbot.rust-lang.org/builders/auto-linux-64-x-android/builds/2389
success: http://buildbot.rust-lang.org/builders/auto-win-32-opt/builds/3213
success: http://buildbot.rust-lang.org/builders/auto-win-32-nopt-c/builds/2315
success: http://buildbot.rust-lang.org/builders/auto-win-32-nopt-t/builds/2319
success: http://buildbot.rust-lang.org/builders/auto-bsd-64-opt/builds/2988
981c6b1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fast-forwarding master to auto = 1a9c8cc