Skip to content

Commit 82a0fa3

Browse files
committed
use ProjectionFragment(Ref) type alias
makes it easier to change in the future, which will be needed for borrowck and co
1 parent 7243d73 commit 82a0fa3

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

compiler/rustc_middle/src/mir/statement.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ impl<'tcx> PlaceTy<'tcx> {
161161
pub fn projection_chain_ty(
162162
self,
163163
tcx: TyCtxt<'tcx>,
164-
chain: &[&List<PlaceElem<'tcx>>],
164+
chain: &[ProjectionFragment<'tcx>],
165165
) -> PlaceTy<'tcx> {
166166
chain
167167
.iter()
@@ -556,6 +556,13 @@ impl From<Local> for PlaceRef<'_> {
556556
}
557557
}
558558

559+
// In the future this will also have the type being projected alongside it.
560+
// This will be needed to represent derefs of non-pointer types like `Box`.
561+
//
562+
// (`Ty::builtin_deref` currently works on `Box` but that will be changed too)
563+
pub type ProjectionFragment<'tcx> = &'tcx List<PlaceElem<'tcx>>;
564+
pub type ProjectionFragmentRef<'tcx> = &'tcx [PlaceElem<'tcx>];
565+
559566
/// A place possibly containing derefs in the middle of its projection by chaining projection lists.
560567
///
561568
/// In `AnalysisPhase::PostCleanup` and later, [`Place`] and [`PlaceRef`] cannot represent these
@@ -567,15 +574,15 @@ pub struct CompoundPlace<'tcx> {
567574
/// - All segments in the chain other than the first must start with a deref.
568575
/// - Derefs may only appear at the start of a segment.
569576
/// - No segment may be empty.
570-
pub projection_chain: &'tcx List<&'tcx List<PlaceElem<'tcx>>>,
577+
pub projection_chain: &'tcx List<ProjectionFragment<'tcx>>,
571578
}
572579

573580
/// Borrowed form of [`CompoundPlace`].
574581
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
575582
pub struct CompoundPlaceRef<'tcx> {
576583
pub local: Local,
577-
pub projection_chain_base: &'tcx [&'tcx List<PlaceElem<'tcx>>],
578-
pub last_projection: &'tcx [PlaceElem<'tcx>],
584+
pub projection_chain_base: &'tcx [ProjectionFragment<'tcx>],
585+
pub last_projection: ProjectionFragmentRef<'tcx>,
579586
}
580587

581588
// these impls are bare-bones for now

compiler/rustc_middle/src/ty/context.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ use crate::metadata::ModChild;
6868
use crate::middle::codegen_fn_attrs::{CodegenFnAttrs, TargetFeature};
6969
use crate::middle::resolve_bound_vars;
7070
use crate::mir::interpret::{self, Allocation, ConstAllocation};
71-
use crate::mir::{Body, Local, Place, PlaceElem, ProjectionKind, Promoted};
71+
use crate::mir::{Body, Local, Place, PlaceElem, ProjectionFragment, ProjectionKind, Promoted};
7272
use crate::query::plumbing::QuerySystem;
7373
use crate::query::{IntoQueryParam, LocalCrate, Providers, TyCtxtAt};
7474
use crate::thir::Thir;
@@ -2781,7 +2781,7 @@ slice_interners!(
27812781
poly_existential_predicates: intern_poly_existential_predicates(PolyExistentialPredicate<'tcx>),
27822782
projs: pub mk_projs(ProjectionKind),
27832783
place_elems: pub mk_place_elems(PlaceElem<'tcx>),
2784-
place_elem_chains: pub mk_place_elem_chain(&'tcx List<PlaceElem<'tcx>>),
2784+
place_elem_chains: pub mk_place_elem_chain(ProjectionFragment<'tcx>),
27852785
bound_variable_kinds: pub mk_bound_variable_kinds(ty::BoundVariableKind),
27862786
fields: pub mk_fields(FieldIdx),
27872787
local_def_ids: intern_local_def_ids(LocalDefId),
@@ -3175,7 +3175,7 @@ impl<'tcx> TyCtxt<'tcx> {
31753175
pub fn mk_place_elem_chain_from_iter<I, T>(self, iter: I) -> T::Output
31763176
where
31773177
I: Iterator<Item = T>,
3178-
T: CollectAndApply<&'tcx List<PlaceElem<'tcx>>, &'tcx List<&'tcx List<PlaceElem<'tcx>>>>,
3178+
T: CollectAndApply<&'tcx List<PlaceElem<'tcx>>, &'tcx List<ProjectionFragment<'tcx>>>,
31793179
{
31803180
T::collect_and_apply(iter, |xs| self.mk_place_elem_chain(xs))
31813181
}

compiler/rustc_middle/src/ty/structural_impls.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_span::source_map::Spanned;
1313
use rustc_type_ir::{ConstKind, TypeFolder, VisitorResult, try_visit};
1414

1515
use super::{GenericArg, GenericArgKind, Pattern, Region};
16-
use crate::mir::PlaceElem;
16+
use crate::mir::{PlaceElem, ProjectionFragment};
1717
use crate::ty::print::{FmtPrinter, Printer, with_no_trimmed_paths};
1818
use crate::ty::{
1919
self, FallibleTypeFolder, Lift, Term, TermKind, Ty, TyCtxt, TypeFoldable, TypeSuperFoldable,
@@ -797,7 +797,7 @@ macro_rules! list_fold {
797797
list_fold! {
798798
&'tcx ty::List<ty::PolyExistentialPredicate<'tcx>> : mk_poly_existential_predicates,
799799
&'tcx ty::List<PlaceElem<'tcx>> : mk_place_elems,
800-
&'tcx ty::List<&'tcx ty::List<PlaceElem<'tcx>>> : mk_place_elem_chain,
800+
&'tcx ty::List<ProjectionFragment<'tcx>> : mk_place_elem_chain,
801801
&'tcx ty::List<ty::Pattern<'tcx>> : mk_patterns,
802802
&'tcx ty::List<ty::ArgOutlivesPredicate<'tcx>> : mk_outlives,
803803
}

0 commit comments

Comments
 (0)