Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"expected type parameter but found type parameter" #3404

Closed
catamorphism opened this issue Sep 7, 2012 · 4 comments · Fixed by #18264
Closed

"expected type parameter but found type parameter" #3404

catamorphism opened this issue Sep 7, 2012 · 4 comments · Fixed by #18264
Labels
A-type-system Area: Type system P-low Low priority

Comments

@catamorphism
Copy link
Contributor

This is a terrible error message. See compile-fail/issue-2611-5.rs, which I'm about to check in, for an example program that triggers it.

@metajack
Copy link
Contributor

metajack commented Jul 8, 2013

Reproduced on 65ed803

@thestinger
Copy link
Contributor

Triage bump, still an issue. This is often caused by a mismatch between lifetimes.

@dradtke
Copy link

dradtke commented Jan 10, 2014

Confirmed that this is still an issue with Rust 0.9. I ran into it playing around with linked list implementations:

pub enum List<T> {
    Cons(T, ~List<T>),
    Nil,
}

impl<T> List<T> {
    fn prepend<T>(mut self, value: T) {
        self = Cons(value, ~self);
    }
}

This causes the compiler to emit two errors, neither of which is very helpful:

error: mismatched types: expected `~List<T>` but found `~List<T>` (expected type parameter but found type parameter)
error: mismatched types: expected `List<T>` but found `List<T>` (expected type parameter but found type parameter)

@pnkfelix
Copy link
Member

accepted for P-low.

bors added a commit that referenced this issue Oct 31, 2014
…atsakis

This PR aims to improve the readability of diagnostic messages that involve unresolved type variables. Currently, messages like the following:

```rust
mismatched types: expected `core::result::Result<uint,()>`, found `core::option::Option<<generic #1>>`
<anon>:6     let a: Result<uint, ()> = None;
                                       ^~~~
mismatched types: expected `&mut <generic #2>`, found `uint`
<anon>:7     f(42u);
               ^~~
```

tend to appear unapproachable to new users. [0] While specific type var IDs are valuable in
diagnostics that deal with more than one such variable, in practice many messages
only mention one. In those cases, leaving out the specific number makes the messages
slightly less terrifying.

```rust
mismatched types: expected `core::result::Result<uint, ()>`, found `core::option::Option<_>`
<anon>:6     let a: Result<uint, ()> = None;
                                       ^~~~
mismatched types: expected `&mut _`, found `uint`
<anon>:7     f(42u);
               ^~~
```

As you can see, I also tweaked the aesthetics slightly by changing type variables to use the type hole syntax _. For integer variables, the syntax used is:

```rust
mismatched types: expected `core::result::Result<uint, ()>`, found `core::option::Option<_#1i>`
<anon>:6     let a: Result<uint, ()> = Some(1);
```

and float variables:

```rust
mismatched types: expected `core::result::Result<uint, ()>`, found `core::option::Option<_#1f>`
<anon>:6     let a: Result<uint, ()> = Some(0.5);
```

[0] https://twitter.com/coda/status/517713085465772032

Closes #2632.
Closes #3404.
Closes #18426.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-type-system Area: Type system P-low Low priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants