Skip to content

Commit 75fedd2

Browse files
authored
Unrolled build for rust-lang#120027
Rollup merge of rust-lang#120027 - Nadrieril:remove-ty-copy-bound, r=compiler-errors pattern_analysis: Remove `Ty: Copy` bound To make it compatible with rust-analyzer's `Ty` which isn't `Copy` (it's an `Arc`). r? ``@compiler-errors``
2 parents 867d39c + 796cdc5 commit 75fedd2

File tree

6 files changed

+32
-31
lines changed

6 files changed

+32
-31
lines changed

compiler/rustc_mir_build/src/thir/pattern/check_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1130,7 +1130,7 @@ fn collect_non_exhaustive_tys<'tcx>(
11301130
non_exhaustive_tys.insert(pat.ty().inner());
11311131
}
11321132
if let Constructor::IntRange(range) = pat.ctor() {
1133-
if cx.is_range_beyond_boundaries(range, pat.ty()) {
1133+
if cx.is_range_beyond_boundaries(range, *pat.ty()) {
11341134
// The range denotes the values before `isize::MIN` or the values after `usize::MAX`/`isize::MAX`.
11351135
non_exhaustive_tys.insert(pat.ty().inner());
11361136
}

compiler/rustc_pattern_analysis/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl<'a, T: ?Sized> Captures<'a> for T {}
8282
/// Most of the crate is parameterized on a type that implements this trait.
8383
pub trait TypeCx: Sized + fmt::Debug {
8484
/// The type of a pattern.
85-
type Ty: Copy + Clone + fmt::Debug; // FIXME: remove Copy
85+
type Ty: Clone + fmt::Debug;
8686
/// Errors that can abort analysis.
8787
type Error: fmt::Debug;
8888
/// The index of an enum variant.
@@ -97,16 +97,16 @@ pub trait TypeCx: Sized + fmt::Debug {
9797
fn is_exhaustive_patterns_feature_on(&self) -> bool;
9898

9999
/// The number of fields for this constructor.
100-
fn ctor_arity(&self, ctor: &Constructor<Self>, ty: Self::Ty) -> usize;
100+
fn ctor_arity(&self, ctor: &Constructor<Self>, ty: &Self::Ty) -> usize;
101101

102102
/// The types of the fields for this constructor. The result must have a length of
103103
/// `ctor_arity()`.
104-
fn ctor_sub_tys(&self, ctor: &Constructor<Self>, ty: Self::Ty) -> &[Self::Ty];
104+
fn ctor_sub_tys(&self, ctor: &Constructor<Self>, ty: &Self::Ty) -> &[Self::Ty];
105105

106106
/// The set of all the constructors for `ty`.
107107
///
108108
/// This must follow the invariants of `ConstructorSet`
109-
fn ctors_for_ty(&self, ty: Self::Ty) -> Result<ConstructorSet<Self>, Self::Error>;
109+
fn ctors_for_ty(&self, ty: &Self::Ty) -> Result<ConstructorSet<Self>, Self::Error>;
110110

111111
/// Best-effort `Debug` implementation.
112112
fn debug_pat(f: &mut fmt::Formatter<'_>, pat: &DeconstructedPat<'_, Self>) -> fmt::Result;

compiler/rustc_pattern_analysis/src/lints.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl<'p, 'tcx> PatternColumn<'p, 'tcx> {
4646
}
4747

4848
fn head_ty(&self) -> Option<RevealedTy<'tcx>> {
49-
self.patterns.first().map(|pat| pat.ty())
49+
self.patterns.first().map(|pat| *pat.ty())
5050
}
5151

5252
/// Do constructor splitting on the constructors of the column.
@@ -101,7 +101,7 @@ fn collect_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
101101
let Some(ty) = column.head_ty() else {
102102
return Ok(Vec::new());
103103
};
104-
let pcx = &PlaceCtxt::new_dummy(cx, ty);
104+
let pcx = &PlaceCtxt::new_dummy(cx, &ty);
105105

106106
let set = column.analyze_ctors(pcx)?;
107107
if set.present.is_empty() {

compiler/rustc_pattern_analysis/src/pat.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ impl<'p, Cx: TypeCx> DeconstructedPat<'p, Cx> {
5454
pub fn ctor(&self) -> &Constructor<Cx> {
5555
&self.ctor
5656
}
57-
pub fn ty(&self) -> Cx::Ty {
58-
self.ty
57+
pub fn ty(&self) -> &Cx::Ty {
58+
&self.ty
5959
}
6060
/// Returns the extra data stored in a pattern. Returns `None` if the pattern is a wildcard that
6161
/// does not correspond to a user-supplied pattern.
@@ -242,15 +242,15 @@ impl<Cx: TypeCx> WitnessPat<Cx> {
242242
/// `Some(_)`.
243243
pub(crate) fn wild_from_ctor(pcx: &PlaceCtxt<'_, Cx>, ctor: Constructor<Cx>) -> Self {
244244
let field_tys = pcx.ctor_sub_tys(&ctor);
245-
let fields = field_tys.iter().map(|ty| Self::wildcard(*ty)).collect();
246-
Self::new(ctor, fields, pcx.ty)
245+
let fields = field_tys.iter().cloned().map(|ty| Self::wildcard(ty)).collect();
246+
Self::new(ctor, fields, pcx.ty.clone())
247247
}
248248

249249
pub fn ctor(&self) -> &Constructor<Cx> {
250250
&self.ctor
251251
}
252-
pub fn ty(&self) -> Cx::Ty {
253-
self.ty
252+
pub fn ty(&self) -> &Cx::Ty {
253+
&self.ty
254254
}
255255

256256
pub fn iter_fields(&self) -> impl Iterator<Item = &WitnessPat<Cx>> {

compiler/rustc_pattern_analysis/src/rustc.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ impl<'p, 'tcx> RustcMatchCheckCtxt<'p, 'tcx> {
766766
let mut subpatterns = pat.iter_fields().map(|p| Box::new(cx.hoist_witness_pat(p)));
767767
let kind = match pat.ctor() {
768768
Bool(b) => PatKind::Constant { value: mir::Const::from_bool(cx.tcx, *b) },
769-
IntRange(range) => return self.hoist_pat_range(range, pat.ty()),
769+
IntRange(range) => return self.hoist_pat_range(range, *pat.ty()),
770770
Struct | Variant(_) | UnionField => match pat.ty().kind() {
771771
ty::Tuple(..) => PatKind::Leaf {
772772
subpatterns: subpatterns
@@ -785,7 +785,7 @@ impl<'p, 'tcx> RustcMatchCheckCtxt<'p, 'tcx> {
785785
RustcMatchCheckCtxt::variant_index_for_adt(&pat.ctor(), *adt_def);
786786
let variant = &adt_def.variant(variant_index);
787787
let subpatterns = cx
788-
.list_variant_nonhidden_fields(pat.ty(), variant)
788+
.list_variant_nonhidden_fields(*pat.ty(), variant)
789789
.zip(subpatterns)
790790
.map(|((field, _ty), pattern)| FieldPat { field, pattern })
791791
.collect();
@@ -796,7 +796,7 @@ impl<'p, 'tcx> RustcMatchCheckCtxt<'p, 'tcx> {
796796
PatKind::Leaf { subpatterns }
797797
}
798798
}
799-
_ => bug!("unexpected ctor for type {:?} {:?}", pat.ctor(), pat.ty()),
799+
_ => bug!("unexpected ctor for type {:?} {:?}", pat.ctor(), *pat.ty()),
800800
},
801801
// Note: given the expansion of `&str` patterns done in `expand_pattern`, we should
802802
// be careful to reconstruct the correct constant pattern here. However a string
@@ -961,21 +961,21 @@ impl<'p, 'tcx> TypeCx for RustcMatchCheckCtxt<'p, 'tcx> {
961961
self.tcx.features().exhaustive_patterns
962962
}
963963

964-
fn ctor_arity(&self, ctor: &crate::constructor::Constructor<Self>, ty: Self::Ty) -> usize {
965-
self.ctor_arity(ctor, ty)
964+
fn ctor_arity(&self, ctor: &crate::constructor::Constructor<Self>, ty: &Self::Ty) -> usize {
965+
self.ctor_arity(ctor, *ty)
966966
}
967967
fn ctor_sub_tys(
968968
&self,
969969
ctor: &crate::constructor::Constructor<Self>,
970-
ty: Self::Ty,
970+
ty: &Self::Ty,
971971
) -> &[Self::Ty] {
972-
self.ctor_sub_tys(ctor, ty)
972+
self.ctor_sub_tys(ctor, *ty)
973973
}
974974
fn ctors_for_ty(
975975
&self,
976-
ty: Self::Ty,
976+
ty: &Self::Ty,
977977
) -> Result<crate::constructor::ConstructorSet<Self>, Self::Error> {
978-
self.ctors_for_ty(ty)
978+
self.ctors_for_ty(*ty)
979979
}
980980

981981
fn debug_pat(
@@ -994,7 +994,7 @@ impl<'p, 'tcx> TypeCx for RustcMatchCheckCtxt<'p, 'tcx> {
994994
overlaps_on: IntRange,
995995
overlaps_with: &[&crate::pat::DeconstructedPat<'_, Self>],
996996
) {
997-
let overlap_as_pat = self.hoist_pat_range(&overlaps_on, pat.ty());
997+
let overlap_as_pat = self.hoist_pat_range(&overlaps_on, *pat.ty());
998998
let overlaps: Vec<_> = overlaps_with
999999
.iter()
10001000
.map(|pat| pat.data().unwrap().span)

compiler/rustc_pattern_analysis/src/usefulness.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -736,13 +736,14 @@ pub(crate) struct PlaceCtxt<'a, Cx: TypeCx> {
736736
#[derivative(Debug = "ignore")]
737737
pub(crate) mcx: MatchCtxt<'a, Cx>,
738738
/// Type of the place under investigation.
739-
pub(crate) ty: Cx::Ty,
739+
#[derivative(Clone(clone_with = "Clone::clone"))] // See rust-derivative#90
740+
pub(crate) ty: &'a Cx::Ty,
740741
}
741742

742743
impl<'a, Cx: TypeCx> PlaceCtxt<'a, Cx> {
743744
/// A `PlaceCtxt` when code other than `is_useful` needs one.
744745
#[cfg_attr(not(feature = "rustc"), allow(dead_code))]
745-
pub(crate) fn new_dummy(mcx: MatchCtxt<'a, Cx>, ty: Cx::Ty) -> Self {
746+
pub(crate) fn new_dummy(mcx: MatchCtxt<'a, Cx>, ty: &'a Cx::Ty) -> Self {
746747
PlaceCtxt { mcx, ty }
747748
}
748749

@@ -1023,8 +1024,8 @@ impl<'p, Cx: TypeCx> Matrix<'p, Cx> {
10231024
matrix
10241025
}
10251026

1026-
fn head_ty(&self) -> Option<Cx::Ty> {
1027-
self.place_ty.first().copied()
1027+
fn head_ty(&self) -> Option<&Cx::Ty> {
1028+
self.place_ty.first()
10281029
}
10291030
fn column_count(&self) -> usize {
10301031
self.place_ty.len()
@@ -1058,7 +1059,7 @@ impl<'p, Cx: TypeCx> Matrix<'p, Cx> {
10581059
let ctor_sub_tys = pcx.ctor_sub_tys(ctor);
10591060
let arity = ctor_sub_tys.len();
10601061
let specialized_place_ty =
1061-
ctor_sub_tys.iter().chain(self.place_ty[1..].iter()).copied().collect();
1062+
ctor_sub_tys.iter().chain(self.place_ty[1..].iter()).cloned().collect();
10621063
let ctor_sub_validity = self.place_validity[0].specialize(ctor);
10631064
let specialized_place_validity = std::iter::repeat(ctor_sub_validity)
10641065
.take(arity)
@@ -1214,7 +1215,7 @@ impl<Cx: TypeCx> WitnessStack<Cx> {
12141215
let len = self.0.len();
12151216
let arity = ctor.arity(pcx);
12161217
let fields = self.0.drain((len - arity)..).rev().collect();
1217-
let pat = WitnessPat::new(ctor.clone(), fields, pcx.ty);
1218+
let pat = WitnessPat::new(ctor.clone(), fields, pcx.ty.clone());
12181219
self.0.push(pat);
12191220
}
12201221
}
@@ -1410,7 +1411,7 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
14101411
return Ok(WitnessMatrix::empty());
14111412
}
14121413

1413-
let Some(ty) = matrix.head_ty() else {
1414+
let Some(ty) = matrix.head_ty().cloned() else {
14141415
// The base case: there are no columns in the matrix. We are morally pattern-matching on ().
14151416
// A row is useful iff it has no (unguarded) rows above it.
14161417
let mut useful = true; // Whether the next row is useful.
@@ -1431,7 +1432,7 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
14311432
};
14321433

14331434
debug!("ty: {ty:?}");
1434-
let pcx = &PlaceCtxt { mcx, ty };
1435+
let pcx = &PlaceCtxt { mcx, ty: &ty };
14351436
let ctors_for_ty = pcx.ctors_for_ty()?;
14361437

14371438
// Whether the place/column we are inspecting is known to contain valid data.

0 commit comments

Comments
 (0)