Skip to content

Commit 389d9a6

Browse files
committed
Lower extern type alias as foreign opaque type.
1 parent b302f69 commit 389d9a6

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

crates/hir_def/src/data.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ pub struct TypeAliasData {
5454
pub name: Name,
5555
pub type_ref: Option<TypeRef>,
5656
pub visibility: RawVisibility,
57+
pub is_extern: bool,
5758
/// Bounds restricting the type alias itself (eg. `type Ty: Bound;` in a trait or impl).
5859
pub bounds: Vec<TypeBound>,
5960
}
@@ -71,6 +72,7 @@ impl TypeAliasData {
7172
name: typ.name.clone(),
7273
type_ref: typ.type_ref.clone(),
7374
visibility: item_tree[typ.visibility].clone(),
75+
is_extern: typ.is_extern,
7476
bounds: typ.bounds.to_vec(),
7577
})
7678
}

crates/hir_ty/src/lower.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,9 +1101,13 @@ fn type_for_type_alias(db: &dyn HirDatabase, t: TypeAliasId) -> Binders<Ty> {
11011101
let resolver = t.resolver(db.upcast());
11021102
let ctx =
11031103
TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable);
1104-
let type_ref = &db.type_alias_data(t).type_ref;
11051104
let substs = Substs::bound_vars(&generics, DebruijnIndex::INNERMOST);
1106-
let inner = Ty::from_hir(&ctx, type_ref.as_ref().unwrap_or(&TypeRef::Error));
1105+
let inner = if db.type_alias_data(t).is_extern {
1106+
Ty::simple(TypeCtor::ForeignType(t))
1107+
} else {
1108+
let type_ref = &db.type_alias_data(t).type_ref;
1109+
Ty::from_hir(&ctx, type_ref.as_ref().unwrap_or(&TypeRef::Error))
1110+
};
11071111
Binders::new(substs.len(), inner)
11081112
}
11091113

0 commit comments

Comments
 (0)