-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Rust should explain why a closure call requires a mutable borrow #80313
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
So it looks like this is the function that needs to be modified:
It seems I might be able to get the information I need from |
Actually, |
@rustbot claim |
Is anyone going to work on this issue? If not, I want to work on this to help me learn how Rust works. |
@1000teslas Go ahead! If you need any help, feel free to reach out to me on Zulip or Discord |
I was working on this, but I guess I should have pinged Aaron: https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/finding.20mutated.20upvars.20in.20borrowck. Oh well :) @1000teslas you can work on this, I have other things that I've been meaning to get to anyway. |
@Aaron1011 What is the intended error? Is it meant to point to my_var, similarly to room_ref in #78938? |
Yes - I was thinking of displaying a message like "a mutable borrow is required because the closure modifies |
I'm not sure how given a |
@1000teslas I think the information you need already exists in You can see an example of retrieving this here: rust/compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs Lines 295 to 298 in edeb631
and of using it: rust/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs Lines 591 to 612 in edeb631
I don't think you'll need to access the MIR |
…1011 Point to span of upvar making closure FnMut For rust-lang#80313.
…1011 Point to span of upvar making closure FnMut For rust-lang#80313.
…1011 Point to span of upvar making closure FnMut For rust-lang#80313.
…1011 Point to span of upvar making closure FnMut For rust-lang#80313.
Fixed by #81158 |
Uh oh!
There was an error while loading. Please reload this page.
The following code:
produces the following error:
The expression
callback()
tries to mutably borrowcallback
due to the mutation ofmy_var
. However, the error message doesn't explain this.We should add a note to the error message pointing to the span of the upvar that caused us to need the mutable borrow.
The text was updated successfully, but these errors were encountered: