Skip to content

Conversation

@oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Nov 3, 2025

Some constifications are annoying because we need to repeat T: Trait bounds from an impl block on the individual constified const fns as T: [const] Trait. We've brainstormed solutions before, and one would be to have separate const impl blocks or sth. However the final syntax will look, I decided to just impl this syntax and either have sth nice on nightly to work with or at least move the discussion along.

Also interacts with the discussion around impl const Trait for Type vs const impl Trait for Type, as we may want to use the latter to keep inherent and trait impls in sync (unless we come up with even another scheme).

  • rustdoc + tests
  • macro stability /regression tests

r? @fee1-dead

cc @traviscross @rust-lang/project-const-traits

@rustbot
Copy link
Collaborator

rustbot commented Nov 3, 2025

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

Some changes occurred in src/tools/rustfmt

cc @rust-lang/rustfmt

Changes to the size of AST and/or HIR nodes.

cc @nnethercote

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustfmt Relevant to the rustfmt team, which will review and decide on the PR/issue. labels Nov 3, 2025
@rust-log-analyzer

This comment has been minimized.

Copy link
Contributor

@traviscross traviscross left a comment

Choose a reason for hiding this comment

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

Looks good to me, including from the side of the lang experiment, as the lang champion.

View changes since this review

Comment on lines 1316 to +1322
fn should_encode_constness(def_kind: DefKind) -> bool {
match def_kind {
DefKind::Fn | DefKind::AssocFn | DefKind::Closure | DefKind::Ctor(_, CtorKind::Fn) => true,
DefKind::Fn
| DefKind::AssocFn
| DefKind::Closure
| DefKind::Ctor(_, CtorKind::Fn)
| DefKind::Impl { of_trait: false } => true,
Copy link
Member

Choose a reason for hiding this comment

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

I see something asymmetric here, and this is something we might want to address either here or some time later.

We only encode impl methods' constness for trait impls and those are inherited from the impl, but is it not better to just look at the parent and only encode constness once? Since we're going with the whole-trait whole-impl approach anyways.

In the other direction, we should not encode const impl also and have all the assocs encode their constness.

Comment on lines +2561 to +2570
return Some(true);
}
if ALL_QUALS.iter().any(|&qual| token.is_keyword(qual)) {
// Ok, we found a legal keyword, keep looking for `impl`
return None;
}
Some(false)
});
if let Some(ret) = action {
return ret;
Copy link
Member

Choose a reason for hiding this comment

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

wonder if using ControlFlow here would be more clearer

Comment on lines 990 to +991
if let Some(of_trait) = of_trait.as_deref() {
result.push_str(format_constness_right(of_trait.constness));
result.push_str(format_constness_right(*constness));
Copy link
Member

Choose a reason for hiding this comment

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

are we not going to format impl const Tr to const impl Tr? Feels like it should be placed at the earlier places now.


const impl Foo {
fn bar() {}
fn baz() {}
Copy link
Member

Choose a reason for hiding this comment

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

should probably run the span until we reach \n, / (start of a comment), or fn, or any other modifier that occurs after fn, this doesn't seem ideal

@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 Nov 4, 2025
@fee1-dead
Copy link
Member

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Nov 4, 2025
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Nov 4, 2025
@rust-bors
Copy link

rust-bors bot commented Nov 4, 2025

☀️ Try build successful (CI)
Build commit: cb034f2 (cb034f2a46aa06b8466754d9310106afca386763, parent: e5efc336720901420a8891dcdb67ca0a475dc03c)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (cb034f2): comparison URL.

Overall result: ❌ regressions - no action needed

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.5% [0.5%, 0.6%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (primary -1.0%, secondary -0.7%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.8% [0.8%, 0.9%] 3
Improvements ✅
(primary)
-1.0% [-1.0%, -1.0%] 1
Improvements ✅
(secondary)
-5.5% [-5.5%, -5.5%] 1
All ❌✅ (primary) -1.0% [-1.0%, -1.0%] 1

Cycles

Results (secondary 0.2%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.4% [1.5%, 3.0%] 5
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-5.5% [-7.6%, -3.3%] 2
All ❌✅ (primary) - - 0

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 473.413s -> 473.703s (0.06%)
Artifact size: 390.72 MiB -> 390.78 MiB (0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Nov 5, 2025
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-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustfmt Relevant to the rustfmt team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants