Skip to content

Commit

Permalink
Rebasing and review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nrc committed Oct 31, 2014
1 parent 318472b commit 2474d7d
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 46 deletions.
4 changes: 2 additions & 2 deletions src/librustc/metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ fn item_to_def_like(item: rbml::Doc, did: ast::DefId, cnum: ast::CrateNum)
// We don't bother to get encode/decode the trait id, we don't need it.
Method => DlDef(def::DefMethod(did, None, provenance)),
StaticMethod => DlDef(def::DefStaticMethod(did, provenance)),
_ => fail!()
_ => panic!()
}
}
Type | ForeignType => DlDef(def::DefTy(did, false)),
Expand Down Expand Up @@ -931,7 +931,7 @@ pub fn get_methods_if_impl(intr: Rc<IdentInterner>,
match family {
StaticMethod | Method => {
impl_methods.push(MethodInfo {
ident: item_name(&*intr, impl_method_doc),
name: item_name(&*intr, impl_method_doc),
def_id: item_def_id(impl_method_doc, cdata),
vis: item_visibility(impl_method_doc),
});
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1418,7 +1418,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
encode_parent_sort(rbml_w, 't');

let trait_item = &ms[i];
let foo = |rbml_w: &mut Encoder| {
let encode_trait_item = |rbml_w: &mut Encoder| {
// If this is a static method, we've already
// encoded this.
if is_nonstatic_method {
Expand All @@ -1431,14 +1431,14 @@ fn encode_info_for_item(ecx: &EncodeContext,
match trait_item {
&RequiredMethod(ref m) => {
encode_attributes(rbml_w, m.attrs.as_slice());
foo(rbml_w);
encode_trait_item(rbml_w);
encode_item_sort(rbml_w, 'r');
encode_method_argument_names(rbml_w, &*m.decl);
}

&ProvidedMethod(ref m) => {
encode_attributes(rbml_w, m.attrs.as_slice());
foo(rbml_w);
encode_trait_item(rbml_w);
encode_item_sort(rbml_w, 'p');
encode_inlined_item(ecx, rbml_w, IITraitItemRef(def_id, trait_item));
encode_method_argument_names(rbml_w, &*m.pe_fn_decl());
Expand Down
44 changes: 44 additions & 0 deletions src/test/auxiliary/method_self_arg1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright 2014 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.

#![crate_type = "lib"]

static mut COUNT: u64 = 1;

pub fn get_count() -> u64 { unsafe { COUNT } }

pub struct Foo;

impl Foo {
pub fn foo(self, x: &Foo) {
unsafe { COUNT *= 2; }
// Test internal call.
Foo::bar(&self);
Foo::bar(x);

Foo::baz(self);
Foo::baz(*x);

Foo::qux(box self);
Foo::qux(box *x);
}

pub fn bar(&self) {
unsafe { COUNT *= 3; }
}

pub fn baz(self) {
unsafe { COUNT *= 5; }
}

pub fn qux(self: Box<Foo>) {
unsafe { COUNT *= 7; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,10 @@
static mut COUNT: u64 = 1;

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

pub struct Foo;

impl Foo {
pub fn foo(self, x: &Foo) {
unsafe { COUNT *= 2; }
// Test internal call.
Foo::bar(&self);
Foo::bar(x);

Foo::baz(self);
Foo::baz(*x);

Foo::qux(box self);
Foo::qux(box *x);
}

pub fn bar(&self) {
unsafe { COUNT *= 3; }
}

pub fn baz(self) {
unsafe { COUNT *= 5; }
}

pub fn qux(self: Box<Foo>) {
unsafe { COUNT *= 7; }
}

pub fn run_trait(self) {
unsafe { COUNT *= 17; }
// Test internal call.
Expand Down
27 changes: 27 additions & 0 deletions src/test/run-pass/method-self-arg-aux1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2014 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.

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

// aux-build:method_self_arg1.rs
extern crate method_self_arg1;
use method_self_arg1::Foo;

fn main() {
let x = Foo;
// Test external call.
Foo::bar(&x);
Foo::baz(x);
Foo::qux(box x);

x.foo(&x);

assert!(method_self_arg1::get_count() == 2u64*3*3*3*5*5*5*7*7*7);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,13 @@

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

// aux-build:method_self_arg.rs
extern crate method_self_arg;
use method_self_arg::{Foo, Bar};
// aux-build:method_self_arg2.rs
extern crate method_self_arg2;
use method_self_arg2::{Foo, Bar};

fn main() {
let x = Foo;
// Test external call.
Foo::bar(&x);
Foo::baz(x);
Foo::qux(box x);

x.foo(&x);

assert!(method_self_arg::get_count() == 2u64*3*3*3*5*5*5*7*7*7);

method_self_arg::reset_count();
// Test external call.
Bar::foo1(&x);
Bar::foo2(x);
Bar::foo3(box x);
Expand All @@ -37,6 +27,5 @@ fn main() {

x.run_trait();

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

0 comments on commit 2474d7d

Please sign in to comment.