Skip to content

Commit b58ef44

Browse files
committed
Remove Ty: Copy bound
1 parent 6ed31ab commit b58ef44

File tree

6 files changed

+32
-31
lines changed

6 files changed

+32
-31
lines changed

Diff for: compiler/rustc_mir_build/src/thir/pattern/check_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1113,7 +1113,7 @@ fn collect_non_exhaustive_tys<'tcx>(
11131113
non_exhaustive_tys.insert(pat.ty().inner());
11141114
}
11151115
if let Constructor::IntRange(range) = pat.ctor() {
1116-
if cx.is_range_beyond_boundaries(range, pat.ty()) {
1116+
if cx.is_range_beyond_boundaries(range, *pat.ty()) {
11171117
// The range denotes the values before `isize::MIN` or the values after `usize::MAX`/`isize::MAX`.
11181118
non_exhaustive_tys.insert(pat.ty().inner());
11191119
}

Diff for: compiler/rustc_pattern_analysis/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl<'a, T: ?Sized> Captures<'a> for T {}
4444
/// Most of the crate is parameterized on a type that implements this trait.
4545
pub trait TypeCx: Sized + fmt::Debug {
4646
/// The type of a pattern.
47-
type Ty: Copy + Clone + fmt::Debug; // FIXME: remove Copy
47+
type Ty: Clone + fmt::Debug;
4848
/// Errors that can abort analysis.
4949
type Error: fmt::Debug;
5050
/// The index of an enum variant.
@@ -59,16 +59,16 @@ pub trait TypeCx: Sized + fmt::Debug {
5959
fn is_exhaustive_patterns_feature_on(&self) -> bool;
6060

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

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

6868
/// The set of all the constructors for `ty`.
6969
///
7070
/// This must follow the invariants of `ConstructorSet`
71-
fn ctors_for_ty(&self, ty: Self::Ty) -> Result<ConstructorSet<Self>, Self::Error>;
71+
fn ctors_for_ty(&self, ty: &Self::Ty) -> Result<ConstructorSet<Self>, Self::Error>;
7272

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

Diff for: 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() {

Diff for: 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>> {

Diff for: 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)

Diff for: compiler/rustc_pattern_analysis/src/usefulness.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -736,15 +736,16 @@ 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
/// Whether the place is the original scrutinee place, as opposed to a subplace of it.
741742
pub(crate) is_scrutinee: bool,
742743
}
743744

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

@@ -1039,8 +1040,8 @@ impl<'p, Cx: TypeCx> Matrix<'p, Cx> {
10391040
matrix
10401041
}
10411042

1042-
fn head_ty(&self) -> Option<Cx::Ty> {
1043-
self.place_ty.first().copied()
1043+
fn head_ty(&self) -> Option<&Cx::Ty> {
1044+
self.place_ty.first()
10441045
}
10451046
fn column_count(&self) -> usize {
10461047
self.place_ty.len()
@@ -1074,7 +1075,7 @@ impl<'p, Cx: TypeCx> Matrix<'p, Cx> {
10741075
let ctor_sub_tys = pcx.ctor_sub_tys(ctor);
10751076
let arity = ctor_sub_tys.len();
10761077
let specialized_place_ty =
1077-
ctor_sub_tys.iter().chain(self.place_ty[1..].iter()).copied().collect();
1078+
ctor_sub_tys.iter().chain(self.place_ty[1..].iter()).cloned().collect();
10781079
let ctor_sub_validity = self.place_validity[0].specialize(ctor);
10791080
let specialized_place_validity = std::iter::repeat(ctor_sub_validity)
10801081
.take(arity)
@@ -1230,7 +1231,7 @@ impl<Cx: TypeCx> WitnessStack<Cx> {
12301231
let len = self.0.len();
12311232
let arity = ctor.arity(pcx);
12321233
let fields = self.0.drain((len - arity)..).rev().collect();
1233-
let pat = WitnessPat::new(ctor.clone(), fields, pcx.ty);
1234+
let pat = WitnessPat::new(ctor.clone(), fields, pcx.ty.clone());
12341235
self.0.push(pat);
12351236
}
12361237
}
@@ -1426,7 +1427,7 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
14261427
return Ok(WitnessMatrix::empty());
14271428
}
14281429

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

14491450
debug!("ty: {ty:?}");
1450-
let pcx = &PlaceCtxt { mcx, ty, is_scrutinee: is_top_level };
1451+
let pcx = &PlaceCtxt { mcx, ty: &ty, is_scrutinee: is_top_level };
14511452

14521453
// Whether the place/column we are inspecting is known to contain valid data.
14531454
let place_validity = matrix.place_validity[0];

0 commit comments

Comments
 (0)