Skip to content

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

Closed
@damccull

Description

@damccull

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions