Skip to content

Parser does not support borrowed explicitly-instanitated polymorphic traits #4774

@pnkfelix

Description

@pnkfelix
% rustc --version
rustc 0.6 (77ee858 2013-02-02 11:54:29 +0100)
host: x86_64-apple-darwin

% cat bug4.rs
pub trait OpInt { fn call(&self, int, int) -> int; }
pub trait OpFlo { fn call(&self, float, float) -> float; }
pub trait Op<T> { fn call(&self, T,T) -> T; }

impl fn(int,int) -> int : OpInt {
    fn call(&self, a:int, b:int) -> int { (*self)(a,b) }
}

impl fn(float,float) -> float : OpFlo {
    fn call(&self, a:float, b:float) -> float { (*self)(a,b) }
}

impl<T> fn(T,T) -> T : Op<T> {
    fn call(&self, a:T, b:T) -> T { (*self)(a,b) }
}

fn squarei(x:int, op:&OpInt) -> int       { op.call(x, x) }
fn squaref(x:float, op:&OpFlo) -> float   { op.call(x, x) }
fn squareg<T : Copy>(x:T, op:&Op<T>) -> T { op.call(x, x) }

fn muli(x:int, y:int) -> int { x * y }
fn mulf(x:float, y:float) -> float { x * y }

fn echo<T>(x:T) { io::println(fmt!("%?", x)); }

fn main() {
    let r = squarei(3, (|x,y|muli(x,y)) as &OpInt); echo(r);
    let s = squaref(3f, (|x,y|mulf(x,y)) as &OpFlo); echo(s);

    // This seems analagous to cases above, but parser fails on it.
    let t = squareg(3, &muli as &Op::<int>); echo(t);
}

% rustc bug4.rs
bug4.rs:31:35: 31:37 error: expected `,` but found `::`
bug4.rs:31     let t = squareg(3, &muli as &Op::<int>); echo(t);
                                              ^~

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions