Skip to content

Commit 4f134b6

Browse files
committed
Expand target for autocompletion
1 parent c8ef819 commit 4f134b6

File tree

14 files changed

+448
-464
lines changed

14 files changed

+448
-464
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ authors = ["rust-analyzer team"]
1212
[profile.dev]
1313
# Disabling debug info speeds up builds a bunch,
1414
# and we don't rely on it for debugging that much.
15-
debug = 2
15+
debug = 0
1616

1717
[profile.dev.package]
1818
# These speed up local tests.

crates/hir-ty/src/infer/unify.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,6 @@ pub fn could_unify_deeply(
106106
let ty2_with_vars = vars.apply(tys.value.1.clone(), Interner);
107107
let ty1_with_vars = table.normalize_associated_types_in(ty1_with_vars);
108108
let ty2_with_vars = table.normalize_associated_types_in(ty2_with_vars);
109-
// table.resolve_obligations_as_possible();
110-
// table.propagate_diverging_flag();
111-
// let ty1_with_vars = table.resolve_completely(ty1_with_vars);
112-
// let ty2_with_vars = table.resolve_completely(ty2_with_vars);
113109
table.unify_deeply(&ty1_with_vars, &ty2_with_vars)
114110
}
115111

crates/hir/src/lib.rs

Lines changed: 51 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,20 +1084,21 @@ impl Field {
10841084
Type::new(db, var_id, ty)
10851085
}
10861086

1087-
pub fn ty_with_generics(
1088-
&self,
1089-
db: &dyn HirDatabase,
1090-
mut generics: impl Iterator<Item = Type>,
1091-
) -> Type {
1087+
pub fn ty_with_args(&self, db: &dyn HirDatabase, generics: impl Iterator<Item = Type>) -> Type {
10921088
let var_id = self.parent.into();
10931089
let def_id: AdtId = match self.parent {
10941090
VariantDef::Struct(it) => it.id.into(),
10951091
VariantDef::Union(it) => it.id.into(),
10961092
VariantDef::Variant(it) => it.parent_enum(db).id.into(),
10971093
};
1094+
let mut generics = generics.map(|it| it.ty.clone());
10981095
let substs = TyBuilder::subst_for_def(db, def_id, None)
1099-
.fill(|_| {
1100-
GenericArg::new(Interner, GenericArgData::Ty(generics.next().unwrap().ty.clone()))
1096+
.fill(|x| {
1097+
let ty = generics.next().unwrap_or_else(|| TyKind::Error.intern(Interner));
1098+
match x {
1099+
ParamKind::Type => ty.cast(Interner),
1100+
ParamKind::Const(ty) => unknown_const_as_generic(ty.clone()),
1101+
}
11011102
})
11021103
.build();
11031104
let ty = db.field_types(var_id)[self.id].clone().substitute(Interner, &substs);
@@ -1157,14 +1158,15 @@ impl Struct {
11571158
Type::from_def(db, self.id)
11581159
}
11591160

1160-
pub fn ty_with_generics(
1161-
self,
1162-
db: &dyn HirDatabase,
1163-
mut generics: impl Iterator<Item = Type>,
1164-
) -> Type {
1161+
pub fn ty_with_args(self, db: &dyn HirDatabase, generics: impl Iterator<Item = Type>) -> Type {
1162+
let mut generics = generics.map(|it| it.ty.clone());
11651163
let substs = TyBuilder::subst_for_def(db, self.id, None)
1166-
.fill(|_| {
1167-
GenericArg::new(Interner, GenericArgData::Ty(generics.next().unwrap().ty.clone()))
1164+
.fill(|x| {
1165+
let ty = generics.next().unwrap_or_else(|| TyKind::Error.intern(Interner));
1166+
match x {
1167+
ParamKind::Type => ty.cast(Interner),
1168+
ParamKind::Const(ty) => unknown_const_as_generic(ty.clone()),
1169+
}
11681170
})
11691171
.build();
11701172
let ty = db.ty(self.id.into()).substitute(Interner, &substs);
@@ -1270,16 +1272,18 @@ impl Enum {
12701272
Type::from_def(db, self.id)
12711273
}
12721274

1273-
pub fn ty_with_generics(
1274-
&self,
1275-
db: &dyn HirDatabase,
1276-
mut generics: impl Iterator<Item = Type>,
1277-
) -> Type {
1275+
pub fn ty_with_args(&self, db: &dyn HirDatabase, generics: impl Iterator<Item = Type>) -> Type {
1276+
let mut generics = generics.map(|it| it.ty.clone());
12781277
let substs = TyBuilder::subst_for_def(db, self.id, None)
1279-
.fill(|_| {
1280-
GenericArg::new(Interner, GenericArgData::Ty(generics.next().unwrap().ty.clone()))
1278+
.fill(|x| {
1279+
let ty = generics.next().unwrap_or_else(|| TyKind::Error.intern(Interner));
1280+
match x {
1281+
ParamKind::Type => ty.cast(Interner),
1282+
ParamKind::Const(ty) => unknown_const_as_generic(ty.clone()),
1283+
}
12811284
})
12821285
.build();
1286+
12831287
let ty = db.ty(self.id.into()).substitute(Interner, &substs);
12841288
Type::new(db, self.id, ty)
12851289
}
@@ -1853,33 +1857,29 @@ impl Function {
18531857
Type::new_with_resolver_inner(db, &resolver, ty)
18541858
}
18551859

1856-
pub fn ret_type_with_generics(
1860+
pub fn ret_type_with_args(
18571861
self,
18581862
db: &dyn HirDatabase,
1859-
mut generics: impl Iterator<Item = Type>,
1863+
generics: impl Iterator<Item = Type>,
18601864
) -> Type {
18611865
let resolver = self.id.resolver(db.upcast());
18621866
let parent_id: Option<GenericDefId> = match self.id.lookup(db.upcast()).container {
18631867
ItemContainerId::ImplId(it) => Some(it.into()),
18641868
ItemContainerId::TraitId(it) => Some(it.into()),
18651869
ItemContainerId::ModuleId(_) | ItemContainerId::ExternBlockId(_) => None,
18661870
};
1867-
let parent_substs = parent_id.map(|id| {
1868-
TyBuilder::subst_for_def(db, id, None)
1869-
.fill(|_| {
1870-
GenericArg::new(
1871-
Interner,
1872-
GenericArgData::Ty(generics.next().unwrap().ty.clone()),
1873-
)
1874-
})
1875-
.build()
1876-
});
1871+
let mut generics = generics.map(|it| it.ty.clone());
1872+
let mut filler = |x: &_| {
1873+
let ty = generics.next().unwrap_or_else(|| TyKind::Error.intern(Interner));
1874+
match x {
1875+
ParamKind::Type => ty.cast(Interner),
1876+
ParamKind::Const(ty) => unknown_const_as_generic(ty.clone()),
1877+
}
1878+
};
18771879

1878-
let substs = TyBuilder::subst_for_def(db, self.id, parent_substs)
1879-
.fill(|_| {
1880-
GenericArg::new(Interner, GenericArgData::Ty(generics.next().unwrap().ty.clone()))
1881-
})
1882-
.build();
1880+
let parent_substs =
1881+
parent_id.map(|id| TyBuilder::subst_for_def(db, id, None).fill(&mut filler).build());
1882+
let substs = TyBuilder::subst_for_def(db, self.id, parent_substs).fill(&mut filler).build();
18831883

18841884
let callable_sig = db.callable_item_signature(self.id.into()).substitute(Interner, &substs);
18851885
let ty = callable_sig.ret().clone();
@@ -2197,11 +2197,7 @@ impl SelfParam {
21972197
Type { env: environment, ty }
21982198
}
21992199

2200-
pub fn ty_with_generics(
2201-
&self,
2202-
db: &dyn HirDatabase,
2203-
mut generics: impl Iterator<Item = Type>,
2204-
) -> Type {
2200+
pub fn ty_with_args(&self, db: &dyn HirDatabase, generics: impl Iterator<Item = Type>) -> Type {
22052201
let parent_id: GenericDefId = match self.func.lookup(db.upcast()).container {
22062202
ItemContainerId::ImplId(it) => it.into(),
22072203
ItemContainerId::TraitId(it) => it.into(),
@@ -2210,16 +2206,18 @@ impl SelfParam {
22102206
}
22112207
};
22122208

2213-
let parent_substs = TyBuilder::subst_for_def(db, parent_id, None)
2214-
.fill(|_| {
2215-
GenericArg::new(Interner, GenericArgData::Ty(generics.next().unwrap().ty.clone()))
2216-
})
2217-
.build();
2218-
let substs = TyBuilder::subst_for_def(db, self.func, Some(parent_substs))
2219-
.fill(|_| {
2220-
GenericArg::new(Interner, GenericArgData::Ty(generics.next().unwrap().ty.clone()))
2221-
})
2222-
.build();
2209+
let mut generics = generics.map(|it| it.ty.clone());
2210+
let mut filler = |x: &_| {
2211+
let ty = generics.next().unwrap_or_else(|| TyKind::Error.intern(Interner));
2212+
match x {
2213+
ParamKind::Type => ty.cast(Interner),
2214+
ParamKind::Const(ty) => unknown_const_as_generic(ty.clone()),
2215+
}
2216+
};
2217+
2218+
let parent_substs = TyBuilder::subst_for_def(db, parent_id, None).fill(&mut filler).build();
2219+
let substs =
2220+
TyBuilder::subst_for_def(db, self.func, Some(parent_substs)).fill(&mut filler).build();
22232221
let callable_sig =
22242222
db.callable_item_signature(self.func.into()).substitute(Interner, &substs);
22252223
let environment = db.trait_environment(self.func.into());

0 commit comments

Comments
 (0)