Skip to content

[WIP] Support underscore as associated const name#158970

Draft
makai410 wants to merge 1 commit into
rust-lang:mainfrom
makai410:us-assoc-cnst
Draft

[WIP] Support underscore as associated const name#158970
makai410 wants to merge 1 commit into
rust-lang:mainfrom
makai410:us-assoc-cnst

Conversation

@makai410

@makai410 makai410 commented Jul 8, 2026

Copy link
Copy Markdown
Member

Tracking:

TODOs for myself:

  • check assoc const underscore in that connected region part of checking name collision
  • add more tests
  • suppress E0438 and E0046 when underscore const in the trait/trait impl context (probably need to poison the assoc item at some point?)

r? @ghost

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 8, 2026
@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job aarch64-gnu-llvm-21-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
-    |               ^ `_` is not a valid name for this `const` item
+    |               ^
+    |
+    = note: see issue #158944 <https://github.com/rust-lang/rust/issues/158944> for more information
+    = help: add `#![feature(associated_const_underscore)]` to the crate attributes to enable
+    = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
18 
19 error[E0438]: const `_` is not a member of trait `A`
20   --> $DIR/assoc-const-underscore-semantic-fail.rs:10:9

24 
---
To only update this specific test, also pass `--test-args parser/assoc/assoc-const-underscore-semantic-fail.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/parser/assoc/assoc-const-underscore-semantic-fail.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/parser/assoc/assoc-const-underscore-semantic-fail" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "incomplete_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers"
stdout: none
--- stderr -------------------------------
error: `const` items in this context need a name
##[error]  --> /checkout/tests/ui/parser/assoc/assoc-const-underscore-semantic-fail.rs:7:15
   |
LL |         const _: () = (); //~ ERROR `const` items in this context need a name
   |               ^ `_` is not a valid name for this `const` item

error: `const` items in this context need a name
##[error]  --> /checkout/tests/ui/parser/assoc/assoc-const-underscore-semantic-fail.rs:10:15
   |
LL |         const _: () = (); //~ ERROR `const` items in this context need a name
   |               ^ `_` is not a valid name for this `const` item

error[E0658]: naming associated constants with `_` is unstable
##[error]  --> /checkout/tests/ui/parser/assoc/assoc-const-underscore-semantic-fail.rs:15:15
   |
LL |         const _: () = (); //~ ERROR `const` items in this context need a name
   |               ^
   |
   = note: see issue #158944 <https://github.com/rust-lang/rust/issues/158944> for more information
   = help: add `#![feature(associated_const_underscore)]` to the crate attributes to enable
   = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error[E0438]: const `_` is not a member of trait `A`
##[error]  --> /checkout/tests/ui/parser/assoc/assoc-const-underscore-semantic-fail.rs:10:9
   |
LL |         const _: () = (); //~ ERROR `const` items in this context need a name
   |         ^^^^^^^^^^^^^^^^^ not a member of trait `A`

error: aborting due to 4 previous errors

Some errors have detailed explanations: E0438, E0658.
For more information about an error, try `rustc --explain E0438`.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants