Skip to content

Commit 0b838e3

Browse files
committed
Expand target for autocompletion
1 parent a946970 commit 0b838e3

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
@@ -1085,20 +1085,21 @@ impl Field {
10851085
Type::new(db, var_id, ty)
10861086
}
10871087

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

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

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

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

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

18851885
let callable_sig = db.callable_item_signature(self.id.into()).substitute(Interner, &substs);
18861886
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)