diff options
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 15 | ||||
-rw-r--r-- | crates/ra_hir/src/semantics.rs | 16 |
2 files changed, 17 insertions, 14 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 27e94b7fe..e09eb77c2 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -31,7 +31,7 @@ use hir_ty::{ | |||
31 | ApplicationTy, Canonical, GenericPredicate, InEnvironment, Substs, TraitEnvironment, Ty, | 31 | ApplicationTy, Canonical, GenericPredicate, InEnvironment, Substs, TraitEnvironment, Ty, |
32 | TyDefId, TypeCtor, | 32 | TyDefId, TypeCtor, |
33 | }; | 33 | }; |
34 | use ra_db::{CrateId, CrateName, Edition, FileId}; | 34 | use ra_db::{CrateId, Edition, FileId}; |
35 | use ra_prof::profile; | 35 | use ra_prof::profile; |
36 | use ra_syntax::ast::{self, AttrsOwner, NameOwner}; | 36 | use ra_syntax::ast::{self, AttrsOwner, NameOwner}; |
37 | use rustc_hash::FxHashSet; | 37 | use rustc_hash::FxHashSet; |
@@ -94,8 +94,8 @@ impl Crate { | |||
94 | db.crate_graph()[self.id].edition | 94 | db.crate_graph()[self.id].edition |
95 | } | 95 | } |
96 | 96 | ||
97 | pub fn display_name(self, db: &dyn HirDatabase) -> Option<CrateName> { | 97 | pub fn display_name(self, db: &dyn HirDatabase) -> Option<String> { |
98 | db.crate_graph()[self.id].display_name.as_ref().cloned() | 98 | db.crate_graph()[self.id].display_name.clone() |
99 | } | 99 | } |
100 | 100 | ||
101 | pub fn query_external_importables( | 101 | pub fn query_external_importables( |
@@ -543,7 +543,7 @@ impl_froms!(Adt: Struct, Union, Enum); | |||
543 | impl Adt { | 543 | impl Adt { |
544 | pub fn has_non_default_type_params(self, db: &dyn HirDatabase) -> bool { | 544 | pub fn has_non_default_type_params(self, db: &dyn HirDatabase) -> bool { |
545 | let subst = db.generic_defaults(self.into()); | 545 | let subst = db.generic_defaults(self.into()); |
546 | subst.iter().any(|ty| ty == &Ty::Unknown) | 546 | subst.iter().any(|ty| &ty.value == &Ty::Unknown) |
547 | } | 547 | } |
548 | 548 | ||
549 | /// Turns this ADT into a type. Any type parameters of the ADT will be | 549 | /// Turns this ADT into a type. Any type parameters of the ADT will be |
@@ -775,7 +775,7 @@ pub struct TypeAlias { | |||
775 | impl TypeAlias { | 775 | impl TypeAlias { |
776 | pub fn has_non_default_type_params(self, db: &dyn HirDatabase) -> bool { | 776 | pub fn has_non_default_type_params(self, db: &dyn HirDatabase) -> bool { |
777 | let subst = db.generic_defaults(self.id.into()); | 777 | let subst = db.generic_defaults(self.id.into()); |
778 | subst.iter().any(|ty| ty == &Ty::Unknown) | 778 | subst.iter().any(|ty| &ty.value == &Ty::Unknown) |
779 | } | 779 | } |
780 | 780 | ||
781 | pub fn module(self, db: &dyn HirDatabase) -> Module { | 781 | pub fn module(self, db: &dyn HirDatabase) -> Module { |
@@ -1035,7 +1035,10 @@ impl TypeParam { | |||
1035 | let local_idx = hir_ty::param_idx(db, self.id)?; | 1035 | let local_idx = hir_ty::param_idx(db, self.id)?; |
1036 | let resolver = self.id.parent.resolver(db.upcast()); | 1036 | let resolver = self.id.parent.resolver(db.upcast()); |
1037 | let environment = TraitEnvironment::lower(db, &resolver); | 1037 | let environment = TraitEnvironment::lower(db, &resolver); |
1038 | params.get(local_idx).cloned().map(|ty| Type { | 1038 | let ty = params.get(local_idx)?.clone(); |
1039 | let subst = Substs::type_params(db, self.id.parent); | ||
1040 | let ty = ty.subst(&subst.prefix(local_idx)); | ||
1041 | Some(Type { | ||
1039 | krate: self.id.parent.module(db.upcast()).krate, | 1042 | krate: self.id.parent.module(db.upcast()).krate, |
1040 | ty: InEnvironment { value: ty, environment }, | 1043 | ty: InEnvironment { value: ty, environment }, |
1041 | }) | 1044 | }) |
diff --git a/crates/ra_hir/src/semantics.rs b/crates/ra_hir/src/semantics.rs index 6a49c424a..810c49d6f 100644 --- a/crates/ra_hir/src/semantics.rs +++ b/crates/ra_hir/src/semantics.rs | |||
@@ -297,19 +297,19 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> { | |||
297 | self.with_ctx(|ctx| ctx.file_to_def(file)).map(Module::from) | 297 | self.with_ctx(|ctx| ctx.file_to_def(file)).map(Module::from) |
298 | } | 298 | } |
299 | 299 | ||
300 | pub fn scope(&self, node: &SyntaxNode) -> SemanticsScope<'db, DB> { | 300 | pub fn scope(&self, node: &SyntaxNode) -> SemanticsScope<'db> { |
301 | let node = self.find_file(node.clone()); | 301 | let node = self.find_file(node.clone()); |
302 | let resolver = self.analyze2(node.as_ref(), None).resolver; | 302 | let resolver = self.analyze2(node.as_ref(), None).resolver; |
303 | SemanticsScope { db: self.db, resolver } | 303 | SemanticsScope { db: self.db, resolver } |
304 | } | 304 | } |
305 | 305 | ||
306 | pub fn scope_at_offset(&self, node: &SyntaxNode, offset: TextSize) -> SemanticsScope<'db, DB> { | 306 | pub fn scope_at_offset(&self, node: &SyntaxNode, offset: TextSize) -> SemanticsScope<'db> { |
307 | let node = self.find_file(node.clone()); | 307 | let node = self.find_file(node.clone()); |
308 | let resolver = self.analyze2(node.as_ref(), Some(offset)).resolver; | 308 | let resolver = self.analyze2(node.as_ref(), Some(offset)).resolver; |
309 | SemanticsScope { db: self.db, resolver } | 309 | SemanticsScope { db: self.db, resolver } |
310 | } | 310 | } |
311 | 311 | ||
312 | pub fn scope_for_def(&self, def: Trait) -> SemanticsScope<'db, DB> { | 312 | pub fn scope_for_def(&self, def: Trait) -> SemanticsScope<'db> { |
313 | let resolver = def.id.resolver(self.db); | 313 | let resolver = def.id.resolver(self.db); |
314 | SemanticsScope { db: self.db, resolver } | 314 | SemanticsScope { db: self.db, resolver } |
315 | } | 315 | } |
@@ -419,12 +419,12 @@ fn find_root(node: &SyntaxNode) -> SyntaxNode { | |||
419 | node.ancestors().last().unwrap() | 419 | node.ancestors().last().unwrap() |
420 | } | 420 | } |
421 | 421 | ||
422 | pub struct SemanticsScope<'a, DB> { | 422 | pub struct SemanticsScope<'a> { |
423 | pub db: &'a DB, | 423 | pub db: &'a dyn HirDatabase, |
424 | resolver: Resolver, | 424 | resolver: Resolver, |
425 | } | 425 | } |
426 | 426 | ||
427 | impl<'a, DB: HirDatabase> SemanticsScope<'a, DB> { | 427 | impl<'a> SemanticsScope<'a> { |
428 | pub fn module(&self) -> Option<Module> { | 428 | pub fn module(&self) -> Option<Module> { |
429 | Some(Module { id: self.resolver.module()? }) | 429 | Some(Module { id: self.resolver.module()? }) |
430 | } | 430 | } |
@@ -433,13 +433,13 @@ impl<'a, DB: HirDatabase> SemanticsScope<'a, DB> { | |||
433 | // FIXME: rename to visible_traits to not repeat scope? | 433 | // FIXME: rename to visible_traits to not repeat scope? |
434 | pub fn traits_in_scope(&self) -> FxHashSet<TraitId> { | 434 | pub fn traits_in_scope(&self) -> FxHashSet<TraitId> { |
435 | let resolver = &self.resolver; | 435 | let resolver = &self.resolver; |
436 | resolver.traits_in_scope(self.db) | 436 | resolver.traits_in_scope(self.db.upcast()) |
437 | } | 437 | } |
438 | 438 | ||
439 | pub fn process_all_names(&self, f: &mut dyn FnMut(Name, ScopeDef)) { | 439 | pub fn process_all_names(&self, f: &mut dyn FnMut(Name, ScopeDef)) { |
440 | let resolver = &self.resolver; | 440 | let resolver = &self.resolver; |
441 | 441 | ||
442 | resolver.process_all_names(self.db, &mut |name, def| { | 442 | resolver.process_all_names(self.db.upcast(), &mut |name, def| { |
443 | let def = match def { | 443 | let def = match def { |
444 | resolver::ScopeDef::PerNs(it) => { | 444 | resolver::ScopeDef::PerNs(it) => { |
445 | let items = ScopeDef::all_items(it); | 445 | let items = ScopeDef::all_items(it); |