Skip to content

Commit 45a15af

Browse files
committed
---
yaml --- r: 164843 b: refs/heads/try c: 7855893 h: refs/heads/master i: 164841: 849772f 164839: 80ac796 v: v3
1 parent b526600 commit 45a15af

File tree

5 files changed

+103
-1
lines changed

5 files changed

+103
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: f8f2c7a9537c7f333b242f616aefb75a83860927
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 8443b09e361b96d1f9b7f45a65ed0d31c0e86e70
5-
refs/heads/try: 5fe0ad1c0fde4c93ec010e95457d5831d11f013d
5+
refs/heads/try: 7855893ac7cbac32dcc801dcefe1ec845fa92616
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
88
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
// Simple smoke test that unsafe traits can be compiled etc.
12+
13+
pub unsafe trait Foo {
14+
fn foo(&self) -> int;
15+
}
16+
17+
unsafe impl Foo for int {
18+
fn foo(&self) -> int { *self }
19+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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:trait-safety-lib.rs
12+
13+
// Check that unsafe traits require unsafe impls and that inherent
14+
// impls cannot be unsafe.
15+
16+
extern crate "trait-safety-lib" as lib;
17+
18+
struct Bar;
19+
impl lib::Foo for Bar { //~ ERROR requires an `unsafe impl` declaration
20+
fn foo(&self) -> int {
21+
*self as int
22+
}
23+
}
24+
25+
fn main() { }
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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:trait-safety-lib.rs
12+
13+
// Simple smoke test that unsafe traits can be compiled across crates.
14+
15+
extern crate "trait-safety-lib" as lib;
16+
17+
use lib::Foo;
18+
19+
struct Bar { x: int }
20+
unsafe impl Foo for Bar {
21+
fn foo(&self) -> int { self.x }
22+
}
23+
24+
fn take_foo<F:Foo>(f: &F) -> int { f.foo() }
25+
26+
fn main() {
27+
let x: int = 22;
28+
assert_eq!(22, take_foo(&x));
29+
30+
let x: Bar = Bar { x: 23 };
31+
assert_eq!(23, take_foo(&x));
32+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
// Simple smoke test that unsafe traits can be compiled etc.
12+
13+
unsafe trait Foo {
14+
fn foo(&self) -> int;
15+
}
16+
17+
unsafe impl Foo for int {
18+
fn foo(&self) -> int { *self }
19+
}
20+
21+
fn take_foo<F:Foo>(f: &F) -> int { f.foo() }
22+
23+
fn main() {
24+
let x: int = 22;
25+
assert_eq!(22, take_foo(&x));
26+
}

0 commit comments

Comments
 (0)