Skip to content

New const traits syntax #139858

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Apr 15, 2025

This PR only affects the AST and doesn't actually change anything semantically.

All occurrences of ~const outside of libcore have been replaced by [const]. Within libcore we have to wait for rustfmt to be bumped in the bootstrap compiler. This will happen "automatically" (when rustfmt is run) during the bootstrap bump, as rustfmt converts ~const into [const]. After this we can remove the ~const support from the parser

Caveat discovered during impl: there is no legacy bare trait object recovery for [const] Trait as that snippet in type position goes down the slice /array parsing code and will error

r? @fee1-dead

cc @nikomatsakis @traviscross @compiler-errors

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Apr 15, 2025
@rustbot
Copy link
Collaborator

rustbot commented Apr 15, 2025

Some changes occurred in src/tools/rustfmt

cc @rust-lang/rustfmt

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

@oli-obk oli-obk force-pushed the new-const-traits-syntax branch from f6be056 to 2003458 Compare April 15, 2025 09:04
@rust-log-analyzer

This comment has been minimized.

@oli-obk oli-obk force-pushed the new-const-traits-syntax branch from 2003458 to d6da247 Compare April 15, 2025 09:51
@rustbot

This comment was marked as outdated.

@rust-log-analyzer

This comment has been minimized.

@oli-obk oli-obk force-pushed the new-const-traits-syntax branch from d6da247 to e16c40b Compare April 15, 2025 12:38
@rust-log-analyzer

This comment has been minimized.

@oli-obk oli-obk force-pushed the new-const-traits-syntax branch from 234ba91 to ef1acde Compare April 17, 2025 13:04
@oli-obk oli-obk force-pushed the new-const-traits-syntax branch from ef1acde to 5fa25d4 Compare April 29, 2025 09:04
@rust-log-analyzer

This comment has been minimized.

@oli-obk oli-obk force-pushed the new-const-traits-syntax branch from 5fa25d4 to 7762468 Compare April 29, 2025 09:55
@bors
Copy link
Collaborator

bors commented May 6, 2025

☔ The latest upstream changes (presumably #140695) made this pull request unmergeable. Please resolve the merge conflicts.

@compiler-errors
Copy link
Member

Have we actually settled on a syntax here? Sorry for punting it back over, but would like to get an update here if it's actually ready to review :> ping me when it's ready, sorry for the delays!

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 22, 2025
@rustbot
Copy link
Collaborator

rustbot commented May 22, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@traviscross
Copy link
Contributor

Have we actually settled on a syntax here?

No. Discussion is ongoing.

@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot assigned fee1-dead and unassigned compiler-errors Jun 25, 2025
@oli-obk oli-obk force-pushed the new-const-traits-syntax branch from d292dc6 to ae4dc9e Compare June 25, 2025 13:29
@oli-obk oli-obk added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 25, 2025
@rust-log-analyzer

This comment has been minimized.

@oli-obk oli-obk force-pushed the new-const-traits-syntax branch from ae4dc9e to 2e751d2 Compare June 25, 2025 14:52
@rust-log-analyzer

This comment has been minimized.

@oli-obk oli-obk force-pushed the new-const-traits-syntax branch from 2e751d2 to aca6032 Compare June 25, 2025 16:25
@rust-log-analyzer

This comment has been minimized.

@oli-obk oli-obk force-pushed the new-const-traits-syntax branch from aca6032 to 06bc396 Compare June 26, 2025 08:51
@oli-obk
Copy link
Contributor Author

oli-obk commented Jun 26, 2025

Afaict the syntax with which to move forward was settled as much as it could be in the last lang team design meeting. The lang team wants to get hands-on experience with the feature to see how it feels, so this PR is ready to be merged now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not necessary for this PR; but would be nice if we renamed the "tilde-const" in the file names to either something syntax agnostic ("maybe-const") or matches the latest syntax

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in a follow-up commit

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 26, 2025
@oli-obk oli-obk force-pushed the new-const-traits-syntax branch from dc95649 to c548946 Compare June 26, 2025 10:25
@oli-obk
Copy link
Contributor Author

oli-obk commented Jun 26, 2025

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 26, 2025
@rust-log-analyzer

This comment has been minimized.

@oli-obk oli-obk force-pushed the new-const-traits-syntax branch from c548946 to a9f1140 Compare June 26, 2025 10:45
@rustbot rustbot added the A-tidy Area: The tidy tool label Jun 26, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jun 26, 2025

There are changes to the tidy tool.

cc @jieyouxu

@rustbot rustbot added the T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) label Jun 26, 2025
@rust-log-analyzer
Copy link
Collaborator

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

