Skip to content

Commit 4a9eec4

Browse files
bors[bot]Veykril
andauthored
Merge #7826
7826: Introduce Ty::Alias r=Veykril a=Veykril bors r+ Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2 parents cda13d5 + 5d121cd commit 4a9eec4

File tree

14 files changed

+109
-98
lines changed

14 files changed

+109
-98
lines changed

crates/hir/src/code_model.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use hir_ty::{
3131
display::{write_bounds_like_dyn_trait_with_prefix, HirDisplayError, HirFormatter},
3232
method_resolution,
3333
traits::{FnTrait, Solution, SolutionVariables},
34-
BoundVar, CallableDefId, CallableSig, Canonical, DebruijnIndex, GenericPredicate,
34+
AliasTy, BoundVar, CallableDefId, CallableSig, Canonical, DebruijnIndex, GenericPredicate,
3535
InEnvironment, Obligation, ProjectionPredicate, ProjectionTy, Scalar, Substs, TraitEnvironment,
3636
Ty, TyDefId, TyVariableKind,
3737
};
@@ -1648,7 +1648,7 @@ impl Type {
16481648
.build();
16491649
let predicate = ProjectionPredicate {
16501650
projection_ty: ProjectionTy { associated_ty: alias.id, parameters: subst },
1651-
ty: Ty::Bound(BoundVar::new(DebruijnIndex::INNERMOST, 0)),
1651+
ty: Ty::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0)),
16521652
};
16531653
let goal = Canonical {
16541654
value: InEnvironment::new(
@@ -1709,7 +1709,7 @@ impl Type {
17091709
}
17101710

17111711
pub fn is_raw_ptr(&self) -> bool {
1712-
matches!(&self.ty.value, Ty::RawPtr(..))
1712+
matches!(&self.ty.value, Ty::Raw(..))
17131713
}
17141714

17151715
pub fn contains_unknown(&self) -> bool {
@@ -1937,7 +1937,7 @@ impl Type {
19371937
walk_bounds(db, &type_.derived(ty.clone()), &bounds, cb);
19381938
}
19391939
}
1940-
Ty::Opaque(opaque_ty) => {
1940+
Ty::Alias(AliasTy::Opaque(opaque_ty)) => {
19411941
if let Some(bounds) = ty.impl_trait_bounds(db) {
19421942
walk_bounds(db, &type_.derived(ty.clone()), &bounds, cb);
19431943
}

crates/hir_ty/src/autoderef.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ fn deref_by_trait(
8181

8282
// Now do the assoc type projection
8383
let projection = super::traits::ProjectionPredicate {
84-
ty: Ty::Bound(BoundVar::new(DebruijnIndex::INNERMOST, ty.value.kinds.len())),
84+
ty: Ty::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, ty.value.kinds.len())),
8585
projection_ty: super::ProjectionTy { associated_ty: target, parameters },
8686
};
8787

@@ -114,7 +114,8 @@ fn deref_by_trait(
114114
// new variables in that case
115115

116116
for i in 1..vars.0.kinds.len() {
117-
if vars.0.value[i - 1] != Ty::Bound(BoundVar::new(DebruijnIndex::INNERMOST, i - 1))
117+
if vars.0.value[i - 1]
118+
!= Ty::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, i - 1))
118119
{
119120
warn!("complex solution for derefing {:?}: {:?}, ignoring", ty.value, solution);
120121
return None;

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 Ty::RawPtr(..) = &infer[*expr] {
113+
if let Ty::Raw(..) = &infer[*expr] {
114114
unsafe_exprs.push(UnsafeExpr { expr: current, inside_unsafe_block });
115115
}
116116
}

crates/hir_ty/src/display.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
use std::{borrow::Cow, fmt};
44

55
use crate::{
6-
db::HirDatabase, primitive, utils::generics, CallableDefId, CallableSig, GenericPredicate,
7-
Lifetime, Obligation, OpaqueTy, OpaqueTyId, ProjectionTy, Scalar, Substs, TraitRef, Ty,
6+
db::HirDatabase, primitive, utils::generics, AliasTy, CallableDefId, CallableSig,
7+
GenericPredicate, Lifetime, Obligation, OpaqueTy, OpaqueTyId, ProjectionTy, Scalar, Substs,
8+
TraitRef, Ty,
89
};
910
use arrayvec::ArrayVec;
1011
use hir_def::{
@@ -284,12 +285,12 @@ impl HirDisplay for Ty {
284285
t.hir_fmt(f)?;
285286
write!(f, "; _]")?;
286287
}
287-
Ty::RawPtr(m, parameters) | Ty::Ref(m, parameters) => {
288+
Ty::Raw(m, parameters) | Ty::Ref(m, parameters) => {
288289
let t = parameters.as_single();
289290
let ty_display =
290291
t.into_displayable(f.db, f.max_size, f.omit_verbose_types, f.display_target);
291292

292-
if matches!(self, Ty::RawPtr(..)) {
293+
if matches!(self, Ty::Raw(..)) {
293294
write!(f, "*{}", m.as_keyword_for_ptr())?;
294295
} else {
295296
write!(f, "&{}", m.as_keyword_for_ref())?;
@@ -300,10 +301,10 @@ impl HirDisplay for Ty {
300301
Ty::Dyn(predicates) if predicates.len() > 1 => {
301302
Cow::Borrowed(predicates.as_ref())
302303
}
303-
&Ty::Opaque(OpaqueTy {
304+
&Ty::Alias(AliasTy::Opaque(OpaqueTy {
304305
opaque_ty_id: OpaqueTyId::ReturnTypeImplTrait(func, idx),
305306
ref parameters,
306-
}) => {
307+
})) => {
307308
datas =
308309
f.db.return_type_impl_traits(func).expect("impl trait id without data");
309310
let data = (*datas)
@@ -518,7 +519,6 @@ impl HirDisplay for Ty {
518519
write!(f, "{{closure}}")?;
519520
}
520521
}
521-
Ty::Projection(p_ty) => p_ty.hir_fmt(f)?,
522522
Ty::Placeholder(id) => {
523523
let generics = generics(f.db.upcast(), id.parent);
524524
let param_data = &generics.params.types[id.local_id];
@@ -537,11 +537,12 @@ impl HirDisplay for Ty {
537537
}
538538
}
539539
}
540-
Ty::Bound(idx) => write!(f, "?{}.{}", idx.debruijn.depth(), idx.index)?,
540+
Ty::BoundVar(idx) => write!(f, "?{}.{}", idx.debruijn.depth(), idx.index)?,
541541
Ty::Dyn(predicates) => {
542542
write_bounds_like_dyn_trait_with_prefix("dyn", predicates, f)?;
543543
}
544-
Ty::Opaque(opaque_ty) => {
544+
Ty::Alias(AliasTy::Projection(p_ty)) => p_ty.hir_fmt(f)?,
545+
Ty::Alias(AliasTy::Opaque(opaque_ty)) => {
545546
match opaque_ty.opaque_ty_id {
546547
OpaqueTyId::ReturnTypeImplTrait(func, idx) => {
547548
let datas =

crates/hir_ty/src/infer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use super::{
4040
InEnvironment, ProjectionTy, Substs, TraitEnvironment, TraitRef, Ty, TypeWalk,
4141
};
4242
use crate::{
43-
db::HirDatabase, infer::diagnostics::InferenceDiagnostic, lower::ImplTraitLoweringMode,
43+
db::HirDatabase, infer::diagnostics::InferenceDiagnostic, lower::ImplTraitLoweringMode, AliasTy,
4444
};
4545

4646
pub(crate) use unify::unify;
@@ -395,7 +395,7 @@ impl<'a> InferenceContext<'a> {
395395
fn normalize_associated_types_in(&mut self, ty: Ty) -> Ty {
396396
let ty = self.resolve_ty_as_possible(ty);
397397
ty.fold(&mut |ty| match ty {
398-
Ty::Projection(proj_ty) => self.normalize_projection_ty(proj_ty),
398+
Ty::Alias(AliasTy::Projection(proj_ty)) => self.normalize_projection_ty(proj_ty),
399399
_ => ty,
400400
})
401401
}

crates/hir_ty/src/infer/coerce.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,19 @@ impl<'a> InferenceContext<'a> {
7373
match (&mut from_ty, to_ty) {
7474
// `*mut T` -> `*const T`
7575
// `&mut T` -> `&T`
76-
(Ty::RawPtr(m1, ..), Ty::RawPtr(m2 @ Mutability::Shared, ..))
76+
(Ty::Raw(m1, ..), Ty::Raw(m2 @ Mutability::Shared, ..))
7777
| (Ty::Ref(m1, ..), Ty::Ref(m2 @ Mutability::Shared, ..)) => {
7878
*m1 = *m2;
7979
}
8080
// `&T` -> `*const T`
8181
// `&mut T` -> `*mut T`/`*const T`
82-
(Ty::Ref(.., substs), &Ty::RawPtr(m2 @ Mutability::Shared, ..))
83-
| (Ty::Ref(Mutability::Mut, substs), &Ty::RawPtr(m2, ..)) => {
84-
from_ty = Ty::RawPtr(m2, substs.clone());
82+
(Ty::Ref(.., substs), &Ty::Raw(m2 @ Mutability::Shared, ..))
83+
| (Ty::Ref(Mutability::Mut, substs), &Ty::Raw(m2, ..)) => {
84+
from_ty = Ty::Raw(m2, substs.clone());
8585
}
8686

8787
// Illegal mutability conversion
88-
(Ty::RawPtr(Mutability::Shared, ..), Ty::RawPtr(Mutability::Mut, ..))
88+
(Ty::Raw(Mutability::Shared, ..), Ty::Raw(Mutability::Mut, ..))
8989
| (Ty::Ref(Mutability::Shared, ..), Ty::Ref(Mutability::Mut, ..)) => return false,
9090

9191
// `{function_type}` -> `fn()`

crates/hir_ty/src/infer/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ impl<'a> InferenceContext<'a> {
479479
};
480480
let inner_ty = self.infer_expr_inner(*expr, &expectation);
481481
match rawness {
482-
Rawness::RawPtr => Ty::RawPtr(*mutability, Substs::single(inner_ty)),
482+
Rawness::RawPtr => Ty::Raw(*mutability, Substs::single(inner_ty)),
483483
Rawness::Ref => Ty::Ref(*mutability, Substs::single(inner_ty)),
484484
}
485485
}

crates/hir_ty/src/infer/unify.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl<'a, 'b> Canonicalizer<'a, 'b> {
6868
} else {
6969
let root = self.ctx.table.var_unification_table.find(inner);
7070
let position = self.add(InferenceVar::from_inner(root), kind);
71-
Ty::Bound(BoundVar::new(binders, position))
71+
Ty::BoundVar(BoundVar::new(binders, position))
7272
}
7373
}
7474
_ => ty,
@@ -110,7 +110,7 @@ impl<T> Canonicalized<T> {
110110
pub(super) fn decanonicalize_ty(&self, mut ty: Ty) -> Ty {
111111
ty.walk_mut_binders(
112112
&mut |ty, binders| {
113-
if let &mut Ty::Bound(bound) = ty {
113+
if let &mut Ty::BoundVar(bound) = ty {
114114
if bound.debruijn >= binders {
115115
let (v, k) = self.free_vars[bound.index];
116116
*ty = Ty::InferenceVar(v, k);
@@ -168,7 +168,7 @@ pub(crate) fn unify(tys: &Canonical<(Ty, Ty)>) -> Option<Substs> {
168168
// (kind of hacky)
169169
for (i, var) in vars.iter().enumerate() {
170170
if &*table.resolve_ty_shallow(var) == var {
171-
table.unify(var, &Ty::Bound(BoundVar::new(DebruijnIndex::INNERMOST, i)));
171+
table.unify(var, &Ty::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, i)));
172172
}
173173
}
174174
Some(

0 commit comments

Comments
 (0)