aboutsummaryrefslogtreecommitdiff
path: root/crates/hir
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir')
-rw-r--r--crates/hir/src/attrs.rs8
-rw-r--r--crates/hir/src/has_source.rs15
-rw-r--r--crates/hir/src/lib.rs23
3 files changed, 21 insertions, 25 deletions
diff --git a/crates/hir/src/attrs.rs b/crates/hir/src/attrs.rs
index dab8da7bb..4a11622fc 100644
--- a/crates/hir/src/attrs.rs
+++ b/crates/hir/src/attrs.rs
@@ -1,6 +1,6 @@
1//! Attributes & documentation for hir types. 1//! Attributes & documentation for hir types.
2use hir_def::{ 2use hir_def::{
3 attr::{Attrs, Documentation}, 3 attr::{AttrsWithOwner, Documentation},
4 path::ModPath, 4 path::ModPath,
5 per_ns::PerNs, 5 per_ns::PerNs,
6 resolver::HasResolver, 6 resolver::HasResolver,
@@ -16,7 +16,7 @@ use crate::{
16}; 16};
17 17
18pub trait HasAttrs { 18pub trait HasAttrs {
19 fn attrs(self, db: &dyn HirDatabase) -> Attrs; 19 fn attrs(self, db: &dyn HirDatabase) -> AttrsWithOwner;
20 fn docs(self, db: &dyn HirDatabase) -> Option<Documentation>; 20 fn docs(self, db: &dyn HirDatabase) -> Option<Documentation>;
21 fn resolve_doc_path( 21 fn resolve_doc_path(
22 self, 22 self,
@@ -36,7 +36,7 @@ pub enum Namespace {
36macro_rules! impl_has_attrs { 36macro_rules! impl_has_attrs {
37 ($(($def:ident, $def_id:ident),)*) => {$( 37 ($(($def:ident, $def_id:ident),)*) => {$(
38 impl HasAttrs for $def { 38 impl HasAttrs for $def {
39 fn attrs(self, db: &dyn HirDatabase) -> Attrs { 39 fn attrs(self, db: &dyn HirDatabase) -> AttrsWithOwner {
40 let def = AttrDefId::$def_id(self.into()); 40 let def = AttrDefId::$def_id(self.into());
41 db.attrs(def) 41 db.attrs(def)
42 } 42 }
@@ -70,7 +70,7 @@ impl_has_attrs![
70macro_rules! impl_has_attrs_enum { 70macro_rules! impl_has_attrs_enum {
71 ($($variant:ident),* for $enum:ident) => {$( 71 ($($variant:ident),* for $enum:ident) => {$(
72 impl HasAttrs for $variant { 72 impl HasAttrs for $variant {
73 fn attrs(self, db: &dyn HirDatabase) -> Attrs { 73 fn attrs(self, db: &dyn HirDatabase) -> AttrsWithOwner {
74 $enum::$variant(self).attrs(db) 74 $enum::$variant(self).attrs(db)
75 } 75 }
76 fn docs(self, db: &dyn HirDatabase) -> Option<Documentation> { 76 fn docs(self, db: &dyn HirDatabase) -> Option<Documentation> {
diff --git a/crates/hir/src/has_source.rs b/crates/hir/src/has_source.rs
index d57fad9ed..dc10a4d0f 100644
--- a/crates/hir/src/has_source.rs
+++ b/crates/hir/src/has_source.rs
@@ -6,7 +6,7 @@ use hir_def::{
6 src::{HasChildSource, HasSource as _}, 6 src::{HasChildSource, HasSource as _},
7 Lookup, VariantId, 7 Lookup, VariantId,
8}; 8};
9use hir_expand::{InFile, MacroDefKind}; 9use hir_expand::InFile;
10use syntax::ast; 10use syntax::ast;
11 11
12use crate::{ 12use crate::{
@@ -113,15 +113,10 @@ impl HasSource for TypeAlias {
113impl HasSource for MacroDef { 113impl HasSource for MacroDef {
114 type Ast = Either<ast::Macro, ast::Fn>; 114 type Ast = Either<ast::Macro, ast::Fn>;
115 fn source(self, db: &dyn HirDatabase) -> Option<InFile<Self::Ast>> { 115 fn source(self, db: &dyn HirDatabase) -> Option<InFile<Self::Ast>> {
116 Some(match &self.id.kind { 116 Some(self.id.ast_id().either(
117 MacroDefKind::Declarative(id) 117 |id| id.with_value(Either::Left(id.to_node(db.upcast()))),
118 | MacroDefKind::BuiltIn(_, id) 118 |id| id.with_value(Either::Right(id.to_node(db.upcast()))),
119 | MacroDefKind::BuiltInDerive(_, id) 119 ))
120 | MacroDefKind::BuiltInEager(_, id) => {
121 id.with_value(Either::Left(id.to_node(db.upcast())))
122 }
123 MacroDefKind::ProcMacro(_, id) => id.map(|_| Either::Right(id.to_node(db.upcast()))),
124 })
125 } 120 }
126} 121}
127impl HasSource for Impl { 122impl HasSource for Impl {
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index 5ebd0a3b8..30e577671 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -56,9 +56,9 @@ use hir_ty::{
56 primitive::UintTy, 56 primitive::UintTy,
57 to_assoc_type_id, 57 to_assoc_type_id,
58 traits::{FnTrait, Solution, SolutionVariables}, 58 traits::{FnTrait, Solution, SolutionVariables},
59 AliasEq, AliasTy, BoundVar, CallableDefId, CallableSig, Canonical, DebruijnIndex, 59 AliasEq, AliasTy, BoundVar, CallableDefId, CallableSig, Canonical, Cast, DebruijnIndex,
60 GenericPredicate, InEnvironment, Interner, Obligation, ProjectionTy, Scalar, Substitution, Ty, 60 InEnvironment, Interner, ProjectionTy, Scalar, Substitution, Ty, TyDefId, TyKind,
61 TyDefId, TyKind, TyVariableKind, 61 TyVariableKind, WhereClause,
62}; 62};
63use itertools::Itertools; 63use itertools::Itertools;
64use rustc_hash::FxHashSet; 64use rustc_hash::FxHashSet;
@@ -89,7 +89,7 @@ pub use crate::{
89pub use { 89pub use {
90 hir_def::{ 90 hir_def::{
91 adt::StructKind, 91 adt::StructKind,
92 attr::{Attr, Attrs, Documentation}, 92 attr::{Attr, Attrs, AttrsWithOwner, Documentation},
93 body::scope::ExprScopes, 93 body::scope::ExprScopes,
94 find_path::PrefixKind, 94 find_path::PrefixKind,
95 import_map, 95 import_map,
@@ -1461,7 +1461,7 @@ impl TypeParam {
1461 db.generic_predicates_for_param(self.id) 1461 db.generic_predicates_for_param(self.id)
1462 .into_iter() 1462 .into_iter()
1463 .filter_map(|pred| match &pred.value { 1463 .filter_map(|pred| match &pred.value {
1464 hir_ty::GenericPredicate::Implemented(trait_ref) => { 1464 hir_ty::WhereClause::Implemented(trait_ref) => {
1465 Some(Trait::from(trait_ref.hir_trait_id())) 1465 Some(Trait::from(trait_ref.hir_trait_id()))
1466 } 1466 }
1467 _ => None, 1467 _ => None,
@@ -1767,7 +1767,7 @@ impl Type {
1767 let goal = Canonical { 1767 let goal = Canonical {
1768 value: hir_ty::InEnvironment::new( 1768 value: hir_ty::InEnvironment::new(
1769 self.ty.environment.clone(), 1769 self.ty.environment.clone(),
1770 hir_ty::Obligation::Trait(trait_ref), 1770 trait_ref.cast(&Interner),
1771 ), 1771 ),
1772 kinds: Arc::new([]), 1772 kinds: Arc::new([]),
1773 }; 1773 };
@@ -1789,14 +1789,15 @@ impl Type {
1789 let goal = Canonical { 1789 let goal = Canonical {
1790 value: InEnvironment::new( 1790 value: InEnvironment::new(
1791 self.ty.environment.clone(), 1791 self.ty.environment.clone(),
1792 Obligation::AliasEq(AliasEq { 1792 AliasEq {
1793 alias: AliasTy::Projection(ProjectionTy { 1793 alias: AliasTy::Projection(ProjectionTy {
1794 associated_ty_id: to_assoc_type_id(alias.id), 1794 associated_ty_id: to_assoc_type_id(alias.id),
1795 substitution: subst, 1795 substitution: subst,
1796 }), 1796 }),
1797 ty: TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0)) 1797 ty: TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0))
1798 .intern(&Interner), 1798 .intern(&Interner),
1799 }), 1799 }
1800 .cast(&Interner),
1800 ), 1801 ),
1801 kinds: Arc::new([TyVariableKind::General]), 1802 kinds: Arc::new([TyVariableKind::General]),
1802 }; 1803 };
@@ -2022,7 +2023,7 @@ impl Type {
2022 self.ty.value.impl_trait_bounds(db).map(|it| { 2023 self.ty.value.impl_trait_bounds(db).map(|it| {
2023 it.into_iter() 2024 it.into_iter()
2024 .filter_map(|pred| match pred { 2025 .filter_map(|pred| match pred {
2025 hir_ty::GenericPredicate::Implemented(trait_ref) => { 2026 hir_ty::WhereClause::Implemented(trait_ref) => {
2026 Some(Trait::from(trait_ref.hir_trait_id())) 2027 Some(Trait::from(trait_ref.hir_trait_id()))
2027 } 2028 }
2028 _ => None, 2029 _ => None,
@@ -2060,12 +2061,12 @@ impl Type {
2060 fn walk_bounds( 2061 fn walk_bounds(
2061 db: &dyn HirDatabase, 2062 db: &dyn HirDatabase,
2062 type_: &Type, 2063 type_: &Type,
2063 bounds: &[GenericPredicate], 2064 bounds: &[WhereClause],
2064 cb: &mut impl FnMut(Type), 2065 cb: &mut impl FnMut(Type),
2065 ) { 2066 ) {
2066 for pred in bounds { 2067 for pred in bounds {
2067 match pred { 2068 match pred {
2068 GenericPredicate::Implemented(trait_ref) => { 2069 WhereClause::Implemented(trait_ref) => {
2069 cb(type_.clone()); 2070 cb(type_.clone());
2070 walk_substs(db, type_, &trait_ref.substitution, cb); 2071 walk_substs(db, type_, &trait_ref.substitution, cb);
2071 } 2072 }