Click to see the possible cause of the failure (guessed by this bot)
---- [run-make] tests/run-make/const-trait-stable-toolchain stdout ----

error: rmake recipe failed to complete
status: exit status: 101
command: cd "/checkout/obj/build/aarch64-unknown-linux-gnu/test/run-make/const-trait-stable-toolchain/rmake_out" && env -u RUSTFLAGS AR="ar" BUILD_ROOT="/checkout/obj/build/aarch64-unknown-linux-gnu" CARGO="/checkout/obj/build/aarch64-unknown-linux-gnu/stage1-tools-bin/cargo" CC="cc" CC_DEFAULT_FLAGS="-ffunction-sections -fdata-sections -fPIC" CXX="c++" CXX_DEFAULT_FLAGS="-ffunction-sections -fdata-sections -fPIC" HOST_RUSTC_DYLIB_PATH="/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/lib" LD_LIBRARY_PATH="/checkout/obj/build/aarch64-unknown-linux-gnu/bootstrap-tools/aarch64-unknown-linux-gnu/release/deps:/checkout/obj/build/aarch64-unknown-linux-gnu/stage0/lib/rustlib/aarch64-unknown-linux-gnu/lib" LD_LIB_PATH_ENVVAR="LD_LIBRARY_PATH" LLVM_BIN_DIR="/usr/lib/llvm-19/bin" LLVM_COMPONENTS="aarch64 aarch64asmparser aarch64codegen aarch64desc aarch64disassembler aarch64info aarch64utils aggressiveinstcombine all all-targets amdgpu amdgpuasmparser amdgpucodegen amdgpudesc amdgpudisassembler amdgpuinfo amdgputargetmca amdgpuutils analysis arm armasmparser armcodegen armdesc armdisassembler arminfo armutils asmparser asmprinter avr avrasmparser avrcodegen avrdesc avrdisassembler avrinfo binaryformat bitreader bitstreamreader bitwriter bpf bpfasmparser bpfcodegen bpfdesc bpfdisassembler bpfinfo cfguard codegen codegendata codegentypes core coroutines coverage debuginfobtf debuginfocodeview debuginfodwarf debuginfogsym debuginfologicalview debuginfomsf debuginfopdb demangle dlltooldriver dwarflinker dwarflinkerclassic dwarflinkerparallel dwp engine executionengine extensions filecheck frontenddriver frontendhlsl frontendoffloading frontendopenacc frontendopenmp fuzzercli fuzzmutate globalisel hexagon hexagonasmparser hexagoncodegen hexagondesc hexagondisassembler hexagoninfo hipstdpar instcombine instrumentation interfacestub interpreter ipo irprinter irreader jitlink lanai lanaiasmparser lanaicodegen lanaidesc lanaidisassembler lanaiinfo libdriver lineeditor linker loongarch loongarchasmparser loongarchcodegen loongarchdesc loongarchdisassembler loongarchinfo lto m68k m68kasmparser m68kcodegen m68kdesc m68kdisassembler m68kinfo mc mca mcdisassembler mcjit mcparser mips mipsasmparser mipscodegen mipsdesc mipsdisassembler mipsinfo mirparser msp430 msp430asmparser msp430codegen msp430desc msp430disassembler msp430info native nativecodegen nvptx nvptxcodegen nvptxdesc nvptxinfo objcarcopts objcopy object objectyaml option orcdebugging orcjit orcshared orctargetprocess passes perfjitevents powerpc powerpcasmparser powerpccodegen powerpcdesc powerpcdisassembler powerpcinfo profiledata remarks riscv riscvasmparser riscvcodegen riscvdesc riscvdisassembler riscvinfo riscvtargetmca runtimedyld sandboxir scalaropts selectiondag sparc sparcasmparser sparccodegen sparcdesc sparcdisassembler sparcinfo support symbolize systemz systemzasmparser systemzcodegen systemzdesc systemzdisassembler systemzinfo tablegen target targetparser textapi textapibinaryreader transformutils ve veasmparser vecodegen vectorize vedesc vedisassembler veinfo webassembly webassemblyasmparser webassemblycodegen webassemblydesc webassemblydisassembler webassemblyinfo webassemblyutils windowsdriver windowsmanifest x86 x86asmparser x86codegen x86desc x86disassembler x86info x86targetmca xcore xcorecodegen xcoredesc xcoredisassembler xcoreinfo xray xtensa xtensaasmparser xtensacodegen xtensadesc xtensadisassembler xtensainfo" LLVM_FILECHECK="/usr/lib/llvm-19/bin/FileCheck" NODE="/usr/bin/node" PYTHON="/usr/bin/python3" RUSTC="/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" RUSTDOC="/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustdoc" SOURCE_ROOT="/checkout" TARGET="aarch64-unknown-linux-gnu" TARGET_EXE_DYLIB_PATH="/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/lib/rustlib/aarch64-unknown-linux-gnu/lib" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/run-make/const-trait-stable-toolchain/rmake"
stdout: none
--- stderr -------------------------------

thread 'main' panicked at /checkout/tests/run-make/const-trait-stable-toolchain/rmake.rs:25:10:
test failed: `const-super-trait-stable-enabled.stderr` is different from `(rustc)`

--- const-super-trait-stable-enabled.stderr
+++ (rustc)
@@ -1,10 +1,10 @@
-error: `~const` is not allowed here
+error: `[const]` is not allowed here
  --> const-super-trait.rs:7:12
   |
 7 | trait Bar: ~const Foo {}
   |            ^^^^^^
   |
-note: this trait is not a `#[const_trait]`, so it cannot have `~const` trait bounds
+note: this trait is not a `#[const_trait]`, so it cannot have `[const]` trait bounds
  --> const-super-trait.rs:7:1
   |
 7 | trait Bar: ~const Foo {}
@@ -16,25 +16,25 @@
 1 | #![cfg_attr(feature_enabled, feature(const_trait_impl))]
   |                              ^^^^^^^^^^^^^^^^^^^^^^^^^
 
-error: `~const` can only be applied to `#[const_trait]` traits
+error: `[const]` can only be applied to `#[const_trait]` traits
  --> const-super-trait.rs:7:12
   |
 7 | trait Bar: ~const Foo {}
   |            ^^^^^^ can't be applied to `Foo`
   |
-note: `Foo` can't be used with `~const` because it isn't annotated with `#[const_trait]`
+note: `Foo` can't be used with `[const]` because it isn't annotated with `#[const_trait]`
  --> const-super-trait.rs:3:1
   |
 3 | trait Foo {
   | ^^^^^^^^^
 
-error: `~const` can only be applied to `#[const_trait]` traits
+error: `[const]` can only be applied to `#[const_trait]` traits
  --> const-super-trait.rs:9:17
   |
 9 | const fn foo<T: ~const Bar>(x: &T) {
   |                 ^^^^^^ can't be applied to `Bar`
   |
-note: `Bar` can't be used with `~const` because it isn't annotated with `#[const_trait]`
+note: `Bar` can't be used with `[const]` because it isn't annotated with `#[const_trait]`
  --> const-super-trait.rs:7:1
   |
 7 | trait Bar: ~const Foo {}

note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-run-make Area: port run-make Makefiles to rmake.rs A-tidy Area: The tidy tool S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants