Skip to content

Commit 56e849c

Browse files
committed
Avoid &Rc<T> arguments.
Either `&T` or `Rc<T>` is preferable.
1 parent d9975ce commit 56e849c

File tree

7 files changed

+22
-25
lines changed

7 files changed

+22
-25
lines changed

compiler/rustc_borrowck/src/nll.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ pub(crate) fn compute_regions<'a, 'tcx>(
9898

9999
let universal_regions = Rc::new(universal_regions);
100100

101-
let elements = &Rc::new(DenseLocationMap::new(body));
101+
let elements = Rc::new(DenseLocationMap::new(body));
102102

103103
// Run the MIR type-checker.
104104
let MirTypeckResults { constraints, universal_region_relations, opaque_type_values } =
@@ -107,13 +107,13 @@ pub(crate) fn compute_regions<'a, 'tcx>(
107107
param_env,
108108
body,
109109
promoted,
110-
&universal_regions,
110+
universal_regions.clone(),
111111
location_table,
112112
borrow_set,
113113
&mut all_facts,
114114
flow_inits,
115115
move_data,
116-
elements,
116+
elements.clone(),
117117
upvars,
118118
);
119119

@@ -165,7 +165,7 @@ pub(crate) fn compute_regions<'a, 'tcx>(
165165
universe_causes,
166166
type_tests,
167167
liveness_constraints,
168-
elements,
168+
elements.clone(),
169169
);
170170

171171
// If requested: dump NLL facts, and run legacy polonius analysis.

compiler/rustc_borrowck/src/region_infer/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
407407
universe_causes: FxIndexMap<ty::UniverseIndex, UniverseInfo<'tcx>>,
408408
type_tests: Vec<TypeTest<'tcx>>,
409409
liveness_constraints: LivenessValues,
410-
elements: &Rc<DenseLocationMap>,
410+
elements: Rc<DenseLocationMap>,
411411
) -> Self {
412412
debug!("universal_regions: {:#?}", universal_regions);
413413
debug!("outlives constraints: {:#?}", outlives_constraints);
@@ -430,7 +430,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
430430
}
431431

432432
let mut scc_values =
433-
RegionValues::new(elements, universal_regions.len(), &placeholder_indices);
433+
RegionValues::new(elements, universal_regions.len(), placeholder_indices);
434434

