Introduce const Trait (always-const trait bounds) - #119099
Conversation
This comment has been minimized.
This comment has been minimized.
| let id = lcx.next_node_id(); | ||
| let hir_id = lcx.next_id(); |
There was a problem hiding this comment.
I've moved this {Node,Hir}Id creation below the HirId registration for the hir::ExprKind::Path above to accommodate the control flow, I hope that doesn't break any invariants (?).
There was a problem hiding this comment.
No, as long as you didn't move it outside of a nested self.with_* function.
There was a problem hiding this comment.
Actually... hm... it's probably fine...
compiler-errors
left a comment
There was a problem hiding this comment.
Do we have tests to check that we deny ~const in const items and structs and stuff?
|
b265a78 to
1ab36f6
Compare
| || self.check(&token::Not) | ||
| || self.check(&token::Question) | ||
| || self.check(&token::Tilde) | ||
| || self.check_keyword(kw::Const) |
There was a problem hiding this comment.
I need to investigate if this visibly changes the MBE matching behavior for stable users. I hope not since this check is required for correctness.
There was a problem hiding this comment.
Doesn't seem to be a problem. I've added a test to ensure that const Trait doesn't regress stable code: tests/ui/rfcs/rfc-2632-const-trait-impl/mbe-bare-trait-objects-const-trait-bounds.rs
There was a problem hiding this comment.
It's obvious in hindsight but this doesn't regress the aforementioned test because I haven't (and I won't) add kw::Const & TokenKind::Tilde to can_begin_type.
This comment has been minimized.
This comment has been minimized.
1ab36f6 to
932c309
Compare
|
Some changes occurred in src/tools/rustfmt cc @rust-lang/rustfmt |
This comment has been minimized.
This comment has been minimized.
310df46 to
2abd167
Compare
|
☔ The latest upstream changes (presumably #119163) made this pull request unmergeable. Please resolve the merge conflicts. |
| self.sess.emit_err(errors::ModifierLifetime { | ||
| span, | ||
| modifier: "const", | ||
| padding: " ", | ||
| }); |
There was a problem hiding this comment.
I did not see an ui test for the padding suggestion. Could you give me a link to it or add it?
There was a problem hiding this comment.
Well, padding didn't actually make sense. I've removed it. I could run-rustfix for the -Zparse-only test tests/ui/parser/bounds-type.rs but I'm not sure if it's worth it esp. since it concerns a maybe-incorrect suggestion.
There was a problem hiding this comment.
No need for run-rustfix, just an ui test that would have covered this code path with stderr would be fine. Though removing it also works.
There was a problem hiding this comment.
It's a tool-only suggestion atm, hence it doesn't show up on stderr.
commented
Dec 27, 2023
|
Network error |
commented
Dec 27, 2023
commented
Dec 27, 2023
|
☀️ Test successful - checks-actions |
commented
Dec 27, 2023
|
Finished benchmarking commit (88d69b7): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 670.98s -> 672.366s (0.21%) |
commented
Jan 21, 2024
|
@fmease @compiler-errors @fee1-dead I'm hoping I can get some help. I've bisected rust-lang/rustfmt#6035 back to this PR. With the following input: rustfmt 1.7.0-dev (88d69b7 2023-12-27) outputs: m!(const N: usize = 0;);but the commit just before (rustfmt 1.7.0-dev (a861c89 2023-12-27)) outputs: m!(
const N: usize = 0;
);Any idea why the formatting would have changed? |
Feature
const_trait_implcurrently lacks a way to express “always const” trait bounds. This makes it impossible to define generic items like fns or structs which contain types that depend on const method calls (*). While the final design and esp. the syntax of effects / keyword generics isn't set in stone, some version of “always const” trait bounds will very likely form a part of it. Further, their implementation is trivial thanks to theeffectsbackbone.Not sure if this needs t-lang sign-off though.
(*):
Lastly, “always const” trait bounds are a perfect fit for
generic_const_items.Previously, we (oli, fee1-dead and I) wanted to reinterpret
~const Traitasconst Traitin generic const items which would've been quite surprising and not very generalizable.Supersedes #117530.
cc @oli-obk
As discussed
r? fee1-dead (or compiler)