Skip to content

Detect unused "passing self into closure" pattern to side-step borrow checker #109271

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

Closed
estebank opened this issue Mar 17, 2023 · 0 comments · Fixed by #110061
Closed

Detect unused "passing self into closure" pattern to side-step borrow checker #109271

estebank opened this issue Mar 17, 2023 · 0 comments · Fixed by #110061
Assignees
Labels
A-closures Area: Closures (`|…| { … }`) A-diagnostics Area: Messages for errors, warnings, and lints A-lifetimes Area: Lifetimes / regions D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@estebank
Copy link
Contributor

Code

.

Current output

error[E0500]: closure requires unique access to `*self` but it is already borrowed
   --> compiler/rustc_resolve/src/macros.rs:828:25
    |
824 |                       self.visit_scopes(
    |                       -    ------------ first borrow later used by call
    |  _____________________|
    | |
825 | |                         ScopeSet::Macro(MacroKind::Derive),
826 | |                         &parent_scope,
827 | |                         ident.span.ctxt(),
828 | |                         |this, scope, use_prelude, ctxt| {
    | |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ closure construction occurs here
...   |
839 | |                                                     let x = self.get_macro_by_def_id(def_id);
    | |                                                             ---- second borrow occurs due to use of `*self` in closure
...   |
861 | |                         },
862 | |                     );
    | |_____________________- borrow occurs here

Desired output

error[E0500]: closure requires unique access to `*self` but it is already borrowed
   --> compiler/rustc_resolve/src/macros.rs:828:25
    |
824 |                       self.visit_scopes(
    |                       -    ------------ first borrow later used by call
    |  _____________________|
    | |
825 | |                         ScopeSet::Macro(MacroKind::Derive),
826 | |                         &parent_scope,
827 | |                         ident.span.ctxt(),
828 | |                         |this, scope, use_prelude, ctxt| {
    | |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ closure construction occurs here
...   |
839 | |                                                     let x = self.get_macro_by_def_id(def_id);
    | |                                                             ----
    | |                                                             |
    | |                                                             second borrow occurs due to use of `*self` in closure
    | |                                                             help: a closure argument with the same type as `self` is available, you might have meant to use that: `this`
...   |
861 | |                         },
862 | |                     );
    | |_____________________- borrow occurs here

Rationale and extra context

No response

Other cases

No response

Anything else?

No response

@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints A-lifetimes Area: Lifetimes / regions A-closures Area: Closures (`|…| { … }`) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. D-papercut Diagnostics: An error or lint that needs small tweaks. labels Mar 17, 2023
@WaffleLapkin WaffleLapkin self-assigned this Mar 30, 2023
@bors bors closed this as completed in b9fd498 Apr 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-closures Area: Closures (`|…| { … }`) A-diagnostics Area: Messages for errors, warnings, and lints A-lifetimes Area: Lifetimes / regions D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants