Skip to content

Document binary operator argument passing conventions #7777

Closed
@brendanzab

Description

@brendanzab

This works:

fn mul<T:Num>(x: &T, y: &T) -> T { *x * *y }

But this doesn't:

fn mul<T:Num>(&x: &T, &y: &T) -> T { x * y }
<anon>:7:23: 7:25 error: cannot move out of dereference of & pointer
<anon>:7          fn mul<T:Num>(&x: &T, &y: &T) -> T { x * y }
                                ^~
<anon>:7:31: 7:33 error: cannot move out of dereference of & pointer
<anon>:7          fn mul<T:Num>(&x: &T, &y: &T) -> T { x * y }
                                        ^~

The above &t: &T pattern could cut down on tons of repetitive derefs within function bodies.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions