aboutsummaryrefslogtreecommitdiff
path: root/crates/hir
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2020-10-06 18:07:34 +0100
committerLukas Wirth <[email protected]>2020-10-06 18:20:42 +0100
commitaaa3905fdd18a7981d40ac371099ae9044e833a8 (patch)
treedbacb3b28efc4404f664edd802b1467b2bf57e37 /crates/hir
parentec1f4599809b6e1b10418fa78e1d7bfc3c817319 (diff)
Shorten type hints for std::iter Iterators
Diffstat (limited to 'crates/hir')
-rw-r--r--crates/hir/src/code_model.rs37
-rw-r--r--crates/hir/src/lib.rs2
2 files changed, 36 insertions, 3 deletions
diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs
index c75d46bff..031c91ccf 100644
--- a/crates/hir/src/code_model.rs
+++ b/crates/hir/src/code_model.rs
@@ -30,8 +30,12 @@ use hir_expand::{
30use hir_ty::{ 30use hir_ty::{
31 autoderef, 31 autoderef,
32 display::{HirDisplayError, HirFormatter}, 32 display::{HirDisplayError, HirFormatter},
33 method_resolution, ApplicationTy, CallableDefId, Canonical, FnSig, GenericPredicate, 33 method_resolution,
34 InEnvironment, Substs, TraitEnvironment, Ty, TyDefId, TypeCtor, 34 traits::Solution,
35 traits::SolutionVariables,
36 ApplicationTy, BoundVar, CallableDefId, Canonical, DebruijnIndex, FnSig, GenericPredicate,
37 InEnvironment, Obligation, ProjectionPredicate, ProjectionTy, Substs, TraitEnvironment, Ty,
38 TyDefId, TyKind, TypeCtor,
35}; 39};
36use rustc_hash::FxHashSet; 40use rustc_hash::FxHashSet;
37use stdx::impl_from; 41use stdx::impl_from;
@@ -1362,6 +1366,35 @@ impl Type {
1362 db.trait_solve(self.krate, goal).is_some() 1366 db.trait_solve(self.krate, goal).is_some()
1363 } 1367 }
1364 1368
1369 pub fn normalize_trait_assoc_type(
1370 &self,
1371 db: &dyn HirDatabase,
1372 r#trait: Trait,
1373 args: &[Type],
1374 alias: TypeAlias,
1375 ) -> Option<Ty> {
1376 let subst = Substs::build_for_def(db, r#trait.id)
1377 .push(self.ty.value.clone())
1378 .fill(args.iter().map(|t| t.ty.value.clone()))
1379 .build();
1380 let predicate = ProjectionPredicate {
1381 projection_ty: ProjectionTy { associated_ty: alias.id, parameters: subst },
1382 ty: Ty::Bound(BoundVar::new(DebruijnIndex::INNERMOST, 0)),
1383 };
1384 let goal = Canonical {
1385 value: InEnvironment::new(
1386 self.ty.environment.clone(),
1387 Obligation::Projection(predicate),
1388 ),
1389 kinds: Arc::new([TyKind::General]),
1390 };
1391
1392 match db.trait_solve(self.krate, goal)? {
1393 Solution::Unique(SolutionVariables(subst)) => subst.value.first().cloned(),
1394 Solution::Ambig(_) => None,
1395 }
1396 }
1397
1365 pub fn is_copy(&self, db: &dyn HirDatabase) -> bool { 1398 pub fn is_copy(&self, db: &dyn HirDatabase) -> bool {
1366 let lang_item = db.lang_item(self.krate, SmolStr::new("copy")); 1399 let lang_item = db.lang_item(self.krate, SmolStr::new("copy"));
1367 let copy_trait = match lang_item { 1400 let copy_trait = match lang_item {
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index 171118d98..4094a76cb 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -55,7 +55,7 @@ pub use hir_def::{
55 type_ref::{Mutability, TypeRef}, 55 type_ref::{Mutability, TypeRef},
56}; 56};
57pub use hir_expand::{ 57pub use hir_expand::{
58 name::AsName, name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc, 58 name::known, name::AsName, name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc,
59 /* FIXME */ MacroDefId, MacroFile, Origin, 59 /* FIXME */ MacroDefId, MacroFile, Origin,
60}; 60};
61pub use hir_ty::display::HirDisplay; 61pub use hir_ty::display::HirDisplay;