Skip to content

Vec<foo::bar:A> (with single :) in a struct field causes misleading errors #94812

Closed
@TaKO8Ki

Description

@TaKO8Ki

Given the following code:

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=43eaa091f27b11807fadff36c41b3945

mod foo {
    mod bar {
        struct A;
    }
}

struct Foo {
  a: Vec<foo::bar:A>,
}

The current output is:

error: expected one of `,` or `>`, found `:`
 [--> src/lib.rs:8:18
](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=c816dd29ce8ce457fbdaa7f0eb66d2d3#)  |
8 |   a: Vec<foo::bar:A>,
  |                  ^ expected one of `,` or `>`
  |
help: expressions must be enclosed in braces to be used as const generic arguments
  |
8 |   a: Vec<{ foo::bar:A }>,
  |          +            +

error[[E0747]](https://doc.rust-lang.org/nightly/error-index.html#E0747): constant provided when a type was expected
 [--> src/lib.rs:8:10
](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=c816dd29ce8ce457fbdaa7f0eb66d2d3#)  |
8 |   a: Vec<foo::bar:A>,
  |          ^^^^^^^^^^

For more information about this error, try `rustc --explain E0747`.
error: could not compile `playground` due to 2 previous errors

Ideally the output should look like:

error[[E0405]](https://doc.rust-lang.org/nightly/error-index.html#E0405): cannot find trait `A` in this scope
 [--> src/lib.rs:6:14
](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=c816dd29ce8ce457fbdaa7f0eb66d2d3#)  |
6 |   a: Vec<foo::bar:A>,
  |                   ^ not found in this scope
  |
help: you might have meant to write a path instead of an associated type bound
  |
6 |   a: Vec<foo::var::A>,
  |                  ~~

Metadata

Metadata

Assignees

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