Skip to content

Commit f2f8593

Browse files
committed
PlaceholderLike Copy -> Clone
1 parent c0b3412 commit f2f8593

File tree

7 files changed

+28
-26
lines changed

7 files changed

+28
-26
lines changed

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -879,16 +879,16 @@ impl Placeholder<BoundVar> {
879879
pub type PlaceholderRegion = Placeholder<BoundRegion>;
880880

881881
impl rustc_type_ir::inherent::PlaceholderLike for PlaceholderRegion {
882-
fn universe(self) -> UniverseIndex {
882+
fn universe(&self) -> UniverseIndex {
883883
self.universe
884884
}
885885

886886
fn var(&self) -> BoundVar {
887887
self.bound.var
888888
}
889889

890-
fn with_updated_universe(self, ui: UniverseIndex) -> Self {
891-
Placeholder { universe: ui, ..self }
890+
fn with_updated_universe(&self, ui: UniverseIndex) -> Self {
891+
Placeholder { universe: ui, ..*self }
892892
}
893893

894894
fn new(ui: UniverseIndex, var: BoundVar) -> Self {
@@ -899,16 +899,16 @@ impl rustc_type_ir::inherent::PlaceholderLike for PlaceholderRegion {
899899
pub type PlaceholderType = Placeholder<BoundTy>;
900900

901901
impl rustc_type_ir::inherent::PlaceholderLike for PlaceholderType {
902-
fn universe(self) -> UniverseIndex {
902+
fn universe(&self) -> UniverseIndex {
903903
self.universe
904904
}
905905

906906
fn var(&self) -> BoundVar {
907907
self.bound.var
908908
}
909909

910-
fn with_updated_universe(self, ui: UniverseIndex) -> Self {
911-
Placeholder { universe: ui, ..self }
910+
fn with_updated_universe(&self, ui: UniverseIndex) -> Self {
911+
Placeholder { universe: ui, ..*self }
912912
}
913913

914914
fn new(ui: UniverseIndex, var: BoundVar) -> Self {
@@ -926,16 +926,16 @@ pub struct BoundConst<'tcx> {
926926
pub type PlaceholderConst = Placeholder<BoundVar>;
927927

928928
impl rustc_type_ir::inherent::PlaceholderLike for PlaceholderConst {
929-
fn universe(self) -> UniverseIndex {
929+
fn universe(&self) -> UniverseIndex {
930930
self.universe
931931
}
932932

933933
fn var(&self) -> BoundVar {
934934
self.bound
935935
}
936936

937-
fn with_updated_universe(self, ui: UniverseIndex) -> Self {
938-
Placeholder { universe: ui, ..self }
937+
fn with_updated_universe(&self, ui: UniverseIndex) -> Self {
938+
Placeholder { universe: ui, ..*self }
939939
}
940940

941941
fn new(ui: UniverseIndex, var: BoundVar) -> Self {

compiler/rustc_type_ir/src/canonical.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,20 +83,21 @@ impl<I: Interner, V: fmt::Display> fmt::Display for Canonical<I, V> {
8383
/// canonical value. This is sufficient information for code to create
8484
/// a copy of the canonical value in some other inference context,
8585
/// with fresh inference variables replacing the canonical values.
86-
#[derive_where(Clone, Copy, Hash, PartialEq, Eq, Debug; I: Interner)]
86+
#[derive_where(Clone, Hash, PartialEq, Eq, Debug; I: Interner)]
87+
#[derive_where(Copy; I: Interner, I::PlaceholderTy: Copy, I::PlaceholderRegion: Copy, I::PlaceholderConst: Copy)]
8788
#[derive(TypeVisitable_Generic, TypeFoldable_Generic)]
8889
#[cfg_attr(feature = "nightly", derive(TyDecodable, TyEncodable, HashStable_NoContext))]
8990
pub struct CanonicalVarInfo<I: Interner> {
9091
pub kind: CanonicalVarKind<I>,
9192
}
9293

9394
impl<I: Interner> CanonicalVarInfo<I> {
94-
pub fn universe(self) -> UniverseIndex {
95+
pub fn universe(&self) -> UniverseIndex {
9596
self.kind.universe()
9697
}
9798

9899
#[must_use]
99-
pub fn with_updated_universe(self, ui: UniverseIndex) -> CanonicalVarInfo<I> {
100+
pub fn with_updated_universe(&self, ui: UniverseIndex) -> CanonicalVarInfo<I> {
100101
CanonicalVarInfo { kind: self.kind.with_updated_universe(ui) }
101102
}
102103

@@ -137,7 +138,8 @@ impl<I: Interner> CanonicalVarInfo<I> {
137138
/// Describes the "kind" of the canonical variable. This is a "kind"
138139
/// in the type-theory sense of the term -- i.e., a "meta" type system
139140
/// that analyzes type-like values.
140-
#[derive_where(Clone, Copy, Hash, PartialEq, Eq, Debug; I: Interner)]
141+
#[derive_where(Clone, Hash, PartialEq, Eq, Debug; I: Interner)]
142+
#[derive_where(Copy; I: Interner, I::PlaceholderTy: Copy, I::PlaceholderRegion: Copy, I::PlaceholderConst: Copy)]
141143
#[derive(TypeVisitable_Generic, TypeFoldable_Generic)]
142144
#[cfg_attr(feature = "nightly", derive(TyDecodable, TyEncodable, HashStable_NoContext))]
143145
pub enum CanonicalVarKind<I: Interner> {
@@ -163,11 +165,11 @@ pub enum CanonicalVarKind<I: Interner> {
163165
}
164166

165167
impl<I: Interner> CanonicalVarKind<I> {
166-
pub fn universe(self) -> UniverseIndex {
168+
pub fn universe(&self) -> UniverseIndex {
167169
match self {
168-
CanonicalVarKind::Ty(CanonicalTyVarKind::General(ui)) => ui,
169-
CanonicalVarKind::Region(ui) => ui,
170-
CanonicalVarKind::Const(ui) => ui,
170+
CanonicalVarKind::Ty(CanonicalTyVarKind::General(ui)) => *ui,
171+
CanonicalVarKind::Region(ui) => *ui,
172+
CanonicalVarKind::Const(ui) => *ui,
171173
CanonicalVarKind::PlaceholderTy(placeholder) => placeholder.universe(),
172174
CanonicalVarKind::PlaceholderRegion(placeholder) => placeholder.universe(),
173175
CanonicalVarKind::PlaceholderConst(placeholder) => placeholder.universe(),
@@ -181,7 +183,7 @@ impl<I: Interner> CanonicalVarKind<I> {
181183
///
182184
/// In case this is a float or int variable, this causes an ICE if
183185
/// the updated universe is not the root.
184-
pub fn with_updated_universe(self, ui: UniverseIndex) -> CanonicalVarKind<I> {
186+
pub fn with_updated_universe(&self, ui: UniverseIndex) -> CanonicalVarKind<I> {
185187
match self {
186188
CanonicalVarKind::Ty(CanonicalTyVarKind::General(_)) => {
187189
CanonicalVarKind::Ty(CanonicalTyVarKind::General(ui))
@@ -200,7 +202,7 @@ impl<I: Interner> CanonicalVarKind<I> {
200202
}
201203
CanonicalVarKind::Ty(CanonicalTyVarKind::Int | CanonicalTyVarKind::Float) => {
202204
assert_eq!(ui, UniverseIndex::ROOT);
203-
self
205+
self.clone()
204206
}
205207
}
206208
}

compiler/rustc_type_ir/src/const_kind.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::{self as ty, DebruijnIndex, Interner};
1111

1212
/// Represents a constant in Rust.
1313
#[derive_where(Clone, Hash, PartialEq, Eq; I: Interner)]
14-
#[derive_where(Copy; I: Interner, I::Ty: Copy, I::GenericArgs: Copy, I::ValueConst: Copy, I::ExprConst: Copy, I::ParamConst: Copy, I::BoundConst: Copy)]
14+
#[derive_where(Copy; I: Interner, I::Ty: Copy, I::GenericArgs: Copy, I::ValueConst: Copy, I::ExprConst: Copy, I::ParamConst: Copy, I::BoundConst: Copy, I::PlaceholderConst: Copy)]
1515
#[cfg_attr(feature = "nightly", derive(TyEncodable, TyDecodable, HashStable_NoContext))]
1616
pub enum ConstKind<I: Interner> {
1717
/// A const generic parameter.

compiler/rustc_type_ir/src/inherent.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -495,11 +495,11 @@ pub trait Clause<I: Interner<Clause = Self>>:
495495
}
496496

497497
/// Common capabilities of placeholder kinds
498-
pub trait PlaceholderLike: Copy + Debug + Hash + Eq {
499-
fn universe(self) -> ty::UniverseIndex;
498+
pub trait PlaceholderLike: Clone + Debug + Hash + Eq {
499+
fn universe(&self) -> ty::UniverseIndex;
500500
fn var(&self) -> ty::BoundVar;
501501

502-
fn with_updated_universe(self, ui: ty::UniverseIndex) -> Self;
502+
fn with_updated_universe(&self, ui: ty::UniverseIndex) -> Self;
503503

504504
fn new(ui: ty::UniverseIndex, var: ty::BoundVar) -> Self;
505505
}

compiler/rustc_type_ir/src/region_kind.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ rustc_index::newtype_index! {
126126
/// [2]: https://smallcultfollowing.com/babysteps/blog/2013/11/04/intermingled-parameter-lists/
127127
/// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/traits/hrtb.html
128128
#[derive_where(Clone, Hash, PartialEq, Eq; I: Interner)]
129-
#[derive_where(Copy; I: Interner, I::EarlyParamRegion: Copy, I::BoundRegion: Copy)]
129+
#[derive_where(Copy; I: Interner, I::EarlyParamRegion: Copy, I::BoundRegion: Copy, I::PlaceholderRegion: Copy)]
130130
#[cfg_attr(feature = "nightly", derive(TyEncodable, TyDecodable))]
131131
pub enum RegionKind<I: Interner> {
132132
/// A region parameter; for example `'a` in `impl<'a> Trait for &'a ()`.

compiler/rustc_type_ir/src/ty_kind.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl AliasTyKind {
6666
/// converted to this representation using `<dyn HirTyLowerer>::lower_ty`.
6767
#[cfg_attr(feature = "nightly", rustc_diagnostic_item = "IrTyKind")]
6868
#[derive_where(Clone, Hash, PartialEq, Eq; I: Interner)]
69-
#[derive_where(Copy; I: Interner, I::AdtDef: Copy, I::GenericArgs: Copy, I::Ty: Copy, I::Const: Copy, I::Region: Copy, I::BoundVarKinds: Copy, I::Tys: Copy, I::BoundExistentialPredicates: Copy, I::ParamTy: Copy, I::BoundTy: Copy)]
69+
#[derive_where(Copy; I: Interner, I::AdtDef: Copy, I::GenericArgs: Copy, I::Ty: Copy, I::Const: Copy, I::Region: Copy, I::BoundVarKinds: Copy, I::Tys: Copy, I::BoundExistentialPredicates: Copy, I::ParamTy: Copy, I::BoundTy: Copy, I::PlaceholderTy: Copy)]
7070
#[cfg_attr(feature = "nightly", derive(TyEncodable, TyDecodable, HashStable_NoContext))]
7171
pub enum TyKind<I: Interner> {
7272
/// The primitive boolean type. Written as `bool`.

tests/rustdoc-js/auxiliary/interner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ pub trait PlaceholderLike {
134134
// Required methods
135135
fn universe(self) -> UniverseIndex;
136136
fn var(self) -> BoundVar;
137-
fn with_updated_universe(self, ui: UniverseIndex) -> Self;
137+
fn with_updated_universe(&self, ui: UniverseIndex) -> Self;
138138
fn new(ui: UniverseIndex, var: BoundVar) -> Self;
139139
}
140140

0 commit comments

Comments
 (0)