`move` needed in closure within `gen` block isn't being suggested
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
With the following in CrateMetadata (compiler/rustc_metadata/src/rmeta/decoder.rs), where we are using generators that need a move:
pub(crate) fn proc_macros_for_crate(
&self,
krate: CrateNum,
cstore: &CStore,
) -> impl Iterator<Item = DefId> {
gen move {
for def_id in self.root.proc_macro_data.as_ref().into_iter().flat_map(|data| {
data.macros
.decode(CrateMetadataRef { cdata: self, cstore })
.map(move |index| DefId { index, krate })
}) {
yield def_id;
}
}
}
we currently emit
error[E0626]: borrow may still be in use when `gen` block yields
--> compiler/rustc_metadata/src/rmeta/decoder.rs:2026:49
|
2022 | gen move {
| -------- within this `gen` block
...
2026 | .map(|index| DefId { index, krate })
| ^^^^^
2027 | }) {
2028 | yield def_id;
| ------------ possible yield occurs here
which doesn't suggest .map(move |index| DefId { index, krate }).
If we remove any of the other move for the other closure or the gen, we do get the appropriate suggestion.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in compiler/rustc_metadata/src/rmeta/decoder.rs at CrateMetadata::proc_macros_for_crate and reproduce the E0626 diagnostic from the shown gen block. Trace how the compiler handles move suggestions for closures inside gen blocks, comparing this case with the variants where a suggestion is emitted. Done means the diagnostic suggests .map(move |index| DefId { index, krate }) for the reported example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100