Skip to content

Require rustc_comptime fns to also be const - #157671

Closed
oli-obk wants to merge 1 commit into
rust-lang:mainfrom
oli-obk:ralfification
Closed

Require rustc_comptime fns to also be const#157671
oli-obk wants to merge 1 commit into
rust-lang:mainfrom
oli-obk:ralfification

Conversation

@oli-obk

Copy link
Copy Markdown
Contributor

r? @RalfJung

as per #157647 (comment)

I think I only did that because it was easier to produce a diagnostic suggestion for removing const than for adding const 😆

@rustbotrustbot 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. labels Jun 9, 2026
@rustbot

Copy link
Copy Markdown
Collaborator

RalfJung is not on the review rotation at the moment.
They may take a while to respond.

#[rustc_comptime]
fn conditionally_const<T: [const] Trait>() {
//~^ ERROR: `[const]` is not allowed here
const fn conditionally_const<T: [const] Trait>() {

@fee1-deadfee1-deadJun 9, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We still need this error though.. because comptime isn't conditionally const

View changes since the review

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Yea that's not possible, this check happens on ast xD now that you remind me of this, that probably was another reason I did it this way

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah, that's a bummer.

Well, it's an unstable feature, so I guess we'll just have to live with this oddity for now.

As a matter of style it'd be good to typically put the attribute directly above the function, to minimize the risk of it being missed.

@oli-obkoli-obk closed this Jun 11, 2026
@rustbotrustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 11, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-compilerRelevant 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.

4 participants

@oli-obk@rustbot@RalfJung@fee1-dead