Skip to content

Commit f3b2296

Browse files
committed
Auto-deref the base expr in trans_method_callee
(specifically in the method_trait case) -- if you wrote x.f() and x has type @t for a trait T, x wasn't getting auto-deref'ed. This was bad. Closes #2935
1 parent aacd18f commit f3b2296

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/rustc/middle/trans/impl.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import lib::llvm::llvm;
1414
import lib::llvm::{ValueRef, TypeRef};
1515
import lib::llvm::llvm::LLVMGetParam;
1616
import std::map::hashmap;
17+
import util::ppaux::{ty_to_str, tys_to_str};
18+
19+
import syntax::print::pprust::expr_to_str;
1720

1821
fn trans_impl(ccx: @crate_ctxt, path: path, name: ast::ident,
1922
methods: ~[@ast::method], tps: ~[ast::ty_param]) {
@@ -70,6 +73,9 @@ fn trans_method_callee(bcx: block, callee_id: ast::node_id,
7073
typeck::method_trait(_, off) => {
7174
let {bcx, val} = trans_temp_expr(bcx, self);
7275
let fty = node_id_type(bcx, callee_id);
76+
let self_ty = node_id_type(bcx, self.id);
77+
let {bcx, val, _} = autoderef(bcx, self.id, val, self_ty,
78+
uint::max_value);
7379
trans_trait_callee(bcx, val, fty, off)
7480
}
7581
}

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//type t = { a: int };
2+
// type t = { a: bool };
3+
type t = bool;
4+
5+
trait it {
6+
fn f();
7+
}
8+
9+
impl of it for t {
10+
fn f() { }
11+
}
12+
13+
fn main() {
14+
// let x = ({a: 4i} as it);
15+
// let y = @({a: 4i});
16+
// let z = @({a: 4i} as it);
17+
// let z = @({a: true} as it);
18+
let z = @(true as it);
19+
// x.f();
20+
// y.f();
21+
// (*z).f();
22+
#error["ok so far..."];
23+
z.f(); //segfault
24+
}

0 commit comments

Comments
 (0)