Skip to content

Suggestion reorders visibility incorrectly for type const items #157368

Description

@reddevilmidzy

Code

#![feature(min_generic_const_args)]
#![feature(inherent_associated_types)]

pub struct Foo([u8; Bar::LEN]);

pub struct Bar;

impl Bar {
    pub const LEN: usize = 1;
}


fn main() {
}

Current output

error: use of `const` in the type system not defined as `type const`
 --> src/main.rs:4:21
  |
4 | pub struct Foo([u8; Bar::LEN]);
  |                     ^^^^^^^^
  |
help: add `type` before `const` for `Bar::LEN`
  |
9 |     type pub const LEN: usize = 1;
  |     ++++

Desired output

error: use of `const` in the type system not defined as `type const`
 --> src/main.rs:4:21
  |
4 | pub struct Foo([u8; Bar::LEN]);
  |                     ^^^^^^^^
  |
help: add `type` before `const` for `Bar::LEN`
  |
9 |     pub type const LEN: usize = 1;
  |         ++++

Rationale and extra context

should suggest pub type const instead of type pub const.

Other cases

Rust Version

rustc 1.98.0-nightly (54333ff07 2026-05-22)
binary: rustc
commit-hash: 54333ff079780f803f65dcee30c544050b35f544
commit-date: 2026-05-22
host: x86_64-unknown-linux-gnu
release: 1.98.0-nightly
LLVM version: 22.1.6

Anything else?

No response

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsF-inherent_associated_types`#![feature(inherent_associated_types)]`F-min_generic_const_args`#![feature(min_generic_const_args)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions