Remove Substs from Ty::ForeignType

This commit is contained in:
Lukas Wirth 2021-02-28 20:44:09 +01:00
parent 0e995adcf6
commit a3fd2faba5
5 changed files with 9 additions and 18 deletions

View File

@ -471,14 +471,9 @@ impl HirDisplay for Ty {
projection_ty.hir_fmt(f)?;
}
}
Ty::ForeignType(type_alias, parameters) => {
Ty::ForeignType(type_alias) => {
let type_alias = f.db.type_alias_data(*type_alias);
write!(f, "{}", type_alias.name)?;
if parameters.len() > 0 {
write!(f, "<")?;
f.write_joined(&*parameters.0, ", ")?;
write!(f, ">")?;
}
}
Ty::OpaqueType(opaque_ty_id, parameters) => {
match opaque_ty_id {

View File

@ -169,7 +169,7 @@ pub enum Ty {
Closure { def: DefWithBodyId, expr: ExprId, substs: Substs },
/// Represents a foreign type declared in external blocks.
ForeignType(TypeAliasId, Substs),
ForeignType(TypeAliasId),
/// A pointer to a function. Written as `fn() -> i32`.
///
@ -755,7 +755,6 @@ impl Ty {
| Ty::Tuple(_, substs)
| Ty::OpaqueType(_, substs)
| Ty::AssociatedType(_, substs)
| Ty::ForeignType(_, substs)
| Ty::Closure { substs, .. } => {
assert_eq!(substs.len(), new_substs.len());
*substs = new_substs;
@ -779,7 +778,6 @@ impl Ty {
| Ty::Tuple(_, substs)
| Ty::OpaqueType(_, substs)
| Ty::AssociatedType(_, substs)
| Ty::ForeignType(_, substs)
| Ty::Closure { substs, .. } => Some(substs),
_ => None,
}
@ -797,7 +795,6 @@ impl Ty {
| Ty::Tuple(_, substs)
| Ty::OpaqueType(_, substs)
| Ty::AssociatedType(_, substs)
| Ty::ForeignType(_, substs)
| Ty::Closure { substs, .. } => Some(substs),
_ => None,
}

View File

@ -1100,10 +1100,10 @@ fn type_for_type_alias(db: &dyn HirDatabase, t: TypeAliasId) -> Binders<Ty> {
let resolver = t.resolver(db.upcast());
let ctx =
TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable);
let substs = Substs::bound_vars(&generics, DebruijnIndex::INNERMOST);
if db.type_alias_data(t).is_extern {
Binders::new(substs.len(), Ty::ForeignType(t, substs))
Binders::new(0, Ty::ForeignType(t))
} else {
let substs = Substs::bound_vars(&generics, DebruijnIndex::INNERMOST);
let type_ref = &db.type_alias_data(t).type_ref;
let inner = Ty::from_hir(&ctx, type_ref.as_ref().unwrap_or(&TypeRef::Error));
Binders::new(substs.len(), inner)

View File

@ -235,7 +235,7 @@ impl Ty {
Ty::Adt(def_id, _) => {
return mod_to_crate_ids(def_id.module(db.upcast()));
}
Ty::ForeignType(type_alias_id, _) => {
Ty::ForeignType(type_alias_id) => {
return mod_to_crate_ids(type_alias_id.lookup(db.upcast()).module(db.upcast()));
}
Ty::Scalar(Scalar::Bool) => lang_item_crate!("bool"),

View File

@ -55,7 +55,7 @@ impl ToChalk for Ty {
chalk_ir::TyKind::OpaqueType(id, substitution).intern(&Interner)
}
Ty::ForeignType(type_alias, _) => {
Ty::ForeignType(type_alias) => {
let foreign_type = TypeAliasAsForeignType(type_alias);
let foreign_type_id = foreign_type.to_chalk(db);
chalk_ir::TyKind::Foreign(foreign_type_id).intern(&Interner)
@ -221,10 +221,9 @@ impl ToChalk for Ty {
Ty::Closure { def, expr, substs: from_chalk(db, subst) }
}
chalk_ir::TyKind::Foreign(foreign_def_id) => Ty::ForeignType(
from_chalk::<TypeAliasAsForeignType, _>(db, foreign_def_id).0,
Substs::empty(),
),
chalk_ir::TyKind::Foreign(foreign_def_id) => {
Ty::ForeignType(from_chalk::<TypeAliasAsForeignType, _>(db, foreign_def_id).0)
}
chalk_ir::TyKind::Generator(_, _) => unimplemented!(), // FIXME
chalk_ir::TyKind::GeneratorWitness(_, _) => unimplemented!(), // FIXME
}