So, I am writing the simplest function you can imagine. And hey, there's an error in it:
enum Stack<T> {
Nil,
Cons(T, Box<Stack<T>>)
}
fn isEmpty<T>(s: Stack<T>) -> bool {
match s {
Nil => true,
_ => false,
}
}
Excitingly rustc tells me:
$ cargo build --verbose
Compiling stack v0.1.0 (file:///home/pmatos/Projects/okasaki-rust/chp2-persistence/stack)
Runningrustc src/lib.rs --crate-name stack --crate-type lib -g --out-dir /home/pmatos/Projects/okasaki-rust/chp2-persistence/stack/target/debug --emit=dep-info,link -L dependency=/home/pmatos/Projects/okasaki-rust/chp2-persistence/stack/target/debug -L dependency=/home/pmatos/Projects/okasaki-rust/chp2-persistence/stack/target/debug/deps
src/lib.rs:10:9: 10:12 warning: pattern bindingNil
is named the same as one of the variants of the typeStack<T>
[E0170]
src/lib.rs:10 Nil => true,
^~~
src/lib.rs:10:9: 10:12 help: runrustc --explain E0170
to see a detailed explanation
src/lib.rs:10:9: 10:12 help: if you meant to match on a variant, consider making the path in the pattern qualified:Stack<T>::Nil
src/lib.rs:11:9: 11:10 error: unreachable pattern [E0001]
src/lib.rs:11 _ => false,
^
src/lib.rs:11:9: 11:10 help: runrustc --explain E0001
to see a detailed explanation
error: aborting due to previous error
Could not compilestack
.
Caused by:
Process didn't exit successfully:rustc src/lib.rs --crate-name stack --crate-type lib -g --out-dir /home/pmatos/Projects/okasaki-rust/chp2-persistence/stack/target/debug --emit=dep-info,link -L dependency=/home/pmatos/Projects/okasaki-rust/chp2-persistence/stack/target/debug -L dependency=/home/pmatos/Projects/okasaki-rust/chp2-persistence/stack/target/debug/deps
(exit code: 101)
So now I follow rustc advice:
enum Stack<T> {
Nil,
Cons(T, Box<Stack<T>>)
}
fn isEmpty<T>(s: Stack<T>) -> bool {
match s {
Stack<T>::Nil => true,
_ => false,
}
}
But this is wrong again and now rust helps you no further. Any hints?
$ cargo build --verbose
Compiling stack v0.1.0 (file:///home/pmatos/Projects/okasaki-rust/chp2-persistence/stack)
Runningrustc src/lib.rs --crate-name stack --crate-type lib -g --out-dir /home/pmatos/Projects/okasaki-rust/chp2-persistence/stack/target/debug --emit=dep-info,link -L dependency=/home/pmatos/Projects/okasaki-rust/chp2-persistence/stack/target/debug -L dependency=/home/pmatos/Projects/okasaki-rust/chp2-persistence/stack/target/debug/deps
src/lib.rs:10:14: 10:15 error: expected one of=>
,@
,if
, or|
, found<
src/lib.rs:10 Stack::Nil => true,
^
Could not compilestack
.
Caused by:
Process didn't exit successfully:rustc src/lib.rs --crate-name stack --crate-type lib -g --out-dir /home/pmatos/Projects/okasaki-rust/chp2-persistence/stack/target/debug --emit=dep-info,link -L dependency=/home/pmatos/Projects/okasaki-rust/chp2-persistence/stack/target/debug -L dependency=/home/pmatos/Projects/okasaki-rust/chp2-persistence/stack/target/debug/deps
(exit code: 101)