ExprUseVisitor: Treat ByValue use of Copy types as ImmBorrow#87069
ExprUseVisitor: Treat ByValue use of Copy types as ImmBorrow#87069bors merged 5 commits intorust-lang:masterfrom
Conversation
| match mode { | ||
| ConsumeMode::Move => self.delegate.consume(place_with_id, diag_expr_id, mode), | ||
| ConsumeMode::Copy => { | ||
| self.delegate.borrow(place_with_id, diag_expr_id, ty::BorrowKind::ImmBorrow) |
There was a problem hiding this comment.
Hmm, I had expected to make this change within the upvar delegate, and not the ExprUseVisitor. It seems potentially useful to some clients to know that this was a "by-value copy" -- I think there is other code in clippy that uses this, for example.
There was a problem hiding this comment.
Otherwise we should just remove the ConsumeMode
nikomatsakis
left a comment
There was a problem hiding this comment.
Suggested edit to the comment, and a simplification
| // The value found at `place` is moved, depending | ||
| // on `mode`. Where `diag_expr_id` is the id used for diagnostics for `place`. | ||
| // | ||
| // The parameter `diag_expr_id` indicates the HIR id that ought to be used for | ||
| // diagnostics. Around pattern matching such as `let pat = expr`, the diagnostic | ||
| // id will be the id of the expression `expr` but the place itself will have | ||
| // the id of the binding in the pattern `pat`. |
There was a problem hiding this comment.
| // The value found at `place` is moved, depending | |
| // on `mode`. Where `diag_expr_id` is the id used for diagnostics for `place`. | |
| // | |
| // The parameter `diag_expr_id` indicates the HIR id that ought to be used for | |
| // diagnostics. Around pattern matching such as `let pat = expr`, the diagnostic | |
| // id will be the id of the expression `expr` but the place itself will have | |
| // the id of the binding in the pattern `pat`. | |
| // The value found at `place` is moved, meaning that it is used by value | |
| // and is not known to have `Copy` type. | |
| // | |
| // If a value is used by value but *does* have `Copy` type, that is treated as a | |
| // "shared borrow". This corresponds to the minimal access that a closure needs | |
| // to perform that operation (a shared reference). | |
| // | |
| // The parameter `diag_expr_id` indicates the HIR id that ought to be used for | |
| // diagnostics. Around pattern matching such as `let pat = expr`, the diagnostic | |
| // id will be the id of the expression `expr` but the place itself will have | |
| // the id of the binding in the pattern `pat`. |
There was a problem hiding this comment.
I didn't add the detail about closures because ExprUseVisitor and therefore this delegate is used in other contexts too
| let mode = copy_or_move(mc, &place); | ||
| match mode { | ||
| ConsumeMode::Move => delegate.consume(place, discr_place.hir_id), | ||
| ConsumeMode::Copy => delegate.borrow( | ||
| place, | ||
| discr_place.hir_id, | ||
| ty::BorrowKind::ImmBorrow, | ||
| ), | ||
| } |
There was a problem hiding this comment.
| let mode = copy_or_move(mc, &place); | |
| match mode { | |
| ConsumeMode::Move => delegate.consume(place, discr_place.hir_id), | |
| ConsumeMode::Copy => delegate.borrow( | |
| place, | |
| discr_place.hir_id, | |
| ty::BorrowKind::ImmBorrow, | |
| ), | |
| } | |
| self.delegate_consume(place, discr_place.hir_id); |
Does this not work?
There was a problem hiding this comment.
we need 2229 enabled to make this work 🙃. The closure is passed to self.mc. I'll just refactor into a helper.
63c5900 to
c4ac836
Compare
|
@bors r+ |
|
📌 Commit 75291ee has been approved by |
…matsakis ExprUseVisitor: Treat ByValue use of Copy types as ImmBorrow r? `@nikomatsakis`
…matsakis ExprUseVisitor: Treat ByValue use of Copy types as ImmBorrow r? ``@nikomatsakis``
…laumeGomez Rollup of 7 pull requests Successful merges: - rust-lang#86983 (Add or improve natvis definitions for common standard library types) - rust-lang#87069 (ExprUseVisitor: Treat ByValue use of Copy types as ImmBorrow) - rust-lang#87138 (Correct invariant documentation for `steps_between`) - rust-lang#87145 (Make --cap-lints and related options leave crate hash alone) - rust-lang#87161 (RFC2229: Use the correct place type) - rust-lang#87162 (Fix type decl layout "overflow") - rust-lang#87167 (Fix sidebar display on small devices) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
…matsakis ExprUseVisitor: Treat ByValue use of Copy types as ImmBorrow r? ```@nikomatsakis```
r? @nikomatsakis