Skip to content

Instantly share code, notes, and snippets.

@s3thi
Last active December 16, 2015 02:19
Show Gist options
  • Save s3thi/5361229 to your computer and use it in GitHub Desktop.
Save s3thi/5361229 to your computer and use it in GitHub Desktop.
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