Last active
December 16, 2015 02:19
-
-
Save s3thi/5361229 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern mod std; | |
use std::list::*; | |
pub fn last_box<T>(l: @List<T>) -> T { | |
match *l { | |
Nil => fail!(), | |
Cons(hd, @Nil) => hd, | |
Cons(_, tl) => last_box(tl) | |
} | |
} | |
#[cfg(test)] | |
mod tests { | |
use super::*; | |
use std::list::*; | |
#[test] #[should_fail] | |
fn empty() { | |
last_box(@Nil::<int>); | |
} | |
} | |
/* | |
Fails with the following error: | |
01_lastbox.rs:5:7: 5:9 error: moving out of dereference of immutable @ pointer | |
01_lastbox.rs:5 match *l { | |
^~ | |
error: aborting due to previous error | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment