Check closure's constness validity in the constness query#155772
Check closure's constness validity in the constness query#155772rust-bors[bot] merged 2 commits intorust-lang:mainfrom
Conversation
|
r? @mati865 rustbot has assigned @mati865. Use Why was this reviewer chosen?The reviewer was selected based on:
|
| | | ||
| LL | (const || { (()).foo() })(); | ||
| | ^^^^^ | ||
| | ^^^^^^^^ |
There was a problem hiding this comment.
The only downside of this PR is that we highlight more than the const part of the closure now
| Node::Expr(e) if let ExprKind::Closure(c) = e.kind => { | ||
| match c.constness { | ||
| Constness::Const => if tcx.hir_body_const_context(tcx.local_parent(def_id)).is_none() { | ||
| tcx.dcx().span_err(tcx.def_span(def_id), "cannot use `const` closures outside of const contexts"); |
There was a problem hiding this comment.
A hacky way could be to use https://doc.rust-lang.org/stable/nightly-rustc/rustc_span/source_map/struct.SourceMap.html#method.span_until_whitespace since we always know that const is the first keyword (for now).
But this is not necessary
| match c.constness { | ||
| Constness::Const => if tcx.hir_body_const_context(tcx.local_parent(def_id)).is_none() { |
There was a problem hiding this comment.
I would use if let Constness::Const = c.constness && tcx.hir_body_const_context(tcx.local_parent(def_id)).is_none() here
|
Reminder, once the PR becomes ready for a review, use |
ee5b899 to
415454f
Compare
|
@bors r=fee1-dead rollup |
This comment has been minimized.
This comment has been minimized.
415454f to
ae91b21
Compare
This comment has been minimized.
This comment has been minimized.
|
@bors r=fee1-dead rollup |
This comment has been minimized.
This comment has been minimized.
… r=fee1-dead Check closure's constness validity in the constness query fixes rust-lang#155584 instead of checking during ast lowering, where it's not easily possible to obtain all the right information in time. While lowering an assoc item we don't know if the parent was a const trait or a const impl. Tracing this information is quite annoying, and complicates a lot of code, which checking here after the fact is trivial.
|
This pull request was unapproved. This PR was contained in a rollup (#155791), which was unapproved. |
instead of during ast lowering, where it's not easily possible to obtain all the right information in time
ae91b21 to
8e1c34f
Compare
|
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. |
|
@bors r=fee1-dead rollup |
|
⌛ Testing commit 8e1c34f with merge 7a841ad... Workflow: https://github.com/rust-lang/rust/actions/runs/24978916136 |
… r=fee1-dead Check closure's constness validity in the constness query fixes rust-lang#155584 instead of checking during ast lowering, where it's not easily possible to obtain all the right information in time. While lowering an assoc item we don't know if the parent was a const trait or a const impl. Tracing this information is quite annoying, and complicates a lot of code, which checking here after the fact is trivial.
Check closure's constness validity in the constness query fixes #155584 instead of checking during ast lowering, where it's not easily possible to obtain all the right information in time. While lowering an assoc item we don't know if the parent was a const trait or a const impl. Tracing this information is quite annoying, and complicates a lot of code, which checking here after the fact is trivial.
|
@bors yield to encompassing rollup |
|
Auto build was cancelled. Cancelled workflows: The next pull request likely to be tested is #155857. |
|
⌛ Testing commit 8e1c34f with merge 786c9b5... Workflow: https://github.com/rust-lang/rust/actions/runs/24982905857 |
Check closure's constness validity in the constness query fixes #155584 instead of checking during ast lowering, where it's not easily possible to obtain all the right information in time. While lowering an assoc item we don't know if the parent was a const trait or a const impl. Tracing this information is quite annoying, and complicates a lot of code, which checking here after the fact is trivial.
|
once again after a spurious failure @bors yield |
|
Auto build was cancelled. Cancelled workflows: The next pull request likely to be tested is #155863. |
Rollup merge of #155772 - oli-obk:const-closures-everywhere, r=fee1-dead Check closure's constness validity in the constness query fixes #155584 instead of checking during ast lowering, where it's not easily possible to obtain all the right information in time. While lowering an assoc item we don't know if the parent was a const trait or a const impl. Tracing this information is quite annoying, and complicates a lot of code, which checking here after the fact is trivial.
View all comments
fixes #155584
instead of checking during ast lowering, where it's not easily possible to obtain all the right information in time. While lowering an assoc item we don't know if the parent was a const trait or a const impl. Tracing this information is quite annoying, and complicates a lot of code, which checking here after the fact is trivial.