Skip to content

Commit 846d4f0

Browse files
committed
Auto merge of #82536 - sexxi-goose:handle-patterns-take-2, r=nikomatsakis
2229: Handle patterns within closures correctly when `capture_disjoint_fields` is enabled This PR fixes several issues related to handling patterns within closures when `capture_disjoint_fields` is enabled. 1. Matching is always considered a use of the place, even with `_` patterns 2. Compiler ICE when capturing fields in closures through `let` assignments To do so, we - Introduced new Fake Reads - Delayed use of `Place` in favor of `PlaceBuilder` - Ensured that `PlaceBuilder` can be resolved before attempting to extract `Place` in any of the pattern matching code Closes rust-lang/project-rfc-2229/issues/27 Closes rust-lang/project-rfc-2229/issues/24 r? `@nikomatsakis`
2 parents 1d57c3e + 9d5daa6 commit 846d4f0

File tree

4 files changed

+12
-0
lines changed

4 files changed

+12
-0
lines changed

clippy_lints/src/escape.rs

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use rustc_hir::intravisit;
22
use rustc_hir::{self, AssocItemKind, Body, FnDecl, HirId, HirIdSet, Impl, ItemKind, Node};
33
use rustc_infer::infer::TyCtxtInferExt;
44
use rustc_lint::{LateContext, LateLintPass};
5+
use rustc_middle::mir::FakeReadCause;
56
use rustc_middle::ty::{self, TraitRef, Ty};
67
use rustc_session::{declare_tool_lint, impl_lint_pass};
78
use rustc_span::source_map::Span;
@@ -184,6 +185,8 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
184185
}
185186
}
186187
}
188+
189+
fn fake_read(&mut self, _: rustc_typeck::expr_use_visitor::Place<'tcx>, _: FakeReadCause, _: HirId) { }
187190
}
188191

189192
impl<'a, 'tcx> EscapeDelegate<'a, 'tcx> {

clippy_lints/src/loops/mut_range_bound.rs

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use if_chain::if_chain;
44
use rustc_hir::{BindingAnnotation, Expr, HirId, Node, PatKind};
55
use rustc_infer::infer::TyCtxtInferExt;
66
use rustc_lint::LateContext;
7+
use rustc_middle::mir::FakeReadCause;
78
use rustc_middle::ty;
89
use rustc_span::source_map::Span;
910
use rustc_typeck::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId};
@@ -106,6 +107,8 @@ impl<'tcx> Delegate<'tcx> for MutatePairDelegate<'_, 'tcx> {
106107
}
107108
}
108109
}
110+
111+
fn fake_read(&mut self, _: rustc_typeck::expr_use_visitor::Place<'tcx>, _: FakeReadCause, _:HirId) { }
109112
}
110113

111114
impl MutatePairDelegate<'_, '_> {

clippy_lints/src/needless_pass_by_value.rs

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use rustc_hir::intravisit::FnKind;
1111
use rustc_hir::{BindingAnnotation, Body, FnDecl, GenericArg, HirId, Impl, ItemKind, Node, PatKind, QPath, TyKind};
1212
use rustc_infer::infer::TyCtxtInferExt;
1313
use rustc_lint::{LateContext, LateLintPass};
14+
use rustc_middle::mir::FakeReadCause;
1415
use rustc_middle::ty::{self, TypeFoldable};
1516
use rustc_session::{declare_lint_pass, declare_tool_lint};
1617
use rustc_span::symbol::kw;
@@ -333,4 +334,6 @@ impl<'tcx> euv::Delegate<'tcx> for MovedVariablesCtxt {
333334
fn borrow(&mut self, _: &euv::PlaceWithHirId<'tcx>, _: HirId, _: ty::BorrowKind) {}
334335

335336
fn mutate(&mut self, _: &euv::PlaceWithHirId<'tcx>, _: HirId) {}
337+
338+
fn fake_read(&mut self, _: rustc_typeck::expr_use_visitor::Place<'tcx>, _: FakeReadCause, _: HirId) { }
336339
}

clippy_utils/src/usage.rs

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use rustc_hir::intravisit::{NestedVisitorMap, Visitor};
77
use rustc_hir::{Expr, ExprKind, HirId, Path};
88
use rustc_infer::infer::TyCtxtInferExt;
99
use rustc_lint::LateContext;
10+
use rustc_middle::mir::FakeReadCause;
1011
use rustc_middle::hir::map::Map;
1112
use rustc_middle::ty;
1213
use rustc_typeck::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId};
@@ -77,6 +78,8 @@ impl<'tcx> Delegate<'tcx> for MutVarsDelegate {
7778
fn mutate(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId) {
7879
self.update(&cmt)
7980
}
81+
82+
fn fake_read(&mut self, _: rustc_typeck::expr_use_visitor::Place<'tcx>, _: FakeReadCause, _:HirId) { }
8083
}
8184

8285
pub struct ParamBindingIdCollector {

0 commit comments

Comments
 (0)