Syntactically reject equality predicates#153513
Conversation
|
@bors try |
This comment has been minimized.
This comment has been minimized.
[crater only] Syntactically reject equality predicates
|
@craterbot check |
|
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
|
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
|
🎉 Experiment
Footnotes
|
|
@craterbot run mode=check-only crates=https://crater-reports.s3.amazonaws.com/pr-153513/retry-regressed-list.txt p=1 |
|
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
This comment has been minimized.
This comment has been minimized.
|
r=me with CI fixed |
|
The Rustfmt subtree was changed cc @rust-lang/rustfmt The Clippy subtree was changed cc @rust-lang/clippy |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
|
@bors r=jackh726 |
View all comments
Background (History)
Equality predicates have been syntactically valid since PR #39158 / nightly-2017-02-02 / 1.16 (released 2017-03-16, 9 years ago), both forms that is:
$ty = $tyand$ty == $ty. They're not registered as an unstable feature despite having a tracking issue (#20041). Naturally, they don't have a feature gate. Of course, we reject them post-expansion, so they are still semantically invalid.Parser scaffolding for
$ident = $tywas added in RUST-19391 (2014) which was then generalized to$ty = $tyin RUST-20002 (2014) and extended to additionally cover$ty == $tyin RUST-39158 (2017). As mentioned, the last PR also made them grammatical.RUST-87471 (2021) attempted to start impl'ing typeck'ing but it was closed due to concerns: #87471 (comment) (already back in 2017 there were concerns: https://github.com/rust-lang/rust/pull/39158/changes#r97811244).
In 2022, T-lang discussed this feature during a meeting and raised concerns: #20041 (comment). However, they were inclined to accept a restricted form, namely
T::AssocTy = $ty(Tis a (self) ty param or a self ty alias) and<$ty as Trait>::AssocTy = $tysince that's trivial to support in HIR ty lowering (this is still accurate).Change
This renders equality predicates
$ty = $tyand$ty == $tysyntactically invalid again. On stable, they're merely semantically invalid. This is motivated by the fact that=or==?$ty = $tyto$term = $termdue to ambiguities 1 that would require backtracking whereas$typepath = $termwouldn't have that problemI've merely upgraded the semantic hard error to a syntactic hard error, I've intentionally not introduced an unstable feature under which equality predicates become legal.
That's because a hard error is easier to push through procedurally, it's an important first step (we can always turn it into a feature gate error later on) and since this potential feature isn't backed by any official lang experiment.
I don't consider T-lang's message #20041 (comment) from 2022 to be sufficient because it doesn't answer questions like (1.i), (1.ii) or whether code like
T: Trait<A>, <T as Trait<B>>::AssocTy = Ty(A≠B) orT: Trait<'r>, for<'a> <T as Trait<'a>>::AssocTy = Tyshould be legal (which would be more powerful / could lead to typechecking issues, idk) or not assuming we're going with the restricted form ofc (we would need input from T-types).Lang nomination
#153513 (comment)
Footnotes
Code like
fn f() -> i32 where { 0 }is intentionally legal today but if we had$term = $termthe{ 0 }could then also be the start of an equality predicate like{ 0 } = 0. ↩