Skip to content

move needed in closure within gen block isn't being suggested #145461

@estebank

Description

@estebank

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`D-lack-of-suggestionDiagnostics: Adding a (structured) suggestion would increase the quality of the diagnostic.F-gen_blocks`gen {}` expressions that produce `Iterator`sT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions