[rust-dev] "expected type parameter but found type parameters"

Paul Nathan pnathan at vandals.uidaho.edu
Wed Dec 26 09:23:08 PST 2012


Good morning, 

I am exploring Rust's traits in relation to working on data structures. Unfortunately, I have managed to back myself into a hole with an error message that I can't understand the problem with; to wit, "has an incompatible type: expected type parameter but found type parameter" is an error I don't understand.

I've stuffed the code up on github: https://github.com/pnathan/flaky-data-structures/tree/non-compiling

Here's my Rust version:

$ rustc --version
rustc 0.5 (8b98e5a 2012-12-20 17:01:38 -0800)
host: x86_64-apple-darwin

And here are the error messages:

$ make
rustc --test linear/linear.rs -o linear/test_linear
linear/linear.rs:50:4: 59:5 error: method `head` has an incompatible type: expected type parameter but found type parameter
linear/linear.rs:50     fn head<T> (list: @List_Data<T>) -> Option<T> {
linear/linear.rs:51         match (list)  {
linear/linear.rs:52           @Nil => {
linear/linear.rs:53             None
linear/linear.rs:54           }
linear/linear.rs:55           @Cons(e, _) => {
                    ...
linear/linear.rs:60:4: 62:5 error: method `length` has an incompatible type: expected type parameter but found type parameter
linear/linear.rs:60     fn length<T>(list: @List_Data<T>) -> u64 {
linear/linear.rs:61         0
linear/linear.rs:62     }
linear/linear.rs:68:4: 70:5 error: method `size` has an incompatible type: expected type parameter but found type parameter
linear/linear.rs:68     fn size<T> (cont: @List_Data<T>) -> u64 {
linear/linear.rs:69         0
linear/linear.rs:70     }
linear/linear.rs:76:4: 80:5 error: method `peek` has an incompatible type: expected type parameter but found type parameter
linear/linear.rs:76     fn peek<T>(list : @List_Data<T>) -> Option<@T> {
linear/linear.rs:77         None
linear/linear.rs:78         // head
linear/linear.rs:79         //head(list)
linear/linear.rs:80     }
linear/linear.rs:82:4: 84:5 error: method `pop` has an incompatible type: expected type parameter but found type parameter
linear/linear.rs:82     fn pop<T>(list : @List_Data<T>) -> (Option<@T>, @List<@T>) {
linear/linear.rs:83         (None, @Nil)
linear/linear.rs:84     }
linear/linear.rs:51:8: 58:9 error: mismatched types: expected `core::option::Option<'b>` but found `core::option::Option<@'b>` (expected type parameter but found @-ptr)
linear/linear.rs:51         match (list)  {
linear/linear.rs:52           @Nil => {
linear/linear.rs:53             None
linear/linear.rs:54           }
linear/linear.rs:55           @Cons(e, _) => {
linear/linear.rs:56             Some(e)
                    ...
linear/linear.rs:83:8: 83:20 error: mismatched types: expected `(core::option::Option<@'b>, at List<@'b>)` but found `(core::option::Option<<V2>>, at List_Data<<V3>>)` (expected trait List but found @-ptr)
linear/linear.rs:83         (None, @Nil)
                            ^~~~~~~~~~~~
error: aborting due to 7 previous errors
make: *** [test_linear] Error 101


Regards,
Paul Nathan







More information about the Rust-dev mailing list