Skip to content

Commit b8135fd

Browse files
committed
add #[rustc_pass_by_value] to more types
1 parent 67b3e81 commit b8135fd

File tree

27 files changed

+165
-152
lines changed

27 files changed

+165
-152
lines changed

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
220220
PlaceRef {
221221
local,
222222
projection:
223-
[
224-
proj_base @ ..,
223+
&[
224+
ref proj_base @ ..,
225225
ProjectionElem::Deref,
226226
ProjectionElem::Field(field, _),
227227
ProjectionElem::Deref,
@@ -342,7 +342,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
342342
Applicability::MachineApplicable,
343343
);
344344
let tcx = self.infcx.tcx;
345-
if let ty::Closure(id, _) = the_place_err.ty(self.body, tcx).ty.kind() {
345+
if let ty::Closure(id, _) = *the_place_err.ty(self.body, tcx).ty.kind() {
346346
self.show_mutating_upvar(tcx, id, the_place_err, &mut err);
347347
}
348348
}
@@ -382,7 +382,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
382382
let tcx = self.infcx.tcx;
383383
if let ty::Ref(_, ty, Mutability::Mut) = the_place_err.ty(self.body, tcx).ty.kind()
384384
{
385-
if let ty::Closure(id, _) = ty.kind() {
385+
if let ty::Closure(id, _) = *ty.kind() {
386386
self.show_mutating_upvar(tcx, id, the_place_err, &mut err);
387387
}
388388
}
@@ -687,7 +687,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
687687
fn show_mutating_upvar(
688688
&self,
689689
tcx: TyCtxt<'_>,
690-
id: &hir::def_id::DefId,
690+
id: hir::def_id::DefId,
691691
the_place_err: PlaceRef<'tcx>,
692692
err: &mut Diagnostic,
693693
) {
@@ -701,7 +701,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
701701
let upvar = ty::place_to_string_for_capture(tcx, closure_kind_origin);
702702
let root_hir_id = upvar_id.var_path.hir_id;
703703
// we have an origin for this closure kind starting at this root variable so it's safe to unwrap here
704-
let captured_places = tables.closure_min_captures[id].get(&root_hir_id).unwrap();
704+
let captured_places = tables.closure_min_captures[&id].get(&root_hir_id).unwrap();
705705

706706
let origin_projection = closure_kind_origin
707707
.projections
@@ -1083,7 +1083,7 @@ fn is_closure_or_generator(ty: Ty<'_>) -> bool {
10831083
fn get_mut_span_in_struct_field<'tcx>(
10841084
tcx: TyCtxt<'tcx>,
10851085
ty: Ty<'tcx>,
1086-
field: &mir::Field,
1086+
field: mir::Field,
10871087
) -> Option<Span> {
10881088
// Expect our local to be a reference to a struct of some kind.
10891089
if let ty::Ref(_, ty, _) = ty.kind()

compiler/rustc_borrowck/src/location.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl LocationTable {
100100
}
101101

102102
impl LocationIndex {
103-
fn is_start(&self) -> bool {
103+
fn is_start(self) -> bool {
104104
// even indices are start points; odd indices are mid points
105105
(self.index() % 2) == 0
106106
}

compiler/rustc_borrowck/src/nll.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ fn populate_polonius_move_facts(
8585
) {
8686
all_facts
8787
.path_is_var
88-
.extend(move_data.rev_lookup.iter_locals_enumerated().map(|(v, &m)| (m, v)));
88+
.extend(move_data.rev_lookup.iter_locals_enumerated().map(|(l, r)| (r, l)));
8989

9090
for (child, move_path) in move_data.move_paths.iter_enumerated() {
9191
if let Some(parent) = move_path.parent {
@@ -135,7 +135,7 @@ fn populate_polonius_move_facts(
135135
}
136136
}
137137

138-
for (local, &path) in move_data.rev_lookup.iter_locals_enumerated() {
138+
for (local, path) in move_data.rev_lookup.iter_locals_enumerated() {
139139
if body.local_kind(local) != LocalKind::Arg {
140140
// Non-arguments start out deinitialised; we simulate this with an
141141
// initial move:
@@ -226,7 +226,7 @@ pub(crate) fn compute_regions<'cx, 'tcx>(
226226
fr1={:?}, fr2={:?}",
227227
fr1, fr2
228228
);
229-
all_facts.known_placeholder_subset.push((*fr1, *fr2));
229+
all_facts.known_placeholder_subset.push((fr1, fr2));
230230
}
231231
}
232232
}

compiler/rustc_borrowck/src/region_infer/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -942,14 +942,14 @@ impl<'tcx> RegionInferenceContext<'tcx> {
942942

943943
debug!("try_promote_type_test: ur={:?}", ur);
944944

945-
let non_local_ub = self.universal_region_relations.non_local_upper_bounds(&ur);
945+
let non_local_ub = self.universal_region_relations.non_local_upper_bounds(ur);
946946
debug!("try_promote_type_test: non_local_ub={:?}", non_local_ub);
947947

948948
// This is slightly too conservative. To show T: '1, given `'2: '1`
949949
// and `'3: '1` we only need to prove that T: '2 *or* T: '3, but to
950950
// avoid potential non-determinism we approximate this by requiring
951951
// T: '1 and T: '2.
952-
for &upper_bound in non_local_ub {
952+
for upper_bound in non_local_ub {
953953
debug_assert!(self.universal_regions.is_universal_region(upper_bound));
954954
debug_assert!(!self.universal_regions.is_local_free_region(upper_bound));
955955

@@ -1588,12 +1588,12 @@ impl<'tcx> RegionInferenceContext<'tcx> {
15881588
// always will.) We'll call them `shorter_fr+` -- they're ever
15891589
// so slightly larger than `shorter_fr`.
15901590
let shorter_fr_plus =
1591-
self.universal_region_relations.non_local_upper_bounds(&shorter_fr);
1591+
self.universal_region_relations.non_local_upper_bounds(shorter_fr);
15921592
debug!(
15931593
"try_propagate_universal_region_error: shorter_fr_plus={:?}",
15941594
shorter_fr_plus
15951595
);
1596-
for &&fr in &shorter_fr_plus {
1596+
for fr in shorter_fr_plus {
15971597
// Push the constraint `fr-: shorter_fr+`
15981598
propagated_outlives_requirements.push(ClosureOutlivesRequirement {
15991599
subject: ClosureOutlivesSubject::Region(fr_minus),

compiler/rustc_borrowck/src/type_check/free_region_relations.rs

+16-17
Original file line numberDiff line numberDiff line change
@@ -99,18 +99,17 @@ impl UniversalRegionRelations<'_> {
9999
crate fn postdom_upper_bound(&self, fr1: RegionVid, fr2: RegionVid) -> RegionVid {
100100
assert!(self.universal_regions.is_universal_region(fr1));
101101
assert!(self.universal_regions.is_universal_region(fr2));
102-
*self
103-
.inverse_outlives
104-
.postdom_upper_bound(&fr1, &fr2)
105-
.unwrap_or(&self.universal_regions.fr_static)
102+
self.inverse_outlives
103+
.postdom_upper_bound(fr1, fr2)
104+
.unwrap_or(self.universal_regions.fr_static)
106105
}
107106

108107
/// Finds an "upper bound" for `fr` that is not local. In other
109108
/// words, returns the smallest (*) known region `fr1` that (a)
110109
/// outlives `fr` and (b) is not local.
111110
///
112111
/// (*) If there are multiple competing choices, we return all of them.
113-
crate fn non_local_upper_bounds<'a>(&'a self, fr: &'a RegionVid) -> Vec<&'a RegionVid> {
112+
crate fn non_local_upper_bounds<'a>(&'a self, fr: RegionVid) -> Vec<RegionVid> {
114113
debug!("non_local_upper_bound(fr={:?})", fr);
115114
let res = self.non_local_bounds(&self.inverse_outlives, fr);
116115
assert!(!res.is_empty(), "can't find an upper bound!?");
@@ -120,7 +119,7 @@ impl UniversalRegionRelations<'_> {
120119
/// Returns the "postdominating" bound of the set of
121120
/// `non_local_upper_bounds` for the given region.
122121
crate fn non_local_upper_bound(&self, fr: RegionVid) -> RegionVid {
123-
let upper_bounds = self.non_local_upper_bounds(&fr);
122+
let upper_bounds = self.non_local_upper_bounds(fr);
124123

125124
// In case we find more than one, reduce to one for
126125
// convenience. This is to prevent us from generating more
@@ -130,7 +129,7 @@ impl UniversalRegionRelations<'_> {
130129
debug!("non_local_bound: post_dom={:?}", post_dom);
131130

132131
post_dom
133-
.and_then(|&post_dom| {
132+
.and_then(|post_dom| {
134133
// If the mutual immediate postdom is not local, then
135134
// there is no non-local result we can return.
136135
if !self.universal_regions.is_local_free_region(post_dom) {
@@ -150,7 +149,7 @@ impl UniversalRegionRelations<'_> {
150149
/// one. See `TransitiveRelation::postdom_upper_bound` for details.
151150
crate fn non_local_lower_bound(&self, fr: RegionVid) -> Option<RegionVid> {
152151
debug!("non_local_lower_bound(fr={:?})", fr);
153-
let lower_bounds = self.non_local_bounds(&self.outlives, &fr);
152+
let lower_bounds = self.non_local_bounds(&self.outlives, fr);
154153

155154
// In case we find more than one, reduce to one for
156155
// convenience. This is to prevent us from generating more
@@ -159,7 +158,7 @@ impl UniversalRegionRelations<'_> {
159158

160159
debug!("non_local_bound: post_dom={:?}", post_dom);
161160

162-
post_dom.and_then(|&post_dom| {
161+
post_dom.and_then(|post_dom| {
163162
// If the mutual immediate postdom is not local, then
164163
// there is no non-local result we can return.
165164
if !self.universal_regions.is_local_free_region(post_dom) {
@@ -176,19 +175,19 @@ impl UniversalRegionRelations<'_> {
176175
fn non_local_bounds<'a>(
177176
&self,
178177
relation: &'a TransitiveRelation<RegionVid>,
179-
fr0: &'a RegionVid,
180-
) -> Vec<&'a RegionVid> {
178+
fr0: RegionVid,
179+
) -> Vec<RegionVid> {
181180
// This method assumes that `fr0` is one of the universally
182181
// quantified region variables.
183-
assert!(self.universal_regions.is_universal_region(*fr0));
182+
assert!(self.universal_regions.is_universal_region(fr0));
184183

185184
let mut external_parents = vec![];
186185
let mut queue = vec![fr0];
187186

188187
// Keep expanding `fr` into its parents until we reach
189188
// non-local regions.
190189
while let Some(fr) = queue.pop() {
191-
if !self.universal_regions.is_local_free_region(*fr) {
190+
if !self.universal_regions.is_local_free_region(fr) {
192191
external_parents.push(fr);
193192
continue;
194193
}
@@ -205,17 +204,17 @@ impl UniversalRegionRelations<'_> {
205204
///
206205
/// This will only ever be true for universally quantified regions.
207206
crate fn outlives(&self, fr1: RegionVid, fr2: RegionVid) -> bool {
208-
self.outlives.contains(&fr1, &fr2)
207+
self.outlives.contains(fr1, fr2)
209208
}
210209

211210
/// Returns a vector of free regions `x` such that `fr1: x` is
212211
/// known to hold.
213-
crate fn regions_outlived_by(&self, fr1: RegionVid) -> Vec<&RegionVid> {
214-
self.outlives.reachable_from(&fr1)
212+
crate fn regions_outlived_by(&self, fr1: RegionVid) -> Vec<RegionVid> {
213+
self.outlives.reachable_from(fr1)
215214
}
216215

217216
/// Returns the _non-transitive_ set of known `outlives` constraints between free regions.
218-
crate fn known_outlives(&self) -> impl Iterator<Item = (&RegionVid, &RegionVid)> {
217+
crate fn known_outlives(&self) -> impl Iterator<Item = (RegionVid, RegionVid)> + '_ {
219218
self.outlives.base_edges()
220219
}
221220
}

compiler/rustc_borrowck/src/type_check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
11981198
tcx,
11991199
self.param_env,
12001200
proj,
1201-
|this, field, &()| {
1201+
|this, field, ()| {
12021202
let ty = this.field_ty(tcx, field);
12031203
self.normalize(ty, locations)
12041204
},

compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl<'ll, 'tcx> CoverageInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
9090
/// call. Since the function is never called, all other `CodeRegion`s can be
9191
/// added as `unreachable_region`s.
9292
fn define_unused_fn(&self, def_id: DefId) {
93-
let instance = declare_unused_fn(self, &def_id);
93+
let instance = declare_unused_fn(self, def_id);
9494
codegen_unused_fn_and_counter(self, instance);
9595
add_unused_function_coverage(self, instance, def_id);
9696
}
@@ -184,12 +184,12 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
184184
}
185185
}
186186

187-
fn declare_unused_fn<'tcx>(cx: &CodegenCx<'_, 'tcx>, def_id: &DefId) -> Instance<'tcx> {
187+
fn declare_unused_fn<'tcx>(cx: &CodegenCx<'_, 'tcx>, def_id: DefId) -> Instance<'tcx> {
188188
let tcx = cx.tcx;
189189

190190
let instance = Instance::new(
191-
*def_id,
192-
InternalSubsts::for_item(tcx, *def_id, |param, _| {
191+
def_id,
192+
InternalSubsts::for_item(tcx, def_id, |param, _| {
193193
if let ty::GenericParamDefKind::Lifetime = param.kind {
194194
tcx.lifetimes.re_erased.into()
195195
} else {

compiler/rustc_data_structures/src/transitive_relation.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ struct Edge {
4949
target: Index,
5050
}
5151

52-
impl<T: Eq + Hash> TransitiveRelation<T> {
52+
impl<T: Eq + Hash + Copy> TransitiveRelation<T> {
5353
pub fn is_empty(&self) -> bool {
5454
self.edges.is_empty()
5555
}
@@ -58,8 +58,8 @@ impl<T: Eq + Hash> TransitiveRelation<T> {
5858
self.elements.iter()
5959
}
6060

61-
fn index(&self, a: &T) -> Option<Index> {
62-
self.elements.get_index_of(a).map(Index)
61+
fn index(&self, a: T) -> Option<Index> {
62+
self.elements.get_index_of(&a).map(Index)
6363
}
6464

6565
fn add_index(&mut self, a: T) -> Index {
@@ -76,12 +76,12 @@ impl<T: Eq + Hash> TransitiveRelation<T> {
7676
/// `None`.
7777
pub fn maybe_map<F, U>(&self, mut f: F) -> Option<TransitiveRelation<U>>
7878
where
79-
F: FnMut(&T) -> Option<U>,
80-
U: Clone + Debug + Eq + Hash + Clone,
79+
F: FnMut(T) -> Option<U>,
80+
U: Clone + Debug + Eq + Hash + Copy,
8181
{
8282
let mut result = TransitiveRelation::default();
8383
for edge in &self.edges {
84-
result.add(f(&self.elements[edge.source.0])?, f(&self.elements[edge.target.0])?);
84+
result.add(f(self.elements[edge.source.0])?, f(self.elements[edge.target.0])?);
8585
}
8686
Some(result)
8787
}
@@ -100,7 +100,7 @@ impl<T: Eq + Hash> TransitiveRelation<T> {
100100
}
101101

102102
/// Checks whether `a < target` (transitively)
103-
pub fn contains(&self, a: &T, b: &T) -> bool {
103+
pub fn contains(&self, a: T, b: T) -> bool {
104104
match (self.index(a), self.index(b)) {
105105
(Some(a), Some(b)) => self.with_closure(|closure| closure.contains(a.0, b.0)),
106106
(None, _) | (_, None) => false,
@@ -113,10 +113,10 @@ impl<T: Eq + Hash> TransitiveRelation<T> {
113113
/// Really this probably ought to be `impl Iterator<Item = &T>`, but
114114
/// I'm too lazy to make that work, and -- given the caching
115115
/// strategy -- it'd be a touch tricky anyhow.
116-
pub fn reachable_from(&self, a: &T) -> Vec<&T> {
116+
pub fn reachable_from(&self, a: T) -> Vec<T> {
117117
match self.index(a) {
118118
Some(a) => {
119-
self.with_closure(|closure| closure.iter(a.0).map(|i| &self.elements[i]).collect())
119+
self.with_closure(|closure| closure.iter(a.0).map(|i| self.elements[i]).collect())
120120
}
121121
None => vec![],
122122
}
@@ -157,15 +157,15 @@ impl<T: Eq + Hash> TransitiveRelation<T> {
157157
/// a -> a1
158158
/// b -> b1
159159
/// ```
160-
pub fn postdom_upper_bound(&self, a: &T, b: &T) -> Option<&T> {
160+
pub fn postdom_upper_bound(&self, a: T, b: T) -> Option<T> {
161161
let mubs = self.minimal_upper_bounds(a, b);
162162
self.mutual_immediate_postdominator(mubs)
163163
}
164164

165165
/// Viewing the relation as a graph, computes the "mutual
166166
/// immediate postdominator" of a set of points (if one
167167
/// exists). See `postdom_upper_bound` for details.
168-
pub fn mutual_immediate_postdominator<'a>(&'a self, mut mubs: Vec<&'a T>) -> Option<&'a T> {
168+
pub fn mutual_immediate_postdominator<'a>(&'a self, mut mubs: Vec<T>) -> Option<T> {
169169
loop {
170170
match mubs.len() {
171171
0 => return None,
@@ -189,7 +189,7 @@ impl<T: Eq + Hash> TransitiveRelation<T> {
189189
/// internal indices).
190190
///
191191
/// Note that this set can, in principle, have any size.
192-
pub fn minimal_upper_bounds(&self, a: &T, b: &T) -> Vec<&T> {
192+
pub fn minimal_upper_bounds(&self, a: T, b: T) -> Vec<T> {
193193
let (Some(mut a), Some(mut b)) = (self.index(a), self.index(b)) else {
194194
return vec![];
195195
};
@@ -267,7 +267,7 @@ impl<T: Eq + Hash> TransitiveRelation<T> {
267267
lub_indices
268268
.into_iter()
269269
.rev() // (4)
270-
.map(|i| &self.elements[i])
270+
.map(|i| self.elements[i])
271271
.collect()
272272
}
273273

@@ -290,7 +290,7 @@ impl<T: Eq + Hash> TransitiveRelation<T> {
290290
///
291291
/// then `parents(a)` returns `[b, c]`. The `postdom_parent` function
292292
/// would further reduce this to just `f`.
293-
pub fn parents(&self, a: &T) -> Vec<&T> {
293+
pub fn parents(&self, a: T) -> Vec<T> {
294294
let Some(a) = self.index(a) else {
295295
return vec![];
296296
};
@@ -314,7 +314,7 @@ impl<T: Eq + Hash> TransitiveRelation<T> {
314314
ancestors
315315
.into_iter()
316316
.rev() // (4)
317-
.map(|i| &self.elements[i])
317+
.map(|i| self.elements[i])
318318
.collect()
319319
}
320320

@@ -350,10 +350,10 @@ impl<T: Eq + Hash> TransitiveRelation<T> {
350350

351351
/// Lists all the base edges in the graph: the initial _non-transitive_ set of element
352352
/// relations, which will be later used as the basis for the transitive closure computation.
353-
pub fn base_edges(&self) -> impl Iterator<Item = (&T, &T)> {
353+
pub fn base_edges(&self) -> impl Iterator<Item = (T, T)> + '_ {
354354
self.edges
355355
.iter()
356-
.map(move |edge| (&self.elements[edge.source.0], &self.elements[edge.target.0]))
356+
.map(move |edge| (self.elements[edge.source.0], self.elements[edge.target.0]))
357357
}
358358
}
359359

0 commit comments

Comments
 (0)