Skip to content

Commit fc3ed0c

Browse files
committed
rollup merge of rust-lang#18413 : bkoropoff/issue-18412
2 parents f3ba518 + 12619be commit fc3ed0c

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

src/librustc/middle/trans/expr.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ fn trans_def<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
833833
834834
let _icx = push_ctxt("trans_def_lvalue");
835835
match def {
836-
def::DefFn(..) | def::DefStaticMethod(..) |
836+
def::DefFn(..) | def::DefStaticMethod(..) | def::DefMethod(..) |
837837
def::DefStruct(_) | def::DefVariant(..) => {
838838
trans_def_fn_unadjusted(bcx, ref_expr, def)
839839
}
@@ -1191,10 +1191,12 @@ fn trans_def_fn_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
11911191
let llfn = match def {
11921192
def::DefFn(did, _, _) |
11931193
def::DefStruct(did) | def::DefVariant(_, did, _) |
1194-
def::DefStaticMethod(did, def::FromImpl(_), _) => {
1194+
def::DefStaticMethod(did, def::FromImpl(_), _) |
1195+
def::DefMethod(did, _, def::FromImpl(_)) => {
11951196
callee::trans_fn_ref(bcx, did, ExprId(ref_expr.id))
11961197
}
1197-
def::DefStaticMethod(impl_did, def::FromTrait(trait_did), _) => {
1198+
def::DefStaticMethod(impl_did, def::FromTrait(trait_did), _) |
1199+
def::DefMethod(impl_did, _, def::FromTrait(trait_did)) => {
11981200
meth::trans_static_method_callee(bcx, impl_did,
11991201
trait_did, ref_expr.id)
12001202
}

src/librustc/middle/ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3631,7 +3631,7 @@ pub fn expr_kind(tcx: &ctxt, expr: &ast::Expr) -> ExprKind {
36313631
def::DefFn(_, _, true) => RvalueDpsExpr,
36323632

36333633
// Fn pointers are just scalar values.
3634-
def::DefFn(..) | def::DefStaticMethod(..) => RvalueDatumExpr,
3634+
def::DefFn(..) | def::DefStaticMethod(..) | def::DefMethod(..) => RvalueDatumExpr,
36353635

36363636
// Note: there is actually a good case to be made that
36373637
// DefArg's, particularly those of immediate type, ought to

src/test/run-pass/issue-18412.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
#![feature(tuple_indexing)]
12+
13+
// Test that non-static methods can be assigned to local variables as
14+
// function pointers.
15+
16+
trait Foo {
17+
fn foo(&self) -> uint;
18+
}
19+
20+
struct A(uint);
21+
22+
impl A {
23+
fn bar(&self) -> uint { self.0 }
24+
}
25+
26+
impl Foo for A {
27+
fn foo(&self) -> uint { self.bar() }
28+
}
29+
30+
fn main() {
31+
let f = A::bar;
32+
let g = Foo::foo;
33+
let a = A(42);
34+
35+
assert_eq!(f(&a), g(&a));
36+
}

0 commit comments

Comments
 (0)