Can I borrow a pointer to a shared trait in Rust? -
from tutorial on borrowed pointers (broken), bit modified:
struct point {x: float, y: float} fn compute(p1 : &point) {} fn main() { let shared_box : @point = @point {x: 5.0, y: 1.0}; compute(shared_box); }
and fine, because shared box automatically borrowed function.
but doing same trait:
struct point {x: float, y: float} trait tpoint {} impl tpoint point {} fn compute(p1 : &tpoint) {} fn main() { let shared_box : @tpoint = @point {x: 5.0, y: 1.0} @tpoint; compute(shared_box); // ^~~~~~~ error here }
and fails, (compiler version 0.6) saying:
error: mismatched types: expected
&tpoint
found@tpoint
(trait storage differs: expected & found @)
is bug in compiler? or borrowed pointers not allowed traits?
if answer latter, why that?
this known bug in current version of rust:
#3794: casting trait doesn't auto-coerce &t type
there has been work on trying address problem, there technical details need ironed out; interested parties can see of discussion (from few months ago) here on pull request 4178.
Comments
Post a Comment