Skip to content

Commit 2474d7d

Browse files
committed
Rebasing and review changes
1 parent 318472b commit 2474d7d

File tree

6 files changed

+80
-46
lines changed

6 files changed

+80
-46
lines changed

src/librustc/metadata/decoder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ fn item_to_def_like(item: rbml::Doc, did: ast::DefId, cnum: ast::CrateNum)
327327
// We don't bother to get encode/decode the trait id, we don't need it.
328328
Method => DlDef(def::DefMethod(did, None, provenance)),
329329
StaticMethod => DlDef(def::DefStaticMethod(did, provenance)),
330-
_ => fail!()
330+
_ => panic!()
331331
}
332332
}
333333
Type | ForeignType => DlDef(def::DefTy(did, false)),
@@ -931,7 +931,7 @@ pub fn get_methods_if_impl(intr: Rc<IdentInterner>,
931931
match family {
932932
StaticMethod | Method => {
933933
impl_methods.push(MethodInfo {
934-
ident: item_name(&*intr, impl_method_doc),
934+
name: item_name(&*intr, impl_method_doc),
935935
def_id: item_def_id(impl_method_doc, cdata),
936936
vis: item_visibility(impl_method_doc),
937937
});

src/librustc/metadata/encoder.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,7 +1418,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
14181418
encode_parent_sort(rbml_w, 't');
14191419

14201420
let trait_item = &ms[i];
1421-
let foo = |rbml_w: &mut Encoder| {
1421+
let encode_trait_item = |rbml_w: &mut Encoder| {
14221422
// If this is a static method, we've already
14231423
// encoded this.
14241424
if is_nonstatic_method {
@@ -1431,14 +1431,14 @@ fn encode_info_for_item(ecx: &EncodeContext,
14311431
match trait_item {
14321432
&RequiredMethod(ref m) => {
14331433
encode_attributes(rbml_w, m.attrs.as_slice());
1434-
foo(rbml_w);
1434+
encode_trait_item(rbml_w);
14351435
encode_item_sort(rbml_w, 'r');
14361436
encode_method_argument_names(rbml_w, &*m.decl);
14371437
}
14381438

14391439
&ProvidedMethod(ref m) => {
14401440
encode_attributes(rbml_w, m.attrs.as_slice());
1441-
foo(rbml_w);
1441+
encode_trait_item(rbml_w);
14421442
encode_item_sort(rbml_w, 'p');
14431443
encode_inlined_item(ecx, rbml_w, IITraitItemRef(def_id, trait_item));
14441444
encode_method_argument_names(rbml_w, &*m.pe_fn_decl());
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
#![crate_type = "lib"]
12+
13+
static mut COUNT: u64 = 1;
14+
15+
pub fn get_count() -> u64 { unsafe { COUNT } }
16+
17+
pub struct Foo;
18+
19+
impl Foo {
20+
pub fn foo(self, x: &Foo) {
21+
unsafe { COUNT *= 2; }
22+
// Test internal call.
23+
Foo::bar(&self);
24+
Foo::bar(x);
25+
26+
Foo::baz(self);
27+
Foo::baz(*x);
28+
29+
Foo::qux(box self);
30+
Foo::qux(box *x);
31+
}
32+
33+
pub fn bar(&self) {
34+
unsafe { COUNT *= 3; }
35+
}
36+
37+
pub fn baz(self) {
38+
unsafe { COUNT *= 5; }
39+
}
40+
41+
pub fn qux(self: Box<Foo>) {
42+
unsafe { COUNT *= 7; }
43+
}
44+
}

src/test/auxiliary/method_self_arg.rs renamed to src/test/auxiliary/method_self_arg2.rs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,36 +13,10 @@
1313
static mut COUNT: u64 = 1;
1414

1515
pub fn get_count() -> u64 { unsafe { COUNT } }
16-
pub fn reset_count() { unsafe { COUNT = 1; } }
1716

1817
pub struct Foo;
1918

2019
impl Foo {
21-
pub fn foo(self, x: &Foo) {
22-
unsafe { COUNT *= 2; }
23-
// Test internal call.
24-
Foo::bar(&self);
25-
Foo::bar(x);
26-
27-
Foo::baz(self);
28-
Foo::baz(*x);
29-
30-
Foo::qux(box self);
31-
Foo::qux(box *x);
32-
}
33-
34-
pub fn bar(&self) {
35-
unsafe { COUNT *= 3; }
36-
}
37-
38-
pub fn baz(self) {
39-
unsafe { COUNT *= 5; }
40-
}
41-
42-
pub fn qux(self: Box<Foo>) {
43-
unsafe { COUNT *= 7; }
44-
}
45-
4620
pub fn run_trait(self) {
4721
unsafe { COUNT *= 17; }
4822
// Test internal call.
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 (cross-crate)
12+
13+
// aux-build:method_self_arg1.rs
14+
extern crate method_self_arg1;
15+
use method_self_arg1::Foo;
16+
17+
fn main() {
18+
let x = Foo;
19+
// Test external call.
20+
Foo::bar(&x);
21+
Foo::baz(x);
22+
Foo::qux(box x);
23+
24+
x.foo(&x);
25+
26+
assert!(method_self_arg1::get_count() == 2u64*3*3*3*5*5*5*7*7*7);
27+
}

src/test/run-pass/method-self-arg-aux.rs renamed to src/test/run-pass/method-self-arg-aux2.rs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,13 @@
1010

1111
// Test method calls with self as an argument (cross-crate)
1212

13-
// aux-build:method_self_arg.rs
14-
extern crate method_self_arg;
15-
use method_self_arg::{Foo, Bar};
13+
// aux-build:method_self_arg2.rs
14+
extern crate method_self_arg2;
15+
use method_self_arg2::{Foo, Bar};
1616

1717
fn main() {
1818
let x = Foo;
1919
// Test external call.
20-
Foo::bar(&x);
21-
Foo::baz(x);
22-
Foo::qux(box x);
23-
24-
x.foo(&x);
25-
26-
assert!(method_self_arg::get_count() == 2u64*3*3*3*5*5*5*7*7*7);
27-
28-
method_self_arg::reset_count();
29-
// Test external call.
3020
Bar::foo1(&x);
3121
Bar::foo2(x);
3222
Bar::foo3(box x);
@@ -37,6 +27,5 @@ fn main() {
3727

3828
x.run_trait();
3929

40-
println!("{}, {}", method_self_arg::get_count(), 2u64*2*3*3*5*5*7*7*11*11*13*13*17);
41-
assert!(method_self_arg::get_count() == 2u64*2*3*3*5*5*7*7*11*11*13*13*17);
30+
assert!(method_self_arg2::get_count() == 2u64*2*3*3*5*5*7*7*11*11*13*13*17);
4231
}

0 commit comments

Comments
 (0)