-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Inherent const impl #148434
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
base: master
Are you sure you want to change the base?
Inherent const impl #148434
Conversation
|
Some changes occurred in src/tools/clippy cc @rust-lang/clippy Some changes occurred to the CTFE machinery Some changes occurred in src/tools/rustfmt cc @rust-lang/rustfmt Changes to the size of AST and/or HIR nodes. cc @nnethercote |
This comment has been minimized.
This comment has been minimized.
1cc41b4 to
d780ac6
Compare
There was a problem hiding this 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.
| 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, |
There was a problem hiding this comment.
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.
| 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; |
There was a problem hiding this comment.
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
| 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)); |
There was a problem hiding this comment.
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() {} |
There was a problem hiding this comment.
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
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (cb034f2): comparison URL. Overall result: ❌ regressions - no action neededBenchmarking 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 Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
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.
CyclesResults (secondary 0.2%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 473.413s -> 473.703s (0.06%) |
Some constifications are annoying because we need to repeat
T: Traitbounds from an impl block on the individual constifiedconst fns asT: [const] Trait. We've brainstormed solutions before, and one would be to have separateconst implblocks 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 Typevsconst 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).r? @fee1-dead
cc @traviscross @rust-lang/project-const-traits