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

Vec<Type1,Type2> should suggest a tuple if Type2 is not an allocator. #91540

Closed
damccull opened this issue Dec 5, 2021 · 3 comments
Closed
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

@damccull
Copy link

damccull commented Dec 5, 2021

When aliasing a type for a vec of a tuple, it'd be nice to be told something like "You probably meant to use a tuple" instead of getting an error saying you're using unstable library features.

Given the following code:

type MyType = Vec<u32,bool>;

The current output is:

error[E0658]: use of unstable library feature 'allocator_api'
  --> advent-of-code-2021\src\day4\mod.rs:14:28
   |
14 | type BingoBoard = Vec<u32, bool>;
   |                            ^^^^
   |
   = note: see issue #32838 <https://github.com/rust-lang/rust/issues/32838> for more information

Ideally the output should look like:

error[E0658]: use of unstable library feature 'allocator_api'
  --> advent-of-code-2021\src\day4\mod.rs:14:28
   |
14 | type BingoBoard = Vec<u32, bool>;
   |                            ^^^^
   |
   | Maybe you meant to use a tuple instead?
   = note: see issue #32838 <https://github.com/rust-lang/rust/issues/32838> for more information

This would make it easier to identify this typo in the code for those of us who are newer or less experienced rather than having to guess. I'm not sure how the compiler itself works, but the way I imagine this could be checked is if the second type in the Vec declaration does not implement a trait identifying it as an allocator, it should show the friendly message.

@damccull damccull 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 Dec 5, 2021
@damccull
Copy link
Author

damccull commented Dec 5, 2021

@Dylan-DPC pinged as you requested on Discord.

@damccull
Copy link
Author

damccull commented Dec 5, 2021

@ibraheemdev found #82452 and #80237 related.

@TaKO8Ki
Copy link
Member

TaKO8Ki commented Dec 11, 2021

#90856 has already solved this problem. You can try this suggestion in nightly.

@TaKO8Ki TaKO8Ki closed this as completed Dec 11, 2021
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

2 participants