Skip to content

Commit 42b2a1d

Browse files
committed
Expand target for autocompletion
1 parent 868e5eb commit 42b2a1d

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
@@ -1068,20 +1068,21 @@ impl Field {
10681068
Type::new(db, var_id, ty)
10691069
}
10701070

1071-
pub fn ty_with_generics(
1072-
&self,
1073-
db: &dyn HirDatabase,
1074-
mut generics: impl Iterator<Item = Type>,
1075-
) -> Type {
1071+
pub fn ty_with_args(&self, db: &dyn HirDatabase, generics: impl Iterator<Item = Type>) -> Type {
10761072
let var_id = self.parent.into();
10771073
let def_id: AdtId = match self.parent {
10781074
VariantDef::Struct(it) => it.id.into(),
10791075
VariantDef::Union(it) => it.id.into(),
10801076
VariantDef::Variant(it) => it.parent.id.into(),
10811077
};
1078+
let mut generics = generics.map(|it| it.ty.clone());
10821079
let substs = TyBuilder::subst_for_def(db, def_id, None)
1083-
.fill(|_| {
1084-
GenericArg::new(Interner, GenericArgData::Ty(generics.next().unwrap().ty.clone()))
1080+
.fill(|x| {
1081+
let ty = generics.next().unwrap_or_else(|| TyKind::Error.intern(Interner));
1082+
match x {
1083+
ParamKind::Type => ty.cast(Interner),
1084+
ParamKind::Const(ty) => unknown_const_as_generic(ty.clone()),
1085+
}
10851086
})
10861087
.build();
10871088
let ty = db.field_types(var_id)[self.id].clone().substitute(Interner, &substs);
@@ -1141,14 +1142,15 @@ impl Struct {
11411142
Type::from_def(db, self.id)
11421143
}
11431144

1144-
pub fn ty_with_generics(
1145-
self,
1146-
db: &dyn HirDatabase,
1147-
mut generics: impl Iterator<Item = Type>,
1148-
) -> Type {
1145+
pub fn ty_with_args(self, db: &dyn HirDatabase, generics: impl Iterator<Item = Type>) -> Type {
1146+
let mut generics = generics.map(|it| it.ty.clone());
11491147
let substs = TyBuilder::subst_for_def(db, self.id, None)
1150-
.fill(|_| {
1151-
GenericArg::new(Interner, GenericArgData::Ty(generics.next().unwrap().ty.clone()))
1148+
.fill(|x| {
1149+
let ty = generics.next().unwrap_or_else(|| TyKind::Error.intern(Interner));
1150+
match x {
1151+
ParamKind::Type => ty.cast(Interner),
1152+
ParamKind::Const(ty) => unknown_const_as_generic(ty.clone()),
1153+
}
11521154
})
11531155
.build();
11541156
let ty = db.ty(self.id.into()).substitute(Interner, &substs);
@@ -1254,16 +1256,18 @@ impl Enum {
12541256
Type::from_def(db, self.id)
12551257
}
12561258

1257-
pub fn ty_with_generics(
1258-
&self,
1259-
db: &dyn HirDatabase,
1260-
mut generics: impl Iterator<Item = Type>,
1261-
) -> Type {
1259+
pub fn ty_with_args(&self, db: &dyn HirDatabase, generics: impl Iterator<Item = Type>) -> Type {
1260+
let mut generics = generics.map(|it| it.ty.clone());
12621261
let substs = TyBuilder::subst_for_def(db, self.id, None)
1263-
.fill(|_| {
1264-
GenericArg::new(Interner, GenericArgData::Ty(generics.next().unwrap().ty.clone()))
1262+
.fill(|x| {
1263+
let ty = generics.next().unwrap_or_else(|| TyKind::Error.intern(Interner));
1264+
match x {
1265+
ParamKind::Type => ty.cast(Interner),
1266+
ParamKind::Const(ty) => unknown_const_as_generic(ty.clone()),
1267+
}
12651268
})
12661269
.build();
1270+
12671271
let ty = db.ty(self.id.into()).substitute(Interner, &substs);
12681272
Type::new(db, self.id, ty)
12691273
}
@@ -2070,33 +2074,29 @@ impl Function {
20702074
Type::new_with_resolver_inner(db, &resolver, ty)
20712075
}
20722076

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

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

21012101
let callable_sig = db.callable_item_signature(self.id.into()).substitute(Interner, &substs);
21022102
let ty = callable_sig.ret().clone();
@@ -2414,11 +2414,7 @@ impl SelfParam {
24142414
Type { env: environment, ty }
24152415
}
24162416

2417-
pub fn ty_with_generics(
2418-
&self,
2419-
db: &dyn HirDatabase,
2420-
mut generics: impl Iterator<Item = Type>,
2421-
) -> Type {
2417+
pub fn ty_with_args(&self, db: &dyn HirDatabase, generics: impl Iterator<Item = Type>) -> Type {
24222418
let parent_id: GenericDefId = match self.func.lookup(db.upcast()).container {
24232419
ItemContainerId::ImplId(it) => it.into(),
24242420
ItemContainerId::TraitId(it) => it.into(),
@@ -2427,16 +2423,18 @@ impl SelfParam {
24272423
}
24282424
};
24292425

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

0 commit comments

Comments
 (0)