Skip to content

Instantly share code, notes, and snippets.

@MaikKlein
Created May 26, 2013 12:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MaikKlein/5652654 to your computer and use it in GitHub Desktop.
Save MaikKlein/5652654 to your computer and use it in GitHub Desktop.
struct Number{
mut i: int
}
impl Number {
fn mult(&mut self) -> &mut Number{
self.i *= 2;
self
}
}
fn main() {
let mut test = Number {i: 1};
}
/home/maik/hello.rs:19:8: 20:5 error: mismatched types: expected `&mut Number` but found `&mut Number` (lifetime mismatch)
/home/maik/hello.rs:19 self
/home/maik/hello.rs:20 }
/home/maik/hello.rs:17:37: 20:5 note: the anonymous lifetime #2 defined on the block at 17:37...
/home/maik/hello.rs:17 fn mult(&mut self) -> &mut Number{
/home/maik/hello.rs:18 self.i *= 2;
/home/maik/hello.rs:19 self
/home/maik/hello.rs:20 }
/home/maik/hello.rs:17:37: 20:5 note: ...does not necessarily outlive the anonymous lifetime #1 defined on the block at 17:37
/home/maik/hello.rs:17 fn mult(&mut self) -> &mut Number{
/home/maik/hello.rs:18 self.i *= 2;
/home/maik/hello.rs:19 self
/home/maik/hello.rs:20 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment