Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add #[rustc_pass_by_value] to more types #94737

Merged
merged 1 commit into from
Mar 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
PlaceRef {
local,
projection:
[
proj_base @ ..,
&[
ref proj_base @ ..,
ProjectionElem::Deref,
ProjectionElem::Field(field, _),
ProjectionElem::Deref,
Expand Down Expand Up @@ -342,7 +342,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
Applicability::MachineApplicable,
);
let tcx = self.infcx.tcx;
if let ty::Closure(id, _) = the_place_err.ty(self.body, tcx).ty.kind() {
if let ty::Closure(id, _) = *the_place_err.ty(self.body, tcx).ty.kind() {
self.show_mutating_upvar(tcx, id, the_place_err, &mut err);
}
}
Expand Down Expand Up @@ -382,7 +382,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
let tcx = self.infcx.tcx;
if let ty::Ref(_, ty, Mutability::Mut) = the_place_err.ty(self.body, tcx).ty.kind()
{
if let ty::Closure(id, _) = ty.kind() {
if let ty::Closure(id, _) = *ty.kind() {
self.show_mutating_upvar(tcx, id, the_place_err, &mut err);
}
}
Expand Down Expand Up @@ -687,7 +687,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
fn show_mutating_upvar(
&self,
tcx: TyCtxt<'_>,
id: &hir::def_id::DefId,
id: hir::def_id::DefId,
the_place_err: PlaceRef<'tcx>,
err: &mut Diagnostic,
) {
Expand All @@ -701,7 +701,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
let upvar = ty::place_to_string_for_capture(tcx, closure_kind_origin);
let root_hir_id = upvar_id.var_path.hir_id;
// we have an origin for this closure kind starting at this root variable so it's safe to unwrap here
let captured_places = tables.closure_min_captures[id].get(&root_hir_id).unwrap();
let captured_places = tables.closure_min_captures[&id].get(&root_hir_id).unwrap();

let origin_projection = closure_kind_origin
.projections
Expand Down Expand Up @@ -1083,7 +1083,7 @@ fn is_closure_or_generator(ty: Ty<'_>) -> bool {
fn get_mut_span_in_struct_field<'tcx>(
tcx: TyCtxt<'tcx>,
ty: Ty<'tcx>,
field: &mir::Field,
field: mir::Field,
) -> Option<Span> {
// Expect our local to be a reference to a struct of some kind.
if let ty::Ref(_, ty, _) = ty.kind()
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl LocationTable {
}

impl LocationIndex {
fn is_start(&self) -> bool {
fn is_start(self) -> bool {
// even indices are start points; odd indices are mid points
(self.index() % 2) == 0
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_borrowck/src/nll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ fn populate_polonius_move_facts(
) {
all_facts
.path_is_var
.extend(move_data.rev_lookup.iter_locals_enumerated().map(|(v, &m)| (m, v)));
.extend(move_data.rev_lookup.iter_locals_enumerated().map(|(l, r)| (r, l)));

for (child, move_path) in move_data.move_paths.iter_enumerated() {
if let Some(parent) = move_path.parent {
Expand Down Expand Up @@ -135,7 +135,7 @@ fn populate_polonius_move_facts(
}
}

for (local, &path) in move_data.rev_lookup.iter_locals_enumerated() {
for (local, path) in move_data.rev_lookup.iter_locals_enumerated() {
if body.local_kind(local) != LocalKind::Arg {
// Non-arguments start out deinitialised; we simulate this with an
// initial move:
Expand Down Expand Up @@ -226,7 +226,7 @@ pub(crate) fn compute_regions<'cx, 'tcx>(
fr1={:?}, fr2={:?}",
fr1, fr2
);
all_facts.known_placeholder_subset.push((*fr1, *fr2));
all_facts.known_placeholder_subset.push((fr1, fr2));
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_borrowck/src/region_infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -942,14 +942,14 @@ impl<'tcx> RegionInferenceContext<'tcx> {

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

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

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

Expand Down Expand Up @@ -1588,12 +1588,12 @@ impl<'tcx> RegionInferenceContext<'tcx> {
// always will.) We'll call them `shorter_fr+` -- they're ever
// so slightly larger than `shorter_fr`.
let shorter_fr_plus =
self.universal_region_relations.non_local_upper_bounds(&shorter_fr);
self.universal_region_relations.non_local_upper_bounds(shorter_fr);
debug!(
"try_propagate_universal_region_error: shorter_fr_plus={:?}",
shorter_fr_plus
);
for &&fr in &shorter_fr_plus {
for fr in shorter_fr_plus {
// Push the constraint `fr-: shorter_fr+`
propagated_outlives_requirements.push(ClosureOutlivesRequirement {
subject: ClosureOutlivesSubject::Region(fr_minus),
Expand Down
33 changes: 16 additions & 17 deletions compiler/rustc_borrowck/src/type_check/free_region_relations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,17 @@ impl UniversalRegionRelations<'_> {
crate fn postdom_upper_bound(&self, fr1: RegionVid, fr2: RegionVid) -> RegionVid {
assert!(self.universal_regions.is_universal_region(fr1));
assert!(self.universal_regions.is_universal_region(fr2));
*self
.inverse_outlives
.postdom_upper_bound(&fr1, &fr2)
.unwrap_or(&self.universal_regions.fr_static)
self.inverse_outlives
.postdom_upper_bound(fr1, fr2)
.unwrap_or(self.universal_regions.fr_static)
}

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

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

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

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

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

post_dom.and_then(|&post_dom| {
post_dom.and_then(|post_dom| {
// If the mutual immediate postdom is not local, then
// there is no non-local result we can return.
if !self.universal_regions.is_local_free_region(post_dom) {
Expand All @@ -176,19 +175,19 @@ impl UniversalRegionRelations<'_> {
fn non_local_bounds<'a>(
&self,
relation: &'a TransitiveRelation<RegionVid>,
fr0: &'a RegionVid,
) -> Vec<&'a RegionVid> {
fr0: RegionVid,
) -> Vec<RegionVid> {
// This method assumes that `fr0` is one of the universally
// quantified region variables.
assert!(self.universal_regions.is_universal_region(*fr0));
assert!(self.universal_regions.is_universal_region(fr0));

let mut external_parents = vec![];
let mut queue = vec![fr0];

// Keep expanding `fr` into its parents until we reach
// non-local regions.
while let Some(fr) = queue.pop() {
if !self.universal_regions.is_local_free_region(*fr) {
if !self.universal_regions.is_local_free_region(fr) {
external_parents.push(fr);
continue;
}
Expand All @@ -205,17 +204,17 @@ impl UniversalRegionRelations<'_> {
///
/// This will only ever be true for universally quantified regions.
crate fn outlives(&self, fr1: RegionVid, fr2: RegionVid) -> bool {
self.outlives.contains(&fr1, &fr2)
self.outlives.contains(fr1, fr2)
}

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

/// Returns the _non-transitive_ set of known `outlives` constraints between free regions.
crate fn known_outlives(&self) -> impl Iterator<Item = (&RegionVid, &RegionVid)> {
crate fn known_outlives(&self) -> impl Iterator<Item = (RegionVid, RegionVid)> + '_ {
self.outlives.base_edges()
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1198,7 +1198,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
tcx,
self.param_env,
proj,
|this, field, &()| {
|this, field, ()| {
let ty = this.field_ty(tcx, field);
self.normalize(ty, locations)
},
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl<'ll, 'tcx> CoverageInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
/// call. Since the function is never called, all other `CodeRegion`s can be
/// added as `unreachable_region`s.
fn define_unused_fn(&self, def_id: DefId) {
let instance = declare_unused_fn(self, &def_id);
let instance = declare_unused_fn(self, def_id);
codegen_unused_fn_and_counter(self, instance);
add_unused_function_coverage(self, instance, def_id);
}
Expand Down Expand Up @@ -184,12 +184,12 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
}
}

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

let instance = Instance::new(
*def_id,
InternalSubsts::for_item(tcx, *def_id, |param, _| {
def_id,
InternalSubsts::for_item(tcx, def_id, |param, _| {
if let ty::GenericParamDefKind::Lifetime = param.kind {
tcx.lifetimes.re_erased.into()
} else {
Expand Down
34 changes: 17 additions & 17 deletions compiler/rustc_data_structures/src/transitive_relation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ struct Edge {
target: Index,
}

impl<T: Eq + Hash> TransitiveRelation<T> {
impl<T: Eq + Hash + Copy> TransitiveRelation<T> {
pub fn is_empty(&self) -> bool {
self.edges.is_empty()
}
Expand All @@ -58,8 +58,8 @@ impl<T: Eq + Hash> TransitiveRelation<T> {
self.elements.iter()
}

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

fn add_index(&mut self, a: T) -> Index {
Expand All @@ -76,12 +76,12 @@ impl<T: Eq + Hash> TransitiveRelation<T> {
/// `None`.
pub fn maybe_map<F, U>(&self, mut f: F) -> Option<TransitiveRelation<U>>
where
F: FnMut(&T) -> Option<U>,
U: Clone + Debug + Eq + Hash + Clone,
F: FnMut(T) -> Option<U>,
U: Clone + Debug + Eq + Hash + Copy,
{
let mut result = TransitiveRelation::default();
for edge in &self.edges {
result.add(f(&self.elements[edge.source.0])?, f(&self.elements[edge.target.0])?);
result.add(f(self.elements[edge.source.0])?, f(self.elements[edge.target.0])?);
}
Some(result)
}
Expand All @@ -100,7 +100,7 @@ impl<T: Eq + Hash> TransitiveRelation<T> {
}

/// Checks whether `a < target` (transitively)
pub fn contains(&self, a: &T, b: &T) -> bool {
pub fn contains(&self, a: T, b: T) -> bool {
match (self.index(a), self.index(b)) {
(Some(a), Some(b)) => self.with_closure(|closure| closure.contains(a.0, b.0)),
(None, _) | (_, None) => false,
Expand All @@ -113,10 +113,10 @@ impl<T: Eq + Hash> TransitiveRelation<T> {
/// Really this probably ought to be `impl Iterator<Item = &T>`, but
/// I'm too lazy to make that work, and -- given the caching
/// strategy -- it'd be a touch tricky anyhow.
pub fn reachable_from(&self, a: &T) -> Vec<&T> {
pub fn reachable_from(&self, a: T) -> Vec<T> {
match self.index(a) {
Some(a) => {
self.with_closure(|closure| closure.iter(a.0).map(|i| &self.elements[i]).collect())
self.with_closure(|closure| closure.iter(a.0).map(|i| self.elements[i]).collect())
}
None => vec![],
}
Expand Down Expand Up @@ -157,15 +157,15 @@ impl<T: Eq + Hash> TransitiveRelation<T> {
/// a -> a1
/// b -> b1
/// ```
pub fn postdom_upper_bound(&self, a: &T, b: &T) -> Option<&T> {
pub fn postdom_upper_bound(&self, a: T, b: T) -> Option<T> {
let mubs = self.minimal_upper_bounds(a, b);
self.mutual_immediate_postdominator(mubs)
}

/// Viewing the relation as a graph, computes the "mutual
/// immediate postdominator" of a set of points (if one
/// exists). See `postdom_upper_bound` for details.
pub fn mutual_immediate_postdominator<'a>(&'a self, mut mubs: Vec<&'a T>) -> Option<&'a T> {
pub fn mutual_immediate_postdominator<'a>(&'a self, mut mubs: Vec<T>) -> Option<T> {
loop {
match mubs.len() {
0 => return None,
Expand All @@ -189,7 +189,7 @@ impl<T: Eq + Hash> TransitiveRelation<T> {
/// internal indices).
///
/// Note that this set can, in principle, have any size.
pub fn minimal_upper_bounds(&self, a: &T, b: &T) -> Vec<&T> {
pub fn minimal_upper_bounds(&self, a: T, b: T) -> Vec<T> {
let (Some(mut a), Some(mut b)) = (self.index(a), self.index(b)) else {
return vec![];
};
Expand Down Expand Up @@ -267,7 +267,7 @@ impl<T: Eq + Hash> TransitiveRelation<T> {
lub_indices
.into_iter()
.rev() // (4)
.map(|i| &self.elements[i])
.map(|i| self.elements[i])
.collect()
}

Expand All @@ -290,7 +290,7 @@ impl<T: Eq + Hash> TransitiveRelation<T> {
///
/// then `parents(a)` returns `[b, c]`. The `postdom_parent` function
/// would further reduce this to just `f`.
pub fn parents(&self, a: &T) -> Vec<&T> {
pub fn parents(&self, a: T) -> Vec<T> {
let Some(a) = self.index(a) else {
return vec![];
};
Expand All @@ -314,7 +314,7 @@ impl<T: Eq + Hash> TransitiveRelation<T> {
ancestors
.into_iter()
.rev() // (4)
.map(|i| &self.elements[i])
.map(|i| self.elements[i])
.collect()
}

Expand Down Expand Up @@ -350,10 +350,10 @@ impl<T: Eq + Hash> TransitiveRelation<T> {

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

Expand Down
Loading