It appears that if a trait has a function that returns a borrowed pointer with lifetime self (e.g. Map), then pointers to values with that trait can't be stored in other structures.
Here's the example I'm thinking of:
pub trait MyMap {
fn find(&self) -> &self/uint;
}
type MyTy = MyMap;
pub struct AStruct { a : ~MyTy }
pub fn new(init: ~MyTy) -> AStruct {
AStruct {a:init}
}
this signals the error(s):
oiseau:/tmp clements> rustc --test foo.rs
foo.rs:19:4: 19:11 error: cannot infer an appropriate lifetime due to
conflicting requirements
foo.rs:19 AStruct {a:init}
^~~~~~~
foo.rs:18:35: 20:1 note: first, the lifetime cannot outlive the anonymous
lifetime #1 defined on the block at 18:35...
foo.rs:18 pub fn new(init: ~MyTy) -> AStruct {
foo.rs:19 AStruct {a:init}
foo.rs:20 }
foo.rs:19:15: 19:19 note: ...due to the following expression
foo.rs:19 AStruct {a:init}
^~~~
foo.rs:18:35: 20:1 note: but, the lifetime must be valid for the anonymous
lifetime #2 defined on the block at 18:35...
foo.rs:18 pub fn new(init: ~MyTy) -> AStruct {
foo.rs:19 AStruct {a:init}
foo.rs:20 }
foo.rs:19:4: 19:11 note: ...due to the following expression
foo.rs:19 AStruct {a:init}
^~~~~~~
error: aborting due to previous error
Changing the return type of find() to be simply 'uint' makes the problem go
away.
Is this correct behavior? If so, is there an obvious workaround? Without
understanding the problem, it's hard to see what the workaround would be.
Thanks!
John
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ Rust-dev mailing list [email protected] https://mail.mozilla.org/listinfo/rust-dev
