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

Hint for Vec<String, String> #83250

Closed
jsha opened this issue Mar 18, 2021 · 1 comment · Fixed by #90856
Closed

Hint for Vec<String, String> #83250

jsha opened this issue Mar 18, 2021 · 1 comment · Fixed by #90856
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-enhancement Category: An issue proposing an enhancement or a PR with one. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jsha
Copy link
Contributor

jsha commented Mar 18, 2021

Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=5f472854b25b6ccce15820ca0dd45c19

fn foo() {
    let _z: Vec<String, String> = vec![]; // A vector of string pairs, right?
}

The current output is:

error[E0658]: use of unstable library feature 'allocator_api'
 --> src/lib.rs:2:25
  |
2 |     let _z: Vec<String, String> = vec![]; // A vector of string pairs, right?
  |                         ^^^^^^
  |
  = note: see issue #32838 <https://github.com/rust-lang/rust/issues/32838> for more information

error[E0277]: the trait bound `String: Allocator` is not satisfied
   --> src/lib.rs:2:13
    |
2   |     let _z: Vec<String, String> = vec![]; // A vector of string pairs, right?
    |             ^^^^^^^^^^^^^^^^^^^ the trait `Allocator` is not implemented for `String`

error[E0308]: mismatched types
 --> src/lib.rs:2:35
  |
2 |     let _z: Vec<String, String> = vec![]; // A vector of string pairs, right?
  |             -------------------   ^^^^^^ expected struct `String`, found struct `std::alloc::Global`
  |             |
  |             expected due to this
  |
  = note: expected struct `Vec<String, String>`
             found struct `Vec<_, std::alloc::Global>`
  = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 3 previous errors

Ideally the output should look like:

The above, plus:

hint: for a Vec of String pairs, try Vec<(String, String)>

Rationale: The current error messages assume that users know Vec has a second type param, which is rarely used. A vector of pairs is a fairly common type, and I suspect a lot of people make the mistake of forgetting the parentheses.

@jsha jsha added 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. labels Mar 18, 2021
@estebank estebank added A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-papercut Diagnostics: An error or lint that needs small tweaks. labels Mar 18, 2021
@JohnTitor JohnTitor added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Mar 18, 2021
@ken-matsui
Copy link
Contributor

@rustbot claim

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 A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-enhancement Category: An issue proposing an enhancement or a PR with one. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants