Skip to content

Commit 2f87ee7

Browse files
Merge #8310
8310: Rename Ty::interned to Ty::kind r=flodiebold a=flodiebold ... since that's the actual method on Chalk side that matches the signature. Co-authored-by: Florian Diebold <[email protected]>
2 parents 8289b96 + c551604 commit 2f87ee7

17 files changed

+73
-75
lines changed

crates/hir/src/lib.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,22 +1711,22 @@ impl Type {
17111711
}
17121712

17131713
pub fn is_unit(&self) -> bool {
1714-
matches!(self.ty.interned(&Interner), TyKind::Tuple(0, ..))
1714+
matches!(self.ty.kind(&Interner), TyKind::Tuple(0, ..))
17151715
}
17161716
pub fn is_bool(&self) -> bool {
1717-
matches!(self.ty.interned(&Interner), TyKind::Scalar(Scalar::Bool))
1717+
matches!(self.ty.kind(&Interner), TyKind::Scalar(Scalar::Bool))
17181718
}
17191719

17201720
pub fn is_mutable_reference(&self) -> bool {
1721-
matches!(self.ty.interned(&Interner), TyKind::Ref(hir_ty::Mutability::Mut, ..))
1721+
matches!(self.ty.kind(&Interner), TyKind::Ref(hir_ty::Mutability::Mut, ..))
17221722
}
17231723

17241724
pub fn is_usize(&self) -> bool {
1725-
matches!(self.ty.interned(&Interner), TyKind::Scalar(Scalar::Uint(UintTy::Usize)))
1725+
matches!(self.ty.kind(&Interner), TyKind::Scalar(Scalar::Uint(UintTy::Usize)))
17261726
}
17271727

