Skip to content

Spurious type error with indexing and braced const generics #21735

@kpreid

Description

@kpreid

rust-analyzer version: 0.4.2809-standalone (a96b6a9 2026-02-28)
rustc version: rustc 1.96.0-nightly (80381278a 2026-03-01)
editor or extension: VS Code extension 0.4.2809

code snippet to reproduce:

struct Cg<const N: usize> {}

type CgMax = Cg<{ usize::MAX }>;

struct Tg<T>(T);

impl From<&'static Tg<CgMax>> for Tg<CgMax> {
    fn from(_: &Tg<CgMax>) -> Self {
        unimplemented!()
    }
}

fn produce() -> &'static [Tg<CgMax>] {
    &[]
}

#[allow(dead_code)]
fn consume() {
    _ = Tg::from(&produce()[0]);
}

Incorrect diagnostic from rust-analyzer in consume():
expected {unknown}, found &<&'static [Tg<Cg<_>>] as Index<i32>>::Output

(The type alias is not strictly necessary to the reproduction, but the braces are. The i32 mentioned is a red herring; the same incorrect diagnostic appears if the literal index is 0usize.)

@rustbot label +A-ty

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-tytype system / type inference / traits / method resolutionC-bugCategory: bug

    Type

    No type
    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