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

type lacking clone on container has misleading/incorrect error message #60875

Closed
m4b opened this issue May 16, 2019 · 2 comments
Closed

type lacking clone on container has misleading/incorrect error message #60875

m4b opened this issue May 16, 2019 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@m4b
Copy link
Contributor

m4b commented May 16, 2019

Consider:

use std::collections::HashMap;

#[derive(Clone, Debug)]
struct Foo;

#[derive(Debug)]
struct Bar;

type H = HashMap<String, Vec<(Foo, Bar)>>;

fn wat(h: &H) -> H {
    let h: H = h.clone();
    h
}

fn main() {
    let h = H::new();
    println!("{:?}", wat(&h));
}

This reports:

  --> src/main.rs:12:16
   |
12 |     let h: H = h.clone();
   |                ^^^^^^^^^ expected struct `std::collections::HashMap`, found reference
   |
   = note: expected type `std::collections::HashMap<std::string::String, std::vec::Vec<(Foo, Bar)>>`
              found type `&std::collections::HashMap<std::string::String, std::vec::Vec<(Foo, Bar)>>`

error: aborting due to previous error

This is extremely misleading at best (I would expect it to effectively say that one or more types did not implement clone), and debatebly, miscompilation at worst.

I don't want to really argue about the latter, but opening this here so maybe the diagnostics could be improved since I don't think its controversial to say this is really, really misleading, and having programmed for about 3ish years now, I was caught off-guard by this and lost about 20 minutes unncessarily...

@hellow554
Copy link
Contributor

hellow554 commented May 16, 2019

@rustbot modify labels: A-diagnostics T-compiler

@rustbot rustbot added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-diagnostics Area: Messages for errors, warnings, and lints labels May 16, 2019
@estebank
Copy link
Contributor

Closing as duplicate of #34896, #34629, #48677.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants