Skip to content

Commit 232bc6d

Browse files
committed
Expand target for autocompletion
1 parent 8c7e8ad commit 232bc6d

File tree

15 files changed

+455
-467
lines changed

15 files changed

+455
-467
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
@@ -1089,20 +1089,21 @@ impl Field {
10891089
Type::new(db, var_id, ty)
10901090
}
10911091

1092-
pub fn ty_with_generics(
1093-
&self,
1094-
db: &dyn HirDatabase,
1095-
mut generics: impl Iterator<Item = Type>,
1096-
) -> Type {
1092+
pub fn ty_with_args(&self, db: &dyn HirDatabase, generics: impl Iterator<Item = Type>) -> Type {
10971093
let var_id = self.parent.into();
10981094
let def_id: AdtId = match self.parent {
10991095
VariantDef::Struct(it) => it.id.into(),
11001096
VariantDef::Union(it) => it.id.into(),
11011097
VariantDef::Variant(it) => it.parent.id.into(),
11021098
};
1099+
let mut generics = generics.map(|it| it.ty.clone());
11031100
let substs = TyBuilder::subst_for_def(db, def_id, None)
1104-
.fill(|_| {
1105-
GenericArg::new(Interner, GenericArgData::Ty(generics.next().unwrap().ty.clone()))
1101+
.fill(|x| {
1102+
let ty = generics.next().unwrap_or_else(|| TyKind::Error.intern(Interner));
1103+
match x {
1104+
ParamKind::Type => ty.cast(Interner),
1105+
ParamKind::Const(ty) => unknown_const_as_generic(ty.clone()),
1106+
}
11061107
})
11071108
.build();
11081109
let ty = db.field_types(var_id)[self.id].clone().substitute(Interner, &substs);
@@ -1162,14 +1163,15 @@ impl Struct {
11621163
Type::from_def(db, self.id)
11631164
}
11641165

1165-
pub fn ty_with_generics(
1166-
self,
1167-
db: &dyn HirDatabase,
1168-
mut generics: impl Iterator<Item = Type>,
1169-
) -> Type {
1166+
pub fn ty_with_args(self, db: &dyn HirDatabase, generics: impl Iterator<Item = Type>) -> Type {
1167+
let mut generics = generics.map(|it| it.ty.clone());
11701168
let substs = TyBuilder::subst_for_def(db, self.id, None)
1171-
.fill(|_| {
1172-
GenericArg::new(Interner, GenericArgData::Ty(generics.next().unwrap().ty.clone()))
1169+
.fill(|x| {
1170+
let ty = generics.next().unwrap_or_else(|| TyKind::Error.intern(Interner));
1171+
match x {
1172+
ParamKind::Type => ty.cast(Interner),
1173+
ParamKind::Const(ty) => unknown_const_as_generic(ty.clone()),
1174+
}
11731175
})
11741176
.build();
11751177
let ty = db.ty(self.id.into()).substitute(Interner, &substs);
@@ -1275,16 +1277,18 @@ impl Enum {
12751277
Type::from_def(db, self.id)
12761278
}
12771279

1278-
pub fn ty_with_generics(
1279-
&self,
1280-
db: &dyn HirDatabase,
1281-
mut generics: impl Iterator<Item = Type>,
1282-
) -> Type {
1280+
pub fn ty_with_args(&self, db: &dyn HirDatabase, generics: impl Iterator<Item = Type>) -> Type {
1281+
let mut generics = generics.map(|it| it.ty.clone());
12831282
let substs = TyBuilder::subst_for_def(db, self.id, None)
1284-
.fill(|_| {
1285-
GenericArg::new(Interner, GenericArgData::Ty(generics.next().unwrap().ty.clone()))
1283+
.fill(|x| {
1284+
let ty = generics.next().unwrap_or_else(|| TyKind::Error.intern(Interner));
1285+
match x {
1286+
ParamKind::Type => ty.cast(Interner),
1287+
ParamKind::Const(ty) => unknown_const_as_generic(ty.clone()),
1288+
}
12861289
})
12871290
.build();
1291+
12881292
let ty = db.ty(self.id.into()).substitute(Interner, &substs);
12891293
Type::new(db, self.id, ty)
12901294
}
@@ -2103,33 +2107,29 @@ impl Function {
21032107
Type::new_with_resolver_inner(db, &resolver, ty)
21042108
}
21052109

2106-
pub fn ret_type_with_generics(
2110+
pub fn ret_type_with_args(
21072111
self,
21082112
db: &dyn HirDatabase,
2109-
mut generics: impl Iterator<Item = Type>,
2113+
generics: impl Iterator<Item = Type>,
21102114
) -> Type {
21112115
let resolver = self.id.resolver(db.upcast());
21122116
let parent_id: Option<GenericDefId> = match self.id.lookup(db.upcast()).container {
21132117
ItemContainerId::ImplId(it) => Some(it.into()),
21142118
ItemContainerId::TraitId(it) => Some(it.into()),
21152119
ItemContainerId::ModuleId(_) | ItemContainerId::ExternBlockId(_) => None,
21162120
};
2117-
let parent_substs = parent_id.map(|id| {
2118-
TyBuilder::subst_for_def(db, id, None)
2119-
.fill(|_| {
2120-
GenericArg::new(
2121-
Interner,
2122-
GenericArgData::Ty(generics.next().unwrap().ty.clone()),
2123-
)
2124-
})
2125-
.build()
2126-
});
2121+
let mut generics = generics.map(|it| it.ty.clone());
2122+
let mut filler = |x: &_| {
2123+
let ty = generics.next().unwrap_or_else(|| TyKind::Error.intern(Interner));
2124+
match x {
2125+
ParamKind::Type => ty.cast(Interner),
2126+
ParamKind::Const(ty) => unknown_const_as_generic(ty.clone()),
2127+
}
2128+
};
21272129

2128-
let substs = TyBuilder::subst_for_def(db, self.id, parent_substs)
2129-
.fill(|_| {
2130-
GenericArg::new(Interner, GenericArgData::Ty(generics.next().unwrap().ty.clone()))
2131-
})
2132-
.build();
2130+
let parent_substs =
2131+
parent_id.map(|id| TyBuilder::subst_for_def(db, id, None).fill(&mut filler).build());
2132+
let substs = TyBuilder::subst_for_def(db, self.id, parent_substs).fill(&mut filler).build();
21332133

21342134
let callable_sig = db.callable_item_signature(self.id.into()).substitute(Interner, &substs);
21352135
let ty = callable_sig.ret().clone();
@@ -2449,11 +2449,7 @@ impl SelfParam {
24492449
Type { env: environment, ty }
24502450
}
24512451

2452-
pub fn ty_with_generics(
2453-
&self,
2454-
db: &dyn HirDatabase,
2455-
mut generics: impl Iterator<Item = Type>,
2456-
) -> Type {
2452+
pub fn ty_with_args(&self, db: &dyn HirDatabase, generics: impl Iterator<Item = Type>) -> Type {
24572453
let parent_id: GenericDefId = match self.func.lookup(db.upcast()).container {
24582454
ItemContainerId::ImplId(it) => it.into(),
24592455
ItemContainerId::TraitId(it) => it.into(),
@@ -2462,16 +2458,18 @@ impl SelfParam {
24622458
}
24632459
};
24642460

2465-
let parent_substs = TyBuilder::subst_for_def(db, parent_id, None)
2466-
.fill(|_| {
2467-
GenericArg::new(Interner, GenericArgData::Ty(generics.next().unwrap().ty.clone()))
2468-
})
2469-
.build();
2470-
let substs = TyBuilder::subst_for_def(db, self.func, Some(parent_substs))
2471-
.fill(|_| {
2472-
GenericArg::new(Interner, GenericArgData::Ty(generics.next().unwrap().ty.clone()))
2473-
})
2474-
.build();
2461+
let mut generics = generics.map(|it| it.ty.clone());
2462+
let mut filler = |x: &_| {
2463+
let ty = generics.next().unwrap_or_else(|| TyKind::Error.intern(Interner));
2464+
match x {
2465+
ParamKind::Type => ty.cast(Interner),
2466+
ParamKind::Const(ty) => unknown_const_as_generic(ty.clone()),
2467+
}
2468+
};
2469+
2470+
let parent_substs = TyBuilder::subst_for_def(db, parent_id, None).fill(&mut filler).build();
2471+
let substs =
2472+
TyBuilder::subst_for_def(db, self.func, Some(parent_substs)).fill(&mut filler).build();
24752473
let callable_sig =
24762474
db.callable_item_signature(self.func.into()).substitute(Interner, &substs);
24772475
let environment = db.trait_environment(self.func.into());

0 commit comments

Comments
 (0)