Skip to content

Commit 62a9d29

Browse files
committed
Parametrize gather_moves by filter.
1 parent 2a29b20 commit 62a9d29

File tree

6 files changed

+231
-158
lines changed

6 files changed

+231
-158
lines changed

compiler/rustc_borrowck/src/lib.rs

+36-4
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use rustc_middle::mir::tcx::PlaceTy;
3333
use rustc_middle::mir::*;
3434
use rustc_middle::query::Providers;
3535
use rustc_middle::traits::DefiningAnchor;
36-
use rustc_middle::ty::{self, CapturedPlace, ParamEnv, RegionVid, TyCtxt};
36+
use rustc_middle::ty::{self, Ty, CapturedPlace, ParamEnv, RegionVid, TyCtxt};
3737
use rustc_session::lint::builtin::UNUSED_MUT;
3838
use rustc_span::{Span, Symbol};
3939
use rustc_target::abi::FieldIdx;
@@ -48,7 +48,7 @@ use rustc_mir_dataflow::impls::{
4848
EverInitializedPlaces, MaybeInitializedPlaces, MaybeUninitializedPlaces,
4949
};
5050
use rustc_mir_dataflow::move_paths::{InitIndex, MoveOutIndex, MovePathIndex};
51-
use rustc_mir_dataflow::move_paths::{InitLocation, LookupResult, MoveData};
51+
use rustc_mir_dataflow::move_paths::{InitLocation, LookupResult, MoveData, PathFilter};
5252
use rustc_mir_dataflow::Analysis;
5353
use rustc_mir_dataflow::MoveDataParamEnv;
5454

@@ -215,10 +215,42 @@ fn do_mir_borrowck<'tcx>(
215215
let location_table_owned = LocationTable::new(body);
216216
let location_table = &location_table_owned;
217217

218-
let move_data = MoveData::gather_moves(&body, tcx, param_env);
218+
let move_path_filter = |ty: Ty<'tcx>| match ty.kind() {
219+
ty::Ref(..) | ty::RawPtr(..) | ty::Slice(_) => PathFilter::Leaf,
220+
ty::Adt(adt, _) => {
221+
if adt.has_dtor(tcx) && !adt.is_box() {
222+
PathFilter::Leaf
223+
} else {
224+
PathFilter::Create
225+
}
226+
}
227+
ty::Bool
228+
| ty::Char
229+
| ty::Int(_)
230+
| ty::Uint(_)
231+
| ty::Float(_)
232+
| ty::Foreign(_)
233+
| ty::Str
234+
| ty::Array(_, _)
235+
| ty::FnDef(_, _)
236+
| ty::FnPtr(_)
237+
| ty::Dynamic(_, _, _)
238+
| ty::Closure(_, _)
239+
| ty::Generator(_, _, _)
240+
| ty::GeneratorWitness(..)
241+
| ty::Never
242+
| ty::Tuple(_)
243+
| ty::Alias(_, _)
244+
| ty::Param(_)
245+
| ty::Bound(_, _)
246+
| ty::Infer(_)
247+
| ty::Error(_)
248+
| ty::Placeholder(_) => PathFilter::Create,
249+
};
250+
let move_data = MoveData::gather_moves(&body, tcx, param_env, move_path_filter);
219251
let promoted_move_data = promoted
220252
.iter_enumerated()
221-
.map(|(idx, body)| (idx, MoveData::gather_moves(&body, tcx, param_env)));
253+
.map(|(idx, body)| (idx, MoveData::gather_moves(&body, tcx, param_env, move_path_filter)));
222254

223255
let mdpe = MoveDataParamEnv { move_data, param_env };
224256

0 commit comments

Comments
 (0)