Skip to content

Compiler accepts const equality bound involving nonsensical nested equality constraint on associated const #102335

Closed
@fmease

Description

@fmease

I expect the following code to be rejected by the compiler but it is actually accepted and compiles successfully:

#![feature(associated_const_equality)]
#![crate_type = "lib"]

trait T {
    type A: S<C<i32 = u64> = 34>;
    //         ^^^^^^^^^^^ this should not be permitted but it is
}

trait S {
    const C: i32;
}

The associated constant S::C does not have any generic parameters / associated items (constants cannot have those anyways in the current version of Rust) and thus the argument list <i32 = u64> should be flagged as erroneous. Interestingly, if you remove the = u64, the compiler correctly identifies this as an error: this associated constant takes 0 generic arguments but 1 generic argument was supplied.

I think i32 = u64 is to be interpreted as a nested equality constraint (and not as a “defaulted” parameter, i.e. a parameter with a default value).

Meta

rustc -Vv:

rustc 1.66.0-nightly (9062b780b 2022-09-21)
binary: rustc
commit-hash: 9062b780b32d2eab060b4432863e085d9504ca5c
commit-date: 2022-09-21
host: x86_64-unknown-linux-gnu
release: 1.66.0-nightly
LLVM version: 15.0.0

@rustbot label T-compiler requires-nightly
I would label this with F-associated_const_equality but sadly that label does not exist. (it now does)
Hence, I am just going to mention its tracking issue: #92827.

CC @JulianKnodt

Metadata

Metadata

Labels

C-bugCategory: This is a bug.F-associated_const_equality`#![feature(associated_const_equality)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions