Skip to content

Commit ef2aed8

Browse files
committed
Expand target for autocompletion
1 parent 311a4f2 commit ef2aed8

File tree

15 files changed

+462
-474
lines changed

15 files changed

+462
-474
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
@@ -1088,20 +1088,21 @@ impl Field {
10881088
Type::new(db, var_id, ty)
10891089
}
10901090

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

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

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

2071-
pub fn ret_type_with_generics(
2075+
pub fn ret_type_with_args(
20722076
self,
20732077
db: &dyn HirDatabase,
2074-
mut generics: impl Iterator<Item = Type>,
2078+
generics: impl Iterator<Item = Type>,
20752079
) -> Type {
20762080
let resolver = self.id.resolver(db.upcast());
20772081
let parent_id: Option<GenericDefId> = match self.id.lookup(db.upcast()).container {
20782082
ItemContainerId::ImplId(it) => Some(it.into()),
20792083
ItemContainerId::TraitId(it) => Some(it.into()),
20802084
ItemContainerId::ModuleId(_) | ItemContainerId::ExternBlockId(_) => None,
20812085
};
2082-
let parent_substs = parent_id.map(|id| {
2083-
TyBuilder::subst_for_def(db, id, None)
2084-
.fill(|_| {
2085-
GenericArg::new(
2086-
Interner,
2087-
GenericArgData::Ty(generics.next().unwrap().ty.clone()),
2088-
)
2089-
})
2090-
.build()
2091-
});
2086+
let mut generics = generics.map(|it| it.ty.clone());
2087+
let mut filler = |x: &_| {
2088+
let ty = generics.next().unwrap_or_else(|| TyKind::Error.intern(Interner));
2089+
match x {
2090+
ParamKind::Type => ty.cast(Interner),
2091+
ParamKind::Const(ty) => unknown_const_as_generic(ty.clone()),
2092+
}
2093+
};
20922094

2093-
let substs = TyBuilder::subst_for_def(db, self.id, parent_substs)
2094-
.fill(|_| {
2095-
GenericArg::new(Interner, GenericArgData::Ty(generics.next().unwrap().ty.clone()))
2096-
})
2097-
.build();
2095+
let parent_substs =
2096+
parent_id.map(|id| TyBuilder::subst_for_def(db, id, None).fill(&mut filler).build());
2097+
let substs = TyBuilder::subst_for_def(db, self.id, parent_substs).fill(&mut filler).build();
20982098

20992099
let callable_sig = db.callable_item_signature(self.id.into()).substitute(Interner, &substs);
21002100
let ty = callable_sig.ret().clone();
@@ -2412,11 +2412,7 @@ impl SelfParam {
24122412
Type { env: environment, ty }
24132413
}
24142414

2415-
pub fn ty_with_generics(
2416-
&self,
2417-
db: &dyn HirDatabase,
2418-
mut generics: impl Iterator<Item = Type>,
2419-
) -> Type {
2415+
pub fn ty_with_args(&self, db: &dyn HirDatabase, generics: impl Iterator<Item = Type>) -> Type {
24202416
let parent_id: GenericDefId = match self.func.lookup(db.upcast()).container {
24212417
ItemContainerId::ImplId(it) => it.into(),
24222418
ItemContainerId::TraitId(it) => it.into(),
@@ -2425,16 +2421,18 @@ impl SelfParam {
24252421
}
24262422
};
24272423

2428-
let parent_substs = TyBuilder::subst_for_def(db, parent_id, None)
2429-
.fill(|_| {
2430-
GenericArg::new(Interner, GenericArgData::Ty(generics.next().unwrap().ty.clone()))
2431-
})
2432-
.build();
2433-
let substs = TyBuilder::subst_for_def(db, self.func, Some(parent_substs))
2434-
.fill(|_| {
2435-
GenericArg::new(Interner, GenericArgData::Ty(generics.next().unwrap().ty.clone()))
2436-
})
2437-
.build();
2424+
let mut generics = generics.map(|it| it.ty.clone());
2425+
let mut filler = |x: &_| {
2426+
let ty = generics.next().unwrap_or_else(|| TyKind::Error.intern(Interner));
2427+
match x {
2428+
ParamKind::Type => ty.cast(Interner),
2429+
ParamKind::Const(ty) => unknown_const_as_generic(ty.clone()),
2430+
}
2431+
};
2432+
2433+
let parent_substs = TyBuilder::subst_for_def(db, parent_id, None).fill(&mut filler).build();
2434+
let substs =
2435+
TyBuilder::subst_for_def(db, self.func, Some(parent_substs)).fill(&mut filler).build();
24382436
let callable_sig =
24392437
db.callable_item_signature(self.func.into()).substitute(Interner, &substs);
24402438
let environment = db.trait_environment(self.func.into());

0 commit comments

Comments
 (0)