Skip to content

Commit c2dba9c

Browse files
committed
Rename InternedObligationCauseCode.
It's a misleading name, because it's not interned.
1 parent 0895fe2 commit c2dba9c

File tree

1 file changed

+17
-15
lines changed
  • compiler/rustc_middle/src/traits

1 file changed

+17
-15
lines changed

compiler/rustc_middle/src/traits/mod.rs

+17-15
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub struct ObligationCause<'tcx> {
5151
/// information.
5252
pub body_id: LocalDefId,
5353

54-
code: InternedObligationCauseCode<'tcx>,
54+
code: ObligationCauseCodeHandle<'tcx>,
5555
}
5656

5757
// This custom hash function speeds up hashing for `Obligation` deduplication
@@ -97,7 +97,7 @@ impl<'tcx> ObligationCause<'tcx> {
9797

9898
pub fn map_code(
9999
&mut self,
100-
f: impl FnOnce(InternedObligationCauseCode<'tcx>) -> ObligationCauseCode<'tcx>,
100+
f: impl FnOnce(ObligationCauseCodeHandle<'tcx>) -> ObligationCauseCode<'tcx>,
101101
) {
102102
self.code = f(std::mem::take(&mut self.code)).into();
103103
}
@@ -152,15 +152,16 @@ pub struct UnifyReceiverContext<'tcx> {
152152
pub args: GenericArgsRef<'tcx>,
153153
}
154154

155+
/// A compact form of `ObligationCauseCode`.
155156
#[derive(Clone, PartialEq, Eq, Default, HashStable)]
156157
#[derive(TypeVisitable, TypeFoldable, TyEncodable, TyDecodable)]
157-
pub struct InternedObligationCauseCode<'tcx> {
158+
pub struct ObligationCauseCodeHandle<'tcx> {
158159
/// `None` for `ObligationCauseCode::Misc` (a common case, occurs ~60% of
159160
/// the time). `Some` otherwise.
160161
code: Option<Arc<ObligationCauseCode<'tcx>>>,
161162
}
162163

163-
impl<'tcx> std::fmt::Debug for InternedObligationCauseCode<'tcx> {
164+
impl<'tcx> std::fmt::Debug for ObligationCauseCodeHandle<'tcx> {
164165
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
165166
let cause: &ObligationCauseCode<'_> = self;
166167
cause.fmt(f)
@@ -169,14 +170,14 @@ impl<'tcx> std::fmt::Debug for InternedObligationCauseCode<'tcx> {
169170

170171
impl<'tcx> ObligationCauseCode<'tcx> {
171172
#[inline(always)]
172-
fn into(self) -> InternedObligationCauseCode<'tcx> {
173-
InternedObligationCauseCode {
173+
fn into(self) -> ObligationCauseCodeHandle<'tcx> {
174+
ObligationCauseCodeHandle {
174175
code: if let ObligationCauseCode::Misc = self { None } else { Some(Arc::new(self)) },
175176
}
176177
}
177178
}
178179

179-
impl<'tcx> std::ops::Deref for InternedObligationCauseCode<'tcx> {
180+
impl<'tcx> std::ops::Deref for ObligationCauseCodeHandle<'tcx> {
180181
type Target = ObligationCauseCode<'tcx>;
181182

182183
fn deref(&self) -> &Self::Target {
@@ -305,7 +306,7 @@ pub enum ObligationCauseCode<'tcx> {
305306
/// The node of the function call.
306307
call_hir_id: HirId,
307308
/// The obligation introduced by this argument.
308-
parent_code: InternedObligationCauseCode<'tcx>,
309+
parent_code: ObligationCauseCodeHandle<'tcx>,
309310
},
310311

311312
/// Error derived when checking an impl item is compatible with
@@ -390,7 +391,8 @@ pub enum ObligationCauseCode<'tcx> {
390391
/// `WellFormed(None)`.
391392
WellFormed(Option<WellFormedLoc>),
392393

393-
/// From `match_impl`. The cause for us having to match an impl, and the DefId we are matching against.
394+
/// From `match_impl`. The cause for us having to match an impl, and the DefId we are matching
395+
/// against.
394396
MatchImpl(ObligationCause<'tcx>, DefId),
395397

396398
BinOp {
@@ -413,7 +415,7 @@ pub enum ObligationCauseCode<'tcx> {
413415
ConstParam(Ty<'tcx>),
414416

415417
/// Obligations emitted during the normalization of a weak type alias.
416-
TypeAlias(InternedObligationCauseCode<'tcx>, Span, DefId),
418+
TypeAlias(ObligationCauseCodeHandle<'tcx>, Span, DefId),
417419
}
418420

419421
/// Whether a value can be extracted into a const.
@@ -578,17 +580,17 @@ pub struct DerivedCause<'tcx> {
578580
pub parent_trait_pred: ty::PolyTraitPredicate<'tcx>,
579581

580582
/// The parent trait had this cause.
581-
pub parent_code: InternedObligationCauseCode<'tcx>,
583+
pub parent_code: ObligationCauseCodeHandle<'tcx>,
582584
}
583585

584586
#[derive(Clone, Debug, PartialEq, Eq, HashStable, TyEncodable, TyDecodable)]
585587
#[derive(TypeVisitable, TypeFoldable)]
586588
pub struct ImplDerivedCause<'tcx> {
587589
pub derived: DerivedCause<'tcx>,
588590
/// The `DefId` of the `impl` that gave rise to the `derived` obligation.
589-
/// If the `derived` obligation arose from a trait alias, which conceptually has a synthetic impl,
590-
/// then this will be the `DefId` of that trait alias. Care should therefore be taken to handle
591-
/// that exceptional case where appropriate.
591+
/// If the `derived` obligation arose from a trait alias, which conceptually has a synthetic
592+
/// impl, then this will be the `DefId` of that trait alias. Care should therefore be taken to
593+
/// handle that exceptional case where appropriate.
592594
pub impl_or_alias_def_id: DefId,
593595
/// The index of the derived predicate in the parent impl's predicates.
594596
pub impl_def_predicate_index: Option<usize>,
@@ -605,7 +607,7 @@ pub struct DerivedHostCause<'tcx> {
605607
pub parent_host_pred: ty::Binder<'tcx, ty::HostEffectPredicate<'tcx>>,
606608

607609
/// The parent trait had this cause.
608-
pub parent_code: InternedObligationCauseCode<'tcx>,
610+
pub parent_code: ObligationCauseCodeHandle<'tcx>,
609611
}
610612

611613
#[derive(Clone, Debug, PartialEq, Eq, HashStable, TyEncodable, TyDecodable)]

0 commit comments

Comments
 (0)