Emit ForbiddenBound for bounds of type params when parsing higher ranked binders#149728
Emit ForbiddenBound for bounds of type params when parsing higher ranked binders#149728mu001999 wants to merge 1 commit intorust-lang:mainfrom
Conversation
|
r? @wesleywiser rustbot has assigned @wesleywiser. Use |
This comment has been minimized.
This comment has been minimized.
|
@rustbot reroll |
|
@rustbot author |
|
Reminder, once the PR becomes ready for a review, use |
|
@rustbot review |
|
@rusbot author |
|
@rustbot blocked on #149728 (comment) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Hi @jdonszelmann, in the lastest rough change, I tried to filter nested items in the bound, and not lower them to hir.
But there still be errors, because they still have Concrete content of the new ICE is: |
|
I think at least it's more difficult than I expected. Do you have any suggestions? |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@rustbot ready |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
another alternative would be to actually lower where-bounds on binders to the HIR, or to already error on them when creating the AST before we collect the I personally feel like erroring pre def-collection might be better 🤔 haven't interacted with this code much so I am not sure :> |
Make sense, I think I could move the check in |
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Some changes occurred in src/tools/rustfmt cc @rust-lang/rustfmt |
This comment has been minimized.
This comment has been minimized.
|
@mu001999 is this ready for review? I think doing it like this is quite reasonable, and we don't error fatally which is nice. |
yep, it's ready :) |
|
r=me after that |
|
|
||
| for param in params { | ||
| if !param.bounds.is_empty() { | ||
| if !matches!(param.kind, ast::GenericParamKind::Type { .. }) && !param.bounds.is_empty() |
There was a problem hiding this comment.
This check is the same as one below
There was a problem hiding this comment.
No, they are different. This is !matches!(param.kind, ast::GenericParamKind::Type { .. }), the below is matches!(param.kind, ast::GenericParamKind::Type { .. })
| let params = params | ||
| .into_iter() | ||
| .map(|mut param| { | ||
| if matches!(param.kind, ast::GenericParamKind::Type { .. }) |
There was a problem hiding this comment.
This one. Might be nice to split out?
There was a problem hiding this comment.
Into a .is_forbidden_bound or whatever
There was a problem hiding this comment.
As the above, .is_forbidden_bound will only check !param.bounds.is_empty() in fact
View all comments
Fixes #149695
Bounds in binders are denied, hir items won't contain and index them. But nested items in the bounds will still be lowered to hir. And their parents, i.e., the block in bounds is not in hir. So that ICE happens when error handling requires visiting hir parents.
This PR collects hirless def ids and skips them when iterating parents.This PR checks such bounds used in higher ranked binders and emit error
ForbiddenBoundwhen parsing. And make sure no such bounds appear in hir.