-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Allow using named consts in pattern types #136284
base: master
Are you sure you want to change the base?
Conversation
Some changes occurred in src/tools/clippy cc @rust-lang/clippy HIR ty lowering was modified cc @fmease |
62ac839
to
5337e0d
Compare
☔ The latest upstream changes (presumably #136454) made this pull request unmergeable. Please resolve the merge conflicts. |
5337e0d
to
611b966
Compare
span: self.lower_span(pattern.span), | ||
}); | ||
hir::ConstArgKind::Anon(ac) | ||
}; |
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.
this is pretty much mgce? 🤔 as in, this also adds consts in the type system.
Can you delegate this to lower_const_arg or whatever instead?
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.
Yes, but at that point I should modify the ast, and I'd prefer to do that in other PRs
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.
please add a FIXME then 😁
let hir::TyKind::Pat(ty, p) = tcx.parent_hir_node(pat.hir_id).expect_ty().kind else { | ||
bug!() | ||
}; | ||
assert_eq!(p.hir_id, pat.hir_id); |
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.
why do we use the same HirId
for the TyKind::Pat
and its pattern?
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.
We don't. This assertion is just x == child(parent(x))
and mostly a leftover from getting the PR to this state
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.
👍
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.
r=me after fixme
let hir::TyKind::Pat(ty, p) = tcx.parent_hir_node(pat.hir_id).expect_ty().kind else { | ||
bug!() | ||
}; | ||
assert_eq!(p.hir_id, pat.hir_id); |
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.
👍
let start = start.map(expr_to_const); | ||
let end = end.map(expr_to_const); | ||
let start = start.map(|expr| self.lower_const_arg(expr, FeedConstTy::No)); | ||
let end = end.map(|expr| self.lower_const_arg(expr, FeedConstTy::No)); |
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.
do we currently not evaluate the range during typeck?
given that we don't feed its types and computing the type relies on typeck?
@@ -0,0 +1,72 @@ | |||
error[E0391]: cycle detected when evaluating type-level constant |
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 guess the answer is: we do evaluate them during typeck and just get cycle errors for now :3
This required a refactoring first: I had to stop using
hir::Pat
inhir::TyKind::Pat
and instead create a separateTyPat
that hasConstArg
for range ends instead ofPatExpr
. Within the type system we should be usingConstArg
for all constants, as otherwise we'd be maintaining two separate const systems that could diverge. The big advantage of this PR is that we now inherit all the rules from const generics and don't have a separate system. While this makes things harder for users (const generic rules wrt what is allowed in those consts), it also means we don't accidentally allow some things like referring to assoc consts or doing math on generic consts.