17281728
pub fn remove_ref(&self) -> Option<Type> {
1729-
match &self.ty.interned(&Interner) {
1729+
match &self.ty.kind(&Interner) {
17301730
TyKind::Ref(.., ty) => Some(self.derived(ty.clone())),
17311731
_ => None,
17321732
}
@@ -1855,15 +1855,15 @@ impl Type {
18551855
}
18561856

18571857
pub fn is_closure(&self) -> bool {
1858-
matches!(&self.ty.interned(&Interner), TyKind::Closure { .. })
1858+
matches!(&self.ty.kind(&Interner), TyKind::Closure { .. })
18591859
}
18601860

18611861
pub fn is_fn(&self) -> bool {
1862-
matches!(&self.ty.interned(&Interner), TyKind::FnDef(..) | TyKind::Function { .. })
1862+
matches!(&self.ty.kind(&Interner), TyKind::FnDef(..) | TyKind::Function { .. })
18631863
}
18641864

18651865
pub fn is_packed(&self, db: &dyn HirDatabase) -> bool {
1866-
let adt_id = match self.ty.interned(&Interner) {
1866+
let adt_id = match self.ty.kind(&Interner) {
18671867
&TyKind::Adt(hir_ty::AdtId(adt_id), ..) => adt_id,
18681868
_ => return false,
18691869
};
@@ -1876,14 +1876,14 @@ impl Type {
18761876
}
18771877

18781878
pub fn is_raw_ptr(&self) -> bool {
1879-
matches!(&self.ty.interned(&Interner), TyKind::Raw(..))
1879+
matches!(&self.ty.kind(&Interner), TyKind::Raw(..))
18801880
}
18811881

18821882
pub fn contains_unknown(&self) -> bool {
18831883
return go(&self.ty);
18841884

18851885
fn go(ty: &Ty) -> bool {
1886-
match ty.interned(&Interner) {
1886+
match ty.kind(&Interner) {
18871887
TyKind::Unknown => true,
18881888

18891889
TyKind::Adt(_, substs)
@@ -1914,7 +1914,7 @@ impl Type {
19141914
}
19151915

19161916
pub fn fields(&self, db: &dyn HirDatabase) -> Vec<(Field, Type)> {
1917-
let (variant_id, substs) = match self.ty.interned(&Interner) {
1917+
let (variant_id, substs) = match self.ty.kind(&Interner) {
19181918
&TyKind::Adt(hir_ty::AdtId(AdtId::StructId(s)), ref substs) => (s.into(), substs),
19191919
&TyKind::Adt(hir_ty::AdtId(AdtId::UnionId(u)), ref substs) => (u.into(), substs),
19201920
_ => return Vec::new(),
@@ -1931,7 +1931,7 @@ impl Type {
19311931
}
19321932

19331933
pub fn tuple_fields(&self, _db: &dyn HirDatabase) -> Vec<Type> {
1934-
if let TyKind::Tuple(_, substs) = &self.ty.interned(&Interner) {
1934+
if let TyKind::Tuple(_, substs) = &self.ty.kind(&Interner) {
19351935
substs
19361936
.iter(&Interner)
19371937
.map(|ty| self.derived(ty.assert_ty_ref(&Interner).clone()))
@@ -2120,7 +2120,7 @@ impl Type {
21202120

21212121
fn walk_type(db: &dyn HirDatabase, type_: &Type, cb: &mut impl FnMut(Type)) {
21222122
let ty = type_.ty.strip_references();
2123-
match ty.interned(&Interner) {
2123+
match ty.kind(&Interner) {
21242124
TyKind::Adt(..) => {
21252125
cb(type_.derived(ty.clone()));
21262126
}

crates/hir_ty/src/autoderef.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ fn deref_by_trait(
131131
// new variables in that case
132132

133133
for i in 1..vars.0.binders.len(&Interner) {
134-
if vars.0.value.at(&Interner, i - 1).assert_ty_ref(&Interner).interned(&Interner)
134+
if vars.0.value.at(&Interner, i - 1).assert_ty_ref(&Interner).kind(&Interner)
135135
!= &TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, i - 1))
136136
{
137137
warn!("complex solution for derefing {:?}: {:?}, ignoring", ty.goal, solution);

crates/hir_ty/src/diagnostics/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
378378
_ => return,
379379
};
380380

381-
let (params, required) = match mismatch.expected.interned(&Interner) {
381+
let (params, required) = match mismatch.expected.kind(&Interner) {
382382
TyKind::Adt(AdtId(hir_def::AdtId::EnumId(enum_id)), ref parameters)
383383
if *enum_id == core_result_enum =>
384384
{

crates/hir_ty/src/diagnostics/match_check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ pub(super) fn is_useful(
626626
// - enum with no variants
627627
// - `!` type
628628
// In those cases, no match arm is useful.
629-
match cx.infer[cx.match_expr].strip_references().interned(&Interner) {
629+
match cx.infer[cx.match_expr].strip_references().kind(&Interner) {
630630
TyKind::Adt(AdtId(hir_def::AdtId::EnumId(enum_id)), ..) => {
631631
if cx.db.enum_data(*enum_id).variants.is_empty() {
632632
return Ok(Usefulness::NotUseful);

crates/hir_ty/src/diagnostics/unsafe_check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ fn walk_unsafe(
110110
}
111111
}
112112
Expr::UnaryOp { expr, op: UnaryOp::Deref } => {
113-
if let TyKind::Raw(..) = &infer[*expr].interned(&Interner) {
113+
if let TyKind::Raw(..) = &infer[*expr].kind(&Interner) {
114114
unsafe_exprs.push(UnsafeExpr { expr: current, inside_unsafe_block });
115115
}
116116
}

crates/hir_ty/src/display.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ impl HirDisplay for Ty {
292292
return write!(f, "{}", TYPE_HINT_TRUNCATION);
293293
}
294294

295-
match self.interned(&Interner) {
295+
match self.kind(&Interner) {
296296
TyKind::Never => write!(f, "!")?,
297297
TyKind::Str => write!(f, "str")?,
298298
TyKind::Scalar(Scalar::Bool) => write!(f, "bool")?,
@@ -314,7 +314,7 @@ impl HirDisplay for Ty {
314314
let ty_display =
315315
t.into_displayable(f.db, f.max_size, f.omit_verbose_types, f.display_target);
316316

317-
if matches!(self.interned(&Interner), TyKind::Raw(..)) {
317+
if matches!(self.kind(&Interner), TyKind::Raw(..)) {
318318
write!(
319319
f,
320320
"*{}",
@@ -336,7 +336,7 @@ impl HirDisplay for Ty {
336336

337337
// FIXME: all this just to decide whether to use parentheses...
338338
let datas;
339-
let predicates: Vec<_> = match t.interned(&Interner) {
339+
let predicates: Vec<_> = match t.kind(&Interner) {
340340
TyKind::Dyn(dyn_ty) if dyn_ty.bounds.skip_binders().interned().len() > 1 => {
341341
dyn_ty.bounds.skip_binders().interned().iter().cloned().collect()
342342
}
@@ -473,7 +473,7 @@ impl HirDisplay for Ty {
473473
let mut default_from = 0;
474474
for (i, parameter) in parameters.iter(&Interner).enumerate() {
475475
match (
476-
parameter.assert_ty_ref(&Interner).interned(&Interner),
476+
parameter.assert_ty_ref(&Interner).kind(&Interner),
477477
default_parameters.get(i),
478478
) {
479479
(&TyKind::Unknown, _) | (_, None) => {

crates/hir_ty/src/infer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ impl<'a> InferenceContext<'a> {
325325

326326
/// Replaces Ty::Unknown by a new type var, so we can maybe still infer it.
327327
fn insert_type_vars_shallow(&mut self, ty: Ty) -> Ty {
328-
match ty.interned(&Interner) {
328+
match ty.kind(&Interner) {
329329
TyKind::Unknown => self.table.new_type_var(),
330330
_ => ty,
331331
}
@@ -438,7 +438,7 @@ impl<'a> InferenceContext<'a> {
438438
/// to do it as well.
439439
fn normalize_associated_types_in(&mut self, ty: Ty) -> Ty {
440440
let ty = self.resolve_ty_as_possible(ty);
441-
ty.fold(&mut |ty| match ty.interned(&Interner) {
441+
ty.fold(&mut |ty| match ty.kind(&Interner) {
442442
TyKind::Alias(AliasTy::Projection(proj_ty)) => {
443443
self.normalize_projection_ty(proj_ty.clone())
444444
}

crates/hir_ty/src/infer/coerce.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl<'a> InferenceContext<'a> {
3636
ty1.clone()
3737
} else {
3838
if let (TyKind::FnDef(..), TyKind::FnDef(..)) =
39-
(ty1.interned(&Interner), ty2.interned(&Interner))
39+
(ty1.kind(&Interner), ty2.kind(&Interner))
4040
{
4141
cov_mark::hit!(coerce_fn_reification);
4242
// Special case: two function types. Try to coerce both to
@@ -55,7 +55,7 @@ impl<'a> InferenceContext<'a> {
5555
}
5656

5757
fn coerce_inner(&mut self, mut from_ty: Ty, to_ty: &Ty) -> bool {
58-
match (from_ty.interned(&Interner), to_ty.interned(&Interner)) {
58+
match (from_ty.kind(&Interner), to_ty.kind(&Interner)) {
5959
// Never type will make type variable to fallback to Never Type instead of Unknown.
6060
(TyKind::Never, TyKind::InferenceVar(tv, TyVariableKind::General)) => {
6161
self.table.type_variable_table.set_diverging(*tv, true);
@@ -73,7 +73,7 @@ impl<'a> InferenceContext<'a> {
7373
}
7474

7575
// Pointer weakening and function to pointer
76-
match (from_ty.interned_mut(), to_ty.interned(&Interner)) {
76+
match (from_ty.interned_mut(), to_ty.kind(&Interner)) {
7777
// `*mut T` -> `*const T`
7878
// `&mut T` -> `&T`
7979
(TyKind::Raw(m1, ..), TyKind::Raw(m2 @ Mutability::Not, ..))
@@ -111,7 +111,7 @@ impl<'a> InferenceContext<'a> {
111111
}
112112

113113
// Auto Deref if cannot coerce
114-
match (from_ty.interned(&Interner), to_ty.interned(&Interner)) {
114+
match (from_ty.kind(&Interner), to_ty.kind(&Interner)) {
115115
// FIXME: DerefMut
116116
(TyKind::Ref(_, st1), TyKind::Ref(_, st2)) => self.unify_autoderef_behind_ref(st1, st2),
117117

crates/hir_ty/src/infer/expr.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ impl<'a> InferenceContext<'a> {
455455
})
456456
.unwrap_or(true)
457457
};
458-
match canonicalized.decanonicalize_ty(derefed_ty.value).interned(&Interner) {
458+
match canonicalized.decanonicalize_ty(derefed_ty.value).kind(&Interner) {
459459
TyKind::Tuple(_, substs) => name.as_tuple_index().and_then(|idx| {
460460
substs
461461
.interned(&Interner)
@@ -577,7 +577,7 @@ impl<'a> InferenceContext<'a> {
577577
None => self.err_ty(),
578578
},
579579
UnaryOp::Neg => {
580-
match inner_ty.interned(&Interner) {
580+
match inner_ty.kind(&Interner) {
581581
// Fast path for builtins
582582
TyKind::Scalar(Scalar::Int(_))
583583
| TyKind::Scalar(Scalar::Uint(_))
@@ -590,7 +590,7 @@ impl<'a> InferenceContext<'a> {
590590
}
591591
}
592592
UnaryOp::Not => {
593-
match inner_ty.interned(&Interner) {
593+
match inner_ty.kind(&Interner) {
594594
// Fast path for builtins
595595
TyKind::Scalar(Scalar::Bool)
596596
| TyKind::Scalar(Scalar::Int(_))
@@ -696,7 +696,7 @@ impl<'a> InferenceContext<'a> {
696696
}
697697
}
698698
Expr::Tuple { exprs } => {
699-
let mut tys = match expected.ty.interned(&Interner) {
699+
let mut tys = match expected.ty.kind(&Interner) {
700700
TyKind::Tuple(_, substs) => substs
701701
.iter(&Interner)
702702
.map(|a| a.assert_ty_ref(&Interner).clone())
@@ -713,7 +713,7 @@ impl<'a> InferenceContext<'a> {
713713
TyKind::Tuple(tys.len(), Substitution::from_iter(&Interner, tys)).intern(&Interner)
714714
}
715715
Expr::Array(array) => {
716-
let elem_ty = match expected.ty.interned(&Interner) {
716+
let elem_ty = match expected.ty.kind(&Interner) {
717717
TyKind::Array(st) | TyKind::Slice(st) => st.clone(),
718718
_ => self.table.new_type_var(),
719719
};
@@ -961,7 +961,7 @@ impl<'a> InferenceContext<'a> {
961961
}
962962

963963
fn register_obligations_for_call(&mut self, callable_ty: &Ty) {
964-
if let TyKind::FnDef(fn_def, parameters) = callable_ty.interned(&Interner) {
964+
if let TyKind::FnDef(fn_def, parameters) = callable_ty.kind(&Interner) {
965965
let def: CallableDefId = from_chalk(self.db, *fn_def);
966966
let generic_predicates = self.db.generic_predicates(def.into());
967967
for predicate in generic_predicates.iter() {

crates/hir_ty/src/infer/pat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ impl<'a> InferenceContext<'a> {
211211
return inner_ty;
212212
}
213213
Pat::Slice { prefix, slice, suffix } => {
214-
let (container_ty, elem_ty): (fn(_) -> _, _) = match expected.interned(&Interner) {
214+
let (container_ty, elem_ty): (fn(_) -> _, _) = match expected.kind(&Interner) {
215215
TyKind::Array(st) => (TyKind::Array, st.clone()),
216216
TyKind::Slice(st) => (TyKind::Slice, st.clone()),
217217
_ => (TyKind::Slice, self.err_ty()),

crates/hir_ty/src/infer/path.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ impl<'a> InferenceContext<'a> {
147147
remaining_segments_for_ty,
148148
true,
149149
);
150-
if let TyKind::Unknown = ty.interned(&Interner) {
150+
if let TyKind::Unknown = ty.kind(&Interner) {
151151
return None;
152152
}
153153

@@ -212,7 +212,7 @@ impl<'a> InferenceContext<'a> {
212212
name: &Name,
213213
id: ExprOrPatId,
214214
) -> Option<(ValueNs, Option<Substitution>)> {
215-
if let TyKind::Unknown = ty.interned(&Interner) {
215+
if let TyKind::Unknown = ty.kind(&Interner) {
216216
return None;
217217
}
218218

crates/hir_ty/src/infer/unify.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl<'a, 'b> Canonicalizer<'a, 'b> {
4949

5050
fn do_canonicalize<T: TypeWalk>(&mut self, t: T, binders: DebruijnIndex) -> T {
5151
t.fold_binders(
52-
&mut |ty, binders| match ty.interned(&Interner) {
52+
&mut |ty, binders| match ty.kind(&Interner) {
5353
&TyKind::InferenceVar(var, kind) => {
5454
let inner = var.to_inner();
5555
if self.var_stack.contains(&inner) {
@@ -304,7 +304,7 @@ impl InferenceTable {
304304
let ty1 = self.resolve_ty_shallow(ty1);
305305
let ty2 = self.resolve_ty_shallow(ty2);
306306
if ty1.equals_ctor(&ty2) {
307-
match (ty1.interned(&Interner), ty2.interned(&Interner)) {
307+
match (ty1.kind(&Interner), ty2.kind(&Interner)) {
308308
(TyKind::Adt(_, substs1), TyKind::Adt(_, substs2))
309309
| (TyKind::FnDef(_, substs1), TyKind::FnDef(_, substs2))
310310
| (
@@ -329,7 +329,7 @@ impl InferenceTable {
329329
}
330330

331331
pub(super) fn unify_inner_trivial(&mut self, ty1: &Ty, ty2: &Ty, depth: usize) -> bool {
332-
match (ty1.interned(&Interner), ty2.interned(&Interner)) {
332+
match (ty1.kind(&Interner), ty2.kind(&Interner)) {
333333
(TyKind::Unknown, _) | (_, TyKind::Unknown) => true,
334334

335335
(TyKind::Placeholder(p1), TyKind::Placeholder(p2)) if *p1 == *p2 => true,
@@ -458,7 +458,7 @@ impl InferenceTable {
458458
if i > 0 {
459459
cov_mark::hit!(type_var_resolves_to_int_var);
460460
}
461-
match ty.interned(&Interner) {
461+
match ty.kind(&Interner) {
462462
TyKind::InferenceVar(tv, _) => {
463463
let inner = tv.to_inner();
464464
match self.var_unification_table.inlined_probe_value(inner).known() {
@@ -481,7 +481,7 @@ impl InferenceTable {
481481
/// be resolved as far as possible, i.e. contain no type variables with
482482
/// known type.
483483
fn resolve_ty_as_possible_inner(&mut self, tv_stack: &mut Vec<TypeVarId>, ty: Ty) -> Ty {
484-
ty.fold(&mut |ty| match ty.interned(&Interner) {
484+
ty.fold(&mut |ty| match ty.kind(&Interner) {
485485
&TyKind::InferenceVar(tv, kind) => {
486486
let inner = tv.to_inner();
487487
if tv_stack.contains(&inner) {
@@ -508,7 +508,7 @@ impl InferenceTable {
508508
/// Resolves the type completely; type variables without known type are
509509
/// replaced by TyKind::Unknown.
510510
fn resolve_ty_completely_inner(&mut self, tv_stack: &mut Vec<TypeVarId>, ty: Ty) -> Ty {
511-
ty.fold(&mut |ty| match ty.interned(&Interner) {
511+
ty.fold(&mut |ty| match ty.kind(&Interner) {
512512
&TyKind::InferenceVar(tv, kind) => {
513513
let inner = tv.to_inner();
514514
if tv_stack.contains(&inner) {

0 commit comments

Comments
 (0)