mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-31 14:31:55 +00:00
Use callee ID when kind-checking expressions that may be overloaded
And fix up test cases that should have failed if not for this bug. Closes #2587
This commit is contained in:
parent
c5e2cf2ee5
commit
46990ad111
@ -241,17 +241,25 @@ fn check_arm(a: arm, cx: ctx, v: visit::vt<ctx>) {
|
||||
|
||||
fn check_expr(e: @expr, cx: ctx, v: visit::vt<ctx>) {
|
||||
debug!("kind::check_expr(%s)", expr_to_str(e, cx.tcx.sess.intr()));
|
||||
let id_to_use = match e.node {
|
||||
expr_index(*)|expr_assign_op(*)|
|
||||
expr_unary(*)|expr_binary(*) => e.callee_id,
|
||||
_ => e.id
|
||||
};
|
||||
|
||||
// Handle any kind bounds on type parameters
|
||||
do option::iter(cx.tcx.node_type_substs.find(e.id)) |ts| {
|
||||
do option::iter(cx.tcx.node_type_substs.find(id_to_use)) |ts| {
|
||||
let bounds = match e.node {
|
||||
expr_path(_) => {
|
||||
let did = ast_util::def_id_of_def(cx.tcx.def_map.get(e.id));
|
||||
ty::lookup_item_type(cx.tcx, did).bounds
|
||||
}
|
||||
_ => {
|
||||
// Type substitions should only occur on paths and
|
||||
// Type substitutions should only occur on paths and
|
||||
// method calls, so this needs to be a method call.
|
||||
|
||||
// Even though the callee_id may have been the id with
|
||||
// node_type_substs, e.id is correct here.
|
||||
ty::method_call_bounds(cx.tcx, cx.method_map, e.id).expect(
|
||||
~"non path/method call expr has type substs??")
|
||||
}
|
||||
@ -265,7 +273,7 @@ fn check_expr(e: @expr, cx: ctx, v: visit::vt<ctx>) {
|
||||
*bounds, (*bounds).len());
|
||||
}
|
||||
do vec::iter2(ts, *bounds) |ty, bound| {
|
||||
check_bounds(cx, e.id, e.span, ty, bound)
|
||||
check_bounds(cx, id_to_use, e.span, ty, bound)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,8 @@
|
||||
// A test case for #2548.
|
||||
|
||||
// xfail-test
|
||||
|
||||
struct foo {
|
||||
x: @mut int;
|
||||
|
||||
new(x: @mut int) { self.x = x; }
|
||||
|
||||
drop {
|
||||
io::println("Goodbye, World!");
|
||||
@ -13,6 +10,10 @@ struct foo {
|
||||
}
|
||||
}
|
||||
|
||||
fn foo(x: @mut int) -> foo {
|
||||
foo { x: x }
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x = @mut 0;
|
||||
|
||||
@ -20,7 +21,8 @@ fn main() {
|
||||
let mut res = foo(x);
|
||||
|
||||
let mut v = ~[mut];
|
||||
v <- ~[mut res] + v;
|
||||
v <- ~[mut res] + v; //~ ERROR instantiating a type parameter with an incompatible type (needs `copy`, got `owned`, missing `copy`)
|
||||
assert (v.len() == 2);
|
||||
}
|
||||
|
||||
assert *x == 1;
|
@ -1,9 +1,9 @@
|
||||
trait vec_monad<A> {
|
||||
fn bind<B>(f: fn(A) -> ~[B]) -> ~[B];
|
||||
fn bind<B: copy>(f: fn(A) -> ~[B]) -> ~[B];
|
||||
}
|
||||
|
||||
impl<A> ~[A]: vec_monad<A> {
|
||||
fn bind<B>(f: fn(A) -> ~[B]) -> ~[B] {
|
||||
fn bind<B: copy>(f: fn(A) -> ~[B]) -> ~[B] {
|
||||
let mut r = ~[];
|
||||
for self.each |elt| { r += f(elt); }
|
||||
r
|
||||
|
@ -28,13 +28,13 @@ impl uint: uint_utils {
|
||||
trait vec_utils<T> {
|
||||
fn length_() -> uint;
|
||||
fn iter_(f: fn(T));
|
||||
fn map_<U>(f: fn(T) -> U) -> ~[U];
|
||||
fn map_<U: copy>(f: fn(T) -> U) -> ~[U];
|
||||
}
|
||||
|
||||
impl<T> ~[T]: vec_utils<T> {
|
||||
fn length_() -> uint { vec::len(self) }
|
||||
fn iter_(f: fn(T)) { for self.each |x| { f(x); } }
|
||||
fn map_<U>(f: fn(T) -> U) -> ~[U] {
|
||||
fn map_<U: copy>(f: fn(T) -> U) -> ~[U] {
|
||||
let mut r = ~[];
|
||||
for self.each |elt| { r += ~[f(elt)]; }
|
||||
r
|
||||
|
@ -5,17 +5,17 @@ impl int: to_str {
|
||||
fn to_str() -> ~str { int::str(self) }
|
||||
}
|
||||
impl ~str: to_str {
|
||||
fn to_str() -> ~str { self }
|
||||
fn to_str() -> ~str { copy self }
|
||||
}
|
||||
impl (): to_str {
|
||||
fn to_str() -> ~str { ~"()" }
|
||||
}
|
||||
|
||||
trait map<T> {
|
||||
fn map<U>(f: fn(T) -> U) -> ~[U];
|
||||
fn map<U: copy>(f: fn(T) -> U) -> ~[U];
|
||||
}
|
||||
impl<T> ~[T]: map<T> {
|
||||
fn map<U>(f: fn(T) -> U) -> ~[U] {
|
||||
fn map<U: copy>(f: fn(T) -> U) -> ~[U] {
|
||||
let mut r = ~[];
|
||||
for self.each |x| { r += ~[f(x)]; }
|
||||
r
|
||||
|
Loading…
Reference in New Issue
Block a user