-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Suggest borrowing when doing if let Some(_)
from non-Copy ADT
#63988
Comments
@estebank can you elaborate on the message you expect to see here? Something like
perhaps? |
@ayazhafiz I believe we should aim at:
|
I took a look at this today. I am a first-time contributor to this project and would like to contribute this enhancement, but I'm not sure how much work this will end up requiring. Here are some notes/leads I've noticed; I'm hoping someone may be able to provide suggestions, and at the very least I hope this is helpful for anyone else wishing to tackle this. Consider the example provided in the first comment of this issue (abbreviated for example):
This error message is generated by rust/src/librustc_mir/borrow_check/conflict_errors.rs Lines 47 to 53 in a6624ed
This function knows about the erroring span (where the value is borrowed after a move; It's not immediately clear to me that it's easy to recover the span of the RHS of rust/src/librustc_mir/dataflow/move_paths/mod.rs Lines 100 to 102 in 7eb65df
rust/src/librustc_mir/dataflow/move_paths/mod.rs Lines 156 to 168 in 7eb65df
I have a feeling that a Looking from the top-down is interesting but doesn't seem too useful. One of the lower-stack callers that generates this error is rust/src/librustc_mir/borrow_check/mod.rs Lines 1218 to 1261 in 7eb65df
Which does exactly what it sounds like, consuming an rvalue (seemingly Right now, I think looking at |
When encountering an used moved value where the previous move happened in a `match` or `if let` pattern, suggest using `ref`. Fix rust-lang#63988. When encountering a `&mut` value that is used in multiple iterations of a loop, suggest reborrowing it with `&mut *`. Fix rust-lang#62112.
…tthewjasper Provide suggestions for some moved value errors When encountering an used moved value where the previous move happened in a `match` or `if let` pattern, suggest using `ref`. Fix rust-lang#63988. When encountering a `&mut` value that is used in multiple iterations of a loop, suggest reborrowing it with `&mut *`. Fix rust-lang#62112.
…tthewjasper Provide suggestions for some moved value errors When encountering an used moved value where the previous move happened in a `match` or `if let` pattern, suggest using `ref`. Fix rust-lang#63988. When encountering a `&mut` value that is used in multiple iterations of a loop, suggest reborrowing it with `&mut *`. Fix rust-lang#62112.
…tthewjasper Provide suggestions for some moved value errors When encountering an used moved value where the previous move happened in a `match` or `if let` pattern, suggest using `ref`. Fix rust-lang#63988. When encountering a `&mut` value that is used in multiple iterations of a loop, suggest reborrowing it with `&mut *`. Fix rust-lang#62112.
…tthewjasper Provide suggestions for some moved value errors When encountering an used moved value where the previous move happened in a `match` or `if let` pattern, suggest using `ref`. Fix rust-lang#63988. When encountering a `&mut` value that is used in multiple iterations of a loop, suggest reborrowing it with `&mut *`. Fix rust-lang#62112.
…tthewjasper Provide suggestions for some moved value errors When encountering an used moved value where the previous move happened in a `match` or `if let` pattern, suggest using `ref`. Fix rust-lang#63988. When encountering a `&mut` value that is used in multiple iterations of a loop, suggest reborrowing it with `&mut *`. Fix rust-lang#62112.
Just got this error:
It should suggest to borrow
x
.The text was updated successfully, but these errors were encountered: