Skip to content

Commit 469322e

Browse files
committed
---
yaml --- r: 138158 b: refs/heads/try c: db640d5 h: refs/heads/master v: v3
1 parent fb5f24b commit 469322e

File tree

4 files changed

+106
-1
lines changed

4 files changed

+106
-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: b6e0d3a5bf4c88650a22f605f822e02c6b163580
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
5-
refs/heads/try: d3f51dcab85f6878fd25636bf1c8b8d4cf35b4ce
5+
refs/heads/try: db640d53b82f70540092b70aa8decade97e55d63
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
// Test method calls with self as an argument cannot subvert type checking.
12+
13+
struct Foo;
14+
15+
impl Foo {
16+
fn bar(&self) {}
17+
}
18+
19+
fn main() {
20+
let x = Foo;
21+
Foo::bar(x); //~ERROR mismatched types: expected `&Foo`, found `Foo`
22+
Foo::bar(&&x); //~ERROR mismatched types: expected `&Foo`, found `&&Foo`
23+
Foo::bar(&42i); //~ERROR mismatched types: expected `&Foo`, found `&int`
24+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
// Test method calls with self as an argument cannot subvert borrow checking.
12+
13+
struct Foo;
14+
15+
impl Foo {
16+
fn bar(&self) {}
17+
fn baz(&mut self) {}
18+
}
19+
20+
fn main() {
21+
let mut x = Foo;
22+
let y = &mut x;
23+
Foo::bar(&x); //~ERROR cannot borrow `x`
24+
25+
let x = Foo;
26+
Foo::baz(&x); //~ERROR cannot borrow immutable dereference of `&`-pointer as mutable
27+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
// Test method calls with self as an argument
12+
13+
static mut COUNT: uint = 1;
14+
15+
struct Foo;
16+
17+
impl Foo {
18+
fn foo(self, x: &Foo) {
19+
unsafe { COUNT *= 2; }
20+
// Test internal call.
21+
Foo::bar(&self);
22+
Foo::bar(x);
23+
24+
Foo::baz(self);
25+
Foo::baz(*x);
26+
27+
Foo::qux(box self);
28+
Foo::qux(box *x);
29+
}
30+
31+
fn bar(&self) {
32+
unsafe { COUNT *= 3; }
33+
}
34+
35+
fn baz(self) {
36+
unsafe { COUNT *= 5; }
37+
}
38+
39+
fn qux(self: Box<Foo>) {
40+
unsafe { COUNT *= 7; }
41+
}
42+
}
43+
44+
fn main() {
45+
let x = Foo;
46+
// Test external call.
47+
Foo::bar(&x);
48+
Foo::baz(x);
49+
Foo::qux(box x);
50+
51+
x.foo(&x);
52+
53+
unsafe { assert!(COUNT == 2u*3*3*3*5*5*5*7*7*7); }
54+
}

0 commit comments

Comments
 (0)