435435
for region in liveness_constraints.regions() {
436436
let scc = constraint_sccs.scc(region);

compiler/rustc_borrowck/src/region_infer/values.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -275,15 +275,16 @@ impl<N: Idx> RegionValues<N> {
275275
/// Each of the regions in num_region_variables will be initialized with an
276276
/// empty set of points and no causal information.
277277
pub(crate) fn new(
278-
elements: &Rc<DenseLocationMap>,
278+
elements: Rc<DenseLocationMap>,
279279
num_universal_regions: usize,
280-
placeholder_indices: &Rc<PlaceholderIndices>,
280+
placeholder_indices: Rc<PlaceholderIndices>,
281281
) -> Self {
282+
let num_points = elements.num_points();
282283
let num_placeholders = placeholder_indices.len();
283284
Self {
284-
elements: elements.clone(),
285-
points: SparseIntervalMatrix::new(elements.num_points()),
286-
placeholder_indices: placeholder_indices.clone(),
285+
elements,
286+
points: SparseIntervalMatrix::new(num_points),
287+
placeholder_indices,
287288
free_regions: SparseBitMatrix::new(num_universal_regions),
288289
placeholders: SparseBitMatrix::new(num_placeholders),
289290
}

compiler/rustc_borrowck/src/type_check/free_region_relations.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ pub(crate) fn create<'tcx>(
5454
infcx: &InferCtxt<'tcx>,
5555
param_env: ty::ParamEnv<'tcx>,
5656
implicit_region_bound: ty::Region<'tcx>,
57-
universal_regions: &Rc<UniversalRegions<'tcx>>,
57+
universal_regions: Rc<UniversalRegions<'tcx>>,
5858
constraints: &mut MirTypeckRegionConstraints<'tcx>,
5959
) -> CreateResult<'tcx> {
6060
UniversalRegionRelationsBuilder {
6161
infcx,
6262
param_env,
6363
implicit_region_bound,
6464
constraints,
65-
universal_regions: universal_regions.clone(),
65+
universal_regions,
6666
region_bound_pairs: Default::default(),
6767
outlives: Default::default(),
6868
inverse_outlives: Default::default(),

compiler/rustc_borrowck/src/type_check/liveness/mod.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::rc::Rc;
2-
31
use itertools::{Either, Itertools};
42
use rustc_data_structures::fx::FxHashSet;
53
use rustc_middle::mir::visit::{TyContext, Visitor};
@@ -33,7 +31,7 @@ mod trace;
3331
pub(super) fn generate<'a, 'tcx>(
3432
typeck: &mut TypeChecker<'_, 'tcx>,
3533
body: &Body<'tcx>,
36-
elements: &Rc<DenseLocationMap>,
34+
elements: &DenseLocationMap,
3735
flow_inits: &mut ResultsCursor<'a, 'tcx, MaybeInitializedPlaces<'a, 'tcx>>,
3836
move_data: &MoveData<'tcx>,
3937
) {

compiler/rustc_borrowck/src/type_check/liveness/trace.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::rc::Rc;
2-
31
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
42
use rustc_index::bit_set::BitSet;
53
use rustc_index::interval::IntervalSet;
@@ -40,7 +38,7 @@ use crate::type_check::{NormalizeLocation, TypeChecker};
4038
pub(super) fn trace<'a, 'tcx>(
4139
typeck: &mut TypeChecker<'_, 'tcx>,
4240
body: &Body<'tcx>,
43-
elements: &Rc<DenseLocationMap>,
41+
elements: &DenseLocationMap,
4442
flow_inits: &mut ResultsCursor<'a, 'tcx, MaybeInitializedPlaces<'a, 'tcx>>,
4543
move_data: &MoveData<'tcx>,
4644
relevant_live_locals: Vec<Local>,

compiler/rustc_borrowck/src/type_check/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,13 @@ pub(crate) fn type_check<'a, 'tcx>(
121121
param_env: ty::ParamEnv<'tcx>,
122122
body: &Body<'tcx>,
123123
promoted: &IndexSlice<Promoted, Body<'tcx>>,
124-
universal_regions: &Rc<UniversalRegions<'tcx>>,
124+
universal_regions: Rc<UniversalRegions<'tcx>>,
125125
location_table: &LocationTable,
126126
borrow_set: &BorrowSet<'tcx>,
127127
all_facts: &mut Option<AllFacts>,
128128
flow_inits: &mut ResultsCursor<'a, 'tcx, MaybeInitializedPlaces<'a, 'tcx>>,
129129
move_data: &MoveData<'tcx>,
130-
elements: &Rc<DenseLocationMap>,
130+
elements: Rc<DenseLocationMap>,
131131
upvars: &[&ty::CapturedPlace<'tcx>],
132132
) -> MirTypeckResults<'tcx> {
133133
let implicit_region_bound = ty::Region::new_var(infcx.tcx, universal_regions.fr_fn_body);
@@ -150,14 +150,14 @@ pub(crate) fn type_check<'a, 'tcx>(
150150
infcx,
151151
param_env,
152152
implicit_region_bound,
153-
universal_regions,
153+
universal_regions.clone(),
154154
&mut constraints,
155155
);
156156

157157
debug!(?normalized_inputs_and_output);
158158

159159
let mut borrowck_context = BorrowCheckContext {
160-
universal_regions,
160+
universal_regions: &universal_regions,
161161
location_table,
162162
borrow_set,
163163
all_facts,
@@ -181,10 +181,10 @@ pub(crate) fn type_check<'a, 'tcx>(
181181
verifier.visit_body(body);
182182

183183
checker.typeck_mir(body);
184-
checker.equate_inputs_and_outputs(body, universal_regions, &normalized_inputs_and_output);
184+
checker.equate_inputs_and_outputs(body, &universal_regions, &normalized_inputs_and_output);
185185
checker.check_signature_annotation(body);
186186

187-
liveness::generate(&mut checker, body, elements, flow_inits, move_data);
187+
liveness::generate(&mut checker, body, &elements, flow_inits, move_data);
188188

189189
translate_outlives_facts(&mut checker);
190190
let opaque_type_values = infcx.take_opaque_types();

0 commit comments

Comments
 (0)