@@ -107,8 +107,13 @@ pub enum ModuleOrigin {
107
107
/// It should not be `None` after collecting definitions.
108
108
Root ( Option < FileId > ) ,
109
109
/// Note that non-inline modules, by definition, live inside non-macro file.
110
- File ( AstId < ast:: Module > , FileId ) ,
111
- Inline ( AstId < ast:: Module > ) ,
110
+ File {
111
+ declaration : AstId < ast:: Module > ,
112
+ definition : FileId ,
113
+ } ,
114
+ Inline {
115
+ definition : AstId < ast:: Module > ,
116
+ } ,
112
117
}
113
118
114
119
impl Default for ModuleOrigin {
@@ -118,49 +123,47 @@ impl Default for ModuleOrigin {
118
123
}
119
124
120
125
impl ModuleOrigin {
121
- pub fn root ( file_id : FileId ) -> Self {
126
+ fn root ( file_id : FileId ) -> Self {
122
127
ModuleOrigin :: Root ( Some ( file_id) )
123
128
}
124
129
125
- pub fn not_sure_file ( file : Option < FileId > , module : AstId < ast:: Module > ) -> Self {
130
+ pub ( crate ) fn not_sure_file ( file : Option < FileId > , declaration : AstId < ast:: Module > ) -> Self {
126
131
match file {
127
- None => ModuleOrigin :: Inline ( module ) ,
128
- Some ( file ) => ModuleOrigin :: File ( module , file ) ,
132
+ None => ModuleOrigin :: Inline { definition : declaration } ,
133
+ Some ( definition ) => ModuleOrigin :: File { declaration , definition } ,
129
134
}
130
135
}
131
136
132
- pub fn not_sure_mod ( file : FileId , module : Option < AstId < ast:: Module > > ) -> Self {
133
- match module {
134
- None => ModuleOrigin :: root ( file) ,
135
- Some ( module) => ModuleOrigin :: File ( module, file) ,
136
- }
137
- }
138
-
139
- pub fn declaration ( & self ) -> Option < AstId < ast:: Module > > {
137
+ fn declaration ( & self ) -> Option < AstId < ast:: Module > > {
140
138
match self {
141
- ModuleOrigin :: File ( m, _) | ModuleOrigin :: Inline ( m) => Some ( * m) ,
139
+ ModuleOrigin :: File { declaration : module, .. }
140
+ | ModuleOrigin :: Inline { definition : module, .. } => Some ( * module) ,
142
141
ModuleOrigin :: Root ( _) => None ,
143
142
}
144
143
}
145
144
146
- pub fn file_id ( & self ) -> Option < FileId > {
145
+ pub ( crate ) fn file_id ( & self ) -> Option < FileId > {
147
146
match self {
148
- ModuleOrigin :: File ( _, file_id) | ModuleOrigin :: Root ( Some ( file_id) ) => Some ( * file_id) ,
147
+ ModuleOrigin :: File { definition : file_id, .. } | ModuleOrigin :: Root ( Some ( file_id) ) => {
148
+ Some ( * file_id)
149
+ }
149
150
_ => None ,
150
151
}
151
152
}
152
153
153
154
/// Returns a node which defines this module.
154
155
/// That is, a file or a `mod foo {}` with items.
155
- pub fn definition_source ( & self , db : & impl DefDatabase ) -> InFile < ModuleSource > {
156
+ fn definition_source ( & self , db : & impl DefDatabase ) -> InFile < ModuleSource > {
156
157
match self {
157
- ModuleOrigin :: File ( _ , file_id) | ModuleOrigin :: Root ( Some ( file_id) ) => {
158
+ ModuleOrigin :: File { definition : file_id, .. } | ModuleOrigin :: Root ( Some ( file_id) ) => {
158
159
let file_id = * file_id;
159
160
let sf = db. parse ( file_id) . tree ( ) ;
160
161
return InFile :: new ( file_id. into ( ) , ModuleSource :: SourceFile ( sf) ) ;
161
162
}
162
163
ModuleOrigin :: Root ( None ) => unreachable ! ( ) ,
163
- ModuleOrigin :: Inline ( m) => InFile :: new ( m. file_id , ModuleSource :: Module ( m. to_node ( db) ) ) ,
164
+ ModuleOrigin :: Inline { definition } => {
165
+ InFile :: new ( definition. file_id , ModuleSource :: Module ( definition. to_node ( db) ) )
166
+ }
164
167
}
165
168
}
166
169
}
0 commit comments