diff options
Diffstat (limited to 'crates')
54 files changed, 486 insertions, 396 deletions
diff --git a/crates/ra_assists/src/assists/early_return.rs b/crates/ra_assists/src/assists/early_return.rs index e839d831e..ad6c5695a 100644 --- a/crates/ra_assists/src/assists/early_return.rs +++ b/crates/ra_assists/src/assists/early_return.rs | |||
@@ -50,7 +50,7 @@ pub(crate) fn convert_to_guarded_return(ctx: AssistCtx<impl HirDatabase>) -> Opt | |||
50 | } | 50 | } |
51 | 51 | ||
52 | // check for early return and continue | 52 | // check for early return and continue |
53 | let first_in_then_block = then_block.syntax().first_child()?.clone(); | 53 | let first_in_then_block = then_block.syntax().first_child()?; |
54 | if ast::ReturnExpr::can_cast(first_in_then_block.kind()) | 54 | if ast::ReturnExpr::can_cast(first_in_then_block.kind()) |
55 | || ast::ContinueExpr::can_cast(first_in_then_block.kind()) | 55 | || ast::ContinueExpr::can_cast(first_in_then_block.kind()) |
56 | || first_in_then_block | 56 | || first_in_then_block |
diff --git a/crates/ra_assists/src/assists/inline_local_variable.rs b/crates/ra_assists/src/assists/inline_local_variable.rs index f43910574..a7fd9b6d2 100644 --- a/crates/ra_assists/src/assists/inline_local_variable.rs +++ b/crates/ra_assists/src/assists/inline_local_variable.rs | |||
@@ -51,10 +51,8 @@ pub(crate) fn inline_local_varialbe(ctx: AssistCtx<impl HirDatabase>) -> Option< | |||
51 | let mut wrap_in_parens = vec![true; refs.len()]; | 51 | let mut wrap_in_parens = vec![true; refs.len()]; |
52 | 52 | ||
53 | for (i, desc) in refs.iter().enumerate() { | 53 | for (i, desc) in refs.iter().enumerate() { |
54 | let usage_node = ctx | 54 | let usage_node = |
55 | .covering_node_for_range(desc.range) | 55 | ctx.covering_node_for_range(desc.range).ancestors().find_map(ast::PathExpr::cast)?; |
56 | .ancestors() | ||
57 | .find_map(|node| ast::PathExpr::cast(node))?; | ||
58 | let usage_parent_option = usage_node.syntax().parent().and_then(ast::Expr::cast); | 56 | let usage_parent_option = usage_node.syntax().parent().and_then(ast::Expr::cast); |
59 | let usage_parent = match usage_parent_option { | 57 | let usage_parent = match usage_parent_option { |
60 | Some(u) => u, | 58 | Some(u) => u, |
diff --git a/crates/ra_assists/src/assists/raw_string.rs b/crates/ra_assists/src/assists/raw_string.rs index 6f4b66c31..58f7157ae 100644 --- a/crates/ra_assists/src/assists/raw_string.rs +++ b/crates/ra_assists/src/assists/raw_string.rs | |||
@@ -131,7 +131,7 @@ pub(crate) fn remove_hash(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { | |||
131 | ctx.add_assist(AssistId("remove_hash"), "remove hash from raw string", |edit| { | 131 | ctx.add_assist(AssistId("remove_hash"), "remove hash from raw string", |edit| { |
132 | edit.target(token.text_range()); | 132 | edit.target(token.text_range()); |
133 | let result = &text[2..text.len() - 1]; | 133 | let result = &text[2..text.len() - 1]; |
134 | let result = if result.starts_with("\"") { | 134 | let result = if result.starts_with('\"') { |
135 | // no more hash, escape | 135 | // no more hash, escape |
136 | let internal_str = &result[1..result.len() - 1]; | 136 | let internal_str = &result[1..result.len() - 1]; |
137 | format!("\"{}\"", internal_str.escape_default().to_string()) | 137 | format!("\"{}\"", internal_str.escape_default().to_string()) |
diff --git a/crates/ra_hir/src/adt.rs b/crates/ra_hir/src/adt.rs index 3e9cd3c63..97424b39e 100644 --- a/crates/ra_hir/src/adt.rs +++ b/crates/ra_hir/src/adt.rs | |||
@@ -3,13 +3,14 @@ | |||
3 | 3 | ||
4 | use std::sync::Arc; | 4 | use std::sync::Arc; |
5 | 5 | ||
6 | use hir_def::type_ref::TypeRef; | ||
7 | use hir_expand::name::AsName; | ||
6 | use ra_arena::{impl_arena_id, Arena, RawId}; | 8 | use ra_arena::{impl_arena_id, Arena, RawId}; |
7 | use ra_syntax::ast::{self, NameOwner, StructKind, TypeAscriptionOwner}; | 9 | use ra_syntax::ast::{self, NameOwner, StructKind, TypeAscriptionOwner}; |
8 | 10 | ||
9 | use crate::{ | 11 | use crate::{ |
10 | db::{AstDatabase, DefDatabase, HirDatabase}, | 12 | db::{AstDatabase, DefDatabase, HirDatabase}, |
11 | type_ref::TypeRef, | 13 | Enum, EnumVariant, FieldSource, HasSource, Module, Name, Source, Struct, StructField, |
12 | AsName, Enum, EnumVariant, FieldSource, HasSource, Module, Name, Source, Struct, StructField, | ||
13 | }; | 14 | }; |
14 | 15 | ||
15 | impl Struct { | 16 | impl Struct { |
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 1a790b2f3..a6ce23dd1 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -5,8 +5,15 @@ pub(crate) mod docs; | |||
5 | 5 | ||
6 | use std::sync::Arc; | 6 | use std::sync::Arc; |
7 | 7 | ||
8 | use hir_def::{CrateModuleId, ModuleId}; | 8 | use hir_def::{ |
9 | use ra_db::{CrateId, Edition, FileId}; | 9 | type_ref::{Mutability, TypeRef}, |
10 | CrateModuleId, ModuleId, | ||
11 | }; | ||
12 | use hir_expand::name::{ | ||
13 | self, AsName, BOOL, CHAR, F32, F64, I128, I16, I32, I64, I8, ISIZE, SELF_TYPE, STR, U128, U16, | ||
14 | U32, U64, U8, USIZE, | ||
15 | }; | ||
16 | use ra_db::{CrateId, Edition}; | ||
10 | use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner}; | 17 | use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner}; |
11 | 18 | ||
12 | use crate::{ | 19 | use crate::{ |
@@ -20,10 +27,6 @@ use crate::{ | |||
20 | TypeAliasId, | 27 | TypeAliasId, |
21 | }, | 28 | }, |
22 | impl_block::ImplBlock, | 29 | impl_block::ImplBlock, |
23 | name::{ | ||
24 | BOOL, CHAR, F32, F64, I128, I16, I32, I64, I8, ISIZE, SELF_TYPE, STR, U128, U16, U32, U64, | ||
25 | U8, USIZE, | ||
26 | }, | ||
27 | nameres::{ImportId, ModuleScope, Namespace}, | 30 | nameres::{ImportId, ModuleScope, Namespace}, |
28 | resolve::{Resolver, Scope, TypeNs}, | 31 | resolve::{Resolver, Scope, TypeNs}, |
29 | traits::TraitData, | 32 | traits::TraitData, |
@@ -31,9 +34,7 @@ use crate::{ | |||
31 | primitive::{FloatBitness, FloatTy, IntBitness, IntTy, Signedness}, | 34 | primitive::{FloatBitness, FloatTy, IntBitness, IntTy, Signedness}, |
32 | InferenceResult, TraitRef, | 35 | InferenceResult, TraitRef, |
33 | }, | 36 | }, |
34 | type_ref::Mutability, | 37 | Either, HasSource, Name, Ty, |
35 | type_ref::TypeRef, | ||
36 | AsName, AstId, Either, HasSource, Name, Ty, | ||
37 | }; | 38 | }; |
38 | 39 | ||
39 | /// hir::Crate describes a single crate. It's the main interface with which | 40 | /// hir::Crate describes a single crate. It's the main interface with which |
@@ -147,31 +148,7 @@ impl_froms!( | |||
147 | BuiltinType | 148 | BuiltinType |
148 | ); | 149 | ); |
149 | 150 | ||
150 | pub enum ModuleSource { | 151 | pub use hir_def::ModuleSource; |
151 | SourceFile(ast::SourceFile), | ||
152 | Module(ast::Module), | ||
153 | } | ||
154 | |||
155 | impl ModuleSource { | ||
156 | pub(crate) fn new( | ||
157 | db: &(impl DefDatabase + AstDatabase), | ||
158 | file_id: Option<FileId>, | ||
159 | decl_id: Option<AstId<ast::Module>>, | ||
160 | ) -> ModuleSource { | ||
161 | match (file_id, decl_id) { | ||
162 | (Some(file_id), _) => { | ||
163 | let source_file = db.parse(file_id).tree(); | ||
164 | ModuleSource::SourceFile(source_file) | ||
165 | } | ||
166 | (None, Some(item_id)) => { | ||
167 | let module = item_id.to_node(db); | ||
168 | assert!(module.item_list().is_some(), "expected inline module"); | ||
169 | ModuleSource::Module(module) | ||
170 | } | ||
171 | (None, None) => panic!(), | ||
172 | } | ||
173 | } | ||
174 | } | ||
175 | 152 | ||
176 | impl Module { | 153 | impl Module { |
177 | pub(crate) fn new(krate: Crate, crate_module_id: CrateModuleId) -> Module { | 154 | pub(crate) fn new(krate: Crate, crate_module_id: CrateModuleId) -> Module { |
@@ -922,9 +899,7 @@ impl Trait { | |||
922 | .where_predicates | 899 | .where_predicates |
923 | .iter() | 900 | .iter() |
924 | .filter_map(|pred| match &pred.type_ref { | 901 | .filter_map(|pred| match &pred.type_ref { |
925 | TypeRef::Path(p) if p.as_ident() == Some(&crate::name::SELF_TYPE) => { | 902 | TypeRef::Path(p) if p.as_ident() == Some(&name::SELF_TYPE) => pred.bound.as_path(), |
926 | pred.bound.as_path() | ||
927 | } | ||
928 | _ => None, | 903 | _ => None, |
929 | }) | 904 | }) |
930 | .filter_map(|path| match resolver.resolve_path_in_type_ns_fully(db, path) { | 905 | .filter_map(|path| match resolver.resolve_path_in_type_ns_fully(db, path) { |
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index 8f6cb2da7..ebfd970eb 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs | |||
@@ -12,18 +12,21 @@ use crate::{ | |||
12 | ids, | 12 | ids, |
13 | impl_block::{ImplBlock, ImplSourceMap, ModuleImplBlocks}, | 13 | impl_block::{ImplBlock, ImplSourceMap, ModuleImplBlocks}, |
14 | lang_item::{LangItemTarget, LangItems}, | 14 | lang_item::{LangItemTarget, LangItems}, |
15 | nameres::{CrateDefMap, ImportSourceMap, Namespace, RawItems}, | 15 | nameres::{CrateDefMap, Namespace}, |
16 | traits::TraitData, | 16 | traits::TraitData, |
17 | ty::{ | 17 | ty::{ |
18 | method_resolution::CrateImplBlocks, traits::Impl, CallableDef, FnSig, GenericPredicate, | 18 | method_resolution::CrateImplBlocks, traits::Impl, CallableDef, FnSig, GenericPredicate, |
19 | InferenceResult, Substs, Ty, TypableDef, TypeCtor, | 19 | InferenceResult, Substs, Ty, TypableDef, TypeCtor, |
20 | }, | 20 | }, |
21 | type_alias::TypeAliasData, | 21 | type_alias::TypeAliasData, |
22 | Const, ConstData, Crate, DefWithBody, Enum, ExprScopes, FnData, Function, HirFileId, Module, | 22 | Const, ConstData, Crate, DefWithBody, Enum, ExprScopes, FnData, Function, Module, Static, |
23 | Static, Struct, StructField, Trait, TypeAlias, | 23 | Struct, StructField, Trait, TypeAlias, |
24 | }; | 24 | }; |
25 | 25 | ||
26 | pub use hir_def::db::{InternDatabase, InternDatabaseStorage}; | 26 | pub use hir_def::db::{ |
27 | DefDatabase2, DefDatabase2Storage, InternDatabase, InternDatabaseStorage, RawItemsQuery, | ||
28 | RawItemsWithSourceMapQuery, | ||
29 | }; | ||
27 | pub use hir_expand::db::{ | 30 | pub use hir_expand::db::{ |
28 | AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery, | 31 | AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery, |
29 | ParseMacroQuery, | 32 | ParseMacroQuery, |
@@ -32,7 +35,7 @@ pub use hir_expand::db::{ | |||
32 | // This database uses `AstDatabase` internally, | 35 | // This database uses `AstDatabase` internally, |
33 | #[salsa::query_group(DefDatabaseStorage)] | 36 | #[salsa::query_group(DefDatabaseStorage)] |
34 | #[salsa::requires(AstDatabase)] | 37 | #[salsa::requires(AstDatabase)] |
35 | pub trait DefDatabase: InternDatabase + HirDebugDatabase + AstDatabase { | 38 | pub trait DefDatabase: HirDebugDatabase + DefDatabase2 { |
36 | #[salsa::invoke(crate::adt::StructData::struct_data_query)] | 39 | #[salsa::invoke(crate::adt::StructData::struct_data_query)] |
37 | fn struct_data(&self, s: Struct) -> Arc<StructData>; | 40 | fn struct_data(&self, s: Struct) -> Arc<StructData>; |
38 | 41 | ||
@@ -45,15 +48,6 @@ pub trait DefDatabase: InternDatabase + HirDebugDatabase + AstDatabase { | |||
45 | #[salsa::invoke(crate::traits::TraitItemsIndex::trait_items_index)] | 48 | #[salsa::invoke(crate::traits::TraitItemsIndex::trait_items_index)] |
46 | fn trait_items_index(&self, module: Module) -> crate::traits::TraitItemsIndex; | 49 | fn trait_items_index(&self, module: Module) -> crate::traits::TraitItemsIndex; |
47 | 50 | ||
48 | #[salsa::invoke(RawItems::raw_items_with_source_map_query)] | ||
49 | fn raw_items_with_source_map( | ||
50 | &self, | ||
51 | file_id: HirFileId, | ||
52 | ) -> (Arc<RawItems>, Arc<ImportSourceMap>); | ||
53 | |||
54 | #[salsa::invoke(RawItems::raw_items_query)] | ||
55 | fn raw_items(&self, file_id: HirFileId) -> Arc<RawItems>; | ||
56 | |||
57 | #[salsa::invoke(CrateDefMap::crate_def_map_query)] | 51 | #[salsa::invoke(CrateDefMap::crate_def_map_query)] |
58 | fn crate_def_map(&self, krate: Crate) -> Arc<CrateDefMap>; | 52 | fn crate_def_map(&self, krate: Crate) -> Arc<CrateDefMap>; |
59 | 53 | ||
diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs index d238741ba..6e23197a4 100644 --- a/crates/ra_hir/src/expr.rs +++ b/crates/ra_hir/src/expr.rs | |||
@@ -6,15 +6,17 @@ pub(crate) mod validation; | |||
6 | 6 | ||
7 | use std::{ops::Index, sync::Arc}; | 7 | use std::{ops::Index, sync::Arc}; |
8 | 8 | ||
9 | use hir_def::{ | ||
10 | path::GenericArgs, | ||
11 | type_ref::{Mutability, TypeRef}, | ||
12 | }; | ||
9 | use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; | 13 | use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; |
10 | use ra_syntax::{ast, AstPtr}; | 14 | use ra_syntax::{ast, AstPtr}; |
11 | use rustc_hash::FxHashMap; | 15 | use rustc_hash::FxHashMap; |
12 | 16 | ||
13 | use crate::{ | 17 | use crate::{ |
14 | db::HirDatabase, | 18 | db::HirDatabase, |
15 | path::GenericArgs, | ||
16 | ty::primitive::{UncertainFloatTy, UncertainIntTy}, | 19 | ty::primitive::{UncertainFloatTy, UncertainIntTy}, |
17 | type_ref::{Mutability, TypeRef}, | ||
18 | DefWithBody, Either, HasSource, Name, Path, Resolver, Source, | 20 | DefWithBody, Either, HasSource, Name, Path, Resolver, Source, |
19 | }; | 21 | }; |
20 | 22 | ||
diff --git a/crates/ra_hir/src/expr/lower.rs b/crates/ra_hir/src/expr/lower.rs index b3a9a2e6b..6463dd65e 100644 --- a/crates/ra_hir/src/expr/lower.rs +++ b/crates/ra_hir/src/expr/lower.rs | |||
@@ -1,5 +1,10 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | use hir_def::{path::GenericArgs, type_ref::TypeRef}; | ||
4 | use hir_expand::{ | ||
5 | hygiene::Hygiene, | ||
6 | name::{self, AsName, Name}, | ||
7 | }; | ||
3 | use ra_arena::Arena; | 8 | use ra_arena::Arena; |
4 | use ra_syntax::{ | 9 | use ra_syntax::{ |
5 | ast::{ | 10 | ast::{ |
@@ -12,10 +17,7 @@ use test_utils::tested_by; | |||
12 | 17 | ||
13 | use crate::{ | 18 | use crate::{ |
14 | db::HirDatabase, | 19 | db::HirDatabase, |
15 | name::{AsName, Name, SELF_PARAM}, | ||
16 | path::GenericArgs, | ||
17 | ty::primitive::{FloatTy, IntTy, UncertainFloatTy, UncertainIntTy}, | 20 | ty::primitive::{FloatTy, IntTy, UncertainFloatTy, UncertainIntTy}, |
18 | type_ref::TypeRef, | ||
19 | AstId, DefWithBody, Either, HirFileId, MacroCallLoc, MacroFileKind, Mutability, Path, Resolver, | 21 | AstId, DefWithBody, Either, HirFileId, MacroCallLoc, MacroFileKind, Mutability, Path, Resolver, |
20 | Source, | 22 | Source, |
21 | }; | 23 | }; |
@@ -78,7 +80,7 @@ where | |||
78 | let ptr = AstPtr::new(&self_param); | 80 | let ptr = AstPtr::new(&self_param); |
79 | let param_pat = self.alloc_pat( | 81 | let param_pat = self.alloc_pat( |
80 | Pat::Bind { | 82 | Pat::Bind { |
81 | name: SELF_PARAM, | 83 | name: name::SELF_PARAM, |
82 | mode: BindingAnnotation::Unannotated, | 84 | mode: BindingAnnotation::Unannotated, |
83 | subpat: None, | 85 | subpat: None, |
84 | }, | 86 | }, |
@@ -595,7 +597,8 @@ where | |||
595 | } | 597 | } |
596 | 598 | ||
597 | fn parse_path(&mut self, path: ast::Path) -> Option<Path> { | 599 | fn parse_path(&mut self, path: ast::Path) -> Option<Path> { |
598 | Path::from_src(Source { ast: path, file_id: self.current_file_id }, self.db) | 600 | let hygiene = Hygiene::new(self.db, self.current_file_id); |
601 | Path::from_src(path, &hygiene) | ||
599 | } | 602 | } |
600 | } | 603 | } |
601 | 604 | ||
diff --git a/crates/ra_hir/src/expr/validation.rs b/crates/ra_hir/src/expr/validation.rs index 1aa853c3e..c685edda1 100644 --- a/crates/ra_hir/src/expr/validation.rs +++ b/crates/ra_hir/src/expr/validation.rs | |||
@@ -2,6 +2,7 @@ | |||
2 | 2 | ||
3 | use std::sync::Arc; | 3 | use std::sync::Arc; |
4 | 4 | ||
5 | use hir_def::path::known; | ||
5 | use ra_syntax::ast; | 6 | use ra_syntax::ast; |
6 | use rustc_hash::FxHashSet; | 7 | use rustc_hash::FxHashSet; |
7 | 8 | ||
@@ -9,7 +10,6 @@ use crate::{ | |||
9 | db::HirDatabase, | 10 | db::HirDatabase, |
10 | diagnostics::{DiagnosticSink, MissingFields, MissingOkInTailExpr}, | 11 | diagnostics::{DiagnosticSink, MissingFields, MissingOkInTailExpr}, |
11 | expr::AstPtr, | 12 | expr::AstPtr, |
12 | path::known, | ||
13 | ty::{ApplicationTy, InferenceResult, Ty, TypeCtor}, | 13 | ty::{ApplicationTy, InferenceResult, Ty, TypeCtor}, |
14 | Adt, Function, Name, Path, | 14 | Adt, Function, Name, Path, |
15 | }; | 15 | }; |
diff --git a/crates/ra_hir/src/from_source.rs b/crates/ra_hir/src/from_source.rs index 93713bb14..a9de01455 100644 --- a/crates/ra_hir/src/from_source.rs +++ b/crates/ra_hir/src/from_source.rs | |||
@@ -1,16 +1,11 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | use ra_db::{FileId, FilePosition}; | 3 | use hir_expand::name::AsName; |
4 | use ra_syntax::{ | 4 | use ra_syntax::ast::{self, AstNode, NameOwner}; |
5 | algo::find_node_at_offset, | ||
6 | ast::{self, AstNode, NameOwner}, | ||
7 | SyntaxNode, | ||
8 | }; | ||
9 | 5 | ||
10 | use crate::{ | 6 | use crate::{ |
11 | db::{AstDatabase, DefDatabase, HirDatabase}, | 7 | db::{AstDatabase, DefDatabase, HirDatabase}, |
12 | ids::{AstItemDef, LocationCtx}, | 8 | ids::{AstItemDef, LocationCtx}, |
13 | name::AsName, | ||
14 | AstId, Const, Crate, Enum, EnumVariant, FieldSource, Function, HasSource, ImplBlock, Module, | 9 | AstId, Const, Crate, Enum, EnumVariant, FieldSource, Function, HasSource, ImplBlock, Module, |
15 | ModuleSource, Source, Static, Struct, StructField, Trait, TypeAlias, Union, VariantDef, | 10 | ModuleSource, Source, Static, Struct, StructField, Trait, TypeAlias, Union, VariantDef, |
16 | }; | 11 | }; |
@@ -129,41 +124,6 @@ impl FromSource for StructField { | |||
129 | } | 124 | } |
130 | } | 125 | } |
131 | 126 | ||
132 | // FIXME: simplify it | ||
133 | impl ModuleSource { | ||
134 | pub fn from_position( | ||
135 | db: &(impl DefDatabase + AstDatabase), | ||
136 | position: FilePosition, | ||
137 | ) -> ModuleSource { | ||
138 | let parse = db.parse(position.file_id); | ||
139 | match &find_node_at_offset::<ast::Module>(parse.tree().syntax(), position.offset) { | ||
140 | Some(m) if !m.has_semi() => ModuleSource::Module(m.clone()), | ||
141 | _ => { | ||
142 | let source_file = parse.tree(); | ||
143 | ModuleSource::SourceFile(source_file) | ||
144 | } | ||
145 | } | ||
146 | } | ||
147 | |||
148 | pub fn from_child_node( | ||
149 | db: &(impl DefDatabase + AstDatabase), | ||
150 | file_id: FileId, | ||
151 | child: &SyntaxNode, | ||
152 | ) -> ModuleSource { | ||
153 | if let Some(m) = child.ancestors().filter_map(ast::Module::cast).find(|it| !it.has_semi()) { | ||
154 | ModuleSource::Module(m) | ||
155 | } else { | ||
156 | let source_file = db.parse(file_id).tree(); | ||
157 | ModuleSource::SourceFile(source_file) | ||
158 | } | ||
159 | } | ||
160 | |||
161 | pub fn from_file_id(db: &(impl DefDatabase + AstDatabase), file_id: FileId) -> ModuleSource { | ||
162 | let source_file = db.parse(file_id).tree(); | ||
163 | ModuleSource::SourceFile(source_file) | ||
164 | } | ||
165 | } | ||
166 | |||
167 | impl Module { | 127 | impl Module { |
168 | pub fn from_declaration(db: &impl HirDatabase, src: Source<ast::Module>) -> Option<Self> { | 128 | pub fn from_declaration(db: &impl HirDatabase, src: Source<ast::Module>) -> Option<Self> { |
169 | let src_parent = Source { | 129 | let src_parent = Source { |
diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs index 4ce7551c3..52e1fbf29 100644 --- a/crates/ra_hir/src/generics.rs +++ b/crates/ra_hir/src/generics.rs | |||
@@ -5,15 +5,17 @@ | |||
5 | 5 | ||
6 | use std::sync::Arc; | 6 | use std::sync::Arc; |
7 | 7 | ||
8 | use hir_def::{ | ||
9 | path::Path, | ||
10 | type_ref::{TypeBound, TypeRef}, | ||
11 | }; | ||
12 | use hir_expand::name::{self, AsName}; | ||
8 | use ra_syntax::ast::{self, DefaultTypeParamOwner, NameOwner, TypeBoundsOwner, TypeParamsOwner}; | 13 | use ra_syntax::ast::{self, DefaultTypeParamOwner, NameOwner, TypeBoundsOwner, TypeParamsOwner}; |
9 | 14 | ||
10 | use crate::{ | 15 | use crate::{ |
11 | db::{AstDatabase, DefDatabase, HirDatabase}, | 16 | db::{AstDatabase, DefDatabase, HirDatabase}, |
12 | name::SELF_TYPE, | 17 | Adt, Const, Container, Enum, EnumVariant, Function, HasSource, ImplBlock, Name, Struct, Trait, |
13 | path::Path, | 18 | TypeAlias, Union, |
14 | type_ref::{TypeBound, TypeRef}, | ||
15 | Adt, AsName, Const, Container, Enum, EnumVariant, Function, HasSource, ImplBlock, Name, Struct, | ||
16 | Trait, TypeAlias, Union, | ||
17 | }; | 19 | }; |
18 | 20 | ||
19 | /// Data about a generic parameter (to a function, struct, impl, ...). | 21 | /// Data about a generic parameter (to a function, struct, impl, ...). |
@@ -94,11 +96,15 @@ impl GenericParams { | |||
94 | GenericDef::Adt(Adt::Enum(it)) => generics.fill(&it.source(db).ast, start), | 96 | GenericDef::Adt(Adt::Enum(it)) => generics.fill(&it.source(db).ast, start), |
95 | GenericDef::Trait(it) => { | 97 | GenericDef::Trait(it) => { |
96 | // traits get the Self type as an implicit first type parameter | 98 | // traits get the Self type as an implicit first type parameter |
97 | generics.params.push(GenericParam { idx: start, name: SELF_TYPE, default: None }); | 99 | generics.params.push(GenericParam { |
100 | idx: start, | ||
101 | name: name::SELF_TYPE, | ||
102 | default: None, | ||
103 | }); | ||
98 | generics.fill(&it.source(db).ast, start + 1); | 104 | generics.fill(&it.source(db).ast, start + 1); |
99 | // add super traits as bounds on Self | 105 | // add super traits as bounds on Self |
100 | // i.e., trait Foo: Bar is equivalent to trait Foo where Self: Bar | 106 | // i.e., trait Foo: Bar is equivalent to trait Foo where Self: Bar |
101 | let self_param = TypeRef::Path(SELF_TYPE.into()); | 107 | let self_param = TypeRef::Path(name::SELF_TYPE.into()); |
102 | generics.fill_bounds(&it.source(db).ast, self_param); | 108 | generics.fill_bounds(&it.source(db).ast, self_param); |
103 | } | 109 | } |
104 | GenericDef::TypeAlias(it) => generics.fill(&it.source(db).ast, start), | 110 | GenericDef::TypeAlias(it) => generics.fill(&it.source(db).ast, start), |
diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs index 06f21fc33..b1a014074 100644 --- a/crates/ra_hir/src/impl_block.rs +++ b/crates/ra_hir/src/impl_block.rs | |||
@@ -3,6 +3,8 @@ | |||
3 | use rustc_hash::FxHashMap; | 3 | use rustc_hash::FxHashMap; |
4 | use std::sync::Arc; | 4 | use std::sync::Arc; |
5 | 5 | ||
6 | use hir_def::{attr::Attr, type_ref::TypeRef}; | ||
7 | use hir_expand::hygiene::Hygiene; | ||
6 | use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; | 8 | use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; |
7 | use ra_cfg::CfgOptions; | 9 | use ra_cfg::CfgOptions; |
8 | use ra_syntax::{ | 10 | use ra_syntax::{ |
@@ -11,7 +13,6 @@ use ra_syntax::{ | |||
11 | }; | 13 | }; |
12 | 14 | ||
13 | use crate::{ | 15 | use crate::{ |
14 | attr::Attr, | ||
15 | code_model::{Module, ModuleSource}, | 16 | code_model::{Module, ModuleSource}, |
16 | db::{AstDatabase, DefDatabase, HirDatabase}, | 17 | db::{AstDatabase, DefDatabase, HirDatabase}, |
17 | generics::HasGenericParams, | 18 | generics::HasGenericParams, |
@@ -19,7 +20,6 @@ use crate::{ | |||
19 | ids::MacroCallLoc, | 20 | ids::MacroCallLoc, |
20 | resolve::Resolver, | 21 | resolve::Resolver, |
21 | ty::Ty, | 22 | ty::Ty, |
22 | type_ref::TypeRef, | ||
23 | AssocItem, AstId, Const, Function, HasSource, HirFileId, MacroFileKind, Path, Source, TraitRef, | 23 | AssocItem, AstId, Const, Function, HasSource, HirFileId, MacroFileKind, Path, Source, TraitRef, |
24 | TypeAlias, | 24 | TypeAlias, |
25 | }; | 25 | }; |
@@ -228,10 +228,11 @@ impl ModuleImplBlocks { | |||
228 | owner: &dyn ast::ModuleItemOwner, | 228 | owner: &dyn ast::ModuleItemOwner, |
229 | file_id: HirFileId, | 229 | file_id: HirFileId, |
230 | ) { | 230 | ) { |
231 | let hygiene = Hygiene::new(db, file_id); | ||
231 | for item in owner.items_with_macros() { | 232 | for item in owner.items_with_macros() { |
232 | match item { | 233 | match item { |
233 | ast::ItemOrMacro::Item(ast::ModuleItem::ImplBlock(impl_block_ast)) => { | 234 | ast::ItemOrMacro::Item(ast::ModuleItem::ImplBlock(impl_block_ast)) => { |
234 | let attrs = Attr::from_attrs_owner(file_id, &impl_block_ast, db); | 235 | let attrs = Attr::from_attrs_owner(&impl_block_ast, &hygiene); |
235 | if attrs.map_or(false, |attrs| { | 236 | if attrs.map_or(false, |attrs| { |
236 | attrs.iter().any(|attr| attr.is_cfg_enabled(cfg_options) == Some(false)) | 237 | attrs.iter().any(|attr| attr.is_cfg_enabled(cfg_options) == Some(false)) |
237 | }) { | 238 | }) { |
@@ -248,7 +249,7 @@ impl ModuleImplBlocks { | |||
248 | } | 249 | } |
249 | ast::ItemOrMacro::Item(_) => (), | 250 | ast::ItemOrMacro::Item(_) => (), |
250 | ast::ItemOrMacro::Macro(macro_call) => { | 251 | ast::ItemOrMacro::Macro(macro_call) => { |
251 | let attrs = Attr::from_attrs_owner(file_id, ¯o_call, db); | 252 | let attrs = Attr::from_attrs_owner(¯o_call, &hygiene); |
252 | if attrs.map_or(false, |attrs| { | 253 | if attrs.map_or(false, |attrs| { |
253 | attrs.iter().any(|attr| attr.is_cfg_enabled(cfg_options) == Some(false)) | 254 | attrs.iter().any(|attr| attr.is_cfg_enabled(cfg_options) == Some(false)) |
254 | }) { | 255 | }) { |
@@ -257,9 +258,8 @@ impl ModuleImplBlocks { | |||
257 | 258 | ||
258 | //FIXME: we should really cut down on the boilerplate required to process a macro | 259 | //FIXME: we should really cut down on the boilerplate required to process a macro |
259 | let ast_id = AstId::new(file_id, db.ast_id_map(file_id).ast_id(¯o_call)); | 260 | let ast_id = AstId::new(file_id, db.ast_id_map(file_id).ast_id(¯o_call)); |
260 | if let Some(path) = macro_call | 261 | if let Some(path) = |
261 | .path() | 262 | macro_call.path().and_then(|path| Path::from_src(path, &hygiene)) |
262 | .and_then(|path| Path::from_src(Source { ast: path, file_id }, db)) | ||
263 | { | 263 | { |
264 | if let Some(def) = self.module.resolver(db).resolve_path_as_macro(db, &path) | 264 | if let Some(def) = self.module.resolver(db).resolve_path_as_macro(db, &path) |
265 | { | 265 | { |
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 0f2d233bb..603b0c3dc 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs | |||
@@ -26,24 +26,19 @@ macro_rules! impl_froms { | |||
26 | } | 26 | } |
27 | } | 27 | } |
28 | 28 | ||
29 | mod either; | ||
30 | pub mod debug; | 29 | pub mod debug; |
31 | 30 | ||
32 | pub mod db; | 31 | pub mod db; |
33 | #[macro_use] | 32 | #[macro_use] |
34 | pub mod mock; | 33 | pub mod mock; |
35 | mod path; | ||
36 | pub mod source_binder; | 34 | pub mod source_binder; |
37 | 35 | ||
38 | mod ids; | 36 | mod ids; |
39 | mod name; | ||
40 | mod nameres; | 37 | mod nameres; |
41 | mod adt; | 38 | mod adt; |
42 | mod traits; | 39 | mod traits; |
43 | mod type_alias; | 40 | mod type_alias; |
44 | mod type_ref; | ||
45 | mod ty; | 41 | mod ty; |
46 | mod attr; | ||
47 | mod impl_block; | 42 | mod impl_block; |
48 | mod expr; | 43 | mod expr; |
49 | mod lang_item; | 44 | mod lang_item; |
@@ -59,36 +54,34 @@ pub mod from_source; | |||
59 | #[cfg(test)] | 54 | #[cfg(test)] |
60 | mod marks; | 55 | mod marks; |
61 | 56 | ||
62 | use hir_expand::{ | 57 | use hir_expand::AstId; |
63 | ast_id_map::{AstIdMap, FileAstId}, | ||
64 | AstId, | ||
65 | }; | ||
66 | 58 | ||
67 | use crate::{ids::MacroFileKind, name::AsName, resolve::Resolver}; | 59 | use crate::{ids::MacroFileKind, resolve::Resolver}; |
68 | 60 | ||
69 | pub use crate::{ | 61 | pub use crate::{ |
70 | adt::VariantDef, | 62 | adt::VariantDef, |
71 | either::Either, | 63 | code_model::{ |
64 | docs::{DocDef, Docs, Documentation}, | ||
65 | src::{HasBodySource, HasSource, Source}, | ||
66 | Adt, AssocItem, BuiltinType, Const, ConstData, Container, Crate, CrateDependency, | ||
67 | DefWithBody, Enum, EnumVariant, FieldSource, FnData, Function, HasBody, MacroDef, Module, | ||
68 | ModuleDef, ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union, | ||
69 | }, | ||
72 | expr::ExprScopes, | 70 | expr::ExprScopes, |
73 | from_source::FromSource, | 71 | from_source::FromSource, |
74 | generics::{GenericDef, GenericParam, GenericParams, HasGenericParams}, | 72 | generics::{GenericDef, GenericParam, GenericParams, HasGenericParams}, |
75 | ids::{HirFileId, MacroCallId, MacroCallLoc, MacroDefId, MacroFile}, | 73 | ids::{HirFileId, MacroCallId, MacroCallLoc, MacroDefId, MacroFile}, |
76 | impl_block::ImplBlock, | 74 | impl_block::ImplBlock, |
77 | name::Name, | ||
78 | nameres::{ImportId, Namespace, PerNs}, | 75 | nameres::{ImportId, Namespace, PerNs}, |
79 | path::{Path, PathKind}, | ||
80 | resolve::ScopeDef, | 76 | resolve::ScopeDef, |
81 | source_binder::{PathResolution, ScopeEntryWithSyntax, SourceAnalyzer}, | 77 | source_binder::{PathResolution, ScopeEntryWithSyntax, SourceAnalyzer}, |
82 | ty::{ | 78 | ty::{ |
83 | display::HirDisplay, ApplicationTy, CallableDef, Substs, TraitRef, Ty, TypeCtor, TypeWalk, | 79 | display::HirDisplay, ApplicationTy, CallableDef, Substs, TraitRef, Ty, TypeCtor, TypeWalk, |
84 | }, | 80 | }, |
85 | type_ref::Mutability, | ||
86 | }; | 81 | }; |
87 | 82 | ||
88 | pub use self::code_model::{ | 83 | pub use hir_def::{ |
89 | docs::{DocDef, Docs, Documentation}, | 84 | path::{Path, PathKind}, |
90 | src::{HasBodySource, HasSource, Source}, | 85 | type_ref::Mutability, |
91 | Adt, AssocItem, BuiltinType, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, | ||
92 | Enum, EnumVariant, FieldSource, FnData, Function, HasBody, MacroDef, Module, ModuleDef, | ||
93 | ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union, | ||
94 | }; | 86 | }; |
87 | pub use hir_expand::{either::Either, name::Name}; | ||
diff --git a/crates/ra_hir/src/marks.rs b/crates/ra_hir/src/marks.rs index 79af24b20..b423489a1 100644 --- a/crates/ra_hir/src/marks.rs +++ b/crates/ra_hir/src/marks.rs | |||
@@ -2,6 +2,7 @@ | |||
2 | 2 | ||
3 | test_utils::marks!( | 3 | test_utils::marks!( |
4 | bogus_paths | 4 | bogus_paths |
5 | // FIXME: restore this mark once hir is split | ||
5 | name_res_works_for_broken_modules | 6 | name_res_works_for_broken_modules |
6 | can_import_enum_variant | 7 | can_import_enum_variant |
7 | type_var_cycles_resolve_completely | 8 | type_var_cycles_resolve_completely |
diff --git a/crates/ra_hir/src/mock.rs b/crates/ra_hir/src/mock.rs index 0b278deb3..35dfaf3ba 100644 --- a/crates/ra_hir/src/mock.rs +++ b/crates/ra_hir/src/mock.rs | |||
@@ -22,6 +22,7 @@ pub const WORKSPACE: SourceRootId = SourceRootId(0); | |||
22 | db::InternDatabaseStorage, | 22 | db::InternDatabaseStorage, |
23 | db::AstDatabaseStorage, | 23 | db::AstDatabaseStorage, |
24 | db::DefDatabaseStorage, | 24 | db::DefDatabaseStorage, |
25 | db::DefDatabase2Storage, | ||
25 | db::HirDatabaseStorage | 26 | db::HirDatabaseStorage |
26 | )] | 27 | )] |
27 | #[derive(Debug)] | 28 | #[derive(Debug)] |
diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs index b325979f5..39f585b44 100644 --- a/crates/ra_hir/src/nameres.rs +++ b/crates/ra_hir/src/nameres.rs | |||
@@ -48,7 +48,6 @@ | |||
48 | //! on the result | 48 | //! on the result |
49 | 49 | ||
50 | mod per_ns; | 50 | mod per_ns; |
51 | mod raw; | ||
52 | mod collector; | 51 | mod collector; |
53 | mod mod_resolution; | 52 | mod mod_resolution; |
54 | #[cfg(test)] | 53 | #[cfg(test)] |
@@ -74,12 +73,9 @@ use crate::{ | |||
74 | Trait, | 73 | Trait, |
75 | }; | 74 | }; |
76 | 75 | ||
77 | pub(crate) use self::raw::{ImportSourceMap, RawItems}; | 76 | pub use self::per_ns::{Namespace, PerNs}; |
78 | 77 | ||
79 | pub use self::{ | 78 | pub use hir_def::nameres::raw::ImportId; |
80 | per_ns::{Namespace, PerNs}, | ||
81 | raw::ImportId, | ||
82 | }; | ||
83 | 79 | ||
84 | /// Contains all top-level defs from a macro-expanded crate | 80 | /// Contains all top-level defs from a macro-expanded crate |
85 | #[derive(Debug, PartialEq, Eq)] | 81 | #[derive(Debug, PartialEq, Eq)] |
@@ -328,7 +324,8 @@ impl CrateDefMap { | |||
328 | ) -> ResolvePathResult { | 324 | ) -> ResolvePathResult { |
329 | let mut segments = path.segments.iter().enumerate(); | 325 | let mut segments = path.segments.iter().enumerate(); |
330 | let mut curr_per_ns: PerNs = match path.kind { | 326 | let mut curr_per_ns: PerNs = match path.kind { |
331 | PathKind::DollarCrate(krate) => { | 327 | PathKind::DollarCrate(crate_id) => { |
328 | let krate = Crate { crate_id }; | ||
332 | if krate == self.krate { | 329 | if krate == self.krate { |
333 | tested_by!(macro_dollar_crate_self); | 330 | tested_by!(macro_dollar_crate_self); |
334 | PerNs::types(Module::new(self.krate, self.root).into()) | 331 | PerNs::types(Module::new(self.krate, self.root).into()) |
diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs index a94a0554c..e2e13805a 100644 --- a/crates/ra_hir/src/nameres/collector.rs +++ b/crates/ra_hir/src/nameres/collector.rs | |||
@@ -1,5 +1,7 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | use hir_def::{attr::Attr, nameres::raw}; | ||
4 | use hir_expand::name; | ||
3 | use ra_cfg::CfgOptions; | 5 | use ra_cfg::CfgOptions; |
4 | use ra_db::FileId; | 6 | use ra_db::FileId; |
5 | use ra_syntax::{ast, SmolStr}; | 7 | use ra_syntax::{ast, SmolStr}; |
@@ -7,12 +9,10 @@ use rustc_hash::FxHashMap; | |||
7 | use test_utils::tested_by; | 9 | use test_utils::tested_by; |
8 | 10 | ||
9 | use crate::{ | 11 | use crate::{ |
10 | attr::Attr, | ||
11 | db::DefDatabase, | 12 | db::DefDatabase, |
12 | ids::{AstItemDef, LocationCtx, MacroCallId, MacroCallLoc, MacroDefId, MacroFileKind}, | 13 | ids::{AstItemDef, LocationCtx, MacroCallId, MacroCallLoc, MacroDefId, MacroFileKind}, |
13 | name::MACRO_RULES, | ||
14 | nameres::{ | 14 | nameres::{ |
15 | diagnostics::DefDiagnostic, mod_resolution::ModDir, raw, Crate, CrateDefMap, CrateModuleId, | 15 | diagnostics::DefDiagnostic, mod_resolution::ModDir, Crate, CrateDefMap, CrateModuleId, |
16 | ModuleData, ModuleDef, PerNs, ReachedFixedPoint, Resolution, ResolveMode, | 16 | ModuleData, ModuleDef, PerNs, ReachedFixedPoint, Resolution, ResolveMode, |
17 | }, | 17 | }, |
18 | Adt, AstId, Const, Enum, Function, HirFileId, MacroDef, Module, Name, Path, PathKind, Static, | 18 | Adt, AstId, Const, Enum, Function, HirFileId, MacroDef, Module, Name, Path, PathKind, Static, |
@@ -725,7 +725,7 @@ where | |||
725 | } | 725 | } |
726 | 726 | ||
727 | fn is_macro_rules(path: &Path) -> bool { | 727 | fn is_macro_rules(path: &Path) -> bool { |
728 | path.as_ident() == Some(&MACRO_RULES) | 728 | path.as_ident() == Some(&name::MACRO_RULES) |
729 | } | 729 | } |
730 | 730 | ||
731 | #[cfg(test)] | 731 | #[cfg(test)] |
diff --git a/crates/ra_hir/src/nameres/tests/mod_resolution.rs b/crates/ra_hir/src/nameres/tests/mod_resolution.rs index f569aacdc..abfe8b1c3 100644 --- a/crates/ra_hir/src/nameres/tests/mod_resolution.rs +++ b/crates/ra_hir/src/nameres/tests/mod_resolution.rs | |||
@@ -2,7 +2,7 @@ use super::*; | |||
2 | 2 | ||
3 | #[test] | 3 | #[test] |
4 | fn name_res_works_for_broken_modules() { | 4 | fn name_res_works_for_broken_modules() { |
5 | covers!(name_res_works_for_broken_modules); | 5 | // covers!(name_res_works_for_broken_modules); |
6 | let map = def_map( | 6 | let map = def_map( |
7 | " | 7 | " |
8 | //- /lib.rs | 8 | //- /lib.rs |
diff --git a/crates/ra_hir/src/resolve.rs b/crates/ra_hir/src/resolve.rs index 8b6269407..f77c9df9f 100644 --- a/crates/ra_hir/src/resolve.rs +++ b/crates/ra_hir/src/resolve.rs | |||
@@ -1,7 +1,11 @@ | |||
1 | //! Name resolution. | 1 | //! Name resolution. |
2 | use std::sync::Arc; | 2 | use std::sync::Arc; |
3 | 3 | ||
4 | use hir_def::CrateModuleId; | 4 | use hir_def::{ |
5 | path::{Path, PathKind}, | ||
6 | CrateModuleId, | ||
7 | }; | ||
8 | use hir_expand::name::{self, Name}; | ||
5 | use rustc_hash::FxHashSet; | 9 | use rustc_hash::FxHashSet; |
6 | 10 | ||
7 | use crate::{ | 11 | use crate::{ |
@@ -13,9 +17,7 @@ use crate::{ | |||
13 | }, | 17 | }, |
14 | generics::GenericParams, | 18 | generics::GenericParams, |
15 | impl_block::ImplBlock, | 19 | impl_block::ImplBlock, |
16 | name::{Name, SELF_PARAM, SELF_TYPE}, | ||
17 | nameres::{CrateDefMap, PerNs}, | 20 | nameres::{CrateDefMap, PerNs}, |
18 | path::{Path, PathKind}, | ||
19 | Adt, BuiltinType, Const, Enum, EnumVariant, Function, MacroDef, ModuleDef, Static, Struct, | 21 | Adt, BuiltinType, Const, Enum, EnumVariant, Function, MacroDef, ModuleDef, Static, Struct, |
20 | Trait, TypeAlias, | 22 | Trait, TypeAlias, |
21 | }; | 23 | }; |
@@ -150,13 +152,13 @@ impl Resolver { | |||
150 | } | 152 | } |
151 | } | 153 | } |
152 | Scope::ImplBlockScope(impl_) => { | 154 | Scope::ImplBlockScope(impl_) => { |
153 | if first_name == &SELF_TYPE { | 155 | if first_name == &name::SELF_TYPE { |
154 | let idx = if path.segments.len() == 1 { None } else { Some(1) }; | 156 | let idx = if path.segments.len() == 1 { None } else { Some(1) }; |
155 | return Some((TypeNs::SelfType(*impl_), idx)); | 157 | return Some((TypeNs::SelfType(*impl_), idx)); |
156 | } | 158 | } |
157 | } | 159 | } |
158 | Scope::AdtScope(adt) => { | 160 | Scope::AdtScope(adt) => { |
159 | if first_name == &SELF_TYPE { | 161 | if first_name == &name::SELF_TYPE { |
160 | let idx = if path.segments.len() == 1 { None } else { Some(1) }; | 162 | let idx = if path.segments.len() == 1 { None } else { Some(1) }; |
161 | return Some((TypeNs::AdtSelfType(*adt), idx)); | 163 | return Some((TypeNs::AdtSelfType(*adt), idx)); |
162 | } | 164 | } |
@@ -205,7 +207,7 @@ impl Resolver { | |||
205 | return None; | 207 | return None; |
206 | } | 208 | } |
207 | let n_segments = path.segments.len(); | 209 | let n_segments = path.segments.len(); |
208 | let tmp = SELF_PARAM; | 210 | let tmp = name::SELF_PARAM; |
209 | let first_name = if path.is_self() { &tmp } else { &path.segments.first()?.name }; | 211 | let first_name = if path.is_self() { &tmp } else { &path.segments.first()?.name }; |
210 | let skip_to_mod = path.kind != PathKind::Plain && !path.is_self(); | 212 | let skip_to_mod = path.kind != PathKind::Plain && !path.is_self(); |
211 | for scope in self.scopes.iter().rev() { | 213 | for scope in self.scopes.iter().rev() { |
@@ -241,13 +243,13 @@ impl Resolver { | |||
241 | Scope::GenericParams(_) => continue, | 243 | Scope::GenericParams(_) => continue, |
242 | 244 | ||
243 | Scope::ImplBlockScope(impl_) if n_segments > 1 => { | 245 | Scope::ImplBlockScope(impl_) if n_segments > 1 => { |
244 | if first_name == &SELF_TYPE { | 246 | if first_name == &name::SELF_TYPE { |
245 | let ty = TypeNs::SelfType(*impl_); | 247 | let ty = TypeNs::SelfType(*impl_); |
246 | return Some(ResolveValueResult::Partial(ty, 1)); | 248 | return Some(ResolveValueResult::Partial(ty, 1)); |
247 | } | 249 | } |
248 | } | 250 | } |
249 | Scope::AdtScope(adt) if n_segments > 1 => { | 251 | Scope::AdtScope(adt) if n_segments > 1 => { |
250 | if first_name == &SELF_TYPE { | 252 | if first_name == &name::SELF_TYPE { |
251 | let ty = TypeNs::AdtSelfType(*adt); | 253 | let ty = TypeNs::AdtSelfType(*adt); |
252 | return Some(ResolveValueResult::Partial(ty, 1)); | 254 | return Some(ResolveValueResult::Partial(ty, 1)); |
253 | } | 255 | } |
@@ -459,10 +461,10 @@ impl Scope { | |||
459 | } | 461 | } |
460 | } | 462 | } |
461 | Scope::ImplBlockScope(i) => { | 463 | Scope::ImplBlockScope(i) => { |
462 | f(SELF_TYPE, ScopeDef::ImplSelfType(*i)); | 464 | f(name::SELF_TYPE, ScopeDef::ImplSelfType(*i)); |
463 | } | 465 | } |
464 | Scope::AdtScope(i) => { | 466 | Scope::AdtScope(i) => { |
465 | f(SELF_TYPE, ScopeDef::AdtSelfType(*i)); | 467 | f(name::SELF_TYPE, ScopeDef::AdtSelfType(*i)); |
466 | } | 468 | } |
467 | Scope::ExprScope(e) => { | 469 | Scope::ExprScope(e) => { |
468 | e.expr_scopes.entries(e.scope_id).iter().for_each(|e| { | 470 | e.expr_scopes.entries(e.scope_id).iter().for_each(|e| { |
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index 730c33226..01f51ba5d 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs | |||
@@ -7,6 +7,8 @@ | |||
7 | //! purely for "IDE needs". | 7 | //! purely for "IDE needs". |
8 | use std::sync::Arc; | 8 | use std::sync::Arc; |
9 | 9 | ||
10 | use hir_def::path::known; | ||
11 | use hir_expand::name::AsName; | ||
10 | use ra_db::FileId; | 12 | use ra_db::FileId; |
11 | use ra_syntax::{ | 13 | use ra_syntax::{ |
12 | ast::{self, AstNode}, | 14 | ast::{self, AstNode}, |
@@ -24,11 +26,10 @@ use crate::{ | |||
24 | BodySourceMap, | 26 | BodySourceMap, |
25 | }, | 27 | }, |
26 | ids::LocationCtx, | 28 | ids::LocationCtx, |
27 | path::known, | ||
28 | resolve::{ScopeDef, TypeNs, ValueNs}, | 29 | resolve::{ScopeDef, TypeNs, ValueNs}, |
29 | ty::method_resolution::implements_trait, | 30 | ty::method_resolution::implements_trait, |
30 | AsName, Const, DefWithBody, Either, Enum, FromSource, Function, HasBody, HirFileId, MacroDef, | 31 | Const, DefWithBody, Either, Enum, FromSource, Function, HasBody, HirFileId, MacroDef, Module, |
31 | Module, Name, Path, Resolver, Static, Struct, Ty, | 32 | Name, Path, Resolver, Static, Struct, Ty, |
32 | }; | 33 | }; |
33 | 34 | ||
34 | fn try_get_resolver_for_node( | 35 | fn try_get_resolver_for_node( |
diff --git a/crates/ra_hir/src/traits.rs b/crates/ra_hir/src/traits.rs index 22f188049..1a45dacba 100644 --- a/crates/ra_hir/src/traits.rs +++ b/crates/ra_hir/src/traits.rs | |||
@@ -1,14 +1,15 @@ | |||
1 | //! HIR for trait definitions. | 1 | //! HIR for trait definitions. |
2 | 2 | ||
3 | use rustc_hash::FxHashMap; | ||
4 | use std::sync::Arc; | 3 | use std::sync::Arc; |
5 | 4 | ||
5 | use hir_expand::name::AsName; | ||
6 | |||
6 | use ra_syntax::ast::{self, NameOwner}; | 7 | use ra_syntax::ast::{self, NameOwner}; |
8 | use rustc_hash::FxHashMap; | ||
7 | 9 | ||
8 | use crate::{ | 10 | use crate::{ |
9 | db::{AstDatabase, DefDatabase}, | 11 | db::{AstDatabase, DefDatabase}, |
10 | ids::LocationCtx, | 12 | ids::LocationCtx, |
11 | name::AsName, | ||
12 | AssocItem, Const, Function, HasSource, Module, Name, Trait, TypeAlias, | 13 | AssocItem, Const, Function, HasSource, Module, Name, Trait, TypeAlias, |
13 | }; | 14 | }; |
14 | 15 | ||
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index cc9746f6d..d2bfcdc7d 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs | |||
@@ -17,8 +17,8 @@ use std::sync::Arc; | |||
17 | use std::{fmt, iter, mem}; | 17 | use std::{fmt, iter, mem}; |
18 | 18 | ||
19 | use crate::{ | 19 | use crate::{ |
20 | db::HirDatabase, expr::ExprId, type_ref::Mutability, util::make_mut_slice, Adt, Crate, | 20 | db::HirDatabase, expr::ExprId, util::make_mut_slice, Adt, Crate, DefWithBody, GenericParams, |
21 | DefWithBody, GenericParams, HasGenericParams, Name, Trait, TypeAlias, | 21 | HasGenericParams, Mutability, Name, Trait, TypeAlias, |
22 | }; | 22 | }; |
23 | use display::{HirDisplay, HirFormatter}; | 23 | use display::{HirDisplay, HirFormatter}; |
24 | 24 | ||
diff --git a/crates/ra_hir/src/ty/autoderef.rs b/crates/ra_hir/src/ty/autoderef.rs index 02492ca14..3645ee831 100644 --- a/crates/ra_hir/src/ty/autoderef.rs +++ b/crates/ra_hir/src/ty/autoderef.rs | |||
@@ -5,10 +5,11 @@ | |||
5 | 5 | ||
6 | use std::iter::successors; | 6 | use std::iter::successors; |
7 | 7 | ||
8 | use hir_expand::name; | ||
8 | use log::{info, warn}; | 9 | use log::{info, warn}; |
9 | 10 | ||
10 | use super::{traits::Solution, Canonical, Substs, Ty, TypeWalk}; | 11 | use super::{traits::Solution, Canonical, Substs, Ty, TypeWalk}; |
11 | use crate::{db::HirDatabase, name, HasGenericParams, Resolver}; | 12 | use crate::{db::HirDatabase, HasGenericParams, Resolver}; |
12 | 13 | ||
13 | const AUTODEREF_RECURSION_LIMIT: usize = 10; | 14 | const AUTODEREF_RECURSION_LIMIT: usize = 10; |
14 | 15 | ||
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index ebaff998e..6694467a3 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs | |||
@@ -21,6 +21,11 @@ use std::sync::Arc; | |||
21 | use ena::unify::{InPlaceUnificationTable, NoError, UnifyKey, UnifyValue}; | 21 | use ena::unify::{InPlaceUnificationTable, NoError, UnifyKey, UnifyValue}; |
22 | use rustc_hash::FxHashMap; | 22 | use rustc_hash::FxHashMap; |
23 | 23 | ||
24 | use hir_def::{ | ||
25 | path::known, | ||
26 | type_ref::{Mutability, TypeRef}, | ||
27 | }; | ||
28 | use hir_expand::name; | ||
24 | use ra_arena::map::ArenaMap; | 29 | use ra_arena::map::ArenaMap; |
25 | use ra_prof::profile; | 30 | use ra_prof::profile; |
26 | use test_utils::tested_by; | 31 | use test_utils::tested_by; |
@@ -37,11 +42,8 @@ use crate::{ | |||
37 | db::HirDatabase, | 42 | db::HirDatabase, |
38 | diagnostics::DiagnosticSink, | 43 | diagnostics::DiagnosticSink, |
39 | expr::{BindingAnnotation, Body, ExprId, PatId}, | 44 | expr::{BindingAnnotation, Body, ExprId, PatId}, |
40 | name, | ||
41 | path::known, | ||
42 | resolve::{Resolver, TypeNs}, | 45 | resolve::{Resolver, TypeNs}, |
43 | ty::infer::diagnostics::InferenceDiagnostic, | 46 | ty::infer::diagnostics::InferenceDiagnostic, |
44 | type_ref::{Mutability, TypeRef}, | ||
45 | Adt, AssocItem, ConstData, DefWithBody, FnData, Function, HasBody, Path, StructField, | 47 | Adt, AssocItem, ConstData, DefWithBody, FnData, Function, HasBody, Path, StructField, |
46 | }; | 48 | }; |
47 | 49 | ||
diff --git a/crates/ra_hir/src/ty/infer/coerce.rs b/crates/ra_hir/src/ty/infer/coerce.rs index 0429a9866..6ea135126 100644 --- a/crates/ra_hir/src/ty/infer/coerce.rs +++ b/crates/ra_hir/src/ty/infer/coerce.rs | |||
@@ -14,8 +14,7 @@ use crate::{ | |||
14 | lang_item::LangItemTarget, | 14 | lang_item::LangItemTarget, |
15 | resolve::Resolver, | 15 | resolve::Resolver, |
16 | ty::{autoderef, Substs, Ty, TypeCtor, TypeWalk}, | 16 | ty::{autoderef, Substs, Ty, TypeCtor, TypeWalk}, |
17 | type_ref::Mutability, | 17 | Adt, Mutability, |
18 | Adt, | ||
19 | }; | 18 | }; |
20 | 19 | ||
21 | impl<'a, D: HirDatabase> InferenceContext<'a, D> { | 20 | impl<'a, D: HirDatabase> InferenceContext<'a, D> { |
diff --git a/crates/ra_hir/src/ty/infer/expr.rs b/crates/ra_hir/src/ty/infer/expr.rs index f8807c742..fed52df39 100644 --- a/crates/ra_hir/src/ty/infer/expr.rs +++ b/crates/ra_hir/src/ty/infer/expr.rs | |||
@@ -3,14 +3,15 @@ | |||
3 | use std::iter::{repeat, repeat_with}; | 3 | use std::iter::{repeat, repeat_with}; |
4 | use std::sync::Arc; | 4 | use std::sync::Arc; |
5 | 5 | ||
6 | use hir_def::path::{GenericArg, GenericArgs}; | ||
7 | use hir_expand::name; | ||
8 | |||
6 | use super::{BindingMode, Expectation, InferenceContext, InferenceDiagnostic, TypeMismatch}; | 9 | use super::{BindingMode, Expectation, InferenceContext, InferenceDiagnostic, TypeMismatch}; |
7 | use crate::{ | 10 | use crate::{ |
8 | db::HirDatabase, | 11 | db::HirDatabase, |
9 | expr::{self, Array, BinaryOp, Expr, ExprId, Literal, Statement, UnaryOp}, | 12 | expr::{self, Array, BinaryOp, Expr, ExprId, Literal, Statement, UnaryOp}, |
10 | generics::{GenericParams, HasGenericParams}, | 13 | generics::{GenericParams, HasGenericParams}, |
11 | name, | ||
12 | nameres::Namespace, | 14 | nameres::Namespace, |
13 | path::{GenericArg, GenericArgs}, | ||
14 | ty::{ | 15 | ty::{ |
15 | autoderef, method_resolution, op, primitive, CallableDef, InferTy, Mutability, Obligation, | 16 | autoderef, method_resolution, op, primitive, CallableDef, InferTy, Mutability, Obligation, |
16 | ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk, | 17 | ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk, |
diff --git a/crates/ra_hir/src/ty/infer/path.rs b/crates/ra_hir/src/ty/infer/path.rs index db979353a..77aa35ce1 100644 --- a/crates/ra_hir/src/ty/infer/path.rs +++ b/crates/ra_hir/src/ty/infer/path.rs | |||
@@ -1,5 +1,7 @@ | |||
1 | //! Path expression resolution. | 1 | //! Path expression resolution. |
2 | 2 | ||
3 | use hir_def::path::PathSegment; | ||
4 | |||
3 | use super::{ExprOrPatId, InferenceContext, TraitRef}; | 5 | use super::{ExprOrPatId, InferenceContext, TraitRef}; |
4 | use crate::{ | 6 | use crate::{ |
5 | db::HirDatabase, | 7 | db::HirDatabase, |
@@ -131,7 +133,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
131 | fn resolve_trait_assoc_item( | 133 | fn resolve_trait_assoc_item( |
132 | &mut self, | 134 | &mut self, |
133 | trait_ref: TraitRef, | 135 | trait_ref: TraitRef, |
134 | segment: &crate::path::PathSegment, | 136 | segment: &PathSegment, |
135 | id: ExprOrPatId, | 137 | id: ExprOrPatId, |
136 | ) -> Option<(ValueNs, Option<Substs>)> { | 138 | ) -> Option<(ValueNs, Option<Substs>)> { |
137 | let trait_ = trait_ref.trait_; | 139 | let trait_ = trait_ref.trait_; |
@@ -170,7 +172,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
170 | fn resolve_ty_assoc_item( | 172 | fn resolve_ty_assoc_item( |
171 | &mut self, | 173 | &mut self, |
172 | ty: Ty, | 174 | ty: Ty, |
173 | segment: &crate::path::PathSegment, | 175 | segment: &PathSegment, |
174 | id: ExprOrPatId, | 176 | id: ExprOrPatId, |
175 | ) -> Option<(ValueNs, Option<Substs>)> { | 177 | ) -> Option<(ValueNs, Option<Substs>)> { |
176 | if let Ty::Unknown = ty { | 178 | if let Ty::Unknown = ty { |
diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs index 366556134..0f49a0e54 100644 --- a/crates/ra_hir/src/ty/lower.rs +++ b/crates/ra_hir/src/ty/lower.rs | |||
@@ -8,6 +8,11 @@ | |||
8 | use std::iter; | 8 | use std::iter; |
9 | use std::sync::Arc; | 9 | use std::sync::Arc; |
10 | 10 | ||
11 | use hir_def::{ | ||
12 | path::{GenericArg, PathSegment}, | ||
13 | type_ref::{TypeBound, TypeRef}, | ||
14 | }; | ||
15 | |||
11 | use super::{ | 16 | use super::{ |
12 | FnSig, GenericPredicate, ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, | 17 | FnSig, GenericPredicate, ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, |
13 | TypeWalk, | 18 | TypeWalk, |
@@ -18,10 +23,8 @@ use crate::{ | |||
18 | generics::HasGenericParams, | 23 | generics::HasGenericParams, |
19 | generics::{GenericDef, WherePredicate}, | 24 | generics::{GenericDef, WherePredicate}, |
20 | nameres::Namespace, | 25 | nameres::Namespace, |
21 | path::{GenericArg, PathSegment}, | ||
22 | resolve::{Resolver, TypeNs}, | 26 | resolve::{Resolver, TypeNs}, |
23 | ty::Adt, | 27 | ty::Adt, |
24 | type_ref::{TypeBound, TypeRef}, | ||
25 | util::make_mut_slice, | 28 | util::make_mut_slice, |
26 | BuiltinType, Const, Enum, EnumVariant, Function, ModuleDef, Path, Static, Struct, StructField, | 29 | BuiltinType, Const, Enum, EnumVariant, Function, ModuleDef, Path, Static, Struct, StructField, |
27 | Trait, TypeAlias, Union, | 30 | Trait, TypeAlias, Union, |
diff --git a/crates/ra_hir/src/ty/method_resolution.rs b/crates/ra_hir/src/ty/method_resolution.rs index 50583a142..eb69344f6 100644 --- a/crates/ra_hir/src/ty/method_resolution.rs +++ b/crates/ra_hir/src/ty/method_resolution.rs | |||
@@ -15,8 +15,7 @@ use crate::{ | |||
15 | resolve::Resolver, | 15 | resolve::Resolver, |
16 | ty::primitive::{FloatBitness, UncertainFloatTy, UncertainIntTy}, | 16 | ty::primitive::{FloatBitness, UncertainFloatTy, UncertainIntTy}, |
17 | ty::{Ty, TypeCtor}, | 17 | ty::{Ty, TypeCtor}, |
18 | type_ref::Mutability, | 18 | AssocItem, Crate, Function, Module, Mutability, Name, Trait, |
19 | AssocItem, Crate, Function, Module, Name, Trait, | ||
20 | }; | 19 | }; |
21 | 20 | ||
22 | /// This is used as a key for indexing impls. | 21 | /// This is used as a key for indexing impls. |
diff --git a/crates/ra_hir/src/ty/traits/chalk.rs b/crates/ra_hir/src/ty/traits/chalk.rs index ab66515be..39ef92182 100644 --- a/crates/ra_hir/src/ty/traits/chalk.rs +++ b/crates/ra_hir/src/ty/traits/chalk.rs | |||
@@ -9,6 +9,8 @@ use chalk_ir::{ | |||
9 | }; | 9 | }; |
10 | use chalk_rust_ir::{AssociatedTyDatum, ImplDatum, StructDatum, TraitDatum}; | 10 | use chalk_rust_ir::{AssociatedTyDatum, ImplDatum, StructDatum, TraitDatum}; |
11 | 11 | ||
12 | use hir_expand::name; | ||
13 | |||
12 | use ra_db::salsa::{InternId, InternKey}; | 14 | use ra_db::salsa::{InternId, InternKey}; |
13 | 15 | ||
14 | use super::{Canonical, ChalkContext, Impl, Obligation}; | 16 | use super::{Canonical, ChalkContext, Impl, Obligation}; |
@@ -734,7 +736,7 @@ fn closure_fn_trait_impl_datum( | |||
734 | substs: Substs::build_for_def(db, trait_).push(self_ty).push(arg_ty).build(), | 736 | substs: Substs::build_for_def(db, trait_).push(self_ty).push(arg_ty).build(), |
735 | }; | 737 | }; |
736 | 738 | ||
737 | let output_ty_id = fn_once_trait.associated_type_by_name(db, &crate::name::OUTPUT_TYPE)?; | 739 | let output_ty_id = fn_once_trait.associated_type_by_name(db, &name::OUTPUT_TYPE)?; |
738 | 740 | ||
739 | let output_ty_value = chalk_rust_ir::AssociatedTyValue { | 741 | let output_ty_value = chalk_rust_ir::AssociatedTyValue { |
740 | associated_ty_id: output_ty_id.to_chalk(db), | 742 | associated_ty_id: output_ty_id.to_chalk(db), |
diff --git a/crates/ra_hir/src/type_alias.rs b/crates/ra_hir/src/type_alias.rs index 674a46102..078e6295e 100644 --- a/crates/ra_hir/src/type_alias.rs +++ b/crates/ra_hir/src/type_alias.rs | |||
@@ -2,12 +2,13 @@ | |||
2 | 2 | ||
3 | use std::sync::Arc; | 3 | use std::sync::Arc; |
4 | 4 | ||
5 | use hir_def::type_ref::TypeRef; | ||
6 | use hir_expand::name::{AsName, Name}; | ||
7 | |||
5 | use ra_syntax::ast::NameOwner; | 8 | use ra_syntax::ast::NameOwner; |
6 | 9 | ||
7 | use crate::{ | 10 | use crate::{ |
8 | db::{AstDatabase, DefDatabase}, | 11 | db::{AstDatabase, DefDatabase}, |
9 | name::{AsName, Name}, | ||
10 | type_ref::TypeRef, | ||
11 | HasSource, TypeAlias, | 12 | HasSource, TypeAlias, |
12 | }; | 13 | }; |
13 | 14 | ||
diff --git a/crates/ra_hir_def/Cargo.toml b/crates/ra_hir_def/Cargo.toml index 75e93f254..746c907e8 100644 --- a/crates/ra_hir_def/Cargo.toml +++ b/crates/ra_hir_def/Cargo.toml | |||
@@ -6,9 +6,16 @@ authors = ["rust-analyzer developers"] | |||
6 | 6 | ||
7 | [dependencies] | 7 | [dependencies] |
8 | log = "0.4.5" | 8 | log = "0.4.5" |
9 | once_cell = "1.0.1" | ||
10 | relative-path = "1.0.0" | ||
11 | rustc-hash = "1.0" | ||
9 | 12 | ||
10 | ra_arena = { path = "../ra_arena" } | 13 | ra_arena = { path = "../ra_arena" } |
11 | ra_db = { path = "../ra_db" } | 14 | ra_db = { path = "../ra_db" } |
12 | ra_syntax = { path = "../ra_syntax" } | 15 | ra_syntax = { path = "../ra_syntax" } |
13 | ra_prof = { path = "../ra_prof" } | 16 | ra_prof = { path = "../ra_prof" } |
14 | hir_expand = { path = "../ra_hir_expand", package = "ra_hir_expand" } | 17 | hir_expand = { path = "../ra_hir_expand", package = "ra_hir_expand" } |
18 | test_utils = { path = "../test_utils" } | ||
19 | mbe = { path = "../ra_mbe", package = "ra_mbe" } | ||
20 | ra_cfg = { path = "../ra_cfg" } | ||
21 | tt = { path = "../ra_tt", package = "ra_tt" } | ||
diff --git a/crates/ra_hir/src/attr.rs b/crates/ra_hir_def/src/attr.rs index bd159a566..0e961ca12 100644 --- a/crates/ra_hir/src/attr.rs +++ b/crates/ra_hir_def/src/attr.rs | |||
@@ -2,6 +2,7 @@ | |||
2 | 2 | ||
3 | use std::sync::Arc; | 3 | use std::sync::Arc; |
4 | 4 | ||
5 | use hir_expand::hygiene::Hygiene; | ||
5 | use mbe::ast_to_token_tree; | 6 | use mbe::ast_to_token_tree; |
6 | use ra_cfg::CfgOptions; | 7 | use ra_cfg::CfgOptions; |
7 | use ra_syntax::{ | 8 | use ra_syntax::{ |
@@ -10,10 +11,10 @@ use ra_syntax::{ | |||
10 | }; | 11 | }; |
11 | use tt::Subtree; | 12 | use tt::Subtree; |
12 | 13 | ||
13 | use crate::{db::AstDatabase, path::Path, HirFileId, Source}; | 14 | use crate::path::Path; |
14 | 15 | ||
15 | #[derive(Debug, Clone, PartialEq, Eq)] | 16 | #[derive(Debug, Clone, PartialEq, Eq)] |
16 | pub(crate) struct Attr { | 17 | pub struct Attr { |
17 | pub(crate) path: Path, | 18 | pub(crate) path: Path, |
18 | pub(crate) input: Option<AttrInput>, | 19 | pub(crate) input: Option<AttrInput>, |
19 | } | 20 | } |
@@ -25,11 +26,8 @@ pub enum AttrInput { | |||
25 | } | 26 | } |
26 | 27 | ||
27 | impl Attr { | 28 | impl Attr { |
28 | pub(crate) fn from_src( | 29 | pub(crate) fn from_src(ast: ast::Attr, hygiene: &Hygiene) -> Option<Attr> { |
29 | Source { file_id, ast }: Source<ast::Attr>, | 30 | let path = Path::from_src(ast.path()?, hygiene)?; |
30 | db: &impl AstDatabase, | ||
31 | ) -> Option<Attr> { | ||
32 | let path = Path::from_src(Source { file_id, ast: ast.path()? }, db)?; | ||
33 | let input = match ast.input() { | 31 | let input = match ast.input() { |
34 | None => None, | 32 | None => None, |
35 | Some(ast::AttrInput::Literal(lit)) => { | 33 | Some(ast::AttrInput::Literal(lit)) => { |
@@ -45,26 +43,22 @@ impl Attr { | |||
45 | Some(Attr { path, input }) | 43 | Some(Attr { path, input }) |
46 | } | 44 | } |
47 | 45 | ||
48 | pub(crate) fn from_attrs_owner( | 46 | pub fn from_attrs_owner(owner: &dyn AttrsOwner, hygiene: &Hygiene) -> Option<Arc<[Attr]>> { |
49 | file_id: HirFileId, | ||
50 | owner: &dyn AttrsOwner, | ||
51 | db: &impl AstDatabase, | ||
52 | ) -> Option<Arc<[Attr]>> { | ||
53 | let mut attrs = owner.attrs().peekable(); | 47 | let mut attrs = owner.attrs().peekable(); |
54 | if attrs.peek().is_none() { | 48 | if attrs.peek().is_none() { |
55 | // Avoid heap allocation | 49 | // Avoid heap allocation |
56 | return None; | 50 | return None; |
57 | } | 51 | } |
58 | Some(attrs.flat_map(|ast| Attr::from_src(Source { file_id, ast }, db)).collect()) | 52 | Some(attrs.flat_map(|ast| Attr::from_src(ast, hygiene)).collect()) |
59 | } | 53 | } |
60 | 54 | ||
61 | pub(crate) fn is_simple_atom(&self, name: &str) -> bool { | 55 | pub fn is_simple_atom(&self, name: &str) -> bool { |
62 | // FIXME: Avoid cloning | 56 | // FIXME: Avoid cloning |
63 | self.path.as_ident().map_or(false, |s| s.to_string() == name) | 57 | self.path.as_ident().map_or(false, |s| s.to_string() == name) |
64 | } | 58 | } |
65 | 59 | ||
66 | // FIXME: handle cfg_attr :-) | 60 | // FIXME: handle cfg_attr :-) |
67 | pub(crate) fn as_cfg(&self) -> Option<&Subtree> { | 61 | pub fn as_cfg(&self) -> Option<&Subtree> { |
68 | if !self.is_simple_atom("cfg") { | 62 | if !self.is_simple_atom("cfg") { |
69 | return None; | 63 | return None; |
70 | } | 64 | } |
@@ -74,7 +68,7 @@ impl Attr { | |||
74 | } | 68 | } |
75 | } | 69 | } |
76 | 70 | ||
77 | pub(crate) fn as_path(&self) -> Option<&SmolStr> { | 71 | pub fn as_path(&self) -> Option<&SmolStr> { |
78 | if !self.is_simple_atom("path") { | 72 | if !self.is_simple_atom("path") { |
79 | return None; | 73 | return None; |
80 | } | 74 | } |
@@ -84,7 +78,7 @@ impl Attr { | |||
84 | } | 78 | } |
85 | } | 79 | } |
86 | 80 | ||
87 | pub(crate) fn is_cfg_enabled(&self, cfg_options: &CfgOptions) -> Option<bool> { | 81 | pub fn is_cfg_enabled(&self, cfg_options: &CfgOptions) -> Option<bool> { |
88 | cfg_options.is_cfg_enabled(self.as_cfg()?) | 82 | cfg_options.is_cfg_enabled(self.as_cfg()?) |
89 | } | 83 | } |
90 | } | 84 | } |
diff --git a/crates/ra_hir_def/src/db.rs b/crates/ra_hir_def/src/db.rs index f6f976c86..b271636b0 100644 --- a/crates/ra_hir_def/src/db.rs +++ b/crates/ra_hir_def/src/db.rs | |||
@@ -1,8 +1,12 @@ | |||
1 | //! Defines database & queries for name resolution. | 1 | //! Defines database & queries for name resolution. |
2 | use std::sync::Arc; | ||
2 | 3 | ||
4 | use hir_expand::{db::AstDatabase, HirFileId}; | ||
3 | use ra_db::{salsa, SourceDatabase}; | 5 | use ra_db::{salsa, SourceDatabase}; |
4 | use ra_syntax::ast; | 6 | use ra_syntax::ast; |
5 | 7 | ||
8 | use crate::nameres::raw::{ImportSourceMap, RawItems}; | ||
9 | |||
6 | #[salsa::query_group(InternDatabaseStorage)] | 10 | #[salsa::query_group(InternDatabaseStorage)] |
7 | pub trait InternDatabase: SourceDatabase { | 11 | pub trait InternDatabase: SourceDatabase { |
8 | #[salsa::interned] | 12 | #[salsa::interned] |
@@ -10,6 +14,8 @@ pub trait InternDatabase: SourceDatabase { | |||
10 | #[salsa::interned] | 14 | #[salsa::interned] |
11 | fn intern_struct(&self, loc: crate::ItemLoc<ast::StructDef>) -> crate::StructId; | 15 | fn intern_struct(&self, loc: crate::ItemLoc<ast::StructDef>) -> crate::StructId; |
12 | #[salsa::interned] | 16 | #[salsa::interned] |
17 | fn intern_union(&self, loc: crate::ItemLoc<ast::StructDef>) -> crate::UnionId; | ||
18 | #[salsa::interned] | ||
13 | fn intern_enum(&self, loc: crate::ItemLoc<ast::EnumDef>) -> crate::EnumId; | 19 | fn intern_enum(&self, loc: crate::ItemLoc<ast::EnumDef>) -> crate::EnumId; |
14 | #[salsa::interned] | 20 | #[salsa::interned] |
15 | fn intern_const(&self, loc: crate::ItemLoc<ast::ConstDef>) -> crate::ConstId; | 21 | fn intern_const(&self, loc: crate::ItemLoc<ast::ConstDef>) -> crate::ConstId; |
@@ -20,3 +26,15 @@ pub trait InternDatabase: SourceDatabase { | |||
20 | #[salsa::interned] | 26 | #[salsa::interned] |
21 | fn intern_type_alias(&self, loc: crate::ItemLoc<ast::TypeAliasDef>) -> crate::TypeAliasId; | 27 | fn intern_type_alias(&self, loc: crate::ItemLoc<ast::TypeAliasDef>) -> crate::TypeAliasId; |
22 | } | 28 | } |
29 | |||
30 | #[salsa::query_group(DefDatabase2Storage)] | ||
31 | pub trait DefDatabase2: InternDatabase + AstDatabase { | ||
32 | #[salsa::invoke(RawItems::raw_items_with_source_map_query)] | ||
33 | fn raw_items_with_source_map( | ||
34 | &self, | ||
35 | file_id: HirFileId, | ||
36 | ) -> (Arc<RawItems>, Arc<ImportSourceMap>); | ||
37 | |||
38 | #[salsa::invoke(RawItems::raw_items_query)] | ||
39 | fn raw_items(&self, file_id: HirFileId) -> Arc<RawItems>; | ||
40 | } | ||
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index 4d6b9db03..7a6c7b301 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs | |||
@@ -8,12 +8,18 @@ | |||
8 | //! actually true. | 8 | //! actually true. |
9 | 9 | ||
10 | pub mod db; | 10 | pub mod db; |
11 | pub mod attr; | ||
12 | pub mod path; | ||
13 | pub mod type_ref; | ||
14 | |||
15 | // FIXME: this should be private | ||
16 | pub mod nameres; | ||
11 | 17 | ||
12 | use std::hash::{Hash, Hasher}; | 18 | use std::hash::{Hash, Hasher}; |
13 | 19 | ||
14 | use hir_expand::{ast_id_map::FileAstId, db::AstDatabase, AstId, HirFileId}; | 20 | use hir_expand::{ast_id_map::FileAstId, db::AstDatabase, AstId, HirFileId}; |
15 | use ra_arena::{impl_arena_id, RawId}; | 21 | use ra_arena::{impl_arena_id, RawId}; |
16 | use ra_db::{salsa, CrateId}; | 22 | use ra_db::{salsa, CrateId, FileId}; |
17 | use ra_syntax::{ast, AstNode, SyntaxNode}; | 23 | use ra_syntax::{ast, AstNode, SyntaxNode}; |
18 | 24 | ||
19 | use crate::db::InternDatabase; | 25 | use crate::db::InternDatabase; |
@@ -24,6 +30,68 @@ pub struct Source<T> { | |||
24 | pub ast: T, | 30 | pub ast: T, |
25 | } | 31 | } |
26 | 32 | ||
33 | pub enum ModuleSource { | ||
34 | SourceFile(ast::SourceFile), | ||
35 | Module(ast::Module), | ||
36 | } | ||
37 | |||
38 | impl ModuleSource { | ||
39 | pub fn new( | ||
40 | db: &impl db::DefDatabase2, | ||
41 | file_id: Option<FileId>, | ||
42 | decl_id: Option<AstId<ast::Module>>, | ||
43 | ) -> ModuleSource { | ||
44 | match (file_id, decl_id) { | ||
45 | (Some(file_id), _) => { | ||
46 | let source_file = db.parse(file_id).tree(); | ||
47 | ModuleSource::SourceFile(source_file) | ||
48 | } | ||
49 | (None, Some(item_id)) => { | ||
50 | let module = item_id.to_node(db); | ||
51 | assert!(module.item_list().is_some(), "expected inline module"); | ||
52 | ModuleSource::Module(module) | ||
53 | } | ||
54 | (None, None) => panic!(), | ||
55 | } | ||
56 | } | ||
57 | |||
58 | // FIXME: this methods do not belong here | ||
59 | pub fn from_position( | ||
60 | db: &impl db::DefDatabase2, | ||
61 | position: ra_db::FilePosition, | ||
62 | ) -> ModuleSource { | ||
63 | let parse = db.parse(position.file_id); | ||
64 | match &ra_syntax::algo::find_node_at_offset::<ast::Module>( | ||
65 | parse.tree().syntax(), | ||
66 | position.offset, | ||
67 | ) { | ||
68 | Some(m) if !m.has_semi() => ModuleSource::Module(m.clone()), | ||
69 | _ => { | ||
70 | let source_file = parse.tree(); | ||
71 | ModuleSource::SourceFile(source_file) | ||
72 | } | ||
73 | } | ||
74 | } | ||
75 | |||
76 | pub fn from_child_node( | ||
77 | db: &impl db::DefDatabase2, | ||
78 | file_id: FileId, | ||
79 | child: &SyntaxNode, | ||
80 | ) -> ModuleSource { | ||
81 | if let Some(m) = child.ancestors().filter_map(ast::Module::cast).find(|it| !it.has_semi()) { | ||
82 | ModuleSource::Module(m) | ||
83 | } else { | ||
84 | let source_file = db.parse(file_id).tree(); | ||
85 | ModuleSource::SourceFile(source_file) | ||
86 | } | ||
87 | } | ||
88 | |||
89 | pub fn from_file_id(db: &impl db::DefDatabase2, file_id: FileId) -> ModuleSource { | ||
90 | let source_file = db.parse(file_id).tree(); | ||
91 | ModuleSource::SourceFile(source_file) | ||
92 | } | ||
93 | } | ||
94 | |||
27 | impl<T> Source<T> { | 95 | impl<T> Source<T> { |
28 | pub fn map<F: FnOnce(T) -> U, U>(self, f: F) -> Source<U> { | 96 | pub fn map<F: FnOnce(T) -> U, U>(self, f: F) -> Source<U> { |
29 | Source { file_id: self.file_id, ast: f(self.ast) } | 97 | Source { file_id: self.file_id, ast: f(self.ast) } |
@@ -156,6 +224,18 @@ impl AstItemDef<ast::StructDef> for StructId { | |||
156 | } | 224 | } |
157 | 225 | ||
158 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 226 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
227 | pub struct UnionId(salsa::InternId); | ||
228 | impl_intern_key!(UnionId); | ||
229 | impl AstItemDef<ast::StructDef> for UnionId { | ||
230 | fn intern(db: &impl InternDatabase, loc: ItemLoc<ast::StructDef>) -> Self { | ||
231 | db.intern_union(loc) | ||
232 | } | ||
233 | fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<ast::StructDef> { | ||
234 | db.lookup_intern_union(self) | ||
235 | } | ||
236 | } | ||
237 | |||
238 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
159 | pub struct EnumId(salsa::InternId); | 239 | pub struct EnumId(salsa::InternId); |
160 | impl_intern_key!(EnumId); | 240 | impl_intern_key!(EnumId); |
161 | impl AstItemDef<ast::EnumDef> for EnumId { | 241 | impl AstItemDef<ast::EnumDef> for EnumId { |
@@ -167,6 +247,17 @@ impl AstItemDef<ast::EnumDef> for EnumId { | |||
167 | } | 247 | } |
168 | } | 248 | } |
169 | 249 | ||
250 | // FIXME: rename to `VariantId`, only enums can ave variants | ||
251 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
252 | pub struct EnumVariantId { | ||
253 | parent: EnumId, | ||
254 | local_id: LocalEnumVariantId, | ||
255 | } | ||
256 | |||
257 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
258 | pub(crate) struct LocalEnumVariantId(RawId); | ||
259 | impl_arena_id!(LocalEnumVariantId); | ||
260 | |||
170 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 261 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
171 | pub struct ConstId(salsa::InternId); | 262 | pub struct ConstId(salsa::InternId); |
172 | impl_intern_key!(ConstId); | 263 | impl_intern_key!(ConstId); |
diff --git a/crates/ra_hir_def/src/nameres.rs b/crates/ra_hir_def/src/nameres.rs new file mode 100644 index 000000000..5893708e8 --- /dev/null +++ b/crates/ra_hir_def/src/nameres.rs | |||
@@ -0,0 +1,3 @@ | |||
1 | //! FIXME: write short doc here | ||
2 | |||
3 | pub mod raw; | ||
diff --git a/crates/ra_hir/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs index 57f2929c3..86c05d602 100644 --- a/crates/ra_hir/src/nameres/raw.rs +++ b/crates/ra_hir_def/src/nameres/raw.rs | |||
@@ -2,18 +2,20 @@ | |||
2 | 2 | ||
3 | use std::{ops::Index, sync::Arc}; | 3 | use std::{ops::Index, sync::Arc}; |
4 | 4 | ||
5 | use hir_expand::{ | ||
6 | ast_id_map::AstIdMap, | ||
7 | db::AstDatabase, | ||
8 | either::Either, | ||
9 | hygiene::Hygiene, | ||
10 | name::{AsName, Name}, | ||
11 | }; | ||
5 | use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; | 12 | use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; |
6 | use ra_syntax::{ | 13 | use ra_syntax::{ |
7 | ast::{self, AttrsOwner, NameOwner}, | 14 | ast::{self, AttrsOwner, NameOwner}, |
8 | AstNode, AstPtr, SourceFile, | 15 | AstNode, AstPtr, SourceFile, |
9 | }; | 16 | }; |
10 | use test_utils::tested_by; | ||
11 | 17 | ||
12 | use crate::{ | 18 | use crate::{attr::Attr, db::DefDatabase2, path::Path, FileAstId, HirFileId, ModuleSource, Source}; |
13 | attr::Attr, | ||
14 | db::{AstDatabase, DefDatabase}, | ||
15 | AsName, AstIdMap, Either, FileAstId, HirFileId, ModuleSource, Name, Path, Source, | ||
16 | }; | ||
17 | 19 | ||
18 | /// `RawItems` is a set of top-level items in a file (except for impls). | 20 | /// `RawItems` is a set of top-level items in a file (except for impls). |
19 | /// | 21 | /// |
@@ -37,10 +39,8 @@ pub struct ImportSourceMap { | |||
37 | type ImportSourcePtr = Either<AstPtr<ast::UseTree>, AstPtr<ast::ExternCrateItem>>; | 39 | type ImportSourcePtr = Either<AstPtr<ast::UseTree>, AstPtr<ast::ExternCrateItem>>; |
38 | type ImportSource = Either<ast::UseTree, ast::ExternCrateItem>; | 40 | type ImportSource = Either<ast::UseTree, ast::ExternCrateItem>; |
39 | 41 | ||
40 | impl ImportSourcePtr { | 42 | fn to_node(ptr: ImportSourcePtr, file: &SourceFile) -> ImportSource { |
41 | fn to_node(self, file: &SourceFile) -> ImportSource { | 43 | ptr.map(|ptr| ptr.to_node(file.syntax()), |ptr| ptr.to_node(file.syntax())) |
42 | self.map(|ptr| ptr.to_node(file.syntax()), |ptr| ptr.to_node(file.syntax())) | ||
43 | } | ||
44 | } | 44 | } |
45 | 45 | ||
46 | impl ImportSourceMap { | 46 | impl ImportSourceMap { |
@@ -48,26 +48,26 @@ impl ImportSourceMap { | |||
48 | self.map.insert(import, ptr) | 48 | self.map.insert(import, ptr) |
49 | } | 49 | } |
50 | 50 | ||
51 | pub(crate) fn get(&self, source: &ModuleSource, import: ImportId) -> ImportSource { | 51 | pub fn get(&self, source: &ModuleSource, import: ImportId) -> ImportSource { |
52 | let file = match source { | 52 | let file = match source { |
53 | ModuleSource::SourceFile(file) => file.clone(), | 53 | ModuleSource::SourceFile(file) => file.clone(), |
54 | ModuleSource::Module(m) => m.syntax().ancestors().find_map(SourceFile::cast).unwrap(), | 54 | ModuleSource::Module(m) => m.syntax().ancestors().find_map(SourceFile::cast).unwrap(), |
55 | }; | 55 | }; |
56 | 56 | ||
57 | self.map[import].to_node(&file) | 57 | to_node(self.map[import], &file) |
58 | } | 58 | } |
59 | } | 59 | } |
60 | 60 | ||
61 | impl RawItems { | 61 | impl RawItems { |
62 | pub(crate) fn raw_items_query( | 62 | pub(crate) fn raw_items_query( |
63 | db: &(impl DefDatabase + AstDatabase), | 63 | db: &(impl DefDatabase2 + AstDatabase), |
64 | file_id: HirFileId, | 64 | file_id: HirFileId, |
65 | ) -> Arc<RawItems> { | 65 | ) -> Arc<RawItems> { |
66 | db.raw_items_with_source_map(file_id).0 | 66 | db.raw_items_with_source_map(file_id).0 |
67 | } | 67 | } |
68 | 68 | ||
69 | pub(crate) fn raw_items_with_source_map_query( | 69 | pub(crate) fn raw_items_with_source_map_query( |
70 | db: &(impl DefDatabase + AstDatabase), | 70 | db: &(impl DefDatabase2 + AstDatabase), |
71 | file_id: HirFileId, | 71 | file_id: HirFileId, |
72 | ) -> (Arc<RawItems>, Arc<ImportSourceMap>) { | 72 | ) -> (Arc<RawItems>, Arc<ImportSourceMap>) { |
73 | let mut collector = RawItemsCollector { | 73 | let mut collector = RawItemsCollector { |
@@ -75,7 +75,7 @@ impl RawItems { | |||
75 | source_ast_id_map: db.ast_id_map(file_id), | 75 | source_ast_id_map: db.ast_id_map(file_id), |
76 | source_map: ImportSourceMap::default(), | 76 | source_map: ImportSourceMap::default(), |
77 | file_id, | 77 | file_id, |
78 | db, | 78 | hygiene: Hygiene::new(db, file_id), |
79 | }; | 79 | }; |
80 | if let Some(node) = db.parse_or_expand(file_id) { | 80 | if let Some(node) = db.parse_or_expand(file_id) { |
81 | if let Some(source_file) = ast::SourceFile::cast(node.clone()) { | 81 | if let Some(source_file) = ast::SourceFile::cast(node.clone()) { |
@@ -87,7 +87,7 @@ impl RawItems { | |||
87 | (Arc::new(collector.raw_items), Arc::new(collector.source_map)) | 87 | (Arc::new(collector.raw_items), Arc::new(collector.source_map)) |
88 | } | 88 | } |
89 | 89 | ||
90 | pub(super) fn items(&self) -> &[RawItem] { | 90 | pub fn items(&self) -> &[RawItem] { |
91 | &self.items | 91 | &self.items |
92 | } | 92 | } |
93 | } | 93 | } |
@@ -124,19 +124,19 @@ impl Index<Macro> for RawItems { | |||
124 | type Attrs = Option<Arc<[Attr]>>; | 124 | type Attrs = Option<Arc<[Attr]>>; |
125 | 125 | ||
126 | #[derive(Debug, PartialEq, Eq, Clone)] | 126 | #[derive(Debug, PartialEq, Eq, Clone)] |
127 | pub(super) struct RawItem { | 127 | pub struct RawItem { |
128 | attrs: Attrs, | 128 | attrs: Attrs, |
129 | pub(super) kind: RawItemKind, | 129 | pub kind: RawItemKind, |
130 | } | 130 | } |
131 | 131 | ||
132 | impl RawItem { | 132 | impl RawItem { |
133 | pub(super) fn attrs(&self) -> &[Attr] { | 133 | pub fn attrs(&self) -> &[Attr] { |
134 | self.attrs.as_ref().map_or(&[], |it| &*it) | 134 | self.attrs.as_ref().map_or(&[], |it| &*it) |
135 | } | 135 | } |
136 | } | 136 | } |
137 | 137 | ||
138 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] | 138 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] |
139 | pub(super) enum RawItemKind { | 139 | pub enum RawItemKind { |
140 | Module(Module), | 140 | Module(Module), |
141 | Import(ImportId), | 141 | Import(ImportId), |
142 | Def(Def), | 142 | Def(Def), |
@@ -144,11 +144,11 @@ pub(super) enum RawItemKind { | |||
144 | } | 144 | } |
145 | 145 | ||
146 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 146 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
147 | pub(super) struct Module(RawId); | 147 | pub struct Module(RawId); |
148 | impl_arena_id!(Module); | 148 | impl_arena_id!(Module); |
149 | 149 | ||
150 | #[derive(Debug, PartialEq, Eq)] | 150 | #[derive(Debug, PartialEq, Eq)] |
151 | pub(super) enum ModuleData { | 151 | pub enum ModuleData { |
152 | Declaration { name: Name, ast_id: FileAstId<ast::Module> }, | 152 | Declaration { name: Name, ast_id: FileAstId<ast::Module> }, |
153 | Definition { name: Name, ast_id: FileAstId<ast::Module>, items: Vec<RawItem> }, | 153 | Definition { name: Name, ast_id: FileAstId<ast::Module>, items: Vec<RawItem> }, |
154 | } | 154 | } |
@@ -159,26 +159,26 @@ impl_arena_id!(ImportId); | |||
159 | 159 | ||
160 | #[derive(Debug, Clone, PartialEq, Eq)] | 160 | #[derive(Debug, Clone, PartialEq, Eq)] |
161 | pub struct ImportData { | 161 | pub struct ImportData { |
162 | pub(super) path: Path, | 162 | pub path: Path, |
163 | pub(super) alias: Option<Name>, | 163 | pub alias: Option<Name>, |
164 | pub(super) is_glob: bool, | 164 | pub is_glob: bool, |
165 | pub(super) is_prelude: bool, | 165 | pub is_prelude: bool, |
166 | pub(super) is_extern_crate: bool, | 166 | pub is_extern_crate: bool, |
167 | pub(super) is_macro_use: bool, | 167 | pub is_macro_use: bool, |
168 | } | 168 | } |
169 | 169 | ||
170 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 170 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
171 | pub(super) struct Def(RawId); | 171 | pub struct Def(RawId); |
172 | impl_arena_id!(Def); | 172 | impl_arena_id!(Def); |
173 | 173 | ||
174 | #[derive(Debug, PartialEq, Eq)] | 174 | #[derive(Debug, PartialEq, Eq)] |
175 | pub(super) struct DefData { | 175 | pub struct DefData { |
176 | pub(super) name: Name, | 176 | pub name: Name, |
177 | pub(super) kind: DefKind, | 177 | pub kind: DefKind, |
178 | } | 178 | } |
179 | 179 | ||
180 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] | 180 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] |
181 | pub(super) enum DefKind { | 181 | pub enum DefKind { |
182 | Function(FileAstId<ast::FnDef>), | 182 | Function(FileAstId<ast::FnDef>), |
183 | Struct(FileAstId<ast::StructDef>), | 183 | Struct(FileAstId<ast::StructDef>), |
184 | Union(FileAstId<ast::StructDef>), | 184 | Union(FileAstId<ast::StructDef>), |
@@ -190,26 +190,26 @@ pub(super) enum DefKind { | |||
190 | } | 190 | } |
191 | 191 | ||
192 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 192 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
193 | pub(super) struct Macro(RawId); | 193 | pub struct Macro(RawId); |
194 | impl_arena_id!(Macro); | 194 | impl_arena_id!(Macro); |
195 | 195 | ||
196 | #[derive(Debug, PartialEq, Eq)] | 196 | #[derive(Debug, PartialEq, Eq)] |
197 | pub(super) struct MacroData { | 197 | pub struct MacroData { |
198 | pub(super) ast_id: FileAstId<ast::MacroCall>, | 198 | pub ast_id: FileAstId<ast::MacroCall>, |
199 | pub(super) path: Path, | 199 | pub path: Path, |
200 | pub(super) name: Option<Name>, | 200 | pub name: Option<Name>, |
201 | pub(super) export: bool, | 201 | pub export: bool, |
202 | } | 202 | } |
203 | 203 | ||
204 | struct RawItemsCollector<DB> { | 204 | struct RawItemsCollector { |
205 | raw_items: RawItems, | 205 | raw_items: RawItems, |
206 | source_ast_id_map: Arc<AstIdMap>, | 206 | source_ast_id_map: Arc<AstIdMap>, |
207 | source_map: ImportSourceMap, | 207 | source_map: ImportSourceMap, |
208 | file_id: HirFileId, | 208 | file_id: HirFileId, |
209 | db: DB, | 209 | hygiene: Hygiene, |
210 | } | 210 | } |
211 | 211 | ||
212 | impl<DB: AstDatabase> RawItemsCollector<&DB> { | 212 | impl RawItemsCollector { |
213 | fn process_module(&mut self, current_module: Option<Module>, body: impl ast::ModuleItemOwner) { | 213 | fn process_module(&mut self, current_module: Option<Module>, body: impl ast::ModuleItemOwner) { |
214 | for item_or_macro in body.items_with_macros() { | 214 | for item_or_macro in body.items_with_macros() { |
215 | match item_or_macro { | 215 | match item_or_macro { |
@@ -297,7 +297,8 @@ impl<DB: AstDatabase> RawItemsCollector<&DB> { | |||
297 | self.push_item(current_module, attrs, RawItemKind::Module(item)); | 297 | self.push_item(current_module, attrs, RawItemKind::Module(item)); |
298 | return; | 298 | return; |
299 | } | 299 | } |
300 | tested_by!(name_res_works_for_broken_modules); | 300 | // FIXME: restore this mark once we complete hir splitting |
301 | // tested_by!(name_res_works_for_broken_modules); | ||
301 | } | 302 | } |
302 | 303 | ||
303 | fn add_use_item(&mut self, current_module: Option<Module>, use_item: ast::UseItem) { | 304 | fn add_use_item(&mut self, current_module: Option<Module>, use_item: ast::UseItem) { |
@@ -305,9 +306,10 @@ impl<DB: AstDatabase> RawItemsCollector<&DB> { | |||
305 | let is_prelude = use_item.has_atom_attr("prelude_import"); | 306 | let is_prelude = use_item.has_atom_attr("prelude_import"); |
306 | let attrs = self.parse_attrs(&use_item); | 307 | let attrs = self.parse_attrs(&use_item); |
307 | 308 | ||
309 | let mut buf = Vec::new(); | ||
308 | Path::expand_use_item( | 310 | Path::expand_use_item( |
309 | Source { ast: use_item, file_id: self.file_id }, | 311 | Source { ast: use_item, file_id: self.file_id }, |
310 | self.db, | 312 | &self.hygiene, |
311 | |path, use_tree, is_glob, alias| { | 313 | |path, use_tree, is_glob, alias| { |
312 | let import_data = ImportData { | 314 | let import_data = ImportData { |
313 | path, | 315 | path, |
@@ -317,14 +319,12 @@ impl<DB: AstDatabase> RawItemsCollector<&DB> { | |||
317 | is_extern_crate: false, | 319 | is_extern_crate: false, |
318 | is_macro_use: false, | 320 | is_macro_use: false, |
319 | }; | 321 | }; |
320 | self.push_import( | 322 | buf.push((import_data, Either::A(AstPtr::new(use_tree)))); |
321 | current_module, | ||
322 | attrs.clone(), | ||
323 | import_data, | ||
324 | Either::A(AstPtr::new(use_tree)), | ||
325 | ); | ||
326 | }, | 323 | }, |
327 | ) | 324 | ); |
325 | for (import_data, ptr) in buf { | ||
326 | self.push_import(current_module, attrs.clone(), import_data, ptr); | ||
327 | } | ||
328 | } | 328 | } |
329 | 329 | ||
330 | fn add_extern_crate_item( | 330 | fn add_extern_crate_item( |
@@ -357,10 +357,7 @@ impl<DB: AstDatabase> RawItemsCollector<&DB> { | |||
357 | 357 | ||
358 | fn add_macro(&mut self, current_module: Option<Module>, m: ast::MacroCall) { | 358 | fn add_macro(&mut self, current_module: Option<Module>, m: ast::MacroCall) { |
359 | let attrs = self.parse_attrs(&m); | 359 | let attrs = self.parse_attrs(&m); |
360 | let path = match m | 360 | let path = match m.path().and_then(|path| Path::from_src(path, &self.hygiene)) { |
361 | .path() | ||
362 | .and_then(|path| Path::from_src(Source { ast: path, file_id: self.file_id }, self.db)) | ||
363 | { | ||
364 | Some(it) => it, | 361 | Some(it) => it, |
365 | _ => return, | 362 | _ => return, |
366 | }; | 363 | }; |
@@ -398,6 +395,6 @@ impl<DB: AstDatabase> RawItemsCollector<&DB> { | |||
398 | } | 395 | } |
399 | 396 | ||
400 | fn parse_attrs(&self, item: &impl ast::AttrsOwner) -> Attrs { | 397 | fn parse_attrs(&self, item: &impl ast::AttrsOwner) -> Attrs { |
401 | Attr::from_attrs_owner(self.file_id, item, self.db) | 398 | Attr::from_attrs_owner(item, &self.hygiene) |
402 | } | 399 | } |
403 | } | 400 | } |
diff --git a/crates/ra_hir/src/path.rs b/crates/ra_hir_def/src/path.rs index bbe536bcb..04039376f 100644 --- a/crates/ra_hir/src/path.rs +++ b/crates/ra_hir_def/src/path.rs | |||
@@ -2,12 +2,18 @@ | |||
2 | 2 | ||
3 | use std::{iter, sync::Arc}; | 3 | use std::{iter, sync::Arc}; |
4 | 4 | ||
5 | use hir_expand::{ | ||
6 | either::Either, | ||
7 | hygiene::Hygiene, | ||
8 | name::{self, AsName, Name}, | ||
9 | }; | ||
10 | use ra_db::CrateId; | ||
5 | use ra_syntax::{ | 11 | use ra_syntax::{ |
6 | ast::{self, NameOwner, TypeAscriptionOwner}, | 12 | ast::{self, NameOwner, TypeAscriptionOwner}, |
7 | AstNode, | 13 | AstNode, |
8 | }; | 14 | }; |
9 | 15 | ||
10 | use crate::{db::AstDatabase, name, type_ref::TypeRef, AsName, Crate, Name, Source}; | 16 | use crate::{type_ref::TypeRef, Source}; |
11 | 17 | ||
12 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 18 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
13 | pub struct Path { | 19 | pub struct Path { |
@@ -55,23 +61,18 @@ pub enum PathKind { | |||
55 | // Type based path like `<T>::foo` | 61 | // Type based path like `<T>::foo` |
56 | Type(Box<TypeRef>), | 62 | Type(Box<TypeRef>), |
57 | // `$crate` from macro expansion | 63 | // `$crate` from macro expansion |
58 | DollarCrate(Crate), | 64 | DollarCrate(CrateId), |
59 | } | 65 | } |
60 | 66 | ||
61 | impl Path { | 67 | impl Path { |
62 | /// Calls `cb` with all paths, represented by this use item. | 68 | /// Calls `cb` with all paths, represented by this use item. |
63 | pub fn expand_use_item( | 69 | pub fn expand_use_item( |
64 | item_src: Source<ast::UseItem>, | 70 | item_src: Source<ast::UseItem>, |
65 | db: &impl AstDatabase, | 71 | hygiene: &Hygiene, |
66 | mut cb: impl FnMut(Path, &ast::UseTree, bool, Option<Name>), | 72 | mut cb: impl FnMut(Path, &ast::UseTree, bool, Option<Name>), |
67 | ) { | 73 | ) { |
68 | if let Some(tree) = item_src.ast.use_tree() { | 74 | if let Some(tree) = item_src.ast.use_tree() { |
69 | expand_use_tree( | 75 | expand_use_tree(None, tree, hygiene, &mut cb); |
70 | None, | ||
71 | tree, | ||
72 | &|| item_src.file_id.macro_crate(db).map(|crate_id| Crate { crate_id }), | ||
73 | &mut cb, | ||
74 | ); | ||
75 | } | 76 | } |
76 | } | 77 | } |
77 | 78 | ||
@@ -88,17 +89,12 @@ impl Path { | |||
88 | /// Converts an `ast::Path` to `Path`. Works with use trees. | 89 | /// Converts an `ast::Path` to `Path`. Works with use trees. |
89 | /// DEPRECATED: It does not handle `$crate` from macro call. | 90 | /// DEPRECATED: It does not handle `$crate` from macro call. |
90 | pub fn from_ast(path: ast::Path) -> Option<Path> { | 91 | pub fn from_ast(path: ast::Path) -> Option<Path> { |
91 | Path::parse(path, &|| None) | 92 | Path::from_src(path, &Hygiene::new_unhygienic()) |
92 | } | 93 | } |
93 | 94 | ||
94 | /// Converts an `ast::Path` to `Path`. Works with use trees. | 95 | /// Converts an `ast::Path` to `Path`. Works with use trees. |
95 | /// It correctly handles `$crate` based path from macro call. | 96 | /// It correctly handles `$crate` based path from macro call. |
96 | pub fn from_src(source: Source<ast::Path>, db: &impl AstDatabase) -> Option<Path> { | 97 | pub fn from_src(mut path: ast::Path, hygiene: &Hygiene) -> Option<Path> { |
97 | let file_id = source.file_id; | ||
98 | Path::parse(source.ast, &|| file_id.macro_crate(db).map(|crate_id| Crate { crate_id })) | ||
99 | } | ||
100 | |||
101 | fn parse(mut path: ast::Path, macro_crate: &impl Fn() -> Option<Crate>) -> Option<Path> { | ||
102 | let mut kind = PathKind::Plain; | 98 | let mut kind = PathKind::Plain; |
103 | let mut segments = Vec::new(); | 99 | let mut segments = Vec::new(); |
104 | loop { | 100 | loop { |
@@ -109,26 +105,28 @@ impl Path { | |||
109 | } | 105 | } |
110 | 106 | ||
111 | match segment.kind()? { | 107 | match segment.kind()? { |
112 | ast::PathSegmentKind::Name(name) => { | 108 | ast::PathSegmentKind::Name(name_ref) => { |
113 | if name.text() == "$crate" { | 109 | // FIXME: this should just return name |
114 | if let Some(macro_crate) = macro_crate() { | 110 | match hygiene.name_ref_to_name(name_ref) { |
115 | kind = PathKind::DollarCrate(macro_crate); | 111 | Either::A(name) => { |
112 | let args = segment | ||
113 | .type_arg_list() | ||
114 | .and_then(GenericArgs::from_ast) | ||
115 | .or_else(|| { | ||
116 | GenericArgs::from_fn_like_path_ast( | ||
117 | segment.param_list(), | ||
118 | segment.ret_type(), | ||
119 | ) | ||
120 | }) | ||
121 | .map(Arc::new); | ||
122 | let segment = PathSegment { name, args_and_bindings: args }; | ||
123 | segments.push(segment); | ||
124 | } | ||
125 | Either::B(crate_id) => { | ||
126 | kind = PathKind::DollarCrate(crate_id); | ||
116 | break; | 127 | break; |
117 | } | 128 | } |
118 | } | 129 | } |
119 | |||
120 | let args = segment | ||
121 | .type_arg_list() | ||
122 | .and_then(GenericArgs::from_ast) | ||
123 | .or_else(|| { | ||
124 | GenericArgs::from_fn_like_path_ast( | ||
125 | segment.param_list(), | ||
126 | segment.ret_type(), | ||
127 | ) | ||
128 | }) | ||
129 | .map(Arc::new); | ||
130 | let segment = PathSegment { name: name.as_name(), args_and_bindings: args }; | ||
131 | segments.push(segment); | ||
132 | } | 130 | } |
133 | ast::PathSegmentKind::Type { type_ref, trait_ref } => { | 131 | ast::PathSegmentKind::Type { type_ref, trait_ref } => { |
134 | assert!(path.qualifier().is_none()); // this can only occur at the first segment | 132 | assert!(path.qualifier().is_none()); // this can only occur at the first segment |
@@ -142,7 +140,7 @@ impl Path { | |||
142 | } | 140 | } |
143 | // <T as Trait<A>>::Foo desugars to Trait<Self=T, A>::Foo | 141 | // <T as Trait<A>>::Foo desugars to Trait<Self=T, A>::Foo |
144 | Some(trait_ref) => { | 142 | Some(trait_ref) => { |
145 | let path = Path::parse(trait_ref.path()?, macro_crate)?; | 143 | let path = Path::from_src(trait_ref.path()?, hygiene)?; |
146 | kind = path.kind; | 144 | kind = path.kind; |
147 | let mut prefix_segments = path.segments; | 145 | let mut prefix_segments = path.segments; |
148 | prefix_segments.reverse(); | 146 | prefix_segments.reverse(); |
@@ -229,7 +227,7 @@ impl Path { | |||
229 | } | 227 | } |
230 | 228 | ||
231 | impl GenericArgs { | 229 | impl GenericArgs { |
232 | pub(crate) fn from_ast(node: ast::TypeArgList) -> Option<GenericArgs> { | 230 | pub fn from_ast(node: ast::TypeArgList) -> Option<GenericArgs> { |
233 | let mut args = Vec::new(); | 231 | let mut args = Vec::new(); |
234 | for type_arg in node.type_args() { | 232 | for type_arg in node.type_args() { |
235 | let type_ref = TypeRef::from_ast_opt(type_arg.type_ref()); | 233 | let type_ref = TypeRef::from_ast_opt(type_arg.type_ref()); |
@@ -293,8 +291,8 @@ impl From<Name> for Path { | |||
293 | fn expand_use_tree( | 291 | fn expand_use_tree( |
294 | prefix: Option<Path>, | 292 | prefix: Option<Path>, |
295 | tree: ast::UseTree, | 293 | tree: ast::UseTree, |
296 | macro_crate: &impl Fn() -> Option<Crate>, | 294 | hygiene: &Hygiene, |
297 | cb: &mut impl FnMut(Path, &ast::UseTree, bool, Option<Name>), | 295 | cb: &mut dyn FnMut(Path, &ast::UseTree, bool, Option<Name>), |
298 | ) { | 296 | ) { |
299 | if let Some(use_tree_list) = tree.use_tree_list() { | 297 | if let Some(use_tree_list) = tree.use_tree_list() { |
300 | let prefix = match tree.path() { | 298 | let prefix = match tree.path() { |
@@ -302,13 +300,13 @@ fn expand_use_tree( | |||
302 | None => prefix, | 300 | None => prefix, |
303 | // E.g. `use something::{inner}` (prefix is `None`, path is `something`) | 301 | // E.g. `use something::{inner}` (prefix is `None`, path is `something`) |
304 | // or `use something::{path::{inner::{innerer}}}` (prefix is `something::path`, path is `inner`) | 302 | // or `use something::{path::{inner::{innerer}}}` (prefix is `something::path`, path is `inner`) |
305 | Some(path) => match convert_path(prefix, path, macro_crate) { | 303 | Some(path) => match convert_path(prefix, path, hygiene) { |
306 | Some(it) => Some(it), | 304 | Some(it) => Some(it), |
307 | None => return, // FIXME: report errors somewhere | 305 | None => return, // FIXME: report errors somewhere |
308 | }, | 306 | }, |
309 | }; | 307 | }; |
310 | for child_tree in use_tree_list.use_trees() { | 308 | for child_tree in use_tree_list.use_trees() { |
311 | expand_use_tree(prefix.clone(), child_tree, macro_crate, cb); | 309 | expand_use_tree(prefix.clone(), child_tree, hygiene, cb); |
312 | } | 310 | } |
313 | } else { | 311 | } else { |
314 | let alias = tree.alias().and_then(|a| a.name()).map(|a| a.as_name()); | 312 | let alias = tree.alias().and_then(|a| a.name()).map(|a| a.as_name()); |
@@ -325,7 +323,7 @@ fn expand_use_tree( | |||
325 | } | 323 | } |
326 | } | 324 | } |
327 | } | 325 | } |
328 | if let Some(path) = convert_path(prefix, ast_path, macro_crate) { | 326 | if let Some(path) = convert_path(prefix, ast_path, hygiene) { |
329 | let is_glob = tree.has_star(); | 327 | let is_glob = tree.has_star(); |
330 | cb(path, &tree, is_glob, alias) | 328 | cb(path, &tree, is_glob, alias) |
331 | } | 329 | } |
@@ -335,37 +333,36 @@ fn expand_use_tree( | |||
335 | } | 333 | } |
336 | } | 334 | } |
337 | 335 | ||
338 | fn convert_path( | 336 | fn convert_path(prefix: Option<Path>, path: ast::Path, hygiene: &Hygiene) -> Option<Path> { |
339 | prefix: Option<Path>, | ||
340 | path: ast::Path, | ||
341 | macro_crate: &impl Fn() -> Option<Crate>, | ||
342 | ) -> Option<Path> { | ||
343 | let prefix = if let Some(qual) = path.qualifier() { | 337 | let prefix = if let Some(qual) = path.qualifier() { |
344 | Some(convert_path(prefix, qual, macro_crate)?) | 338 | Some(convert_path(prefix, qual, hygiene)?) |
345 | } else { | 339 | } else { |
346 | prefix | 340 | prefix |
347 | }; | 341 | }; |
348 | 342 | ||
349 | let segment = path.segment()?; | 343 | let segment = path.segment()?; |
350 | let res = match segment.kind()? { | 344 | let res = match segment.kind()? { |
351 | ast::PathSegmentKind::Name(name) => { | 345 | ast::PathSegmentKind::Name(name_ref) => { |
352 | if name.text() == "$crate" { | 346 | match hygiene.name_ref_to_name(name_ref) { |
353 | if let Some(krate) = macro_crate() { | 347 | Either::A(name) => { |
348 | // no type args in use | ||
349 | let mut res = prefix.unwrap_or_else(|| Path { | ||
350 | kind: PathKind::Plain, | ||
351 | segments: Vec::with_capacity(1), | ||
352 | }); | ||
353 | res.segments.push(PathSegment { | ||
354 | name, | ||
355 | args_and_bindings: None, // no type args in use | ||
356 | }); | ||
357 | res | ||
358 | } | ||
359 | Either::B(crate_id) => { | ||
354 | return Some(Path::from_simple_segments( | 360 | return Some(Path::from_simple_segments( |
355 | PathKind::DollarCrate(krate), | 361 | PathKind::DollarCrate(crate_id), |
356 | iter::empty(), | 362 | iter::empty(), |
357 | )); | 363 | )) |
358 | } | 364 | } |
359 | } | 365 | } |
360 | |||
361 | // no type args in use | ||
362 | let mut res = prefix | ||
363 | .unwrap_or_else(|| Path { kind: PathKind::Plain, segments: Vec::with_capacity(1) }); | ||
364 | res.segments.push(PathSegment { | ||
365 | name: name.as_name(), | ||
366 | args_and_bindings: None, // no type args in use | ||
367 | }); | ||
368 | res | ||
369 | } | 366 | } |
370 | ast::PathSegmentKind::CrateKw => { | 367 | ast::PathSegmentKind::CrateKw => { |
371 | if prefix.is_some() { | 368 | if prefix.is_some() { |
@@ -394,8 +391,9 @@ fn convert_path( | |||
394 | } | 391 | } |
395 | 392 | ||
396 | pub mod known { | 393 | pub mod known { |
394 | use hir_expand::name; | ||
395 | |||
397 | use super::{Path, PathKind}; | 396 | use super::{Path, PathKind}; |
398 | use crate::name; | ||
399 | 397 | ||
400 | pub fn std_iter_into_iterator() -> Path { | 398 | pub fn std_iter_into_iterator() -> Path { |
401 | Path::from_simple_segments( | 399 | Path::from_simple_segments( |
diff --git a/crates/ra_hir/src/type_ref.rs b/crates/ra_hir_def/src/type_ref.rs index 2cf06b250..8af061116 100644 --- a/crates/ra_hir/src/type_ref.rs +++ b/crates/ra_hir_def/src/type_ref.rs | |||
@@ -3,7 +3,7 @@ | |||
3 | 3 | ||
4 | use ra_syntax::ast::{self, TypeAscriptionOwner, TypeBoundsOwner}; | 4 | use ra_syntax::ast::{self, TypeAscriptionOwner, TypeBoundsOwner}; |
5 | 5 | ||
6 | use crate::Path; | 6 | use crate::path::Path; |
7 | 7 | ||
8 | #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] | 8 | #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] |
9 | pub enum Mutability { | 9 | pub enum Mutability { |
@@ -64,7 +64,7 @@ pub enum TypeBound { | |||
64 | 64 | ||
65 | impl TypeRef { | 65 | impl TypeRef { |
66 | /// Converts an `ast::TypeRef` to a `hir::TypeRef`. | 66 | /// Converts an `ast::TypeRef` to a `hir::TypeRef`. |
67 | pub(crate) fn from_ast(node: ast::TypeRef) -> Self { | 67 | pub fn from_ast(node: ast::TypeRef) -> Self { |
68 | match node { | 68 | match node { |
69 | ast::TypeRef::ParenType(inner) => TypeRef::from_ast_opt(inner.type_ref()), | 69 | ast::TypeRef::ParenType(inner) => TypeRef::from_ast_opt(inner.type_ref()), |
70 | ast::TypeRef::TupleType(inner) => { | 70 | ast::TypeRef::TupleType(inner) => { |
@@ -113,7 +113,7 @@ impl TypeRef { | |||
113 | } | 113 | } |
114 | } | 114 | } |
115 | 115 | ||
116 | pub(crate) fn from_ast_opt(node: Option<ast::TypeRef>) -> Self { | 116 | pub fn from_ast_opt(node: Option<ast::TypeRef>) -> Self { |
117 | if let Some(node) = node { | 117 | if let Some(node) = node { |
118 | TypeRef::from_ast(node) | 118 | TypeRef::from_ast(node) |
119 | } else { | 119 | } else { |
@@ -135,7 +135,7 @@ pub(crate) fn type_bounds_from_ast(type_bounds_opt: Option<ast::TypeBoundList>) | |||
135 | } | 135 | } |
136 | 136 | ||
137 | impl TypeBound { | 137 | impl TypeBound { |
138 | pub(crate) fn from_ast(node: ast::TypeBound) -> Self { | 138 | pub fn from_ast(node: ast::TypeBound) -> Self { |
139 | match node.kind() { | 139 | match node.kind() { |
140 | ast::TypeBoundKind::PathType(path_type) => { | 140 | ast::TypeBoundKind::PathType(path_type) => { |
141 | let path = match path_type.path() { | 141 | let path = match path_type.path() { |
diff --git a/crates/ra_hir/src/either.rs b/crates/ra_hir_expand/src/either.rs index 83583ef8b..83583ef8b 100644 --- a/crates/ra_hir/src/either.rs +++ b/crates/ra_hir_expand/src/either.rs | |||
diff --git a/crates/ra_hir_expand/src/hygiene.rs b/crates/ra_hir_expand/src/hygiene.rs new file mode 100644 index 000000000..77428ec99 --- /dev/null +++ b/crates/ra_hir_expand/src/hygiene.rs | |||
@@ -0,0 +1,46 @@ | |||
1 | //! This modules handles hygiene information. | ||
2 | //! | ||
3 | //! Specifically, `ast` + `Hygiene` allows you to create a `Name`. Note that, at | ||
4 | //! this moment, this is horribly incomplete and handles only `$crate`. | ||
5 | use ra_db::CrateId; | ||
6 | use ra_syntax::ast; | ||
7 | |||
8 | use crate::{ | ||
9 | db::AstDatabase, | ||
10 | either::Either, | ||
11 | name::{AsName, Name}, | ||
12 | HirFileId, HirFileIdRepr, | ||
13 | }; | ||
14 | |||
15 | #[derive(Debug)] | ||
16 | pub struct Hygiene { | ||
17 | // This is what `$crate` expands to | ||
18 | def_crate: Option<CrateId>, | ||
19 | } | ||
20 | |||
21 | impl Hygiene { | ||
22 | pub fn new(db: &impl AstDatabase, file_id: HirFileId) -> Hygiene { | ||
23 | let def_crate = match file_id.0 { | ||
24 | HirFileIdRepr::FileId(_) => None, | ||
25 | HirFileIdRepr::MacroFile(macro_file) => { | ||
26 | let loc = db.lookup_intern_macro(macro_file.macro_call_id); | ||
27 | Some(loc.def.krate) | ||
28 | } | ||
29 | }; | ||
30 | Hygiene { def_crate } | ||
31 | } | ||
32 | |||
33 | pub fn new_unhygienic() -> Hygiene { | ||
34 | Hygiene { def_crate: None } | ||
35 | } | ||
36 | |||
37 | // FIXME: this should just return name | ||
38 | pub fn name_ref_to_name(&self, name_ref: ast::NameRef) -> Either<Name, CrateId> { | ||
39 | if let Some(def_crate) = self.def_crate { | ||
40 | if name_ref.text() == "$crate" { | ||
41 | return Either::B(def_crate); | ||
42 | } | ||
43 | } | ||
44 | Either::A(name_ref.as_name()) | ||
45 | } | ||
46 | } | ||
diff --git a/crates/ra_hir_expand/src/lib.rs b/crates/ra_hir_expand/src/lib.rs index 6b3538673..5a0e5a19c 100644 --- a/crates/ra_hir_expand/src/lib.rs +++ b/crates/ra_hir_expand/src/lib.rs | |||
@@ -6,13 +6,16 @@ | |||
6 | 6 | ||
7 | pub mod db; | 7 | pub mod db; |
8 | pub mod ast_id_map; | 8 | pub mod ast_id_map; |
9 | pub mod either; | ||
10 | pub mod name; | ||
11 | pub mod hygiene; | ||
9 | 12 | ||
10 | use std::hash::{Hash, Hasher}; | 13 | use std::hash::{Hash, Hasher}; |
11 | 14 | ||
12 | use ra_db::{salsa, CrateId, FileId}; | 15 | use ra_db::{salsa, CrateId, FileId}; |
13 | use ra_syntax::ast::{self, AstNode}; | 16 | use ra_syntax::ast::{self, AstNode}; |
14 | 17 | ||
15 | use crate::{ast_id_map::FileAstId, db::AstDatabase}; | 18 | use crate::ast_id_map::FileAstId; |
16 | 19 | ||
17 | /// Input to the analyzer is a set of files, where each file is identified by | 20 | /// Input to the analyzer is a set of files, where each file is identified by |
18 | /// `FileId` and contains source code. However, another source of source code in | 21 | /// `FileId` and contains source code. However, another source of source code in |
@@ -50,7 +53,7 @@ impl From<MacroFile> for HirFileId { | |||
50 | impl HirFileId { | 53 | impl HirFileId { |
51 | /// For macro-expansion files, returns the file original source file the | 54 | /// For macro-expansion files, returns the file original source file the |
52 | /// expansion originated from. | 55 | /// expansion originated from. |
53 | pub fn original_file(self, db: &dyn AstDatabase) -> FileId { | 56 | pub fn original_file(self, db: &dyn db::AstDatabase) -> FileId { |
54 | match self.0 { | 57 | match self.0 { |
55 | HirFileIdRepr::FileId(file_id) => file_id, | 58 | HirFileIdRepr::FileId(file_id) => file_id, |
56 | HirFileIdRepr::MacroFile(macro_file) => { | 59 | HirFileIdRepr::MacroFile(macro_file) => { |
@@ -59,17 +62,6 @@ impl HirFileId { | |||
59 | } | 62 | } |
60 | } | 63 | } |
61 | } | 64 | } |
62 | |||
63 | /// Get the crate which the macro lives in, if it is a macro file. | ||
64 | pub fn macro_crate(self, db: &dyn AstDatabase) -> Option<CrateId> { | ||
65 | match self.0 { | ||
66 | HirFileIdRepr::FileId(_) => None, | ||
67 | HirFileIdRepr::MacroFile(macro_file) => { | ||
68 | let loc = db.lookup_intern_macro(macro_file.macro_call_id); | ||
69 | Some(loc.def.krate) | ||
70 | } | ||
71 | } | ||
72 | } | ||
73 | } | 65 | } |
74 | 66 | ||
75 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 67 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
@@ -154,7 +146,7 @@ impl<N: AstNode> AstId<N> { | |||
154 | self.file_id | 146 | self.file_id |
155 | } | 147 | } |
156 | 148 | ||
157 | pub fn to_node(&self, db: &dyn AstDatabase) -> N { | 149 | pub fn to_node(&self, db: &dyn db::AstDatabase) -> N { |
158 | let root = db.parse_or_expand(self.file_id).unwrap(); | 150 | let root = db.parse_or_expand(self.file_id).unwrap(); |
159 | db.ast_id_map(self.file_id).get(self.file_ast_id).to_node(&root) | 151 | db.ast_id_map(self.file_id).get(self.file_ast_id).to_node(&root) |
160 | } | 152 | } |
diff --git a/crates/ra_hir/src/name.rs b/crates/ra_hir_expand/src/name.rs index 1e0b8c350..720896ee8 100644 --- a/crates/ra_hir/src/name.rs +++ b/crates/ra_hir_expand/src/name.rs | |||
@@ -33,7 +33,7 @@ impl Name { | |||
33 | Name(Repr::Text(text)) | 33 | Name(Repr::Text(text)) |
34 | } | 34 | } |
35 | 35 | ||
36 | pub(crate) fn new_tuple_field(idx: usize) -> Name { | 36 | pub fn new_tuple_field(idx: usize) -> Name { |
37 | Name(Repr::TupleField(idx)) | 37 | Name(Repr::TupleField(idx)) |
38 | } | 38 | } |
39 | 39 | ||
@@ -52,11 +52,11 @@ impl Name { | |||
52 | } | 52 | } |
53 | } | 53 | } |
54 | 54 | ||
55 | pub(crate) fn missing() -> Name { | 55 | pub fn missing() -> Name { |
56 | Name::new_text("[missing name]".into()) | 56 | Name::new_text("[missing name]".into()) |
57 | } | 57 | } |
58 | 58 | ||
59 | pub(crate) fn as_tuple_index(&self) -> Option<usize> { | 59 | pub fn as_tuple_index(&self) -> Option<usize> { |
60 | match self.0 { | 60 | match self.0 { |
61 | Repr::TupleField(idx) => Some(idx), | 61 | Repr::TupleField(idx) => Some(idx), |
62 | _ => None, | 62 | _ => None, |
@@ -64,7 +64,7 @@ impl Name { | |||
64 | } | 64 | } |
65 | } | 65 | } |
66 | 66 | ||
67 | pub(crate) trait AsName { | 67 | pub trait AsName { |
68 | fn as_name(&self) -> Name; | 68 | fn as_name(&self) -> Name; |
69 | } | 69 | } |
70 | 70 | ||
@@ -99,44 +99,44 @@ impl AsName for ra_db::Dependency { | |||
99 | } | 99 | } |
100 | 100 | ||
101 | // Primitives | 101 | // Primitives |
102 | pub(crate) const ISIZE: Name = Name::new_inline_ascii(5, b"isize"); | 102 | pub const ISIZE: Name = Name::new_inline_ascii(5, b"isize"); |
103 | pub(crate) const I8: Name = Name::new_inline_ascii(2, b"i8"); | 103 | pub const I8: Name = Name::new_inline_ascii(2, b"i8"); |
104 | pub(crate) const I16: Name = Name::new_inline_ascii(3, b"i16"); | 104 | pub const I16: Name = Name::new_inline_ascii(3, b"i16"); |
105 | pub(crate) const I32: Name = Name::new_inline_ascii(3, b"i32"); | 105 | pub const I32: Name = Name::new_inline_ascii(3, b"i32"); |
106 | pub(crate) const I64: Name = Name::new_inline_ascii(3, b"i64"); | 106 | pub const I64: Name = Name::new_inline_ascii(3, b"i64"); |
107 | pub(crate) const I128: Name = Name::new_inline_ascii(4, b"i128"); | 107 | pub const I128: Name = Name::new_inline_ascii(4, b"i128"); |
108 | pub(crate) const USIZE: Name = Name::new_inline_ascii(5, b"usize"); | 108 | pub const USIZE: Name = Name::new_inline_ascii(5, b"usize"); |
109 | pub(crate) const U8: Name = Name::new_inline_ascii(2, b"u8"); | 109 | pub const U8: Name = Name::new_inline_ascii(2, b"u8"); |
110 | pub(crate) const U16: Name = Name::new_inline_ascii(3, b"u16"); | 110 | pub const U16: Name = Name::new_inline_ascii(3, b"u16"); |
111 | pub(crate) const U32: Name = Name::new_inline_ascii(3, b"u32"); | 111 | pub const U32: Name = Name::new_inline_ascii(3, b"u32"); |
112 | pub(crate) const U64: Name = Name::new_inline_ascii(3, b"u64"); | 112 | pub const U64: Name = Name::new_inline_ascii(3, b"u64"); |
113 | pub(crate) const U128: Name = Name::new_inline_ascii(4, b"u128"); | 113 | pub const U128: Name = Name::new_inline_ascii(4, b"u128"); |
114 | pub(crate) const F32: Name = Name::new_inline_ascii(3, b"f32"); | 114 | pub const F32: Name = Name::new_inline_ascii(3, b"f32"); |
115 | pub(crate) const F64: Name = Name::new_inline_ascii(3, b"f64"); | 115 | pub const F64: Name = Name::new_inline_ascii(3, b"f64"); |
116 | pub(crate) const BOOL: Name = Name::new_inline_ascii(4, b"bool"); | 116 | pub const BOOL: Name = Name::new_inline_ascii(4, b"bool"); |
117 | pub(crate) const CHAR: Name = Name::new_inline_ascii(4, b"char"); | 117 | pub const CHAR: Name = Name::new_inline_ascii(4, b"char"); |
118 | pub(crate) const STR: Name = Name::new_inline_ascii(3, b"str"); | 118 | pub const STR: Name = Name::new_inline_ascii(3, b"str"); |
119 | 119 | ||
120 | // Special names | 120 | // Special names |
121 | pub(crate) const SELF_PARAM: Name = Name::new_inline_ascii(4, b"self"); | 121 | pub const SELF_PARAM: Name = Name::new_inline_ascii(4, b"self"); |
122 | pub(crate) const SELF_TYPE: Name = Name::new_inline_ascii(4, b"Self"); | 122 | pub const SELF_TYPE: Name = Name::new_inline_ascii(4, b"Self"); |
123 | pub(crate) const MACRO_RULES: Name = Name::new_inline_ascii(11, b"macro_rules"); | 123 | pub const MACRO_RULES: Name = Name::new_inline_ascii(11, b"macro_rules"); |
124 | 124 | ||
125 | // Components of known path (value or mod name) | 125 | // Components of known path (value or mod name) |
126 | pub(crate) const STD: Name = Name::new_inline_ascii(3, b"std"); | 126 | pub const STD: Name = Name::new_inline_ascii(3, b"std"); |
127 | pub(crate) const ITER: Name = Name::new_inline_ascii(4, b"iter"); | 127 | pub const ITER: Name = Name::new_inline_ascii(4, b"iter"); |
128 | pub(crate) const OPS: Name = Name::new_inline_ascii(3, b"ops"); | 128 | pub const OPS: Name = Name::new_inline_ascii(3, b"ops"); |
129 | pub(crate) const FUTURE: Name = Name::new_inline_ascii(6, b"future"); | 129 | pub const FUTURE: Name = Name::new_inline_ascii(6, b"future"); |
130 | pub(crate) const RESULT: Name = Name::new_inline_ascii(6, b"result"); | 130 | pub const RESULT: Name = Name::new_inline_ascii(6, b"result"); |
131 | pub(crate) const BOXED: Name = Name::new_inline_ascii(5, b"boxed"); | 131 | pub const BOXED: Name = Name::new_inline_ascii(5, b"boxed"); |
132 | 132 | ||
133 | // Components of known path (type name) | 133 | // Components of known path (type name) |
134 | pub(crate) const INTO_ITERATOR_TYPE: Name = Name::new_inline_ascii(12, b"IntoIterator"); | 134 | pub const INTO_ITERATOR_TYPE: Name = Name::new_inline_ascii(12, b"IntoIterator"); |
135 | pub(crate) const ITEM_TYPE: Name = Name::new_inline_ascii(4, b"Item"); | 135 | pub const ITEM_TYPE: Name = Name::new_inline_ascii(4, b"Item"); |
136 | pub(crate) const TRY_TYPE: Name = Name::new_inline_ascii(3, b"Try"); | 136 | pub const TRY_TYPE: Name = Name::new_inline_ascii(3, b"Try"); |
137 | pub(crate) const OK_TYPE: Name = Name::new_inline_ascii(2, b"Ok"); | 137 | pub const OK_TYPE: Name = Name::new_inline_ascii(2, b"Ok"); |
138 | pub(crate) const FUTURE_TYPE: Name = Name::new_inline_ascii(6, b"Future"); | 138 | pub const FUTURE_TYPE: Name = Name::new_inline_ascii(6, b"Future"); |
139 | pub(crate) const RESULT_TYPE: Name = Name::new_inline_ascii(6, b"Result"); | 139 | pub const RESULT_TYPE: Name = Name::new_inline_ascii(6, b"Result"); |
140 | pub(crate) const OUTPUT_TYPE: Name = Name::new_inline_ascii(6, b"Output"); | 140 | pub const OUTPUT_TYPE: Name = Name::new_inline_ascii(6, b"Output"); |
141 | pub(crate) const TARGET_TYPE: Name = Name::new_inline_ascii(6, b"Target"); | 141 | pub const TARGET_TYPE: Name = Name::new_inline_ascii(6, b"Target"); |
142 | pub(crate) const BOX_TYPE: Name = Name::new_inline_ascii(3, b"Box"); | 142 | pub const BOX_TYPE: Name = Name::new_inline_ascii(3, b"Box"); |
diff --git a/crates/ra_ide_api/src/call_info.rs b/crates/ra_ide_api/src/call_info.rs index 175af3fd9..e494f5620 100644 --- a/crates/ra_ide_api/src/call_info.rs +++ b/crates/ra_ide_api/src/call_info.rs | |||
@@ -95,7 +95,7 @@ impl FnCallNode { | |||
95 | Some(FnCallNode::CallExpr(expr)) | 95 | Some(FnCallNode::CallExpr(expr)) |
96 | } else if let Some(expr) = ast::MethodCallExpr::cast(node.clone()) { | 96 | } else if let Some(expr) = ast::MethodCallExpr::cast(node.clone()) { |
97 | Some(FnCallNode::MethodCallExpr(expr)) | 97 | Some(FnCallNode::MethodCallExpr(expr)) |
98 | } else if let Some(expr) = ast::MacroCall::cast(node.clone()) { | 98 | } else if let Some(expr) = ast::MacroCall::cast(node) { |
99 | Some(FnCallNode::MacroCallExpr(expr)) | 99 | Some(FnCallNode::MacroCallExpr(expr)) |
100 | } else { | 100 | } else { |
101 | None | 101 | None |
diff --git a/crates/ra_ide_api/src/change.rs b/crates/ra_ide_api/src/change.rs index 050249c0e..39c5946c7 100644 --- a/crates/ra_ide_api/src/change.rs +++ b/crates/ra_ide_api/src/change.rs | |||
@@ -43,7 +43,7 @@ impl fmt::Debug for AnalysisChange { | |||
43 | if !self.libraries_added.is_empty() { | 43 | if !self.libraries_added.is_empty() { |
44 | d.field("libraries_added", &self.libraries_added.len()); | 44 | d.field("libraries_added", &self.libraries_added.len()); |
45 | } | 45 | } |
46 | if !self.crate_graph.is_some() { | 46 | if !self.crate_graph.is_none() { |
47 | d.field("crate_graph", &self.crate_graph); | 47 | d.field("crate_graph", &self.crate_graph); |
48 | } | 48 | } |
49 | d.finish() | 49 | d.finish() |
diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs index 956d8ce49..a58fdc036 100644 --- a/crates/ra_ide_api/src/completion/complete_path.rs +++ b/crates/ra_ide_api/src/completion/complete_path.rs | |||
@@ -67,7 +67,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { | |||
67 | }); | 67 | }); |
68 | } | 68 | } |
69 | } | 69 | } |
70 | _ => return, | 70 | _ => {} |
71 | }; | 71 | }; |
72 | } | 72 | } |
73 | 73 | ||
diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs index f7e98e6df..65bb639ed 100644 --- a/crates/ra_ide_api/src/completion/presentation.rs +++ b/crates/ra_ide_api/src/completion/presentation.rs | |||
@@ -136,7 +136,7 @@ impl Completions { | |||
136 | for (idx, s) in docs.match_indices(¯o_name) { | 136 | for (idx, s) in docs.match_indices(¯o_name) { |
137 | let (before, after) = (&docs[..idx], &docs[idx + s.len()..]); | 137 | let (before, after) = (&docs[..idx], &docs[idx + s.len()..]); |
138 | // Ensure to match the full word | 138 | // Ensure to match the full word |
139 | if after.starts_with("!") | 139 | if after.starts_with('!') |
140 | && before | 140 | && before |
141 | .chars() | 141 | .chars() |
142 | .rev() | 142 | .rev() |
@@ -225,7 +225,7 @@ impl Completions { | |||
225 | } else { | 225 | } else { |
226 | (format!("{}($0)", data.name()), format!("{}(…)", name)) | 226 | (format!("{}($0)", data.name()), format!("{}(…)", name)) |
227 | }; | 227 | }; |
228 | builder = builder.lookup_by(name.clone()).label(label).insert_snippet(snippet); | 228 | builder = builder.lookup_by(name).label(label).insert_snippet(snippet); |
229 | } | 229 | } |
230 | 230 | ||
231 | self.add(builder) | 231 | self.add(builder) |
diff --git a/crates/ra_ide_api/src/db.rs b/crates/ra_ide_api/src/db.rs index 9146b647a..785e71808 100644 --- a/crates/ra_ide_api/src/db.rs +++ b/crates/ra_ide_api/src/db.rs | |||
@@ -23,6 +23,7 @@ use crate::{ | |||
23 | hir::db::InternDatabaseStorage, | 23 | hir::db::InternDatabaseStorage, |
24 | hir::db::AstDatabaseStorage, | 24 | hir::db::AstDatabaseStorage, |
25 | hir::db::DefDatabaseStorage, | 25 | hir::db::DefDatabaseStorage, |
26 | hir::db::DefDatabase2Storage, | ||
26 | hir::db::HirDatabaseStorage | 27 | hir::db::HirDatabaseStorage |
27 | )] | 28 | )] |
28 | #[derive(Debug)] | 29 | #[derive(Debug)] |
diff --git a/crates/ra_ide_api/src/references/search_scope.rs b/crates/ra_ide_api/src/references/search_scope.rs index dbd1af597..f2789e0b2 100644 --- a/crates/ra_ide_api/src/references/search_scope.rs +++ b/crates/ra_ide_api/src/references/search_scope.rs | |||
@@ -111,8 +111,7 @@ impl NameDefinition { | |||
111 | if vis.as_str() != "" { | 111 | if vis.as_str() != "" { |
112 | let source_root_id = db.file_source_root(file_id); | 112 | let source_root_id = db.file_source_root(file_id); |
113 | let source_root = db.source_root(source_root_id); | 113 | let source_root = db.source_root(source_root_id); |
114 | let mut res = | 114 | let mut res = source_root.walk().map(|id| (id, None)).collect::<FxHashMap<_, _>>(); |
115 | source_root.walk().map(|id| (id.into(), None)).collect::<FxHashMap<_, _>>(); | ||
116 | 115 | ||
117 | // FIXME: add "pub(in path)" | 116 | // FIXME: add "pub(in path)" |
118 | 117 | ||
@@ -128,7 +127,7 @@ impl NameDefinition { | |||
128 | let root_file = crate_graph.crate_root(crate_id); | 127 | let root_file = crate_graph.crate_root(crate_id); |
129 | let source_root_id = db.file_source_root(root_file); | 128 | let source_root_id = db.file_source_root(root_file); |
130 | let source_root = db.source_root(source_root_id); | 129 | let source_root = db.source_root(source_root_id); |
131 | res.extend(source_root.walk().map(|id| (id.into(), None))); | 130 | res.extend(source_root.walk().map(|id| (id, None))); |
132 | } | 131 | } |
133 | } | 132 | } |
134 | return SearchScope::new(res); | 133 | return SearchScope::new(res); |
diff --git a/crates/ra_ide_api/src/typing.rs b/crates/ra_ide_api/src/typing.rs index 2dfbe6944..d51132f73 100644 --- a/crates/ra_ide_api/src/typing.rs +++ b/crates/ra_ide_api/src/typing.rs | |||
@@ -261,7 +261,7 @@ impl S { | |||
261 | 261 | ||
262 | fn type_char(char_typed: char, before: &str, after: &str) { | 262 | fn type_char(char_typed: char, before: &str, after: &str) { |
263 | let (actual, file_change) = do_type_char(char_typed, before) | 263 | let (actual, file_change) = do_type_char(char_typed, before) |
264 | .expect(&format!("typing `{}` did nothing", char_typed)); | 264 | .unwrap_or_else(|| panic!("typing `{}` did nothing", char_typed)); |
265 | 265 | ||
266 | if after.contains("<|>") { | 266 | if after.contains("<|>") { |
267 | let (offset, after) = extract_offset(after); | 267 | let (offset, after) = extract_offset(after); |
diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index 1a87706fe..379dab438 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs | |||
@@ -196,7 +196,7 @@ pub fn main_loop( | |||
196 | task_receiver.into_iter().for_each(|task| { | 196 | task_receiver.into_iter().for_each(|task| { |
197 | on_task(task, &connection.sender, &mut loop_state.pending_requests, &mut world_state) | 197 | on_task(task, &connection.sender, &mut loop_state.pending_requests, &mut world_state) |
198 | }); | 198 | }); |
199 | libdata_receiver.into_iter().for_each(|lib| drop(lib)); | 199 | libdata_receiver.into_iter().for_each(drop); |
200 | log::info!("...tasks have finished"); | 200 | log::info!("...tasks have finished"); |
201 | log::info!("joining threadpool..."); | 201 | log::info!("joining threadpool..."); |
202 | drop(pool); | 202 | drop(pool); |
diff --git a/crates/ra_mbe/src/mbe_expander/matcher.rs b/crates/ra_mbe/src/mbe_expander/matcher.rs index 0548e8512..33b9d483d 100644 --- a/crates/ra_mbe/src/mbe_expander/matcher.rs +++ b/crates/ra_mbe/src/mbe_expander/matcher.rs | |||
@@ -123,7 +123,6 @@ fn match_subtree( | |||
123 | } | 123 | } |
124 | None => bindings.push_optional(name), | 124 | None => bindings.push_optional(name), |
125 | } | 125 | } |
126 | () | ||
127 | } | 126 | } |
128 | Op::Repeat { subtree, kind, separator } => { | 127 | Op::Repeat { subtree, kind, separator } => { |
129 | match_repeat(bindings, subtree, kind, separator, src)? | 128 | match_repeat(bindings, subtree, kind, separator, src)? |
@@ -159,7 +158,7 @@ impl<'a> TtIter<'a> { | |||
159 | pub(crate) fn expect_lifetime(&mut self) -> Result<&tt::Ident, ()> { | 158 | pub(crate) fn expect_lifetime(&mut self) -> Result<&tt::Ident, ()> { |
160 | let ident = self.expect_ident()?; | 159 | let ident = self.expect_ident()?; |
161 | // check if it start from "`" | 160 | // check if it start from "`" |
162 | if ident.text.chars().next() != Some('\'') { | 161 | if !ident.text.starts_with('\'') { |
163 | return Err(()); | 162 | return Err(()); |
164 | } | 163 | } |
165 | Ok(ident) | 164 | Ok(ident) |
diff --git a/crates/ra_mbe/src/syntax_bridge.rs b/crates/ra_mbe/src/syntax_bridge.rs index 1b543c84b..592fcf527 100644 --- a/crates/ra_mbe/src/syntax_bridge.rs +++ b/crates/ra_mbe/src/syntax_bridge.rs | |||
@@ -383,7 +383,7 @@ mod tests { | |||
383 | "#, | 383 | "#, |
384 | ); | 384 | ); |
385 | let expansion = expand(&rules, "literals!(foo);"); | 385 | let expansion = expand(&rules, "literals!(foo);"); |
386 | let tts = &[expansion.clone().into()]; | 386 | let tts = &[expansion.into()]; |
387 | let buffer = tt::buffer::TokenBuffer::new(tts); | 387 | let buffer = tt::buffer::TokenBuffer::new(tts); |
388 | let mut tt_src = SubtreeTokenSource::new(&buffer); | 388 | let mut tt_src = SubtreeTokenSource::new(&buffer); |
389 | let mut tokens = vec![]; | 389 | let mut tokens = vec![]; |
diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs index 76dad9155..3d5f18bfa 100644 --- a/crates/ra_syntax/src/ast/make.rs +++ b/crates/ra_syntax/src/ast/make.rs | |||
@@ -129,11 +129,11 @@ pub fn where_clause(preds: impl Iterator<Item = ast::WherePred>) -> ast::WhereCl | |||
129 | } | 129 | } |
130 | 130 | ||
131 | pub fn if_expression(condition: &ast::Expr, statement: &str) -> ast::IfExpr { | 131 | pub fn if_expression(condition: &ast::Expr, statement: &str) -> ast::IfExpr { |
132 | return ast_from_text(&format!( | 132 | ast_from_text(&format!( |
133 | "fn f() {{ if !{} {{\n {}\n}}\n}}", | 133 | "fn f() {{ if !{} {{\n {}\n}}\n}}", |
134 | condition.syntax().text(), | 134 | condition.syntax().text(), |
135 | statement | 135 | statement |
136 | )); | 136 | )) |
137 | } | 137 | } |
138 | 138 | ||
139 | fn ast_from_text<N: AstNode>(text: &str) -> N { | 139 | fn ast_from_text<N: AstNode>(text: &str) -> N { |