aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-11-28 10:02:46 +0000
committerGitHub <[email protected]>2019-11-28 10:02:46 +0000
commit16030528b53d38e24c1e5733aa4cc46058d0bbd1 (patch)
treee878f88aebf11c0e54eff2e107dfaa4d192ab272 /crates
parent2702fa1c5d6d8ad504c0d7703b6363ea09ba5570 (diff)
parentccd1b0800a5de5e046e6e9a4b6f49030c1ce3639 (diff)
Merge #2440
2440: Rename Source -> InFile r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_assists/src/assist_ctx.rs4
-rw-r--r--crates/ra_assists/src/assists/add_new.rs6
-rw-r--r--crates/ra_hir/src/code_model.rs6
-rw-r--r--crates/ra_hir/src/code_model/src.rs36
-rw-r--r--crates/ra_hir/src/from_source.rs62
-rw-r--r--crates/ra_hir/src/lib.rs2
-rw-r--r--crates/ra_hir/src/source_binder.rs28
-rw-r--r--crates/ra_hir_def/src/adt.rs6
-rw-r--r--crates/ra_hir_def/src/attr.rs6
-rw-r--r--crates/ra_hir_def/src/body.rs14
-rw-r--r--crates/ra_hir_def/src/body/scope.rs6
-rw-r--r--crates/ra_hir_def/src/diagnostics.rs6
-rw-r--r--crates/ra_hir_def/src/lib.rs26
-rw-r--r--crates/ra_hir_def/src/nameres.rs14
-rw-r--r--crates/ra_hir_def/src/nameres/raw.rs6
-rw-r--r--crates/ra_hir_def/src/path.rs4
-rw-r--r--crates/ra_hir_expand/src/diagnostics.rs4
-rw-r--r--crates/ra_hir_expand/src/lib.rs42
-rw-r--r--crates/ra_hir_ty/src/diagnostics.rs14
-rw-r--r--crates/ra_hir_ty/src/tests.rs4
-rw-r--r--crates/ra_ide/src/call_info.rs2
-rw-r--r--crates/ra_ide/src/completion/completion_context.rs4
-rw-r--r--crates/ra_ide/src/diagnostics.rs2
-rw-r--r--crates/ra_ide/src/display/navigation_target.rs4
-rw-r--r--crates/ra_ide/src/expand.rs8
-rw-r--r--crates/ra_ide/src/expand_macro.rs8
-rw-r--r--crates/ra_ide/src/goto_definition.rs8
-rw-r--r--crates/ra_ide/src/hover.rs2
-rw-r--r--crates/ra_ide/src/impls.rs10
-rw-r--r--crates/ra_ide/src/inlay_hints.rs2
-rw-r--r--crates/ra_ide/src/parent_module.rs4
-rw-r--r--crates/ra_ide/src/references.rs8
-rw-r--r--crates/ra_ide/src/references/classify.rs6
-rw-r--r--crates/ra_ide/src/references/rename.rs2
-rw-r--r--crates/ra_ide/src/runnables.rs6
-rw-r--r--crates/ra_ide/src/syntax_highlighting.rs6
36 files changed, 189 insertions, 189 deletions
diff --git a/crates/ra_assists/src/assist_ctx.rs b/crates/ra_assists/src/assist_ctx.rs
index 0ea84d548..993aebc47 100644
--- a/crates/ra_assists/src/assist_ctx.rs
+++ b/crates/ra_assists/src/assist_ctx.rs
@@ -1,5 +1,5 @@
1//! This module defines `AssistCtx` -- the API surface that is exposed to assists. 1//! This module defines `AssistCtx` -- the API surface that is exposed to assists.
2use hir::{db::HirDatabase, SourceAnalyzer}; 2use hir::{db::HirDatabase, InFile, SourceAnalyzer};
3use ra_db::FileRange; 3use ra_db::FileRange;
4use ra_fmt::{leading_indent, reindent}; 4use ra_fmt::{leading_indent, reindent};
5use ra_syntax::{ 5use ra_syntax::{
@@ -117,7 +117,7 @@ impl<'a, DB: HirDatabase> AssistCtx<'a, DB> {
117 node: &SyntaxNode, 117 node: &SyntaxNode,
118 offset: Option<TextUnit>, 118 offset: Option<TextUnit>,
119 ) -> SourceAnalyzer { 119 ) -> SourceAnalyzer {
120 SourceAnalyzer::new(self.db, hir::Source::new(self.frange.file_id.into(), node), offset) 120 SourceAnalyzer::new(self.db, InFile::new(self.frange.file_id.into(), node), offset)
121 } 121 }
122 122
123 pub(crate) fn covering_node_for_range(&self, range: TextRange) -> SyntaxElement { 123 pub(crate) fn covering_node_for_range(&self, range: TextRange) -> SyntaxElement {
diff --git a/crates/ra_assists/src/assists/add_new.rs b/crates/ra_assists/src/assists/add_new.rs
index 8f68bd5fb..f977547fb 100644
--- a/crates/ra_assists/src/assists/add_new.rs
+++ b/crates/ra_assists/src/assists/add_new.rs
@@ -1,5 +1,5 @@
1use format_buf::format; 1use format_buf::format;
2use hir::{db::HirDatabase, FromSource}; 2use hir::{db::HirDatabase, FromSource, InFile};
3use join_to_string::join; 3use join_to_string::join;
4use ra_syntax::{ 4use ra_syntax::{
5 ast::{ 5 ast::{
@@ -141,7 +141,7 @@ fn find_struct_impl(
141 })?; 141 })?;
142 142
143 let struct_ty = { 143 let struct_ty = {
144 let src = hir::Source { file_id: ctx.frange.file_id.into(), value: strukt.clone() }; 144 let src = InFile { file_id: ctx.frange.file_id.into(), value: strukt.clone() };
145 hir::Struct::from_source(db, src).unwrap().ty(db) 145 hir::Struct::from_source(db, src).unwrap().ty(db)
146 }; 146 };
147 147
@@ -152,7 +152,7 @@ fn find_struct_impl(
152 return false; 152 return false;
153 } 153 }
154 154
155 let src = hir::Source { file_id: ctx.frange.file_id.into(), value: impl_blk.clone() }; 155 let src = InFile { file_id: ctx.frange.file_id.into(), value: impl_blk.clone() };
156 let blk = hir::ImplBlock::from_source(db, src).unwrap(); 156 let blk = hir::ImplBlock::from_source(db, src).unwrap();
157 157
158 let same_ty = blk.target_ty(db) == struct_ty; 158 let same_ty = blk.target_ty(db) == struct_ty;
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index 38d66c2a7..dddac915b 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -30,7 +30,7 @@ use crate::{
30 db::{DefDatabase, HirDatabase}, 30 db::{DefDatabase, HirDatabase},
31 ty::display::HirFormatter, 31 ty::display::HirFormatter,
32 ty::{self, InEnvironment, InferenceResult, TraitEnvironment, Ty, TyDefId, TypeCtor, TypeWalk}, 32 ty::{self, InEnvironment, InferenceResult, TraitEnvironment, Ty, TyDefId, TypeCtor, TypeWalk},
33 CallableDef, Either, HirDisplay, Name, Source, 33 CallableDef, Either, HirDisplay, InFile, Name,
34}; 34};
35 35
36/// hir::Crate describes a single crate. It's the main interface with which 36/// hir::Crate describes a single crate. It's the main interface with which
@@ -118,7 +118,7 @@ impl ModuleSource {
118 } 118 }
119 } 119 }
120 120
121 pub fn from_child_node(db: &impl DefDatabase, child: Source<&SyntaxNode>) -> ModuleSource { 121 pub fn from_child_node(db: &impl DefDatabase, child: InFile<&SyntaxNode>) -> ModuleSource {
122 if let Some(m) = 122 if let Some(m) =
123 child.value.ancestors().filter_map(ast::Module::cast).find(|it| !it.has_semi()) 123 child.value.ancestors().filter_map(ast::Module::cast).find(|it| !it.has_semi())
124 { 124 {
@@ -901,7 +901,7 @@ impl Local {
901 Type { krate, ty: InEnvironment { value: ty, environment } } 901 Type { krate, ty: InEnvironment { value: ty, environment } }
902 } 902 }
903 903
904 pub fn source(self, db: &impl HirDatabase) -> Source<Either<ast::BindPat, ast::SelfParam>> { 904 pub fn source(self, db: &impl HirDatabase) -> InFile<Either<ast::BindPat, ast::SelfParam>> {
905 let (_body, source_map) = db.body_with_source_map(self.parent.into()); 905 let (_body, source_map) = db.body_with_source_map(self.parent.into());
906 let src = source_map.pat_syntax(self.pat_id).unwrap(); // Hmm... 906 let src = source_map.pat_syntax(self.pat_id).unwrap(); // Hmm...
907 let root = src.file_syntax(db); 907 let root = src.file_syntax(db);
diff --git a/crates/ra_hir/src/code_model/src.rs b/crates/ra_hir/src/code_model/src.rs
index bf3ee0834..6fd4e7987 100644
--- a/crates/ra_hir/src/code_model/src.rs
+++ b/crates/ra_hir/src/code_model/src.rs
@@ -9,18 +9,18 @@ use crate::{
9 Module, ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union, 9 Module, ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union,
10}; 10};
11 11
12pub use hir_expand::Source; 12pub use hir_expand::InFile;
13 13
14pub trait HasSource { 14pub trait HasSource {
15 type Ast; 15 type Ast;
16 fn source(self, db: &impl DefDatabase) -> Source<Self::Ast>; 16 fn source(self, db: &impl DefDatabase) -> InFile<Self::Ast>;
17} 17}
18 18
19/// NB: Module is !HasSource, because it has two source nodes at the same time: 19/// NB: Module is !HasSource, because it has two source nodes at the same time:
20/// definition and declaration. 20/// definition and declaration.
21impl Module { 21impl Module {
22 /// Returns a node which defines this module. That is, a file or a `mod foo {}` with items. 22 /// Returns a node which defines this module. That is, a file or a `mod foo {}` with items.
23 pub fn definition_source(self, db: &impl DefDatabase) -> Source<ModuleSource> { 23 pub fn definition_source(self, db: &impl DefDatabase) -> InFile<ModuleSource> {
24 let def_map = db.crate_def_map(self.id.krate); 24 let def_map = db.crate_def_map(self.id.krate);
25 let src = def_map[self.id.local_id].definition_source(db); 25 let src = def_map[self.id.local_id].definition_source(db);
26 src.map(|it| match it { 26 src.map(|it| match it {
@@ -31,7 +31,7 @@ impl Module {
31 31
32 /// Returns a node which declares this module, either a `mod foo;` or a `mod foo {}`. 32 /// Returns a node which declares this module, either a `mod foo;` or a `mod foo {}`.
33 /// `None` for the crate root. 33 /// `None` for the crate root.
34 pub fn declaration_source(self, db: &impl DefDatabase) -> Option<Source<ast::Module>> { 34 pub fn declaration_source(self, db: &impl DefDatabase) -> Option<InFile<ast::Module>> {
35 let def_map = db.crate_def_map(self.id.krate); 35 let def_map = db.crate_def_map(self.id.krate);
36 def_map[self.id.local_id].declaration_source(db) 36 def_map[self.id.local_id].declaration_source(db)
37 } 37 }
@@ -39,7 +39,7 @@ impl Module {
39 39
40impl HasSource for StructField { 40impl HasSource for StructField {
41 type Ast = FieldSource; 41 type Ast = FieldSource;
42 fn source(self, db: &impl DefDatabase) -> Source<FieldSource> { 42 fn source(self, db: &impl DefDatabase) -> InFile<FieldSource> {
43 let var = VariantId::from(self.parent); 43 let var = VariantId::from(self.parent);
44 let src = var.child_source(db); 44 let src = var.child_source(db);
45 src.map(|it| match it[self.id].clone() { 45 src.map(|it| match it[self.id].clone() {
@@ -50,67 +50,67 @@ impl HasSource for StructField {
50} 50}
51impl HasSource for Struct { 51impl HasSource for Struct {
52 type Ast = ast::StructDef; 52 type Ast = ast::StructDef;
53 fn source(self, db: &impl DefDatabase) -> Source<ast::StructDef> { 53 fn source(self, db: &impl DefDatabase) -> InFile<ast::StructDef> {
54 self.id.source(db) 54 self.id.source(db)
55 } 55 }
56} 56}
57impl HasSource for Union { 57impl HasSource for Union {
58 type Ast = ast::UnionDef; 58 type Ast = ast::UnionDef;
59 fn source(self, db: &impl DefDatabase) -> Source<ast::UnionDef> { 59 fn source(self, db: &impl DefDatabase) -> InFile<ast::UnionDef> {
60 self.id.source(db) 60 self.id.source(db)
61 } 61 }
62} 62}
63impl HasSource for Enum { 63impl HasSource for Enum {
64 type Ast = ast::EnumDef; 64 type Ast = ast::EnumDef;
65 fn source(self, db: &impl DefDatabase) -> Source<ast::EnumDef> { 65 fn source(self, db: &impl DefDatabase) -> InFile<ast::EnumDef> {
66 self.id.source(db) 66 self.id.source(db)
67 } 67 }
68} 68}
69impl HasSource for EnumVariant { 69impl HasSource for EnumVariant {
70 type Ast = ast::EnumVariant; 70 type Ast = ast::EnumVariant;
71 fn source(self, db: &impl DefDatabase) -> Source<ast::EnumVariant> { 71 fn source(self, db: &impl DefDatabase) -> InFile<ast::EnumVariant> {
72 self.parent.id.child_source(db).map(|map| map[self.id].clone()) 72 self.parent.id.child_source(db).map(|map| map[self.id].clone())
73 } 73 }
74} 74}
75impl HasSource for Function { 75impl HasSource for Function {
76 type Ast = ast::FnDef; 76 type Ast = ast::FnDef;
77 fn source(self, db: &impl DefDatabase) -> Source<ast::FnDef> { 77 fn source(self, db: &impl DefDatabase) -> InFile<ast::FnDef> {
78 self.id.lookup(db).source(db) 78 self.id.lookup(db).source(db)
79 } 79 }
80} 80}
81impl HasSource for Const { 81impl HasSource for Const {
82 type Ast = ast::ConstDef; 82 type Ast = ast::ConstDef;
83 fn source(self, db: &impl DefDatabase) -> Source<ast::ConstDef> { 83 fn source(self, db: &impl DefDatabase) -> InFile<ast::ConstDef> {
84 self.id.lookup(db).source(db) 84 self.id.lookup(db).source(db)
85 } 85 }
86} 86}
87impl HasSource for Static { 87impl HasSource for Static {
88 type Ast = ast::StaticDef; 88 type Ast = ast::StaticDef;
89 fn source(self, db: &impl DefDatabase) -> Source<ast::StaticDef> { 89 fn source(self, db: &impl DefDatabase) -> InFile<ast::StaticDef> {
90 self.id.lookup(db).source(db) 90 self.id.lookup(db).source(db)
91 } 91 }
92} 92}
93impl HasSource for Trait { 93impl HasSource for Trait {
94 type Ast = ast::TraitDef; 94 type Ast = ast::TraitDef;
95 fn source(self, db: &impl DefDatabase) -> Source<ast::TraitDef> { 95 fn source(self, db: &impl DefDatabase) -> InFile<ast::TraitDef> {
96 self.id.source(db) 96 self.id.source(db)
97 } 97 }
98} 98}
99impl HasSource for TypeAlias { 99impl HasSource for TypeAlias {
100 type Ast = ast::TypeAliasDef; 100 type Ast = ast::TypeAliasDef;
101 fn source(self, db: &impl DefDatabase) -> Source<ast::TypeAliasDef> { 101 fn source(self, db: &impl DefDatabase) -> InFile<ast::TypeAliasDef> {
102 self.id.lookup(db).source(db) 102 self.id.lookup(db).source(db)
103 } 103 }
104} 104}
105impl HasSource for MacroDef { 105impl HasSource for MacroDef {
106 type Ast = ast::MacroCall; 106 type Ast = ast::MacroCall;
107 fn source(self, db: &impl DefDatabase) -> Source<ast::MacroCall> { 107 fn source(self, db: &impl DefDatabase) -> InFile<ast::MacroCall> {
108 Source { file_id: self.id.ast_id.file_id(), value: self.id.ast_id.to_node(db) } 108 InFile { file_id: self.id.ast_id.file_id(), value: self.id.ast_id.to_node(db) }
109 } 109 }
110} 110}
111impl HasSource for ImplBlock { 111impl HasSource for ImplBlock {
112 type Ast = ast::ImplBlock; 112 type Ast = ast::ImplBlock;
113 fn source(self, db: &impl DefDatabase) -> Source<ast::ImplBlock> { 113 fn source(self, db: &impl DefDatabase) -> InFile<ast::ImplBlock> {
114 self.id.source(db) 114 self.id.source(db)
115 } 115 }
116} 116}
@@ -118,7 +118,7 @@ impl HasSource for Import {
118 type Ast = Either<ast::UseTree, ast::ExternCrateItem>; 118 type Ast = Either<ast::UseTree, ast::ExternCrateItem>;
119 119
120 /// Returns the syntax of the last path segment corresponding to this import 120 /// Returns the syntax of the last path segment corresponding to this import
121 fn source(self, db: &impl DefDatabase) -> Source<Self::Ast> { 121 fn source(self, db: &impl DefDatabase) -> InFile<Self::Ast> {
122 let src = self.parent.definition_source(db); 122 let src = self.parent.definition_source(db);
123 let (_, source_map) = db.raw_items_with_source_map(src.file_id); 123 let (_, source_map) = db.raw_items_with_source_map(src.file_id);
124 let root = db.parse_or_expand(src.file_id).unwrap(); 124 let root = db.parse_or_expand(src.file_id).unwrap();
diff --git a/crates/ra_hir/src/from_source.rs b/crates/ra_hir/src/from_source.rs
index 9f7c22b21..82bf641dc 100644
--- a/crates/ra_hir/src/from_source.rs
+++ b/crates/ra_hir/src/from_source.rs
@@ -10,46 +10,46 @@ use ra_syntax::{
10use crate::{ 10use crate::{
11 db::{AstDatabase, DefDatabase, HirDatabase}, 11 db::{AstDatabase, DefDatabase, HirDatabase},
12 AssocItem, Const, DefWithBody, Enum, EnumVariant, FieldSource, Function, HasSource, ImplBlock, 12 AssocItem, Const, DefWithBody, Enum, EnumVariant, FieldSource, Function, HasSource, ImplBlock,
13 Local, MacroDef, Module, ModuleDef, ModuleSource, Source, Static, Struct, StructField, Trait, 13 InFile, Local, MacroDef, Module, ModuleDef, ModuleSource, Static, Struct, StructField, Trait,
14 TypeAlias, Union, VariantDef, 14 TypeAlias, Union, VariantDef,
15}; 15};
16 16
17pub trait FromSource: Sized { 17pub trait FromSource: Sized {
18 type Ast; 18 type Ast;
19 fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self>; 19 fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self>;
20} 20}
21 21
22impl FromSource for Struct { 22impl FromSource for Struct {
23 type Ast = ast::StructDef; 23 type Ast = ast::StructDef;
24 fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> { 24 fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self> {
25 let id = from_source(db, src)?; 25 let id = from_source(db, src)?;
26 Some(Struct { id }) 26 Some(Struct { id })
27 } 27 }
28} 28}
29impl FromSource for Union { 29impl FromSource for Union {
30 type Ast = ast::UnionDef; 30 type Ast = ast::UnionDef;
31 fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> { 31 fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self> {
32 let id = from_source(db, src)?; 32 let id = from_source(db, src)?;
33 Some(Union { id }) 33 Some(Union { id })
34 } 34 }
35} 35}
36impl FromSource for Enum { 36impl FromSource for Enum {
37 type Ast = ast::EnumDef; 37 type Ast = ast::EnumDef;
38 fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> { 38 fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self> {
39 let id = from_source(db, src)?; 39 let id = from_source(db, src)?;
40 Some(Enum { id }) 40 Some(Enum { id })
41 } 41 }
42} 42}
43impl FromSource for Trait { 43impl FromSource for Trait {
44 type Ast = ast::TraitDef; 44 type Ast = ast::TraitDef;
45 fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> { 45 fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self> {
46 let id = from_source(db, src)?; 46 let id = from_source(db, src)?;
47 Some(Trait { id }) 47 Some(Trait { id })
48 } 48 }
49} 49}
50impl FromSource for Function { 50impl FromSource for Function {
51 type Ast = ast::FnDef; 51 type Ast = ast::FnDef;
52 fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> { 52 fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self> {
53 let items = match Container::find(db, src.as_ref().map(|it| it.syntax()))? { 53 let items = match Container::find(db, src.as_ref().map(|it| it.syntax()))? {
54 Container::Trait(it) => it.items(db), 54 Container::Trait(it) => it.items(db),
55 Container::ImplBlock(it) => it.items(db), 55 Container::ImplBlock(it) => it.items(db),
@@ -76,7 +76,7 @@ impl FromSource for Function {
76 76
77impl FromSource for Const { 77impl FromSource for Const {
78 type Ast = ast::ConstDef; 78 type Ast = ast::ConstDef;
79 fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> { 79 fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self> {
80 let items = match Container::find(db, src.as_ref().map(|it| it.syntax()))? { 80 let items = match Container::find(db, src.as_ref().map(|it| it.syntax()))? {
81 Container::Trait(it) => it.items(db), 81 Container::Trait(it) => it.items(db),
82 Container::ImplBlock(it) => it.items(db), 82 Container::ImplBlock(it) => it.items(db),
@@ -102,7 +102,7 @@ impl FromSource for Const {
102} 102}
103impl FromSource for Static { 103impl FromSource for Static {
104 type Ast = ast::StaticDef; 104 type Ast = ast::StaticDef;
105 fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> { 105 fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self> {
106 let module = match Container::find(db, src.as_ref().map(|it| it.syntax()))? { 106 let module = match Container::find(db, src.as_ref().map(|it| it.syntax()))? {
107 Container::Module(it) => it, 107 Container::Module(it) => it,
108 Container::Trait(_) | Container::ImplBlock(_) => return None, 108 Container::Trait(_) | Container::ImplBlock(_) => return None,
@@ -120,7 +120,7 @@ impl FromSource for Static {
120 120
121impl FromSource for TypeAlias { 121impl FromSource for TypeAlias {
122 type Ast = ast::TypeAliasDef; 122 type Ast = ast::TypeAliasDef;
123 fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> { 123 fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self> {
124 let items = match Container::find(db, src.as_ref().map(|it| it.syntax()))? { 124 let items = match Container::find(db, src.as_ref().map(|it| it.syntax()))? {
125 Container::Trait(it) => it.items(db), 125 Container::Trait(it) => it.items(db),
126 Container::ImplBlock(it) => it.items(db), 126 Container::ImplBlock(it) => it.items(db),
@@ -147,11 +147,11 @@ impl FromSource for TypeAlias {
147 147
148impl FromSource for MacroDef { 148impl FromSource for MacroDef {
149 type Ast = ast::MacroCall; 149 type Ast = ast::MacroCall;
150 fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> { 150 fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self> {
151 let kind = MacroDefKind::Declarative; 151 let kind = MacroDefKind::Declarative;
152 152
153 let module_src = ModuleSource::from_child_node(db, src.as_ref().map(|it| it.syntax())); 153 let module_src = ModuleSource::from_child_node(db, src.as_ref().map(|it| it.syntax()));
154 let module = Module::from_definition(db, Source::new(src.file_id, module_src))?; 154 let module = Module::from_definition(db, InFile::new(src.file_id, module_src))?;
155 let krate = module.krate().crate_id(); 155 let krate = module.krate().crate_id();
156 156
157 let ast_id = AstId::new(src.file_id, db.ast_id_map(src.file_id).ast_id(&src.value)); 157 let ast_id = AstId::new(src.file_id, db.ast_id_map(src.file_id).ast_id(&src.value));
@@ -163,7 +163,7 @@ impl FromSource for MacroDef {
163 163
164impl FromSource for ImplBlock { 164impl FromSource for ImplBlock {
165 type Ast = ast::ImplBlock; 165 type Ast = ast::ImplBlock;
166 fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> { 166 fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self> {
167 let id = from_source(db, src)?; 167 let id = from_source(db, src)?;
168 Some(ImplBlock { id }) 168 Some(ImplBlock { id })
169 } 169 }
@@ -171,9 +171,9 @@ impl FromSource for ImplBlock {
171 171
172impl FromSource for EnumVariant { 172impl FromSource for EnumVariant {
173 type Ast = ast::EnumVariant; 173 type Ast = ast::EnumVariant;
174 fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> { 174 fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self> {
175 let parent_enum = src.value.parent_enum(); 175 let parent_enum = src.value.parent_enum();
176 let src_enum = Source { file_id: src.file_id, value: parent_enum }; 176 let src_enum = InFile { file_id: src.file_id, value: parent_enum };
177 let variants = Enum::from_source(db, src_enum)?.variants(db); 177 let variants = Enum::from_source(db, src_enum)?.variants(db);
178 variants.into_iter().find(|v| same_source(&v.source(db), &src)) 178 variants.into_iter().find(|v| same_source(&v.source(db), &src))
179 } 179 }
@@ -181,17 +181,17 @@ impl FromSource for EnumVariant {
181 181
182impl FromSource for StructField { 182impl FromSource for StructField {
183 type Ast = FieldSource; 183 type Ast = FieldSource;
184 fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> { 184 fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self> {
185 let variant_def: VariantDef = match src.value { 185 let variant_def: VariantDef = match src.value {
186 FieldSource::Named(ref field) => { 186 FieldSource::Named(ref field) => {
187 let value = field.syntax().ancestors().find_map(ast::StructDef::cast)?; 187 let value = field.syntax().ancestors().find_map(ast::StructDef::cast)?;
188 let src = Source { file_id: src.file_id, value }; 188 let src = InFile { file_id: src.file_id, value };
189 let def = Struct::from_source(db, src)?; 189 let def = Struct::from_source(db, src)?;
190 VariantDef::from(def) 190 VariantDef::from(def)
191 } 191 }
192 FieldSource::Pos(ref field) => { 192 FieldSource::Pos(ref field) => {
193 let value = field.syntax().ancestors().find_map(ast::EnumVariant::cast)?; 193 let value = field.syntax().ancestors().find_map(ast::EnumVariant::cast)?;
194 let src = Source { file_id: src.file_id, value }; 194 let src = InFile { file_id: src.file_id, value };
195 let def = EnumVariant::from_source(db, src)?; 195 let def = EnumVariant::from_source(db, src)?;
196 VariantDef::from(def) 196 VariantDef::from(def)
197 } 197 }
@@ -206,14 +206,14 @@ impl FromSource for StructField {
206} 206}
207 207
208impl Local { 208impl Local {
209 pub fn from_source(db: &impl HirDatabase, src: Source<ast::BindPat>) -> Option<Self> { 209 pub fn from_source(db: &impl HirDatabase, src: InFile<ast::BindPat>) -> Option<Self> {
210 let file_id = src.file_id; 210 let file_id = src.file_id;
211 let parent: DefWithBody = src.value.syntax().ancestors().find_map(|it| { 211 let parent: DefWithBody = src.value.syntax().ancestors().find_map(|it| {
212 let res = match_ast! { 212 let res = match_ast! {
213 match it { 213 match it {
214 ast::ConstDef(value) => { Const::from_source(db, Source { value, file_id})?.into() }, 214 ast::ConstDef(value) => { Const::from_source(db, InFile { value, file_id})?.into() },
215 ast::StaticDef(value) => { Static::from_source(db, Source { value, file_id})?.into() }, 215 ast::StaticDef(value) => { Static::from_source(db, InFile { value, file_id})?.into() },
216 ast::FnDef(value) => { Function::from_source(db, Source { value, file_id})?.into() }, 216 ast::FnDef(value) => { Function::from_source(db, InFile { value, file_id})?.into() },
217 _ => return None, 217 _ => return None,
218 } 218 }
219 }; 219 };
@@ -227,16 +227,16 @@ impl Local {
227} 227}
228 228
229impl Module { 229impl Module {
230 pub fn from_declaration(db: &impl DefDatabase, src: Source<ast::Module>) -> Option<Self> { 230 pub fn from_declaration(db: &impl DefDatabase, src: InFile<ast::Module>) -> Option<Self> {
231 let parent_declaration = src.value.syntax().ancestors().skip(1).find_map(ast::Module::cast); 231 let parent_declaration = src.value.syntax().ancestors().skip(1).find_map(ast::Module::cast);
232 232
233 let parent_module = match parent_declaration { 233 let parent_module = match parent_declaration {
234 Some(parent_declaration) => { 234 Some(parent_declaration) => {
235 let src_parent = Source { file_id: src.file_id, value: parent_declaration }; 235 let src_parent = InFile { file_id: src.file_id, value: parent_declaration };
236 Module::from_declaration(db, src_parent) 236 Module::from_declaration(db, src_parent)
237 } 237 }
238 _ => { 238 _ => {
239 let src_parent = Source { 239 let src_parent = InFile {
240 file_id: src.file_id, 240 file_id: src.file_id,
241 value: ModuleSource::new(db, Some(src.file_id.original_file(db)), None), 241 value: ModuleSource::new(db, Some(src.file_id.original_file(db)), None),
242 }; 242 };
@@ -248,13 +248,13 @@ impl Module {
248 parent_module.child(db, &child_name.as_name()) 248 parent_module.child(db, &child_name.as_name())
249 } 249 }
250 250
251 pub fn from_definition(db: &impl DefDatabase, src: Source<ModuleSource>) -> Option<Self> { 251 pub fn from_definition(db: &impl DefDatabase, src: InFile<ModuleSource>) -> Option<Self> {
252 match src.value { 252 match src.value {
253 ModuleSource::Module(ref module) => { 253 ModuleSource::Module(ref module) => {
254 assert!(!module.has_semi()); 254 assert!(!module.has_semi());
255 return Module::from_declaration( 255 return Module::from_declaration(
256 db, 256 db,
257 Source { file_id: src.file_id, value: module.clone() }, 257 InFile { file_id: src.file_id, value: module.clone() },
258 ); 258 );
259 } 259 }
260 ModuleSource::SourceFile(_) => (), 260 ModuleSource::SourceFile(_) => (),
@@ -271,13 +271,13 @@ impl Module {
271 } 271 }
272} 272}
273 273
274fn from_source<N, DEF>(db: &(impl DefDatabase + AstDatabase), src: Source<N>) -> Option<DEF> 274fn from_source<N, DEF>(db: &(impl DefDatabase + AstDatabase), src: InFile<N>) -> Option<DEF>
275where 275where
276 N: AstNode, 276 N: AstNode,
277 DEF: AstItemDef<N>, 277 DEF: AstItemDef<N>,
278{ 278{
279 let module_src = ModuleSource::from_child_node(db, src.as_ref().map(|it| it.syntax())); 279 let module_src = ModuleSource::from_child_node(db, src.as_ref().map(|it| it.syntax()));
280 let module = Module::from_definition(db, Source::new(src.file_id, module_src))?; 280 let module = Module::from_definition(db, InFile::new(src.file_id, module_src))?;
281 let ctx = LocationCtx::new(db, module.id, src.file_id); 281 let ctx = LocationCtx::new(db, module.id, src.file_id);
282 let items = db.ast_id_map(src.file_id); 282 let items = db.ast_id_map(src.file_id);
283 let item_id = items.ast_id(&src.value); 283 let item_id = items.ast_id(&src.value);
@@ -291,7 +291,7 @@ enum Container {
291} 291}
292 292
293impl Container { 293impl Container {
294 fn find(db: &impl DefDatabase, src: Source<&SyntaxNode>) -> Option<Container> { 294 fn find(db: &impl DefDatabase, src: InFile<&SyntaxNode>) -> Option<Container> {
295 // FIXME: this doesn't try to handle nested declarations 295 // FIXME: this doesn't try to handle nested declarations
296 for container in src.value.ancestors() { 296 for container in src.value.ancestors() {
297 let res = match_ast! { 297 let res = match_ast! {
@@ -322,6 +322,6 @@ impl Container {
322/// In general, we do not guarantee that we have exactly one instance of a 322/// In general, we do not guarantee that we have exactly one instance of a
323/// syntax tree for each file. We probably should add such guarantee, but, for 323/// syntax tree for each file. We probably should add such guarantee, but, for
324/// the time being, we will use identity-less AstPtr comparison. 324/// the time being, we will use identity-less AstPtr comparison.
325fn same_source<N: AstNode>(s1: &Source<N>, s2: &Source<N>) -> bool { 325fn same_source<N: AstNode>(s1: &InFile<N>, s2: &InFile<N>) -> bool {
326 s1.as_ref().map(AstPtr::new) == s2.as_ref().map(AstPtr::new) 326 s1.as_ref().map(AstPtr::new) == s2.as_ref().map(AstPtr::new)
327} 327}
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index 3c12c61f0..88d2f6e02 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -63,5 +63,5 @@ pub use hir_def::{
63 type_ref::Mutability, 63 type_ref::Mutability,
64}; 64};
65pub use hir_expand::{ 65pub use hir_expand::{
66 either::Either, name::Name, HirFileId, MacroCallId, MacroCallLoc, MacroDefId, MacroFile, Source, 66 either::Either, name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc, MacroDefId, MacroFile,
67}; 67};
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs
index 76c493f1a..1661d92a2 100644
--- a/crates/ra_hir/src/source_binder.rs
+++ b/crates/ra_hir/src/source_binder.rs
@@ -18,7 +18,7 @@ use hir_def::{
18 AssocItemId, DefWithBodyId, 18 AssocItemId, DefWithBodyId,
19}; 19};
20use hir_expand::{ 20use hir_expand::{
21 hygiene::Hygiene, name::AsName, AstId, HirFileId, MacroCallId, MacroFileKind, Source, 21 hygiene::Hygiene, name::AsName, AstId, HirFileId, InFile, MacroCallId, MacroFileKind,
22}; 22};
23use ra_syntax::{ 23use ra_syntax::{
24 ast::{self, AstNode}, 24 ast::{self, AstNode},
@@ -37,7 +37,7 @@ use crate::{
37 GenericParam, Local, MacroDef, Name, Path, ScopeDef, Static, Struct, Trait, Type, TypeAlias, 37 GenericParam, Local, MacroDef, Name, Path, ScopeDef, Static, Struct, Trait, Type, TypeAlias,
38}; 38};
39 39
40fn try_get_resolver_for_node(db: &impl HirDatabase, node: Source<&SyntaxNode>) -> Option<Resolver> { 40fn try_get_resolver_for_node(db: &impl HirDatabase, node: InFile<&SyntaxNode>) -> Option<Resolver> {
41 match_ast! { 41 match_ast! {
42 match (node.value) { 42 match (node.value) {
43 ast::Module(it) => { 43 ast::Module(it) => {
@@ -71,7 +71,7 @@ fn try_get_resolver_for_node(db: &impl HirDatabase, node: Source<&SyntaxNode>) -
71 71
72fn def_with_body_from_child_node( 72fn def_with_body_from_child_node(
73 db: &impl HirDatabase, 73 db: &impl HirDatabase,
74 child: Source<&SyntaxNode>, 74 child: InFile<&SyntaxNode>,
75) -> Option<DefWithBody> { 75) -> Option<DefWithBody> {
76 child.value.ancestors().find_map(|node| { 76 child.value.ancestors().find_map(|node| {
77 match_ast! { 77 match_ast! {
@@ -141,8 +141,8 @@ impl Expansion {
141 pub fn map_token_down( 141 pub fn map_token_down(
142 &self, 142 &self,
143 db: &impl HirDatabase, 143 db: &impl HirDatabase,
144 token: Source<&SyntaxToken>, 144 token: InFile<&SyntaxToken>,
145 ) -> Option<Source<SyntaxToken>> { 145 ) -> Option<InFile<SyntaxToken>> {
146 let exp_info = self.file_id().expansion_info(db)?; 146 let exp_info = self.file_id().expansion_info(db)?;
147 exp_info.map_token_down(token) 147 exp_info.map_token_down(token)
148 } 148 }
@@ -155,7 +155,7 @@ impl Expansion {
155impl SourceAnalyzer { 155impl SourceAnalyzer {
156 pub fn new( 156 pub fn new(
157 db: &impl HirDatabase, 157 db: &impl HirDatabase,
158 node: Source<&SyntaxNode>, 158 node: InFile<&SyntaxNode>,
159 offset: Option<TextUnit>, 159 offset: Option<TextUnit>,
160 ) -> SourceAnalyzer { 160 ) -> SourceAnalyzer {
161 let def_with_body = def_with_body_from_child_node(db, node); 161 let def_with_body = def_with_body_from_child_node(db, node);
@@ -192,12 +192,12 @@ impl SourceAnalyzer {
192 } 192 }
193 193
194 fn expr_id(&self, expr: &ast::Expr) -> Option<ExprId> { 194 fn expr_id(&self, expr: &ast::Expr) -> Option<ExprId> {
195 let src = Source { file_id: self.file_id, value: expr }; 195 let src = InFile { file_id: self.file_id, value: expr };
196 self.body_source_map.as_ref()?.node_expr(src) 196 self.body_source_map.as_ref()?.node_expr(src)
197 } 197 }
198 198
199 fn pat_id(&self, pat: &ast::Pat) -> Option<PatId> { 199 fn pat_id(&self, pat: &ast::Pat) -> Option<PatId> {
200 let src = Source { file_id: self.file_id, value: pat }; 200 let src = InFile { file_id: self.file_id, value: pat };
201 self.body_source_map.as_ref()?.node_pat(src) 201 self.body_source_map.as_ref()?.node_pat(src)
202 } 202 }
203 203
@@ -243,7 +243,7 @@ impl SourceAnalyzer {
243 pub fn resolve_macro_call( 243 pub fn resolve_macro_call(
244 &self, 244 &self,
245 db: &impl HirDatabase, 245 db: &impl HirDatabase,
246 macro_call: Source<&ast::MacroCall>, 246 macro_call: InFile<&ast::MacroCall>,
247 ) -> Option<MacroDef> { 247 ) -> Option<MacroDef> {
248 let hygiene = Hygiene::new(db, macro_call.file_id); 248 let hygiene = Hygiene::new(db, macro_call.file_id);
249 let path = macro_call.value.path().and_then(|ast| Path::from_src(ast, &hygiene))?; 249 let path = macro_call.value.path().and_then(|ast| Path::from_src(ast, &hygiene))?;
@@ -318,7 +318,7 @@ impl SourceAnalyzer {
318 let name = name_ref.as_name(); 318 let name = name_ref.as_name();
319 let source_map = self.body_source_map.as_ref()?; 319 let source_map = self.body_source_map.as_ref()?;
320 let scopes = self.scopes.as_ref()?; 320 let scopes = self.scopes.as_ref()?;
321 let scope = scope_for(scopes, source_map, Source::new(self.file_id, name_ref.syntax()))?; 321 let scope = scope_for(scopes, source_map, InFile::new(self.file_id, name_ref.syntax()))?;
322 let entry = scopes.resolve_name_in_scope(scope, &name)?; 322 let entry = scopes.resolve_name_in_scope(scope, &name)?;
323 Some(ScopeEntryWithSyntax { 323 Some(ScopeEntryWithSyntax {
324 name: entry.name().clone(), 324 name: entry.name().clone(),
@@ -446,7 +446,7 @@ impl SourceAnalyzer {
446 pub fn expand( 446 pub fn expand(
447 &self, 447 &self,
448 db: &impl HirDatabase, 448 db: &impl HirDatabase,
449 macro_call: Source<&ast::MacroCall>, 449 macro_call: InFile<&ast::MacroCall>,
450 ) -> Option<Expansion> { 450 ) -> Option<Expansion> {
451 let def = self.resolve_macro_call(db, macro_call)?.id; 451 let def = self.resolve_macro_call(db, macro_call)?.id;
452 let ast_id = AstId::new( 452 let ast_id = AstId::new(
@@ -463,19 +463,19 @@ impl SourceAnalyzer {
463fn scope_for( 463fn scope_for(
464 scopes: &ExprScopes, 464 scopes: &ExprScopes,
465 source_map: &BodySourceMap, 465 source_map: &BodySourceMap,
466 node: Source<&SyntaxNode>, 466 node: InFile<&SyntaxNode>,
467) -> Option<ScopeId> { 467) -> Option<ScopeId> {
468 node.value 468 node.value
469 .ancestors() 469 .ancestors()
470 .filter_map(ast::Expr::cast) 470 .filter_map(ast::Expr::cast)
471 .filter_map(|it| source_map.node_expr(Source::new(node.file_id, &it))) 471 .filter_map(|it| source_map.node_expr(InFile::new(node.file_id, &it)))
472 .find_map(|it| scopes.scope_for(it)) 472 .find_map(|it| scopes.scope_for(it))
473} 473}
474 474
475fn scope_for_offset( 475fn scope_for_offset(
476 scopes: &ExprScopes, 476 scopes: &ExprScopes,
477 source_map: &BodySourceMap, 477 source_map: &BodySourceMap,
478 offset: Source<TextUnit>, 478 offset: InFile<TextUnit>,
479) -> Option<ScopeId> { 479) -> Option<ScopeId> {
480 scopes 480 scopes
481 .scope_by_expr() 481 .scope_by_expr()
diff --git a/crates/ra_hir_def/src/adt.rs b/crates/ra_hir_def/src/adt.rs
index 3666529b0..3d21dedee 100644
--- a/crates/ra_hir_def/src/adt.rs
+++ b/crates/ra_hir_def/src/adt.rs
@@ -5,7 +5,7 @@ use std::sync::Arc;
5use hir_expand::{ 5use hir_expand::{
6 either::Either, 6 either::Either,
7 name::{AsName, Name}, 7 name::{AsName, Name},
8 Source, 8 InFile,
9}; 9};
10use ra_arena::{map::ArenaMap, Arena}; 10use ra_arena::{map::ArenaMap, Arena};
11use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner}; 11use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner};
@@ -88,7 +88,7 @@ impl EnumData {
88impl HasChildSource for EnumId { 88impl HasChildSource for EnumId {
89 type ChildId = LocalEnumVariantId; 89 type ChildId = LocalEnumVariantId;
90 type Value = ast::EnumVariant; 90 type Value = ast::EnumVariant;
91 fn child_source(&self, db: &impl DefDatabase) -> Source<ArenaMap<Self::ChildId, Self::Value>> { 91 fn child_source(&self, db: &impl DefDatabase) -> InFile<ArenaMap<Self::ChildId, Self::Value>> {
92 let src = self.source(db); 92 let src = self.source(db);
93 let mut trace = Trace::new_for_map(); 93 let mut trace = Trace::new_for_map();
94 lower_enum(&mut trace, &src.value); 94 lower_enum(&mut trace, &src.value);
@@ -145,7 +145,7 @@ impl HasChildSource for VariantId {
145 type ChildId = LocalStructFieldId; 145 type ChildId = LocalStructFieldId;
146 type Value = Either<ast::TupleFieldDef, ast::RecordFieldDef>; 146 type Value = Either<ast::TupleFieldDef, ast::RecordFieldDef>;
147 147
148 fn child_source(&self, db: &impl DefDatabase) -> Source<ArenaMap<Self::ChildId, Self::Value>> { 148 fn child_source(&self, db: &impl DefDatabase) -> InFile<ArenaMap<Self::ChildId, Self::Value>> {
149 let src = match self { 149 let src = match self {
150 VariantId::EnumVariantId(it) => { 150 VariantId::EnumVariantId(it) => {
151 // I don't really like the fact that we call into parent source 151 // I don't really like the fact that we call into parent source
diff --git a/crates/ra_hir_def/src/attr.rs b/crates/ra_hir_def/src/attr.rs
index fffb22201..83783ac7a 100644
--- a/crates/ra_hir_def/src/attr.rs
+++ b/crates/ra_hir_def/src/attr.rs
@@ -2,7 +2,7 @@
2 2
3use std::{ops, sync::Arc}; 3use std::{ops, sync::Arc};
4 4
5use hir_expand::{either::Either, hygiene::Hygiene, AstId, Source}; 5use hir_expand::{either::Either, hygiene::Hygiene, AstId, InFile};
6use mbe::ast_to_token_tree; 6use mbe::ast_to_token_tree;
7use ra_syntax::{ 7use ra_syntax::{
8 ast::{self, AstNode, AttrsOwner}, 8 ast::{self, AstNode, AttrsOwner},
@@ -68,7 +68,7 @@ impl Attrs {
68 } 68 }
69 } 69 }
70 70
71 fn from_attrs_owner(db: &impl DefDatabase, owner: Source<&dyn AttrsOwner>) -> Attrs { 71 fn from_attrs_owner(db: &impl DefDatabase, owner: InFile<&dyn AttrsOwner>) -> Attrs {
72 let hygiene = Hygiene::new(db, owner.file_id); 72 let hygiene = Hygiene::new(db, owner.file_id);
73 Attrs::new(owner.value, &hygiene) 73 Attrs::new(owner.value, &hygiene)
74 } 74 }
@@ -157,7 +157,7 @@ where
157 N: ast::AttrsOwner, 157 N: ast::AttrsOwner,
158 D: DefDatabase, 158 D: DefDatabase,
159{ 159{
160 let src = Source::new(src.file_id(), src.to_node(db)); 160 let src = InFile::new(src.file_id(), src.to_node(db));
161 Attrs::from_attrs_owner(db, src.as_ref().map(|it| it as &dyn AttrsOwner)) 161 Attrs::from_attrs_owner(db, src.as_ref().map(|it| it as &dyn AttrsOwner))
162} 162}
163 163
diff --git a/crates/ra_hir_def/src/body.rs b/crates/ra_hir_def/src/body.rs
index a57a0176d..f21937f10 100644
--- a/crates/ra_hir_def/src/body.rs
+++ b/crates/ra_hir_def/src/body.rs
@@ -6,7 +6,7 @@ pub mod scope;
6use std::{ops::Index, sync::Arc}; 6use std::{ops::Index, sync::Arc};
7 7
8use hir_expand::{ 8use hir_expand::{
9 either::Either, hygiene::Hygiene, AstId, HirFileId, MacroDefId, MacroFileKind, Source, 9 either::Either, hygiene::Hygiene, AstId, HirFileId, InFile, MacroDefId, MacroFileKind,
10}; 10};
11use ra_arena::{map::ArenaMap, Arena}; 11use ra_arena::{map::ArenaMap, Arena};
12use ra_syntax::{ast, AstNode, AstPtr}; 12use ra_syntax::{ast, AstNode, AstPtr};
@@ -73,8 +73,8 @@ impl Expander {
73 std::mem::forget(mark); 73 std::mem::forget(mark);
74 } 74 }
75 75
76 fn to_source<T>(&self, value: T) -> Source<T> { 76 fn to_source<T>(&self, value: T) -> InFile<T> {
77 Source { file_id: self.current_file_id, value } 77 InFile { file_id: self.current_file_id, value }
78 } 78 }
79 79
80 fn parse_path(&mut self, path: ast::Path) -> Option<Path> { 80 fn parse_path(&mut self, path: ast::Path) -> Option<Path> {
@@ -115,10 +115,10 @@ pub struct Body {
115} 115}
116 116
117pub type ExprPtr = Either<AstPtr<ast::Expr>, AstPtr<ast::RecordField>>; 117pub type ExprPtr = Either<AstPtr<ast::Expr>, AstPtr<ast::RecordField>>;
118pub type ExprSource = Source<ExprPtr>; 118pub type ExprSource = InFile<ExprPtr>;
119 119
120pub type PatPtr = Either<AstPtr<ast::Pat>, AstPtr<ast::SelfParam>>; 120pub type PatPtr = Either<AstPtr<ast::Pat>, AstPtr<ast::SelfParam>>;
121pub type PatSource = Source<PatPtr>; 121pub type PatSource = InFile<PatPtr>;
122 122
123/// An item body together with the mapping from syntax nodes to HIR expression 123/// An item body together with the mapping from syntax nodes to HIR expression
124/// IDs. This is needed to go from e.g. a position in a file to the HIR 124/// IDs. This is needed to go from e.g. a position in a file to the HIR
@@ -205,7 +205,7 @@ impl BodySourceMap {
205 self.expr_map_back.get(expr).copied() 205 self.expr_map_back.get(expr).copied()
206 } 206 }
207 207
208 pub fn node_expr(&self, node: Source<&ast::Expr>) -> Option<ExprId> { 208 pub fn node_expr(&self, node: InFile<&ast::Expr>) -> Option<ExprId> {
209 let src = node.map(|it| Either::A(AstPtr::new(it))); 209 let src = node.map(|it| Either::A(AstPtr::new(it)));
210 self.expr_map.get(&src).cloned() 210 self.expr_map.get(&src).cloned()
211 } 211 }
@@ -214,7 +214,7 @@ impl BodySourceMap {
214 self.pat_map_back.get(pat).copied() 214 self.pat_map_back.get(pat).copied()
215 } 215 }
216 216
217 pub fn node_pat(&self, node: Source<&ast::Pat>) -> Option<PatId> { 217 pub fn node_pat(&self, node: InFile<&ast::Pat>) -> Option<PatId> {
218 let src = node.map(|it| Either::A(AstPtr::new(it))); 218 let src = node.map(|it| Either::A(AstPtr::new(it)));
219 self.pat_map.get(&src).cloned() 219 self.pat_map.get(&src).cloned()
220 } 220 }
diff --git a/crates/ra_hir_def/src/body/scope.rs b/crates/ra_hir_def/src/body/scope.rs
index 625aa39dd..ab6599b23 100644
--- a/crates/ra_hir_def/src/body/scope.rs
+++ b/crates/ra_hir_def/src/body/scope.rs
@@ -171,7 +171,7 @@ fn compute_expr_scopes(expr: ExprId, body: &Body, scopes: &mut ExprScopes, scope
171 171
172#[cfg(test)] 172#[cfg(test)]
173mod tests { 173mod tests {
174 use hir_expand::{name::AsName, Source}; 174 use hir_expand::{name::AsName, InFile};
175 use ra_db::{fixture::WithFixture, FileId, SourceDatabase}; 175 use ra_db::{fixture::WithFixture, FileId, SourceDatabase};
176 use ra_syntax::{algo::find_node_at_offset, ast, AstNode}; 176 use ra_syntax::{algo::find_node_at_offset, ast, AstNode};
177 use test_utils::{assert_eq_text, covers, extract_offset}; 177 use test_utils::{assert_eq_text, covers, extract_offset};
@@ -211,7 +211,7 @@ mod tests {
211 let (_body, source_map) = db.body_with_source_map(function.into()); 211 let (_body, source_map) = db.body_with_source_map(function.into());
212 212
213 let expr_id = source_map 213 let expr_id = source_map
214 .node_expr(Source { file_id: file_id.into(), value: &marker.into() }) 214 .node_expr(InFile { file_id: file_id.into(), value: &marker.into() })
215 .unwrap(); 215 .unwrap();
216 let scope = scopes.scope_for(expr_id); 216 let scope = scopes.scope_for(expr_id);
217 217
@@ -318,7 +318,7 @@ mod tests {
318 let expr_scope = { 318 let expr_scope = {
319 let expr_ast = name_ref.syntax().ancestors().find_map(ast::Expr::cast).unwrap(); 319 let expr_ast = name_ref.syntax().ancestors().find_map(ast::Expr::cast).unwrap();
320 let expr_id = 320 let expr_id =
321 source_map.node_expr(Source { file_id: file_id.into(), value: &expr_ast }).unwrap(); 321 source_map.node_expr(InFile { file_id: file_id.into(), value: &expr_ast }).unwrap();
322 scopes.scope_for(expr_id).unwrap() 322 scopes.scope_for(expr_id).unwrap()
323 }; 323 };
324 324
diff --git a/crates/ra_hir_def/src/diagnostics.rs b/crates/ra_hir_def/src/diagnostics.rs
index eda9b2269..095498429 100644
--- a/crates/ra_hir_def/src/diagnostics.rs
+++ b/crates/ra_hir_def/src/diagnostics.rs
@@ -6,7 +6,7 @@ use hir_expand::diagnostics::Diagnostic;
6use ra_db::RelativePathBuf; 6use ra_db::RelativePathBuf;
7use ra_syntax::{ast, AstPtr, SyntaxNodePtr}; 7use ra_syntax::{ast, AstPtr, SyntaxNodePtr};
8 8
9use hir_expand::{HirFileId, Source}; 9use hir_expand::{HirFileId, InFile};
10 10
11#[derive(Debug)] 11#[derive(Debug)]
12pub struct UnresolvedModule { 12pub struct UnresolvedModule {
@@ -19,8 +19,8 @@ impl Diagnostic for UnresolvedModule {
19 fn message(&self) -> String { 19 fn message(&self) -> String {
20 "unresolved module".to_string() 20 "unresolved module".to_string()
21 } 21 }
22 fn source(&self) -> Source<SyntaxNodePtr> { 22 fn source(&self) -> InFile<SyntaxNodePtr> {
23 Source { file_id: self.file, value: self.decl.into() } 23 InFile { file_id: self.file, value: self.decl.into() }
24 } 24 }
25 fn as_any(&self) -> &(dyn Any + Send + 'static) { 25 fn as_any(&self) -> &(dyn Any + Send + 'static) {
26 self 26 self
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs
index bc5530896..9d89692bf 100644
--- a/crates/ra_hir_def/src/lib.rs
+++ b/crates/ra_hir_def/src/lib.rs
@@ -36,7 +36,7 @@ mod marks;
36 36
37use std::hash::{Hash, Hasher}; 37use std::hash::{Hash, Hasher};
38 38
39use hir_expand::{ast_id_map::FileAstId, db::AstDatabase, AstId, HirFileId, MacroDefId, Source}; 39use hir_expand::{ast_id_map::FileAstId, db::AstDatabase, AstId, HirFileId, InFile, MacroDefId};
40use ra_arena::{impl_arena_id, map::ArenaMap, RawId}; 40use ra_arena::{impl_arena_id, map::ArenaMap, RawId};
41use ra_db::{impl_intern_key, salsa, CrateId}; 41use ra_db::{impl_intern_key, salsa, CrateId};
42use ra_syntax::{ast, AstNode}; 42use ra_syntax::{ast, AstNode};
@@ -105,10 +105,10 @@ pub trait AstItemDef<N: AstNode>: salsa::InternKey + Clone {
105 let loc = ItemLoc { module: ctx.module, ast_id: AstId::new(ctx.file_id, ast_id) }; 105 let loc = ItemLoc { module: ctx.module, ast_id: AstId::new(ctx.file_id, ast_id) };
106 Self::intern(ctx.db, loc) 106 Self::intern(ctx.db, loc)
107 } 107 }
108 fn source(self, db: &(impl AstDatabase + InternDatabase)) -> Source<N> { 108 fn source(self, db: &(impl AstDatabase + InternDatabase)) -> InFile<N> {
109 let loc = self.lookup_intern(db); 109 let loc = self.lookup_intern(db);
110 let value = loc.ast_id.to_node(db); 110 let value = loc.ast_id.to_node(db);
111 Source { file_id: loc.ast_id.file_id(), value } 111 InFile { file_id: loc.ast_id.file_id(), value }
112 } 112 }
113 fn module(self, db: &impl InternDatabase) -> ModuleId { 113 fn module(self, db: &impl InternDatabase) -> ModuleId {
114 let loc = self.lookup_intern(db); 114 let loc = self.lookup_intern(db);
@@ -517,42 +517,42 @@ impl HasModule for StaticLoc {
517 517
518pub trait HasSource { 518pub trait HasSource {
519 type Value; 519 type Value;
520 fn source(&self, db: &impl db::DefDatabase) -> Source<Self::Value>; 520 fn source(&self, db: &impl db::DefDatabase) -> InFile<Self::Value>;
521} 521}
522 522
523impl HasSource for FunctionLoc { 523impl HasSource for FunctionLoc {
524 type Value = ast::FnDef; 524 type Value = ast::FnDef;
525 525
526 fn source(&self, db: &impl db::DefDatabase) -> Source<ast::FnDef> { 526 fn source(&self, db: &impl db::DefDatabase) -> InFile<ast::FnDef> {
527 let node = self.ast_id.to_node(db); 527 let node = self.ast_id.to_node(db);
528 Source::new(self.ast_id.file_id(), node) 528 InFile::new(self.ast_id.file_id(), node)
529 } 529 }
530} 530}
531 531
532impl HasSource for TypeAliasLoc { 532impl HasSource for TypeAliasLoc {
533 type Value = ast::TypeAliasDef; 533 type Value = ast::TypeAliasDef;
534 534
535 fn source(&self, db: &impl db::DefDatabase) -> Source<ast::TypeAliasDef> { 535 fn source(&self, db: &impl db::DefDatabase) -> InFile<ast::TypeAliasDef> {
536 let node = self.ast_id.to_node(db); 536 let node = self.ast_id.to_node(db);
537 Source::new(self.ast_id.file_id(), node) 537 InFile::new(self.ast_id.file_id(), node)
538 } 538 }
539} 539}
540 540
541impl HasSource for ConstLoc { 541impl HasSource for ConstLoc {
542 type Value = ast::ConstDef; 542 type Value = ast::ConstDef;
543 543
544 fn source(&self, db: &impl db::DefDatabase) -> Source<ast::ConstDef> { 544 fn source(&self, db: &impl db::DefDatabase) -> InFile<ast::ConstDef> {
545 let node = self.ast_id.to_node(db); 545 let node = self.ast_id.to_node(db);
546 Source::new(self.ast_id.file_id(), node) 546 InFile::new(self.ast_id.file_id(), node)
547 } 547 }
548} 548}
549 549
550impl HasSource for StaticLoc { 550impl HasSource for StaticLoc {
551 type Value = ast::StaticDef; 551 type Value = ast::StaticDef;
552 552
553 fn source(&self, db: &impl db::DefDatabase) -> Source<ast::StaticDef> { 553 fn source(&self, db: &impl db::DefDatabase) -> InFile<ast::StaticDef> {
554 let node = self.ast_id.to_node(db); 554 let node = self.ast_id.to_node(db);
555 Source::new(self.ast_id.file_id(), node) 555 InFile::new(self.ast_id.file_id(), node)
556 } 556 }
557} 557}
558 558
@@ -562,5 +562,5 @@ pub trait HasChildSource {
562 fn child_source( 562 fn child_source(
563 &self, 563 &self,
564 db: &impl db::DefDatabase, 564 db: &impl db::DefDatabase,
565 ) -> Source<ArenaMap<Self::ChildId, Self::Value>>; 565 ) -> InFile<ArenaMap<Self::ChildId, Self::Value>>;
566} 566}
diff --git a/crates/ra_hir_def/src/nameres.rs b/crates/ra_hir_def/src/nameres.rs
index 2359386c2..1b369ea11 100644
--- a/crates/ra_hir_def/src/nameres.rs
+++ b/crates/ra_hir_def/src/nameres.rs
@@ -58,8 +58,8 @@ mod tests;
58use std::sync::Arc; 58use std::sync::Arc;
59 59
60use hir_expand::{ 60use hir_expand::{
61 ast_id_map::FileAstId, diagnostics::DiagnosticSink, either::Either, name::Name, MacroDefId, 61 ast_id_map::FileAstId, diagnostics::DiagnosticSink, either::Either, name::Name, InFile,
62 Source, 62 MacroDefId,
63}; 63};
64use once_cell::sync::Lazy; 64use once_cell::sync::Lazy;
65use ra_arena::Arena; 65use ra_arena::Arena;
@@ -261,21 +261,21 @@ impl ModuleData {
261 pub fn definition_source( 261 pub fn definition_source(
262 &self, 262 &self,
263 db: &impl DefDatabase, 263 db: &impl DefDatabase,
264 ) -> Source<Either<ast::SourceFile, ast::Module>> { 264 ) -> InFile<Either<ast::SourceFile, ast::Module>> {
265 if let Some(file_id) = self.definition { 265 if let Some(file_id) = self.definition {
266 let sf = db.parse(file_id).tree(); 266 let sf = db.parse(file_id).tree();
267 return Source::new(file_id.into(), Either::A(sf)); 267 return InFile::new(file_id.into(), Either::A(sf));
268 } 268 }
269 let decl = self.declaration.unwrap(); 269 let decl = self.declaration.unwrap();
270 Source::new(decl.file_id(), Either::B(decl.to_node(db))) 270 InFile::new(decl.file_id(), Either::B(decl.to_node(db)))
271 } 271 }
272 272
273 /// Returns a node which declares this module, either a `mod foo;` or a `mod foo {}`. 273 /// Returns a node which declares this module, either a `mod foo;` or a `mod foo {}`.
274 /// `None` for the crate root. 274 /// `None` for the crate root.
275 pub fn declaration_source(&self, db: &impl DefDatabase) -> Option<Source<ast::Module>> { 275 pub fn declaration_source(&self, db: &impl DefDatabase) -> Option<InFile<ast::Module>> {
276 let decl = self.declaration?; 276 let decl = self.declaration?;
277 let value = decl.to_node(db); 277 let value = decl.to_node(db);
278 Some(Source { file_id: decl.file_id(), value }) 278 Some(InFile { file_id: decl.file_id(), value })
279 } 279 }
280} 280}
281 281
diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs
index 6eb106094..5196b67ca 100644
--- a/crates/ra_hir_def/src/nameres/raw.rs
+++ b/crates/ra_hir_def/src/nameres/raw.rs
@@ -22,8 +22,8 @@ use ra_syntax::{
22use test_utils::tested_by; 22use test_utils::tested_by;
23 23
24use crate::{ 24use crate::{
25 attr::Attrs, db::DefDatabase, path::Path, trace::Trace, FileAstId, HirFileId, LocalImportId, 25 attr::Attrs, db::DefDatabase, path::Path, trace::Trace, FileAstId, HirFileId, InFile,
26 Source, 26 LocalImportId,
27}; 27};
28 28
29/// `RawItems` is a set of top-level items in a file (except for impls). 29/// `RawItems` is a set of top-level items in a file (except for impls).
@@ -313,7 +313,7 @@ impl RawItemsCollector {
313 313
314 let mut buf = Vec::new(); 314 let mut buf = Vec::new();
315 Path::expand_use_item( 315 Path::expand_use_item(
316 Source { value: use_item, file_id: self.file_id }, 316 InFile { value: use_item, file_id: self.file_id },
317 &self.hygiene, 317 &self.hygiene,
318 |path, use_tree, is_glob, alias| { 318 |path, use_tree, is_glob, alias| {
319 let import_data = ImportData { 319 let import_data = ImportData {
diff --git a/crates/ra_hir_def/src/path.rs b/crates/ra_hir_def/src/path.rs
index 6810a26db..10688df4d 100644
--- a/crates/ra_hir_def/src/path.rs
+++ b/crates/ra_hir_def/src/path.rs
@@ -13,7 +13,7 @@ use ra_syntax::{
13 AstNode, 13 AstNode,
14}; 14};
15 15
16use crate::{type_ref::TypeRef, Source}; 16use crate::{type_ref::TypeRef, InFile};
17 17
18#[derive(Debug, Clone, PartialEq, Eq, Hash)] 18#[derive(Debug, Clone, PartialEq, Eq, Hash)]
19pub struct Path { 19pub struct Path {
@@ -67,7 +67,7 @@ pub enum PathKind {
67impl Path { 67impl Path {
68 /// Calls `cb` with all paths, represented by this use item. 68 /// Calls `cb` with all paths, represented by this use item.
69 pub(crate) fn expand_use_item( 69 pub(crate) fn expand_use_item(
70 item_src: Source<ast::UseItem>, 70 item_src: InFile<ast::UseItem>,
71 hygiene: &Hygiene, 71 hygiene: &Hygiene,
72 mut cb: impl FnMut(Path, &ast::UseTree, bool, Option<Name>), 72 mut cb: impl FnMut(Path, &ast::UseTree, bool, Option<Name>),
73 ) { 73 ) {
diff --git a/crates/ra_hir_expand/src/diagnostics.rs b/crates/ra_hir_expand/src/diagnostics.rs
index 3d37e9335..108c1e38c 100644
--- a/crates/ra_hir_expand/src/diagnostics.rs
+++ b/crates/ra_hir_expand/src/diagnostics.rs
@@ -18,11 +18,11 @@ use std::{any::Any, fmt};
18 18
19use ra_syntax::{SyntaxNode, SyntaxNodePtr, TextRange}; 19use ra_syntax::{SyntaxNode, SyntaxNodePtr, TextRange};
20 20
21use crate::{db::AstDatabase, Source}; 21use crate::{db::AstDatabase, InFile};
22 22
23pub trait Diagnostic: Any + Send + Sync + fmt::Debug + 'static { 23pub trait Diagnostic: Any + Send + Sync + fmt::Debug + 'static {
24 fn message(&self) -> String; 24 fn message(&self) -> String;
25 fn source(&self) -> Source<SyntaxNodePtr>; 25 fn source(&self) -> InFile<SyntaxNodePtr>;
26 fn highlight_range(&self) -> TextRange { 26 fn highlight_range(&self) -> TextRange {
27 self.source().value.range() 27 self.source().value.range()
28 } 28 }
diff --git a/crates/ra_hir_expand/src/lib.rs b/crates/ra_hir_expand/src/lib.rs
index b6a739cda..2c5b6b2bb 100644
--- a/crates/ra_hir_expand/src/lib.rs
+++ b/crates/ra_hir_expand/src/lib.rs
@@ -90,9 +90,9 @@ impl HirFileId {
90 let macro_arg = db.macro_arg(macro_file.macro_call_id)?; 90 let macro_arg = db.macro_arg(macro_file.macro_call_id)?;
91 91
92 Some(ExpansionInfo { 92 Some(ExpansionInfo {
93 expanded: Source::new(self, parse.syntax_node()), 93 expanded: InFile::new(self, parse.syntax_node()),
94 arg: Source::new(loc.ast_id.file_id, arg_tt), 94 arg: InFile::new(loc.ast_id.file_id, arg_tt),
95 def: Source::new(loc.ast_id.file_id, def_tt), 95 def: InFile::new(loc.ast_id.file_id, def_tt),
96 macro_arg, 96 macro_arg,
97 macro_def, 97 macro_def,
98 exp_map, 98 exp_map,
@@ -167,9 +167,9 @@ impl MacroCallId {
167/// ExpansionInfo mainly describes how to map text range between src and expanded macro 167/// ExpansionInfo mainly describes how to map text range between src and expanded macro
168#[derive(Debug, Clone, PartialEq, Eq)] 168#[derive(Debug, Clone, PartialEq, Eq)]
169pub struct ExpansionInfo { 169pub struct ExpansionInfo {
170 expanded: Source<SyntaxNode>, 170 expanded: InFile<SyntaxNode>,
171 arg: Source<ast::TokenTree>, 171 arg: InFile<ast::TokenTree>,
172 def: Source<ast::TokenTree>, 172 def: InFile<ast::TokenTree>,
173 173
174 macro_def: Arc<(db::TokenExpander, mbe::TokenMap)>, 174 macro_def: Arc<(db::TokenExpander, mbe::TokenMap)>,
175 macro_arg: Arc<(tt::Subtree, mbe::TokenMap)>, 175 macro_arg: Arc<(tt::Subtree, mbe::TokenMap)>,
@@ -177,7 +177,7 @@ pub struct ExpansionInfo {
177} 177}
178 178
179impl ExpansionInfo { 179impl ExpansionInfo {
180 pub fn map_token_down(&self, token: Source<&SyntaxToken>) -> Option<Source<SyntaxToken>> { 180 pub fn map_token_down(&self, token: InFile<&SyntaxToken>) -> Option<InFile<SyntaxToken>> {
181 assert_eq!(token.file_id, self.arg.file_id); 181 assert_eq!(token.file_id, self.arg.file_id);
182 let range = 182 let range =
183 token.value.text_range().checked_sub(self.arg.value.syntax().text_range().start())?; 183 token.value.text_range().checked_sub(self.arg.value.syntax().text_range().start())?;
@@ -191,7 +191,7 @@ impl ExpansionInfo {
191 Some(self.expanded.with_value(token)) 191 Some(self.expanded.with_value(token))
192 } 192 }
193 193
194 pub fn map_token_up(&self, token: Source<&SyntaxToken>) -> Option<Source<SyntaxToken>> { 194 pub fn map_token_up(&self, token: InFile<&SyntaxToken>) -> Option<InFile<SyntaxToken>> {
195 let token_id = self.exp_map.token_by_range(token.value.text_range())?; 195 let token_id = self.exp_map.token_by_range(token.value.text_range())?;
196 196
197 let (token_id, origin) = self.macro_def.0.map_id_up(token_id); 197 let (token_id, origin) = self.macro_def.0.map_id_up(token_id);
@@ -254,33 +254,33 @@ impl<N: AstNode> AstId<N> {
254 } 254 }
255} 255}
256 256
257/// `Source<T>` stores a value of `T` inside a particular file/syntax tree. 257/// `InFile<T>` stores a value of `T` inside a particular file/syntax tree.
258/// 258///
259/// Typical usages are: 259/// Typical usages are:
260/// 260///
261/// * `Source<SyntaxNode>` -- syntax node in a file 261/// * `InFile<SyntaxNode>` -- syntax node in a file
262/// * `Source<ast::FnDef>` -- ast node in a file 262/// * `InFile<ast::FnDef>` -- ast node in a file
263/// * `Source<TextUnit>` -- offset in a file 263/// * `InFile<TextUnit>` -- offset in a file
264#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)] 264#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
265pub struct Source<T> { 265pub struct InFile<T> {
266 pub file_id: HirFileId, 266 pub file_id: HirFileId,
267 pub value: T, 267 pub value: T,
268} 268}
269 269
270impl<T> Source<T> { 270impl<T> InFile<T> {
271 pub fn new(file_id: HirFileId, value: T) -> Source<T> { 271 pub fn new(file_id: HirFileId, value: T) -> InFile<T> {
272 Source { file_id, value } 272 InFile { file_id, value }
273 } 273 }
274 274
275 // Similarly, naming here is stupid... 275 // Similarly, naming here is stupid...
276 pub fn with_value<U>(&self, value: U) -> Source<U> { 276 pub fn with_value<U>(&self, value: U) -> InFile<U> {
277 Source::new(self.file_id, value) 277 InFile::new(self.file_id, value)
278 } 278 }
279 279
280 pub fn map<F: FnOnce(T) -> U, U>(self, f: F) -> Source<U> { 280 pub fn map<F: FnOnce(T) -> U, U>(self, f: F) -> InFile<U> {
281 Source::new(self.file_id, f(self.value)) 281 InFile::new(self.file_id, f(self.value))
282 } 282 }
283 pub fn as_ref(&self) -> Source<&T> { 283 pub fn as_ref(&self) -> InFile<&T> {
284 self.with_value(&self.value) 284 self.with_value(&self.value)
285 } 285 }
286 pub fn file_syntax(&self, db: &impl db::AstDatabase) -> SyntaxNode { 286 pub fn file_syntax(&self, db: &impl db::AstDatabase) -> SyntaxNode {
diff --git a/crates/ra_hir_ty/src/diagnostics.rs b/crates/ra_hir_ty/src/diagnostics.rs
index 4a13fac23..5054189cc 100644
--- a/crates/ra_hir_ty/src/diagnostics.rs
+++ b/crates/ra_hir_ty/src/diagnostics.rs
@@ -2,7 +2,7 @@
2 2
3use std::any::Any; 3use std::any::Any;
4 4
5use hir_expand::{db::AstDatabase, name::Name, HirFileId, Source}; 5use hir_expand::{db::AstDatabase, name::Name, HirFileId, InFile};
6use ra_syntax::{ast, AstNode, AstPtr, SyntaxNodePtr}; 6use ra_syntax::{ast, AstNode, AstPtr, SyntaxNodePtr};
7 7
8pub use hir_def::diagnostics::UnresolvedModule; 8pub use hir_def::diagnostics::UnresolvedModule;
@@ -19,8 +19,8 @@ impl Diagnostic for NoSuchField {
19 "no such field".to_string() 19 "no such field".to_string()
20 } 20 }
21 21
22 fn source(&self) -> Source<SyntaxNodePtr> { 22 fn source(&self) -> InFile<SyntaxNodePtr> {
23 Source { file_id: self.file, value: self.field.into() } 23 InFile { file_id: self.file, value: self.field.into() }
24 } 24 }
25 25
26 fn as_any(&self) -> &(dyn Any + Send + 'static) { 26 fn as_any(&self) -> &(dyn Any + Send + 'static) {
@@ -44,8 +44,8 @@ impl Diagnostic for MissingFields {
44 } 44 }
45 message 45 message
46 } 46 }
47 fn source(&self) -> Source<SyntaxNodePtr> { 47 fn source(&self) -> InFile<SyntaxNodePtr> {
48 Source { file_id: self.file, value: self.field_list.into() } 48 InFile { file_id: self.file, value: self.field_list.into() }
49 } 49 }
50 fn as_any(&self) -> &(dyn Any + Send + 'static) { 50 fn as_any(&self) -> &(dyn Any + Send + 'static) {
51 self 51 self
@@ -72,8 +72,8 @@ impl Diagnostic for MissingOkInTailExpr {
72 fn message(&self) -> String { 72 fn message(&self) -> String {
73 "wrap return expression in Ok".to_string() 73 "wrap return expression in Ok".to_string()
74 } 74 }
75 fn source(&self) -> Source<SyntaxNodePtr> { 75 fn source(&self) -> InFile<SyntaxNodePtr> {
76 Source { file_id: self.file, value: self.expr.into() } 76 InFile { file_id: self.file, value: self.expr.into() }
77 } 77 }
78 fn as_any(&self) -> &(dyn Any + Send + 'static) { 78 fn as_any(&self) -> &(dyn Any + Send + 'static) {
79 self 79 self
diff --git a/crates/ra_hir_ty/src/tests.rs b/crates/ra_hir_ty/src/tests.rs
index c8461b447..abbc1546c 100644
--- a/crates/ra_hir_ty/src/tests.rs
+++ b/crates/ra_hir_ty/src/tests.rs
@@ -8,7 +8,7 @@ use hir_def::{
8 body::BodySourceMap, db::DefDatabase, nameres::CrateDefMap, AssocItemId, DefWithBodyId, 8 body::BodySourceMap, db::DefDatabase, nameres::CrateDefMap, AssocItemId, DefWithBodyId,
9 LocalModuleId, Lookup, ModuleDefId, 9 LocalModuleId, Lookup, ModuleDefId,
10}; 10};
11use hir_expand::Source; 11use hir_expand::InFile;
12use insta::assert_snapshot; 12use insta::assert_snapshot;
13use ra_db::{fixture::WithFixture, salsa::Database, FilePosition, SourceDatabase}; 13use ra_db::{fixture::WithFixture, salsa::Database, FilePosition, SourceDatabase};
14use ra_syntax::{ 14use ra_syntax::{
@@ -4680,7 +4680,7 @@ fn type_at_pos(db: &TestDB, pos: FilePosition) -> String {
4680 for decl in crate_def_map[module.local_id].scope.declarations() { 4680 for decl in crate_def_map[module.local_id].scope.declarations() {
4681 if let ModuleDefId::FunctionId(func) = decl { 4681 if let ModuleDefId::FunctionId(func) = decl {
4682 let (_body, source_map) = db.body_with_source_map(func.into()); 4682 let (_body, source_map) = db.body_with_source_map(func.into());
4683 if let Some(expr_id) = source_map.node_expr(Source::new(pos.file_id.into(), &expr)) { 4683 if let Some(expr_id) = source_map.node_expr(InFile::new(pos.file_id.into(), &expr)) {
4684 let infer = db.infer(func.into()); 4684 let infer = db.infer(func.into());
4685 let ty = &infer[expr_id]; 4685 let ty = &infer[expr_id];
4686 return ty.display(db).to_string(); 4686 return ty.display(db).to_string();
diff --git a/crates/ra_ide/src/call_info.rs b/crates/ra_ide/src/call_info.rs
index d559dc4d0..b3c323d38 100644
--- a/crates/ra_ide/src/call_info.rs
+++ b/crates/ra_ide/src/call_info.rs
@@ -18,7 +18,7 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option<Cal
18 // Find the calling expression and it's NameRef 18 // Find the calling expression and it's NameRef
19 let calling_node = FnCallNode::with_node(&syntax, position.offset)?; 19 let calling_node = FnCallNode::with_node(&syntax, position.offset)?;
20 let name_ref = calling_node.name_ref()?; 20 let name_ref = calling_node.name_ref()?;
21 let name_ref = hir::Source::new(position.file_id.into(), name_ref.syntax()); 21 let name_ref = hir::InFile::new(position.file_id.into(), name_ref.syntax());
22 22
23 let analyzer = hir::SourceAnalyzer::new(db, name_ref, None); 23 let analyzer = hir::SourceAnalyzer::new(db, name_ref, None);
24 let (mut call_info, has_self) = match &calling_node { 24 let (mut call_info, has_self) = match &calling_node {
diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs
index b8345c91d..ca0a483d4 100644
--- a/crates/ra_ide/src/completion/completion_context.rs
+++ b/crates/ra_ide/src/completion/completion_context.rs
@@ -54,13 +54,13 @@ impl<'a> CompletionContext<'a> {
54 let src = hir::ModuleSource::from_position(db, position); 54 let src = hir::ModuleSource::from_position(db, position);
55 let module = hir::Module::from_definition( 55 let module = hir::Module::from_definition(
56 db, 56 db,
57 hir::Source { file_id: position.file_id.into(), value: src }, 57 hir::InFile { file_id: position.file_id.into(), value: src },
58 ); 58 );
59 let token = 59 let token =
60 original_parse.tree().syntax().token_at_offset(position.offset).left_biased()?; 60 original_parse.tree().syntax().token_at_offset(position.offset).left_biased()?;
61 let analyzer = hir::SourceAnalyzer::new( 61 let analyzer = hir::SourceAnalyzer::new(
62 db, 62 db,
63 hir::Source::new(position.file_id.into(), &token.parent()), 63 hir::InFile::new(position.file_id.into(), &token.parent()),
64 Some(position.offset), 64 Some(position.offset),
65 ); 65 );
66 let mut ctx = CompletionContext { 66 let mut ctx = CompletionContext {
diff --git a/crates/ra_ide/src/diagnostics.rs b/crates/ra_ide/src/diagnostics.rs
index cc1ccab4b..c50a70d99 100644
--- a/crates/ra_ide/src/diagnostics.rs
+++ b/crates/ra_ide/src/diagnostics.rs
@@ -96,7 +96,7 @@ pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec<Diagnostic>
96 }); 96 });
97 let source_file = db.parse(file_id).tree(); 97 let source_file = db.parse(file_id).tree();
98 let src = 98 let src =
99 hir::Source { file_id: file_id.into(), value: hir::ModuleSource::SourceFile(source_file) }; 99 hir::InFile { file_id: file_id.into(), value: hir::ModuleSource::SourceFile(source_file) };
100 if let Some(m) = hir::Module::from_definition(db, src) { 100 if let Some(m) = hir::Module::from_definition(db, src) {
101 m.diagnostics(db, &mut sink); 101 m.diagnostics(db, &mut sink);
102 }; 102 };
diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs
index 6ac60722b..61dca14ac 100644
--- a/crates/ra_ide/src/display/navigation_target.rs
+++ b/crates/ra_ide/src/display/navigation_target.rs
@@ -1,6 +1,6 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3use hir::{AssocItem, Either, FieldSource, HasSource, ModuleSource, Source}; 3use hir::{AssocItem, Either, FieldSource, HasSource, InFile, ModuleSource};
4use ra_db::{FileId, SourceDatabase}; 4use ra_db::{FileId, SourceDatabase};
5use ra_syntax::{ 5use ra_syntax::{
6 ast::{self, DocCommentsOwner, NameOwner}, 6 ast::{self, DocCommentsOwner, NameOwner},
@@ -141,7 +141,7 @@ impl NavigationTarget {
141 /// Allows `NavigationTarget` to be created from a `NameOwner` 141 /// Allows `NavigationTarget` to be created from a `NameOwner`
142 pub(crate) fn from_named( 142 pub(crate) fn from_named(
143 db: &RootDatabase, 143 db: &RootDatabase,
144 node: Source<&dyn ast::NameOwner>, 144 node: InFile<&dyn ast::NameOwner>,
145 docs: Option<String>, 145 docs: Option<String>,
146 description: Option<String>, 146 description: Option<String>,
147 ) -> NavigationTarget { 147 ) -> NavigationTarget {
diff --git a/crates/ra_ide/src/expand.rs b/crates/ra_ide/src/expand.rs
index 2f1abf509..216d5cfec 100644
--- a/crates/ra_ide/src/expand.rs
+++ b/crates/ra_ide/src/expand.rs
@@ -1,13 +1,13 @@
1//! Utilities to work with files, produced by macros. 1//! Utilities to work with files, produced by macros.
2use std::iter::successors; 2use std::iter::successors;
3 3
4use hir::Source; 4use hir::InFile;
5use ra_db::FileId; 5use ra_db::FileId;
6use ra_syntax::{ast, AstNode, SyntaxNode, SyntaxToken}; 6use ra_syntax::{ast, AstNode, SyntaxNode, SyntaxToken};
7 7
8use crate::{db::RootDatabase, FileRange}; 8use crate::{db::RootDatabase, FileRange};
9 9
10pub(crate) fn original_range(db: &RootDatabase, node: Source<&SyntaxNode>) -> FileRange { 10pub(crate) fn original_range(db: &RootDatabase, node: InFile<&SyntaxNode>) -> FileRange {
11 let expansion = match node.file_id.expansion_info(db) { 11 let expansion = match node.file_id.expansion_info(db) {
12 None => { 12 None => {
13 return FileRange { 13 return FileRange {
@@ -44,8 +44,8 @@ pub(crate) fn descend_into_macros(
44 db: &RootDatabase, 44 db: &RootDatabase,
45 file_id: FileId, 45 file_id: FileId,
46 token: SyntaxToken, 46 token: SyntaxToken,
47) -> Source<SyntaxToken> { 47) -> InFile<SyntaxToken> {
48 let src = Source::new(file_id.into(), token); 48 let src = InFile::new(file_id.into(), token);
49 49
50 successors(Some(src), |token| { 50 successors(Some(src), |token| {
51 let macro_call = token.value.ancestors().find_map(ast::MacroCall::cast)?; 51 let macro_call = token.value.ancestors().find_map(ast::MacroCall::cast)?;
diff --git a/crates/ra_ide/src/expand_macro.rs b/crates/ra_ide/src/expand_macro.rs
index abc602244..862c03304 100644
--- a/crates/ra_ide/src/expand_macro.rs
+++ b/crates/ra_ide/src/expand_macro.rs
@@ -22,7 +22,7 @@ pub(crate) fn expand_macro(db: &RootDatabase, position: FilePosition) -> Option<
22 let name_ref = find_node_at_offset::<ast::NameRef>(file.syntax(), position.offset)?; 22 let name_ref = find_node_at_offset::<ast::NameRef>(file.syntax(), position.offset)?;
23 let mac = name_ref.syntax().ancestors().find_map(ast::MacroCall::cast)?; 23 let mac = name_ref.syntax().ancestors().find_map(ast::MacroCall::cast)?;
24 24
25 let source = hir::Source::new(position.file_id.into(), mac.syntax()); 25 let source = hir::InFile::new(position.file_id.into(), mac.syntax());
26 let expanded = expand_macro_recur(db, source, source.with_value(&mac))?; 26 let expanded = expand_macro_recur(db, source, source.with_value(&mac))?;
27 27
28 // FIXME: 28 // FIXME:
@@ -34,8 +34,8 @@ pub(crate) fn expand_macro(db: &RootDatabase, position: FilePosition) -> Option<
34 34
35fn expand_macro_recur( 35fn expand_macro_recur(
36 db: &RootDatabase, 36 db: &RootDatabase,
37 source: hir::Source<&SyntaxNode>, 37 source: hir::InFile<&SyntaxNode>,
38 macro_call: hir::Source<&ast::MacroCall>, 38 macro_call: hir::InFile<&ast::MacroCall>,
39) -> Option<SyntaxNode> { 39) -> Option<SyntaxNode> {
40 let analyzer = hir::SourceAnalyzer::new(db, source, None); 40 let analyzer = hir::SourceAnalyzer::new(db, source, None);
41 let expansion = analyzer.expand(db, macro_call)?; 41 let expansion = analyzer.expand(db, macro_call)?;
@@ -46,7 +46,7 @@ fn expand_macro_recur(
46 let mut replaces = FxHashMap::default(); 46 let mut replaces = FxHashMap::default();
47 47
48 for child in children.into_iter() { 48 for child in children.into_iter() {
49 let node = hir::Source::new(macro_file_id, &child); 49 let node = hir::InFile::new(macro_file_id, &child);
50 if let Some(new_node) = expand_macro_recur(db, source, node) { 50 if let Some(new_node) = expand_macro_recur(db, source, node) {
51 // Replace the whole node if it is root 51 // Replace the whole node if it is root
52 // `replace_descendants` will not replace the parent node 52 // `replace_descendants` will not replace the parent node
diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs
index c10a6c844..76a741207 100644
--- a/crates/ra_ide/src/goto_definition.rs
+++ b/crates/ra_ide/src/goto_definition.rs
@@ -1,6 +1,6 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3use hir::{db::AstDatabase, Source}; 3use hir::{db::AstDatabase, InFile};
4use ra_syntax::{ 4use ra_syntax::{
5 ast::{self, DocCommentsOwner}, 5 ast::{self, DocCommentsOwner},
6 match_ast, AstNode, SyntaxNode, 6 match_ast, AstNode, SyntaxNode,
@@ -58,7 +58,7 @@ impl ReferenceResult {
58 58
59pub(crate) fn reference_definition( 59pub(crate) fn reference_definition(
60 db: &RootDatabase, 60 db: &RootDatabase,
61 name_ref: Source<&ast::NameRef>, 61 name_ref: InFile<&ast::NameRef>,
62) -> ReferenceResult { 62) -> ReferenceResult {
63 use self::ReferenceResult::*; 63 use self::ReferenceResult::*;
64 64
@@ -94,7 +94,7 @@ pub(crate) fn reference_definition(
94 94
95pub(crate) fn name_definition( 95pub(crate) fn name_definition(
96 db: &RootDatabase, 96 db: &RootDatabase,
97 name: Source<&ast::Name>, 97 name: InFile<&ast::Name>,
98) -> Option<Vec<NavigationTarget>> { 98) -> Option<Vec<NavigationTarget>> {
99 let parent = name.value.syntax().parent()?; 99 let parent = name.value.syntax().parent()?;
100 100
@@ -115,7 +115,7 @@ pub(crate) fn name_definition(
115 None 115 None
116} 116}
117 117
118fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<NavigationTarget> { 118fn named_target(db: &RootDatabase, node: InFile<&SyntaxNode>) -> Option<NavigationTarget> {
119 match_ast! { 119 match_ast! {
120 match (node.value) { 120 match (node.value) {
121 ast::StructDef(it) => { 121 ast::StructDef(it) => {
diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs
index 260a7b869..d8185c688 100644
--- a/crates/ra_ide/src/hover.rs
+++ b/crates/ra_ide/src/hover.rs
@@ -227,7 +227,7 @@ pub(crate) fn type_of(db: &RootDatabase, frange: FileRange) -> Option<String> {
227 .take_while(|it| it.text_range() == leaf_node.text_range()) 227 .take_while(|it| it.text_range() == leaf_node.text_range())
228 .find(|it| ast::Expr::cast(it.clone()).is_some() || ast::Pat::cast(it.clone()).is_some())?; 228 .find(|it| ast::Expr::cast(it.clone()).is_some() || ast::Pat::cast(it.clone()).is_some())?;
229 let analyzer = 229 let analyzer =
230 hir::SourceAnalyzer::new(db, hir::Source::new(frange.file_id.into(), &node), None); 230 hir::SourceAnalyzer::new(db, hir::InFile::new(frange.file_id.into(), &node), None);
231 let ty = if let Some(ty) = ast::Expr::cast(node.clone()).and_then(|e| analyzer.type_of(db, &e)) 231 let ty = if let Some(ty) = ast::Expr::cast(node.clone()).and_then(|e| analyzer.type_of(db, &e))
232 { 232 {
233 ty 233 ty
diff --git a/crates/ra_ide/src/impls.rs b/crates/ra_ide/src/impls.rs
index aa480e399..9b165ee2a 100644
--- a/crates/ra_ide/src/impls.rs
+++ b/crates/ra_ide/src/impls.rs
@@ -16,7 +16,7 @@ pub(crate) fn goto_implementation(
16 let src = hir::ModuleSource::from_position(db, position); 16 let src = hir::ModuleSource::from_position(db, position);
17 let module = hir::Module::from_definition( 17 let module = hir::Module::from_definition(
18 db, 18 db,
19 hir::Source { file_id: position.file_id.into(), value: src }, 19 hir::InFile { file_id: position.file_id.into(), value: src },
20 )?; 20 )?;
21 21
22 if let Some(nominal_def) = find_node_at_offset::<ast::NominalDef>(&syntax, position.offset) { 22 if let Some(nominal_def) = find_node_at_offset::<ast::NominalDef>(&syntax, position.offset) {
@@ -42,15 +42,15 @@ fn impls_for_def(
42) -> Option<Vec<NavigationTarget>> { 42) -> Option<Vec<NavigationTarget>> {
43 let ty = match node { 43 let ty = match node {
44 ast::NominalDef::StructDef(def) => { 44 ast::NominalDef::StructDef(def) => {
45 let src = hir::Source { file_id: position.file_id.into(), value: def.clone() }; 45 let src = hir::InFile { file_id: position.file_id.into(), value: def.clone() };
46 hir::Struct::from_source(db, src)?.ty(db) 46 hir::Struct::from_source(db, src)?.ty(db)
47 } 47 }
48 ast::NominalDef::EnumDef(def) => { 48 ast::NominalDef::EnumDef(def) => {
49 let src = hir::Source { file_id: position.file_id.into(), value: def.clone() }; 49 let src = hir::InFile { file_id: position.file_id.into(), value: def.clone() };
50 hir::Enum::from_source(db, src)?.ty(db) 50 hir::Enum::from_source(db, src)?.ty(db)
51 } 51 }
52 ast::NominalDef::UnionDef(def) => { 52 ast::NominalDef::UnionDef(def) => {
53 let src = hir::Source { file_id: position.file_id.into(), value: def.clone() }; 53 let src = hir::InFile { file_id: position.file_id.into(), value: def.clone() };
54 hir::Union::from_source(db, src)?.ty(db) 54 hir::Union::from_source(db, src)?.ty(db)
55 } 55 }
56 }; 56 };
@@ -73,7 +73,7 @@ fn impls_for_trait(
73 node: &ast::TraitDef, 73 node: &ast::TraitDef,
74 module: hir::Module, 74 module: hir::Module,
75) -> Option<Vec<NavigationTarget>> { 75) -> Option<Vec<NavigationTarget>> {
76 let src = hir::Source { file_id: position.file_id.into(), value: node.clone() }; 76 let src = hir::InFile { file_id: position.file_id.into(), value: node.clone() };
77 let tr = hir::Trait::from_source(db, src)?; 77 let tr = hir::Trait::from_source(db, src)?;
78 78
79 let krate = module.krate(); 79 let krate = module.krate();
diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs
index 45149bf0c..59eced9d7 100644
--- a/crates/ra_ide/src/inlay_hints.rs
+++ b/crates/ra_ide/src/inlay_hints.rs
@@ -38,7 +38,7 @@ fn get_inlay_hints(
38 node: &SyntaxNode, 38 node: &SyntaxNode,
39 max_inlay_hint_length: Option<usize>, 39 max_inlay_hint_length: Option<usize>,
40) -> Option<Vec<InlayHint>> { 40) -> Option<Vec<InlayHint>> {
41 let analyzer = SourceAnalyzer::new(db, hir::Source::new(file_id.into(), node), None); 41 let analyzer = SourceAnalyzer::new(db, hir::InFile::new(file_id.into(), node), None);
42 match_ast! { 42 match_ast! {
43 match node { 43 match node {
44 ast::LetStmt(it) => { 44 ast::LetStmt(it) => {
diff --git a/crates/ra_ide/src/parent_module.rs b/crates/ra_ide/src/parent_module.rs
index 6027e7d54..616d69fce 100644
--- a/crates/ra_ide/src/parent_module.rs
+++ b/crates/ra_ide/src/parent_module.rs
@@ -10,7 +10,7 @@ pub(crate) fn parent_module(db: &RootDatabase, position: FilePosition) -> Vec<Na
10 let src = hir::ModuleSource::from_position(db, position); 10 let src = hir::ModuleSource::from_position(db, position);
11 let module = match hir::Module::from_definition( 11 let module = match hir::Module::from_definition(
12 db, 12 db,
13 hir::Source { file_id: position.file_id.into(), value: src }, 13 hir::InFile { file_id: position.file_id.into(), value: src },
14 ) { 14 ) {
15 None => return Vec::new(), 15 None => return Vec::new(),
16 Some(it) => it, 16 Some(it) => it,
@@ -23,7 +23,7 @@ pub(crate) fn parent_module(db: &RootDatabase, position: FilePosition) -> Vec<Na
23pub(crate) fn crate_for(db: &RootDatabase, file_id: FileId) -> Vec<CrateId> { 23pub(crate) fn crate_for(db: &RootDatabase, file_id: FileId) -> Vec<CrateId> {
24 let src = hir::ModuleSource::from_file_id(db, file_id); 24 let src = hir::ModuleSource::from_file_id(db, file_id);
25 let module = 25 let module =
26 match hir::Module::from_definition(db, hir::Source { file_id: file_id.into(), value: src }) 26 match hir::Module::from_definition(db, hir::InFile { file_id: file_id.into(), value: src })
27 { 27 {
28 Some(it) => it, 28 Some(it) => it,
29 None => return Vec::new(), 29 None => return Vec::new(),
diff --git a/crates/ra_ide/src/references.rs b/crates/ra_ide/src/references.rs
index 21a1ea69e..3e7bfd872 100644
--- a/crates/ra_ide/src/references.rs
+++ b/crates/ra_ide/src/references.rs
@@ -14,7 +14,7 @@ mod name_definition;
14mod rename; 14mod rename;
15mod search_scope; 15mod search_scope;
16 16
17use hir::Source; 17use hir::InFile;
18use once_cell::unsync::Lazy; 18use once_cell::unsync::Lazy;
19use ra_db::{SourceDatabase, SourceDatabaseExt}; 19use ra_db::{SourceDatabase, SourceDatabaseExt};
20use ra_prof::profile; 20use ra_prof::profile;
@@ -107,12 +107,12 @@ fn find_name<'a>(
107 position: FilePosition, 107 position: FilePosition,
108) -> Option<RangeInfo<(String, NameDefinition)>> { 108) -> Option<RangeInfo<(String, NameDefinition)>> {
109 if let Some(name) = find_node_at_offset::<ast::Name>(&syntax, position.offset) { 109 if let Some(name) = find_node_at_offset::<ast::Name>(&syntax, position.offset) {
110 let def = classify_name(db, Source::new(position.file_id.into(), &name))?; 110 let def = classify_name(db, InFile::new(position.file_id.into(), &name))?;
111 let range = name.syntax().text_range(); 111 let range = name.syntax().text_range();
112 return Some(RangeInfo::new(range, (name.text().to_string(), def))); 112 return Some(RangeInfo::new(range, (name.text().to_string(), def)));
113 } 113 }
114 let name_ref = find_node_at_offset::<ast::NameRef>(&syntax, position.offset)?; 114 let name_ref = find_node_at_offset::<ast::NameRef>(&syntax, position.offset)?;
115 let def = classify_name_ref(db, Source::new(position.file_id.into(), &name_ref))?; 115 let def = classify_name_ref(db, InFile::new(position.file_id.into(), &name_ref))?;
116 let range = name_ref.syntax().text_range(); 116 let range = name_ref.syntax().text_range();
117 Some(RangeInfo::new(range, (name_ref.text().to_string(), def))) 117 Some(RangeInfo::new(range, (name_ref.text().to_string(), def)))
118} 118}
@@ -144,7 +144,7 @@ fn process_definition(
144 continue; 144 continue;
145 } 145 }
146 } 146 }
147 if let Some(d) = classify_name_ref(db, Source::new(file_id.into(), &name_ref)) { 147 if let Some(d) = classify_name_ref(db, InFile::new(file_id.into(), &name_ref)) {
148 if d == def { 148 if d == def {
149 refs.push(FileRange { file_id, range }); 149 refs.push(FileRange { file_id, range });
150 } 150 }
diff --git a/crates/ra_ide/src/references/classify.rs b/crates/ra_ide/src/references/classify.rs
index 5cea805ec..b716d32e5 100644
--- a/crates/ra_ide/src/references/classify.rs
+++ b/crates/ra_ide/src/references/classify.rs
@@ -1,6 +1,6 @@
1//! Functions that are used to classify an element from its definition or reference. 1//! Functions that are used to classify an element from its definition or reference.
2 2
3use hir::{FromSource, Module, ModuleSource, PathResolution, Source, SourceAnalyzer}; 3use hir::{FromSource, InFile, Module, ModuleSource, PathResolution, SourceAnalyzer};
4use ra_prof::profile; 4use ra_prof::profile;
5use ra_syntax::{ast, match_ast, AstNode}; 5use ra_syntax::{ast, match_ast, AstNode};
6use test_utils::tested_by; 6use test_utils::tested_by;
@@ -11,7 +11,7 @@ use super::{
11}; 11};
12use crate::db::RootDatabase; 12use crate::db::RootDatabase;
13 13
14pub(crate) fn classify_name(db: &RootDatabase, name: Source<&ast::Name>) -> Option<NameDefinition> { 14pub(crate) fn classify_name(db: &RootDatabase, name: InFile<&ast::Name>) -> Option<NameDefinition> {
15 let _p = profile("classify_name"); 15 let _p = profile("classify_name");
16 let parent = name.value.syntax().parent()?; 16 let parent = name.value.syntax().parent()?;
17 17
@@ -117,7 +117,7 @@ pub(crate) fn classify_name(db: &RootDatabase, name: Source<&ast::Name>) -> Opti
117 117
118pub(crate) fn classify_name_ref( 118pub(crate) fn classify_name_ref(
119 db: &RootDatabase, 119 db: &RootDatabase,
120 name_ref: Source<&ast::NameRef>, 120 name_ref: InFile<&ast::NameRef>,
121) -> Option<NameDefinition> { 121) -> Option<NameDefinition> {
122 let _p = profile("classify_name_ref"); 122 let _p = profile("classify_name_ref");
123 123
diff --git a/crates/ra_ide/src/references/rename.rs b/crates/ra_ide/src/references/rename.rs
index d58496049..ea6b354c2 100644
--- a/crates/ra_ide/src/references/rename.rs
+++ b/crates/ra_ide/src/references/rename.rs
@@ -55,7 +55,7 @@ fn rename_mod(
55) -> Option<SourceChange> { 55) -> Option<SourceChange> {
56 let mut source_file_edits = Vec::new(); 56 let mut source_file_edits = Vec::new();
57 let mut file_system_edits = Vec::new(); 57 let mut file_system_edits = Vec::new();
58 let module_src = hir::Source { file_id: position.file_id.into(), value: ast_module.clone() }; 58 let module_src = hir::InFile { file_id: position.file_id.into(), value: ast_module.clone() };
59 if let Some(module) = hir::Module::from_declaration(db, module_src) { 59 if let Some(module) = hir::Module::from_declaration(db, module_src) {
60 let src = module.definition_source(db); 60 let src = module.definition_source(db);
61 let file_id = src.file_id.original_file(db); 61 let file_id = src.file_id.original_file(db);
diff --git a/crates/ra_ide/src/runnables.rs b/crates/ra_ide/src/runnables.rs
index 8039a5164..e213e1a06 100644
--- a/crates/ra_ide/src/runnables.rs
+++ b/crates/ra_ide/src/runnables.rs
@@ -1,6 +1,6 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3use hir::Source; 3use hir::InFile;
4use itertools::Itertools; 4use itertools::Itertools;
5use ra_db::SourceDatabase; 5use ra_db::SourceDatabase;
6use ra_syntax::{ 6use ra_syntax::{
@@ -66,8 +66,8 @@ fn runnable_mod(db: &RootDatabase, file_id: FileId, module: ast::Module) -> Opti
66 return None; 66 return None;
67 } 67 }
68 let range = module.syntax().text_range(); 68 let range = module.syntax().text_range();
69 let src = hir::ModuleSource::from_child_node(db, Source::new(file_id.into(), &module.syntax())); 69 let src = hir::ModuleSource::from_child_node(db, InFile::new(file_id.into(), &module.syntax()));
70 let module = hir::Module::from_definition(db, Source::new(file_id.into(), src))?; 70 let module = hir::Module::from_definition(db, InFile::new(file_id.into(), src))?;
71 71
72 let path = module.path_to_root(db).into_iter().rev().filter_map(|it| it.name(db)).join("::"); 72 let path = module.path_to_root(db).into_iter().rev().filter_map(|it| it.name(db)).join("::");
73 Some(Runnable { range, kind: RunnableKind::TestMod { path } }) 73 Some(Runnable { range, kind: RunnableKind::TestMod { path } })
diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs
index 9a3e4c82f..e6a79541f 100644
--- a/crates/ra_ide/src/syntax_highlighting.rs
+++ b/crates/ra_ide/src/syntax_highlighting.rs
@@ -2,7 +2,7 @@
2 2
3use rustc_hash::{FxHashMap, FxHashSet}; 3use rustc_hash::{FxHashMap, FxHashSet};
4 4
5use hir::{Name, Source}; 5use hir::{InFile, Name};
6use ra_db::SourceDatabase; 6use ra_db::SourceDatabase;
7use ra_prof::profile; 7use ra_prof::profile;
8use ra_syntax::{ast, AstNode, Direction, SyntaxElement, SyntaxKind, SyntaxKind::*, TextRange, T}; 8use ra_syntax::{ast, AstNode, Direction, SyntaxElement, SyntaxKind, SyntaxKind::*, TextRange, T};
@@ -81,7 +81,7 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRa
81 81
82 let name_ref = node.as_node().cloned().and_then(ast::NameRef::cast).unwrap(); 82 let name_ref = node.as_node().cloned().and_then(ast::NameRef::cast).unwrap();
83 let name_kind = 83 let name_kind =
84 classify_name_ref(db, Source::new(file_id.into(), &name_ref)).map(|d| d.kind); 84 classify_name_ref(db, InFile::new(file_id.into(), &name_ref)).map(|d| d.kind);
85 85
86 if let Some(Local(local)) = &name_kind { 86 if let Some(Local(local)) = &name_kind {
87 if let Some(name) = local.name(db) { 87 if let Some(name) = local.name(db) {
@@ -95,7 +95,7 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRa
95 NAME => { 95 NAME => {
96 let name = node.as_node().cloned().and_then(ast::Name::cast).unwrap(); 96 let name = node.as_node().cloned().and_then(ast::Name::cast).unwrap();
97 let name_kind = 97 let name_kind =
98 classify_name(db, Source::new(file_id.into(), &name)).map(|d| d.kind); 98 classify_name(db, InFile::new(file_id.into(), &name)).map(|d| d.kind);
99 99
100 if let Some(Local(local)) = &name_kind { 100 if let Some(Local(local)) = &name_kind {
101 if let Some(name) = local.name(db) { 101 if let Some(name) = local.name(db) {