aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/adt.rs7
-rw-r--r--crates/ra_hir/src/code_model.rs (renamed from crates/ra_hir/src/code_model_api.rs)391
-rw-r--r--crates/ra_hir/src/code_model_impl.rs4
-rw-r--r--crates/ra_hir/src/code_model_impl/function.rs50
-rw-r--r--crates/ra_hir/src/code_model_impl/konst.rs34
-rw-r--r--crates/ra_hir/src/code_model_impl/krate.rs22
-rw-r--r--crates/ra_hir/src/code_model_impl/module.rs99
-rw-r--r--crates/ra_hir/src/generics.rs13
-rw-r--r--crates/ra_hir/src/impl_block.rs2
-rw-r--r--crates/ra_hir/src/lib.rs7
-rw-r--r--crates/ra_hir/src/nameres/collector.rs6
-rw-r--r--crates/ra_hir/src/nameres/raw.rs19
-rw-r--r--crates/ra_hir/src/resolve.rs2
-rw-r--r--crates/ra_hir/src/ty.rs1
-rw-r--r--crates/ra_hir/src/ty/infer.rs21
-rw-r--r--crates/ra_hir/src/ty/lower.rs10
16 files changed, 331 insertions, 357 deletions
diff --git a/crates/ra_hir/src/adt.rs b/crates/ra_hir/src/adt.rs
index e027eedd9..5e5905f15 100644
--- a/crates/ra_hir/src/adt.rs
+++ b/crates/ra_hir/src/adt.rs
@@ -10,7 +10,7 @@ use ra_syntax::{
10}; 10};
11 11
12use crate::{ 12use crate::{
13 Name, AsName, Struct, Enum, EnumVariant, Crate, 13 Name, AsName, Struct, Union, Enum, EnumVariant, Crate,
14 HirDatabase, HirFileId, StructField, FieldSource, 14 HirDatabase, HirFileId, StructField, FieldSource,
15 type_ref::TypeRef, DefDatabase, 15 type_ref::TypeRef, DefDatabase,
16}; 16};
@@ -18,14 +18,16 @@ use crate::{
18#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] 18#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
19pub enum AdtDef { 19pub enum AdtDef {
20 Struct(Struct), 20 Struct(Struct),
21 Union(Union),
21 Enum(Enum), 22 Enum(Enum),
22} 23}
23impl_froms!(AdtDef: Struct, Enum); 24impl_froms!(AdtDef: Struct, Union, Enum);
24 25
25impl AdtDef { 26impl AdtDef {
26 pub(crate) fn krate(self, db: &impl HirDatabase) -> Option<Crate> { 27 pub(crate) fn krate(self, db: &impl HirDatabase) -> Option<Crate> {
27 match self { 28 match self {
28 AdtDef::Struct(s) => s.module(db), 29 AdtDef::Struct(s) => s.module(db),
30 AdtDef::Union(s) => s.module(db),
29 AdtDef::Enum(e) => e.module(db), 31 AdtDef::Enum(e) => e.module(db),
30 } 32 }
31 .krate(db) 33 .krate(db)
@@ -38,6 +40,7 @@ impl Struct {
38 } 40 }
39} 41}
40 42
43/// Note that we use `StructData` for unions as well!
41#[derive(Debug, Clone, PartialEq, Eq)] 44#[derive(Debug, Clone, PartialEq, Eq)]
42pub struct StructData { 45pub struct StructData {
43 pub(crate) name: Option<Name>, 46 pub(crate) name: Option<Name>,
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model.rs
index 0c4a80bfa..49030ce67 100644
--- a/crates/ra_hir/src/code_model_api.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -1,15 +1,15 @@
1use std::sync::Arc; 1use std::sync::Arc;
2 2
3use ra_db::{CrateId, SourceRootId, Edition}; 3use ra_db::{CrateId, SourceRootId, Edition, FileId};
4use ra_syntax::{ast::self, TreeArc}; 4use ra_syntax::{ast::{self, NameOwner, TypeAscriptionOwner}, TreeArc};
5 5
6use crate::{ 6use crate::{
7 Name, Ty, HirFileId, Either, 7 Name, AsName, AstId, Ty, HirFileId, Either,
8 HirDatabase, DefDatabase, 8 HirDatabase, DefDatabase,
9 type_ref::TypeRef, 9 type_ref::TypeRef,
10 nameres::{ModuleScope, Namespace, ImportId, CrateModuleId}, 10 nameres::{ModuleScope, Namespace, ImportId, CrateModuleId},
11 expr::{Body, BodySourceMap, validation::ExprValidator}, 11 expr::{Body, BodySourceMap, validation::ExprValidator},
12 ty::{ TraitRef, InferenceResult}, 12 ty::{TraitRef, InferenceResult},
13 adt::{EnumVariantId, StructFieldId, VariantDef}, 13 adt::{EnumVariantId, StructFieldId, VariantDef},
14 generics::HasGenericParams, 14 generics::HasGenericParams,
15 docs::{Documentation, Docs, docs_from_ast}, 15 docs::{Documentation, Docs, docs_from_ast},
@@ -18,6 +18,7 @@ use crate::{
18 resolve::Resolver, 18 resolve::Resolver,
19 diagnostics::{DiagnosticSink}, 19 diagnostics::{DiagnosticSink},
20 traits::{TraitItem, TraitData}, 20 traits::{TraitItem, TraitData},
21 type_ref::Mutability,
21}; 22};
22 23
23/// hir::Crate describes a single crate. It's the main interface with which 24/// hir::Crate describes a single crate. It's the main interface with which
@@ -35,19 +36,28 @@ pub struct CrateDependency {
35} 36}
36 37
37impl Crate { 38impl Crate {
38 pub fn crate_id(&self) -> CrateId { 39 pub fn crate_id(self) -> CrateId {
39 self.crate_id 40 self.crate_id
40 } 41 }
41 42
42 pub fn dependencies(&self, db: &impl DefDatabase) -> Vec<CrateDependency> { 43 pub fn dependencies(self, db: &impl DefDatabase) -> Vec<CrateDependency> {
43 self.dependencies_impl(db) 44 db.crate_graph()
45 .dependencies(self.crate_id)
46 .map(|dep| {
47 let krate = Crate { crate_id: dep.crate_id() };
48 let name = dep.as_name();
49 CrateDependency { krate, name }
50 })
51 .collect()
44 } 52 }
45 53
46 pub fn root_module(&self, db: &impl DefDatabase) -> Option<Module> { 54 pub fn root_module(self, db: &impl DefDatabase) -> Option<Module> {
47 self.root_module_impl(db) 55 let module_id = db.crate_def_map(self).root();
56 let module = Module { krate: self, module_id };
57 Some(module)
48 } 58 }
49 59
50 pub fn edition(&self, db: &impl DefDatabase) -> Edition { 60 pub fn edition(self, db: &impl DefDatabase) -> Edition {
51 let crate_graph = db.crate_graph(); 61 let crate_graph = db.crate_graph();
52 crate_graph.edition(self.crate_id) 62 crate_graph.edition(self.crate_id)
53 } 63 }
@@ -71,6 +81,7 @@ pub enum ModuleDef {
71 Module(Module), 81 Module(Module),
72 Function(Function), 82 Function(Function),
73 Struct(Struct), 83 Struct(Struct),
84 Union(Union),
74 Enum(Enum), 85 Enum(Enum),
75 // Can't be directly declared, but can be imported. 86 // Can't be directly declared, but can be imported.
76 EnumVariant(EnumVariant), 87 EnumVariant(EnumVariant),
@@ -83,6 +94,7 @@ impl_froms!(
83 ModuleDef: Module, 94 ModuleDef: Module,
84 Function, 95 Function,
85 Struct, 96 Struct,
97 Union,
86 Enum, 98 Enum,
87 EnumVariant, 99 EnumVariant,
88 Const, 100 Const,
@@ -96,29 +108,66 @@ pub enum ModuleSource {
96 Module(TreeArc<ast::Module>), 108 Module(TreeArc<ast::Module>),
97} 109}
98 110
111impl ModuleSource {
112 pub(crate) fn new(
113 db: &impl DefDatabase,
114 file_id: Option<FileId>,
115 decl_id: Option<AstId<ast::Module>>,
116 ) -> ModuleSource {
117 match (file_id, decl_id) {
118 (Some(file_id), _) => {
119 let source_file = db.parse(file_id);
120 ModuleSource::SourceFile(source_file)
121 }
122 (None, Some(item_id)) => {
123 let module = item_id.to_node(db);
124 assert!(module.item_list().is_some(), "expected inline module");
125 ModuleSource::Module(module.to_owned())
126 }
127 (None, None) => panic!(),
128 }
129 }
130}
131
99impl Module { 132impl Module {
100 /// Name of this module. 133 /// Name of this module.
101 pub fn name(&self, db: &impl HirDatabase) -> Option<Name> { 134 pub fn name(self, db: &impl HirDatabase) -> Option<Name> {
102 self.name_impl(db) 135 let def_map = db.crate_def_map(self.krate);
136 let parent = def_map[self.module_id].parent?;
137 def_map[parent].children.iter().find_map(|(name, module_id)| {
138 if *module_id == self.module_id {
139 Some(name.clone())
140 } else {
141 None
142 }
143 })
103 } 144 }
104 145
105 /// Returns a node which defines this module. That is, a file or a `mod foo {}` with items. 146 /// Returns a node which defines this module. That is, a file or a `mod foo {}` with items.
106 pub fn definition_source(&self, db: &impl DefDatabase) -> (HirFileId, ModuleSource) { 147 pub fn definition_source(self, db: &impl DefDatabase) -> (HirFileId, ModuleSource) {
107 self.definition_source_impl(db) 148 let def_map = db.crate_def_map(self.krate);
149 let decl_id = def_map[self.module_id].declaration;
150 let file_id = def_map[self.module_id].definition;
151 let module_source = ModuleSource::new(db, file_id, decl_id);
152 let file_id = file_id.map(HirFileId::from).unwrap_or_else(|| decl_id.unwrap().file_id());
153 (file_id, module_source)
108 } 154 }
109 155
110 /// Returns a node which declares this module, either a `mod foo;` or a `mod foo {}`. 156 /// Returns a node which declares this module, either a `mod foo;` or a `mod foo {}`.
111 /// `None` for the crate root. 157 /// `None` for the crate root.
112 pub fn declaration_source( 158 pub fn declaration_source(
113 &self, 159 self,
114 db: &impl HirDatabase, 160 db: &impl HirDatabase,
115 ) -> Option<(HirFileId, TreeArc<ast::Module>)> { 161 ) -> Option<(HirFileId, TreeArc<ast::Module>)> {
116 self.declaration_source_impl(db) 162 let def_map = db.crate_def_map(self.krate);
163 let decl = def_map[self.module_id].declaration?;
164 let ast = decl.to_node(db);
165 Some((decl.file_id(), ast))
117 } 166 }
118 167
119 /// Returns the syntax of the last path segment corresponding to this import 168 /// Returns the syntax of the last path segment corresponding to this import
120 pub fn import_source( 169 pub fn import_source(
121 &self, 170 self,
122 db: &impl HirDatabase, 171 db: &impl HirDatabase,
123 import: ImportId, 172 import: ImportId,
124 ) -> Either<TreeArc<ast::UseTree>, TreeArc<ast::ExternCrateItem>> { 173 ) -> Either<TreeArc<ast::UseTree>, TreeArc<ast::ExternCrateItem>> {
@@ -128,33 +177,44 @@ impl Module {
128 } 177 }
129 178
130 /// Returns the crate this module is part of. 179 /// Returns the crate this module is part of.
131 pub fn krate(&self, _db: &impl DefDatabase) -> Option<Crate> { 180 pub fn krate(self, _db: &impl DefDatabase) -> Option<Crate> {
132 Some(self.krate) 181 Some(self.krate)
133 } 182 }
134 183
135 /// Topmost parent of this module. Every module has a `crate_root`, but some 184 /// Topmost parent of this module. Every module has a `crate_root`, but some
136 /// might be missing `krate`. This can happen if a module's file is not included 185 /// might be missing `krate`. This can happen if a module's file is not included
137 /// in the module tree of any target in `Cargo.toml`. 186 /// in the module tree of any target in `Cargo.toml`.
138 pub fn crate_root(&self, db: &impl DefDatabase) -> Module { 187 pub fn crate_root(self, db: &impl DefDatabase) -> Module {
139 self.crate_root_impl(db) 188 let def_map = db.crate_def_map(self.krate);
189 self.with_module_id(def_map.root())
140 } 190 }
141 191
142 /// Finds a child module with the specified name. 192 /// Finds a child module with the specified name.
143 pub fn child(&self, db: &impl HirDatabase, name: &Name) -> Option<Module> { 193 pub fn child(self, db: &impl HirDatabase, name: &Name) -> Option<Module> {
144 self.child_impl(db, name) 194 let def_map = db.crate_def_map(self.krate);
195 let child_id = def_map[self.module_id].children.get(name)?;
196 Some(self.with_module_id(*child_id))
145 } 197 }
146 198
147 /// Iterates over all child modules. 199 /// Iterates over all child modules.
148 pub fn children(&self, db: &impl DefDatabase) -> impl Iterator<Item = Module> { 200 pub fn children(self, db: &impl DefDatabase) -> impl Iterator<Item = Module> {
149 self.children_impl(db) 201 let def_map = db.crate_def_map(self.krate);
202 let children = def_map[self.module_id]
203 .children
204 .iter()
205 .map(|(_, module_id)| self.with_module_id(*module_id))
206 .collect::<Vec<_>>();
207 children.into_iter()
150 } 208 }
151 209
152 /// Finds a parent module. 210 /// Finds a parent module.
153 pub fn parent(&self, db: &impl DefDatabase) -> Option<Module> { 211 pub fn parent(self, db: &impl DefDatabase) -> Option<Module> {
154 self.parent_impl(db) 212 let def_map = db.crate_def_map(self.krate);
213 let parent_id = def_map[self.module_id].parent?;
214 Some(self.with_module_id(parent_id))
155 } 215 }
156 216
157 pub fn path_to_root(&self, db: &impl HirDatabase) -> Vec<Module> { 217 pub fn path_to_root(self, db: &impl HirDatabase) -> Vec<Module> {
158 let mut res = vec![self.clone()]; 218 let mut res = vec![self.clone()];
159 let mut curr = self.clone(); 219 let mut curr = self.clone();
160 while let Some(next) = curr.parent(db) { 220 while let Some(next) = curr.parent(db) {
@@ -165,11 +225,11 @@ impl Module {
165 } 225 }
166 226
167 /// Returns a `ModuleScope`: a set of items, visible in this module. 227 /// Returns a `ModuleScope`: a set of items, visible in this module.
168 pub fn scope(&self, db: &impl HirDatabase) -> ModuleScope { 228 pub fn scope(self, db: &impl HirDatabase) -> ModuleScope {
169 db.crate_def_map(self.krate)[self.module_id].scope.clone() 229 db.crate_def_map(self.krate)[self.module_id].scope.clone()
170 } 230 }
171 231
172 pub fn diagnostics(&self, db: &impl HirDatabase, sink: &mut DiagnosticSink) { 232 pub fn diagnostics(self, db: &impl HirDatabase, sink: &mut DiagnosticSink) {
173 db.crate_def_map(self.krate).add_diagnostics(db, self.module_id, sink); 233 db.crate_def_map(self.krate).add_diagnostics(db, self.module_id, sink);
174 for decl in self.declarations(db) { 234 for decl in self.declarations(db) {
175 match decl { 235 match decl {
@@ -189,7 +249,7 @@ impl Module {
189 } 249 }
190 } 250 }
191 251
192 pub(crate) fn resolver(&self, db: &impl DefDatabase) -> Resolver { 252 pub(crate) fn resolver(self, db: &impl DefDatabase) -> Resolver {
193 let def_map = db.crate_def_map(self.krate); 253 let def_map = db.crate_def_map(self.krate);
194 Resolver::default().push_module_scope(def_map, self.module_id) 254 Resolver::default().push_module_scope(def_map, self.module_id)
195 } 255 }
@@ -214,6 +274,10 @@ impl Module {
214 .map(|(impl_id, _)| ImplBlock::from_id(self, impl_id)) 274 .map(|(impl_id, _)| ImplBlock::from_id(self, impl_id))
215 .collect() 275 .collect()
216 } 276 }
277
278 fn with_module_id(&self, module_id: CrateModuleId) -> Module {
279 Module { module_id, krate: self.krate }
280 }
217} 281}
218 282
219impl Docs for Module { 283impl Docs for Module {
@@ -267,49 +331,49 @@ pub struct Struct {
267} 331}
268 332
269impl Struct { 333impl Struct {
270 pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::StructDef>) { 334 pub fn source(self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::StructDef>) {
271 self.id.source(db) 335 self.id.source(db)
272 } 336 }
273 337
274 pub fn module(&self, db: &impl HirDatabase) -> Module { 338 pub fn module(self, db: &impl HirDatabase) -> Module {
275 self.id.module(db) 339 self.id.module(db)
276 } 340 }
277 341
278 pub fn name(&self, db: &impl HirDatabase) -> Option<Name> { 342 pub fn name(self, db: &impl HirDatabase) -> Option<Name> {
279 db.struct_data(*self).name.clone() 343 db.struct_data(self).name.clone()
280 } 344 }
281 345
282 pub fn fields(&self, db: &impl HirDatabase) -> Vec<StructField> { 346 pub fn fields(self, db: &impl HirDatabase) -> Vec<StructField> {
283 db.struct_data(*self) 347 db.struct_data(self)
284 .variant_data 348 .variant_data
285 .fields() 349 .fields()
286 .into_iter() 350 .into_iter()
287 .flat_map(|it| it.iter()) 351 .flat_map(|it| it.iter())
288 .map(|(id, _)| StructField { parent: (*self).into(), id }) 352 .map(|(id, _)| StructField { parent: self.into(), id })
289 .collect() 353 .collect()
290 } 354 }
291 355
292 pub fn field(&self, db: &impl HirDatabase, name: &Name) -> Option<StructField> { 356 pub fn field(self, db: &impl HirDatabase, name: &Name) -> Option<StructField> {
293 db.struct_data(*self) 357 db.struct_data(self)
294 .variant_data 358 .variant_data
295 .fields() 359 .fields()
296 .into_iter() 360 .into_iter()
297 .flat_map(|it| it.iter()) 361 .flat_map(|it| it.iter())
298 .find(|(_id, data)| data.name == *name) 362 .find(|(_id, data)| data.name == *name)
299 .map(|(id, _)| StructField { parent: (*self).into(), id }) 363 .map(|(id, _)| StructField { parent: self.into(), id })
300 } 364 }
301 365
302 pub fn ty(&self, db: &impl HirDatabase) -> Ty { 366 pub fn ty(self, db: &impl HirDatabase) -> Ty {
303 db.type_for_def((*self).into(), Namespace::Types) 367 db.type_for_def(self.into(), Namespace::Types)
304 } 368 }
305 369
306 pub fn constructor_ty(&self, db: &impl HirDatabase) -> Ty { 370 pub fn constructor_ty(self, db: &impl HirDatabase) -> Ty {
307 db.type_for_def((*self).into(), Namespace::Values) 371 db.type_for_def(self.into(), Namespace::Values)
308 } 372 }
309 373
310 // FIXME move to a more general type 374 // FIXME move to a more general type
311 /// Builds a resolver for type references inside this struct. 375 /// Builds a resolver for type references inside this struct.
312 pub(crate) fn resolver(&self, db: &impl HirDatabase) -> Resolver { 376 pub(crate) fn resolver(self, db: &impl HirDatabase) -> Resolver {
313 // take the outer scope... 377 // take the outer scope...
314 let r = self.module(db).resolver(db); 378 let r = self.module(db).resolver(db);
315 // ...and add generic params, if present 379 // ...and add generic params, if present
@@ -326,46 +390,78 @@ impl Docs for Struct {
326} 390}
327 391
328#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 392#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
393pub struct Union {
394 pub(crate) id: StructId,
395}
396
397impl Union {
398 pub fn source(self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::StructDef>) {
399 self.id.source(db)
400 }
401
402 pub fn name(self, db: &impl HirDatabase) -> Option<Name> {
403 db.struct_data(Struct { id: self.id }).name.clone()
404 }
405
406 pub fn module(self, db: &impl HirDatabase) -> Module {
407 self.id.module(db)
408 }
409
410 // FIXME move to a more general type
411 /// Builds a resolver for type references inside this union.
412 pub(crate) fn resolver(self, db: &impl HirDatabase) -> Resolver {
413 // take the outer scope...
414 let r = self.module(db).resolver(db);
415 // ...and add generic params, if present
416 let p = self.generic_params(db);
417 let r = if !p.params.is_empty() { r.push_generic_params_scope(p) } else { r };
418 r
419 }
420}
421
422impl Docs for Union {
423 fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
424 docs_from_ast(&*self.source(db).1)
425 }
426}
427
428#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
329pub struct Enum { 429pub struct Enum {
330 pub(crate) id: EnumId, 430 pub(crate) id: EnumId,
331} 431}
332 432
333impl Enum { 433impl Enum {
334 pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::EnumDef>) { 434 pub fn source(self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::EnumDef>) {
335 self.id.source(db) 435 self.id.source(db)
336 } 436 }
337 437
338 pub fn module(&self, db: &impl HirDatabase) -> Module { 438 pub fn module(self, db: &impl HirDatabase) -> Module {
339 self.id.module(db) 439 self.id.module(db)
340 } 440 }
341 441
342 pub fn name(&self, db: &impl HirDatabase) -> Option<Name> { 442 pub fn name(self, db: &impl HirDatabase) -> Option<Name> {
343 db.enum_data(*self).name.clone() 443 db.enum_data(self).name.clone()
344 } 444 }
345 445
346 pub fn variants(&self, db: &impl DefDatabase) -> Vec<EnumVariant> { 446 pub fn variants(self, db: &impl DefDatabase) -> Vec<EnumVariant> {
347 db.enum_data(*self) 447 db.enum_data(self).variants.iter().map(|(id, _)| EnumVariant { parent: self, id }).collect()
348 .variants
349 .iter()
350 .map(|(id, _)| EnumVariant { parent: *self, id })
351 .collect()
352 } 448 }
353 449
354 pub fn variant(&self, db: &impl DefDatabase, name: &Name) -> Option<EnumVariant> { 450 pub fn variant(self, db: &impl DefDatabase, name: &Name) -> Option<EnumVariant> {
355 db.enum_data(*self) 451 db.enum_data(self)
356 .variants 452 .variants
357 .iter() 453 .iter()
358 .find(|(_id, data)| data.name.as_ref() == Some(name)) 454 .find(|(_id, data)| data.name.as_ref() == Some(name))
359 .map(|(id, _)| EnumVariant { parent: *self, id }) 455 .map(|(id, _)| EnumVariant { parent: self, id })
360 } 456 }
361 457
362 pub fn ty(&self, db: &impl HirDatabase) -> Ty { 458 pub fn ty(self, db: &impl HirDatabase) -> Ty {
363 db.type_for_def((*self).into(), Namespace::Types) 459 db.type_for_def(self.into(), Namespace::Types)
364 } 460 }
365 461
366 // FIXME: move to a more general type 462 // FIXME: move to a more general type
367 /// Builds a resolver for type references inside this struct. 463 /// Builds a resolver for type references inside this struct.
368 pub(crate) fn resolver(&self, db: &impl HirDatabase) -> Resolver { 464 pub(crate) fn resolver(self, db: &impl HirDatabase) -> Resolver {
369 // take the outer scope... 465 // take the outer scope...
370 let r = self.module(db).resolver(db); 466 let r = self.module(db).resolver(db);
371 // ...and add generic params, if present 467 // ...and add generic params, if present
@@ -438,16 +534,16 @@ pub enum DefWithBody {
438impl_froms!(DefWithBody: Function, Const, Static); 534impl_froms!(DefWithBody: Function, Const, Static);
439 535
440impl DefWithBody { 536impl DefWithBody {
441 pub fn infer(&self, db: &impl HirDatabase) -> Arc<InferenceResult> { 537 pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> {
442 db.infer(*self) 538 db.infer(self)
443 } 539 }
444 540
445 pub fn body(&self, db: &impl HirDatabase) -> Arc<Body> { 541 pub fn body(self, db: &impl HirDatabase) -> Arc<Body> {
446 db.body_hir(*self) 542 db.body_hir(self)
447 } 543 }
448 544
449 pub fn body_source_map(&self, db: &impl HirDatabase) -> Arc<BodySourceMap> { 545 pub fn body_source_map(self, db: &impl HirDatabase) -> Arc<BodySourceMap> {
450 db.body_with_source_map(*self).1 546 db.body_with_source_map(self).1
451 } 547 }
452 548
453 /// Builds a resolver for code inside this item. 549 /// Builds a resolver for code inside this item.
@@ -477,6 +573,44 @@ pub struct FnSignature {
477} 573}
478 574
479impl FnSignature { 575impl FnSignature {
576 pub(crate) fn fn_signature_query(db: &impl DefDatabase, func: Function) -> Arc<FnSignature> {
577 let (_, node) = func.source(db);
578 let name = node.name().map(|n| n.as_name()).unwrap_or_else(Name::missing);
579 let mut params = Vec::new();
580 let mut has_self_param = false;
581 if let Some(param_list) = node.param_list() {
582 if let Some(self_param) = param_list.self_param() {
583 let self_type = if let Some(type_ref) = self_param.ascribed_type() {
584 TypeRef::from_ast(type_ref)
585 } else {
586 let self_type = TypeRef::Path(Name::self_type().into());
587 match self_param.kind() {
588 ast::SelfParamKind::Owned => self_type,
589 ast::SelfParamKind::Ref => {
590 TypeRef::Reference(Box::new(self_type), Mutability::Shared)
591 }
592 ast::SelfParamKind::MutRef => {
593 TypeRef::Reference(Box::new(self_type), Mutability::Mut)
594 }
595 }
596 };
597 params.push(self_type);
598 has_self_param = true;
599 }
600 for param in param_list.params() {
601 let type_ref = TypeRef::from_ast_opt(param.ascribed_type());
602 params.push(type_ref);
603 }
604 }
605 let ret_type = if let Some(type_ref) = node.ret_type().and_then(|rt| rt.type_ref()) {
606 TypeRef::from_ast(type_ref)
607 } else {
608 TypeRef::unit()
609 };
610
611 let sig = FnSignature { name, params, ret_type, has_self_param };
612 Arc::new(sig)
613 }
480 pub fn name(&self) -> &Name { 614 pub fn name(&self) -> &Name {
481 &self.name 615 &self.name
482 } 616 }
@@ -497,50 +631,50 @@ impl FnSignature {
497} 631}
498 632
499impl Function { 633impl Function {
500 pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::FnDef>) { 634 pub fn source(self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::FnDef>) {
501 self.id.source(db) 635 self.id.source(db)
502 } 636 }
503 637
504 pub fn module(&self, db: &impl DefDatabase) -> Module { 638 pub fn module(self, db: &impl DefDatabase) -> Module {
505 self.id.module(db) 639 self.id.module(db)
506 } 640 }
507 641
508 pub fn name(&self, db: &impl HirDatabase) -> Name { 642 pub fn name(self, db: &impl HirDatabase) -> Name {
509 self.signature(db).name.clone() 643 self.signature(db).name.clone()
510 } 644 }
511 645
512 pub(crate) fn body_source_map(&self, db: &impl HirDatabase) -> Arc<BodySourceMap> { 646 pub(crate) fn body_source_map(self, db: &impl HirDatabase) -> Arc<BodySourceMap> {
513 db.body_with_source_map((*self).into()).1 647 db.body_with_source_map(self.into()).1
514 } 648 }
515 649
516 pub fn body(&self, db: &impl HirDatabase) -> Arc<Body> { 650 pub fn body(self, db: &impl HirDatabase) -> Arc<Body> {
517 db.body_hir((*self).into()) 651 db.body_hir(self.into())
518 } 652 }
519 653
520 pub fn ty(&self, db: &impl HirDatabase) -> Ty { 654 pub fn ty(self, db: &impl HirDatabase) -> Ty {
521 db.type_for_def((*self).into(), Namespace::Values) 655 db.type_for_def(self.into(), Namespace::Values)
522 } 656 }
523 657
524 pub fn signature(&self, db: &impl HirDatabase) -> Arc<FnSignature> { 658 pub fn signature(self, db: &impl HirDatabase) -> Arc<FnSignature> {
525 db.fn_signature(*self) 659 db.fn_signature(self)
526 } 660 }
527 661
528 pub fn infer(&self, db: &impl HirDatabase) -> Arc<InferenceResult> { 662 pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> {
529 db.infer((*self).into()) 663 db.infer(self.into())
530 } 664 }
531 665
532 /// The containing impl block, if this is a method. 666 /// The containing impl block, if this is a method.
533 pub fn impl_block(&self, db: &impl DefDatabase) -> Option<ImplBlock> { 667 pub fn impl_block(self, db: &impl DefDatabase) -> Option<ImplBlock> {
534 let module_impls = db.impls_in_module(self.module(db)); 668 let module_impls = db.impls_in_module(self.module(db));
535 ImplBlock::containing(module_impls, (*self).into()) 669 ImplBlock::containing(module_impls, self.into())
536 } 670 }
537 671
538 /// The containing trait, if this is a trait method definition. 672 /// The containing trait, if this is a trait method definition.
539 pub fn parent_trait(&self, db: &impl DefDatabase) -> Option<Trait> { 673 pub fn parent_trait(self, db: &impl DefDatabase) -> Option<Trait> {
540 db.trait_items_index(self.module(db)).get_parent_trait((*self).into()) 674 db.trait_items_index(self.module(db)).get_parent_trait(self.into())
541 } 675 }
542 676
543 pub fn container(&self, db: &impl DefDatabase) -> Option<Container> { 677 pub fn container(self, db: &impl DefDatabase) -> Option<Container> {
544 if let Some(impl_block) = self.impl_block(db) { 678 if let Some(impl_block) = self.impl_block(db) {
545 Some(impl_block.into()) 679 Some(impl_block.into())
546 } else if let Some(trait_) = self.parent_trait(db) { 680 } else if let Some(trait_) = self.parent_trait(db) {
@@ -552,7 +686,7 @@ impl Function {
552 686
553 // FIXME: move to a more general type for 'body-having' items 687 // FIXME: move to a more general type for 'body-having' items
554 /// Builds a resolver for code inside this item. 688 /// Builds a resolver for code inside this item.
555 pub(crate) fn resolver(&self, db: &impl HirDatabase) -> Resolver { 689 pub(crate) fn resolver(self, db: &impl HirDatabase) -> Resolver {
556 // take the outer scope... 690 // take the outer scope...
557 let r = self.container(db).map_or_else(|| self.module(db).resolver(db), |c| c.resolver(db)); 691 let r = self.container(db).map_or_else(|| self.module(db).resolver(db), |c| c.resolver(db));
558 // ...and add generic params, if present 692 // ...and add generic params, if present
@@ -561,10 +695,10 @@ impl Function {
561 r 695 r
562 } 696 }
563 697
564 pub fn diagnostics(&self, db: &impl HirDatabase, sink: &mut DiagnosticSink) { 698 pub fn diagnostics(self, db: &impl HirDatabase, sink: &mut DiagnosticSink) {
565 let infer = self.infer(db); 699 let infer = self.infer(db);
566 infer.add_diagnostics(db, *self, sink); 700 infer.add_diagnostics(db, self, sink);
567 let mut validator = ExprValidator::new(*self, infer, sink); 701 let mut validator = ExprValidator::new(self, infer, sink);
568 validator.validate_body(db); 702 validator.validate_body(db);
569 } 703 }
570} 704}
@@ -581,31 +715,31 @@ pub struct Const {
581} 715}
582 716
583impl Const { 717impl Const {
584 pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::ConstDef>) { 718 pub fn source(self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::ConstDef>) {
585 self.id.source(db) 719 self.id.source(db)
586 } 720 }
587 721
588 pub fn module(&self, db: &impl DefDatabase) -> Module { 722 pub fn module(self, db: &impl DefDatabase) -> Module {
589 self.id.module(db) 723 self.id.module(db)
590 } 724 }
591 725
592 pub fn signature(&self, db: &impl HirDatabase) -> Arc<ConstSignature> { 726 pub fn signature(self, db: &impl HirDatabase) -> Arc<ConstSignature> {
593 db.const_signature(*self) 727 db.const_signature(self)
594 } 728 }
595 729
596 pub fn infer(&self, db: &impl HirDatabase) -> Arc<InferenceResult> { 730 pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> {
597 db.infer((*self).into()) 731 db.infer(self.into())
598 } 732 }
599 733
600 /// The containing impl block, if this is a method. 734 /// The containing impl block, if this is a method.
601 pub fn impl_block(&self, db: &impl DefDatabase) -> Option<ImplBlock> { 735 pub fn impl_block(self, db: &impl DefDatabase) -> Option<ImplBlock> {
602 let module_impls = db.impls_in_module(self.module(db)); 736 let module_impls = db.impls_in_module(self.module(db));
603 ImplBlock::containing(module_impls, (*self).into()) 737 ImplBlock::containing(module_impls, self.into())
604 } 738 }
605 739
606 // FIXME: move to a more general type for 'body-having' items 740 // FIXME: move to a more general type for 'body-having' items
607 /// Builds a resolver for code inside this item. 741 /// Builds a resolver for code inside this item.
608 pub(crate) fn resolver(&self, db: &impl HirDatabase) -> Resolver { 742 pub(crate) fn resolver(self, db: &impl HirDatabase) -> Resolver {
609 // take the outer scope... 743 // take the outer scope...
610 let r = self 744 let r = self
611 .impl_block(db) 745 .impl_block(db)
@@ -636,6 +770,29 @@ impl ConstSignature {
636 pub fn type_ref(&self) -> &TypeRef { 770 pub fn type_ref(&self) -> &TypeRef {
637 &self.type_ref 771 &self.type_ref
638 } 772 }
773
774 pub(crate) fn const_signature_query(
775 db: &impl DefDatabase,
776 konst: Const,
777 ) -> Arc<ConstSignature> {
778 let (_, node) = konst.source(db);
779 const_signature_for(&*node)
780 }
781
782 pub(crate) fn static_signature_query(
783 db: &impl DefDatabase,
784 konst: Static,
785 ) -> Arc<ConstSignature> {
786 let (_, node) = konst.source(db);
787 const_signature_for(&*node)
788 }
789}
790
791fn const_signature_for<N: NameOwner + TypeAscriptionOwner>(node: &N) -> Arc<ConstSignature> {
792 let name = node.name().map(|n| n.as_name()).unwrap_or_else(Name::missing);
793 let type_ref = TypeRef::from_ast_opt(node.ascribed_type());
794 let sig = ConstSignature { name, type_ref };
795 Arc::new(sig)
639} 796}
640 797
641#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 798#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
@@ -644,26 +801,26 @@ pub struct Static {
644} 801}
645 802
646impl Static { 803impl Static {
647 pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::StaticDef>) { 804 pub fn source(self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::StaticDef>) {
648 self.id.source(db) 805 self.id.source(db)
649 } 806 }
650 807
651 pub fn module(&self, db: &impl DefDatabase) -> Module { 808 pub fn module(self, db: &impl DefDatabase) -> Module {
652 self.id.module(db) 809 self.id.module(db)
653 } 810 }
654 811
655 pub fn signature(&self, db: &impl HirDatabase) -> Arc<ConstSignature> { 812 pub fn signature(self, db: &impl HirDatabase) -> Arc<ConstSignature> {
656 db.static_signature(*self) 813 db.static_signature(self)
657 } 814 }
658 815
659 /// Builds a resolver for code inside this item. 816 /// Builds a resolver for code inside this item.
660 pub(crate) fn resolver(&self, db: &impl HirDatabase) -> Resolver { 817 pub(crate) fn resolver(self, db: &impl HirDatabase) -> Resolver {
661 // take the outer scope... 818 // take the outer scope...
662 self.module(db).resolver(db) 819 self.module(db).resolver(db)
663 } 820 }
664 821
665 pub fn infer(&self, db: &impl HirDatabase) -> Arc<InferenceResult> { 822 pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> {
666 db.infer((*self).into()) 823 db.infer(self.into())
667 } 824 }
668} 825}
669 826
@@ -679,11 +836,11 @@ pub struct Trait {
679} 836}
680 837
681impl Trait { 838impl Trait {
682 pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::TraitDef>) { 839 pub fn source(self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::TraitDef>) {
683 self.id.source(db) 840 self.id.source(db)
684 } 841 }
685 842
686 pub fn module(&self, db: &impl DefDatabase) -> Module { 843 pub fn module(self, db: &impl DefDatabase) -> Module {
687 self.id.module(db) 844 self.id.module(db)
688 } 845 }
689 846
@@ -707,7 +864,7 @@ impl Trait {
707 self.trait_data(db).is_auto() 864 self.trait_data(db).is_auto()
708 } 865 }
709 866
710 pub(crate) fn resolver(&self, db: &impl DefDatabase) -> Resolver { 867 pub(crate) fn resolver(self, db: &impl DefDatabase) -> Resolver {
711 let r = self.module(db).resolver(db); 868 let r = self.module(db).resolver(db);
712 // add generic params, if present 869 // add generic params, if present
713 let p = self.generic_params(db); 870 let p = self.generic_params(db);
@@ -728,26 +885,26 @@ pub struct TypeAlias {
728} 885}
729 886
730impl TypeAlias { 887impl TypeAlias {
731 pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::TypeAliasDef>) { 888 pub fn source(self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::TypeAliasDef>) {
732 self.id.source(db) 889 self.id.source(db)
733 } 890 }
734 891
735 pub fn module(&self, db: &impl DefDatabase) -> Module { 892 pub fn module(self, db: &impl DefDatabase) -> Module {
736 self.id.module(db) 893 self.id.module(db)
737 } 894 }
738 895
739 /// The containing impl block, if this is a method. 896 /// The containing impl block, if this is a method.
740 pub fn impl_block(&self, db: &impl DefDatabase) -> Option<ImplBlock> { 897 pub fn impl_block(self, db: &impl DefDatabase) -> Option<ImplBlock> {
741 let module_impls = db.impls_in_module(self.module(db)); 898 let module_impls = db.impls_in_module(self.module(db));
742 ImplBlock::containing(module_impls, (*self).into()) 899 ImplBlock::containing(module_impls, self.into())
743 } 900 }
744 901
745 /// The containing trait, if this is a trait method definition. 902 /// The containing trait, if this is a trait method definition.
746 pub fn parent_trait(&self, db: &impl DefDatabase) -> Option<Trait> { 903 pub fn parent_trait(self, db: &impl DefDatabase) -> Option<Trait> {
747 db.trait_items_index(self.module(db)).get_parent_trait((*self).into()) 904 db.trait_items_index(self.module(db)).get_parent_trait(self.into())
748 } 905 }
749 906
750 pub fn container(&self, db: &impl DefDatabase) -> Option<Container> { 907 pub fn container(self, db: &impl DefDatabase) -> Option<Container> {
751 if let Some(impl_block) = self.impl_block(db) { 908 if let Some(impl_block) = self.impl_block(db) {
752 Some(impl_block.into()) 909 Some(impl_block.into())
753 } else if let Some(trait_) = self.parent_trait(db) { 910 } else if let Some(trait_) = self.parent_trait(db) {
@@ -762,7 +919,7 @@ impl TypeAlias {
762 } 919 }
763 920
764 /// Builds a resolver for the type references in this type alias. 921 /// Builds a resolver for the type references in this type alias.
765 pub(crate) fn resolver(&self, db: &impl HirDatabase) -> Resolver { 922 pub(crate) fn resolver(self, db: &impl HirDatabase) -> Resolver {
766 // take the outer scope... 923 // take the outer scope...
767 let r = self 924 let r = self
768 .impl_block(db) 925 .impl_block(db)
@@ -788,7 +945,7 @@ pub enum Container {
788impl_froms!(Container: Trait, ImplBlock); 945impl_froms!(Container: Trait, ImplBlock);
789 946
790impl Container { 947impl Container {
791 pub(crate) fn resolver(&self, db: &impl DefDatabase) -> Resolver { 948 pub(crate) fn resolver(self, db: &impl DefDatabase) -> Resolver {
792 match self { 949 match self {
793 Container::Trait(trait_) => trait_.resolver(db), 950 Container::Trait(trait_) => trait_.resolver(db),
794 Container::ImplBlock(impl_block) => impl_block.resolver(db), 951 Container::ImplBlock(impl_block) => impl_block.resolver(db),
diff --git a/crates/ra_hir/src/code_model_impl.rs b/crates/ra_hir/src/code_model_impl.rs
deleted file mode 100644
index 24df9a113..000000000
--- a/crates/ra_hir/src/code_model_impl.rs
+++ /dev/null
@@ -1,4 +0,0 @@
1mod krate; // `crate` is invalid ident :(
2mod konst; // `const` is invalid ident :(
3mod module;
4pub(crate) mod function;
diff --git a/crates/ra_hir/src/code_model_impl/function.rs b/crates/ra_hir/src/code_model_impl/function.rs
deleted file mode 100644
index f8bd0f784..000000000
--- a/crates/ra_hir/src/code_model_impl/function.rs
+++ /dev/null
@@ -1,50 +0,0 @@
1use std::sync::Arc;
2
3use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner};
4
5use crate::{
6 Name, AsName, Function, FnSignature,
7 type_ref::{TypeRef, Mutability},
8 DefDatabase,
9};
10
11impl FnSignature {
12 pub(crate) fn fn_signature_query(db: &impl DefDatabase, func: Function) -> Arc<FnSignature> {
13 let (_, node) = func.source(db);
14 let name = node.name().map(|n| n.as_name()).unwrap_or_else(Name::missing);
15 let mut params = Vec::new();
16 let mut has_self_param = false;
17 if let Some(param_list) = node.param_list() {
18 if let Some(self_param) = param_list.self_param() {
19 let self_type = if let Some(type_ref) = self_param.ascribed_type() {
20 TypeRef::from_ast(type_ref)
21 } else {
22 let self_type = TypeRef::Path(Name::self_type().into());
23 match self_param.kind() {
24 ast::SelfParamKind::Owned => self_type,
25 ast::SelfParamKind::Ref => {
26 TypeRef::Reference(Box::new(self_type), Mutability::Shared)
27 }
28 ast::SelfParamKind::MutRef => {
29 TypeRef::Reference(Box::new(self_type), Mutability::Mut)
30 }
31 }
32 };
33 params.push(self_type);
34 has_self_param = true;
35 }
36 for param in param_list.params() {
37 let type_ref = TypeRef::from_ast_opt(param.ascribed_type());
38 params.push(type_ref);
39 }
40 }
41 let ret_type = if let Some(type_ref) = node.ret_type().and_then(|rt| rt.type_ref()) {
42 TypeRef::from_ast(type_ref)
43 } else {
44 TypeRef::unit()
45 };
46
47 let sig = FnSignature { name, params, ret_type, has_self_param };
48 Arc::new(sig)
49 }
50}
diff --git a/crates/ra_hir/src/code_model_impl/konst.rs b/crates/ra_hir/src/code_model_impl/konst.rs
deleted file mode 100644
index db4e5ce5c..000000000
--- a/crates/ra_hir/src/code_model_impl/konst.rs
+++ /dev/null
@@ -1,34 +0,0 @@
1use std::sync::Arc;
2
3use ra_syntax::ast::{NameOwner, TypeAscriptionOwner};
4
5use crate::{
6 Name, AsName, Const, ConstSignature, Static,
7 type_ref::{TypeRef},
8 DefDatabase,
9};
10
11fn const_signature_for<N: NameOwner + TypeAscriptionOwner>(node: &N) -> Arc<ConstSignature> {
12 let name = node.name().map(|n| n.as_name()).unwrap_or_else(Name::missing);
13 let type_ref = TypeRef::from_ast_opt(node.ascribed_type());
14 let sig = ConstSignature { name, type_ref };
15 Arc::new(sig)
16}
17
18impl ConstSignature {
19 pub(crate) fn const_signature_query(
20 db: &impl DefDatabase,
21 konst: Const,
22 ) -> Arc<ConstSignature> {
23 let (_, node) = konst.source(db);
24 const_signature_for(&*node)
25 }
26
27 pub(crate) fn static_signature_query(
28 db: &impl DefDatabase,
29 konst: Static,
30 ) -> Arc<ConstSignature> {
31 let (_, node) = konst.source(db);
32 const_signature_for(&*node)
33 }
34}
diff --git a/crates/ra_hir/src/code_model_impl/krate.rs b/crates/ra_hir/src/code_model_impl/krate.rs
deleted file mode 100644
index 914414fc3..000000000
--- a/crates/ra_hir/src/code_model_impl/krate.rs
+++ /dev/null
@@ -1,22 +0,0 @@
1use crate::{
2 Crate, CrateDependency, AsName, Module, DefDatabase,
3};
4
5impl Crate {
6 pub(crate) fn dependencies_impl(&self, db: &impl DefDatabase) -> Vec<CrateDependency> {
7 let crate_graph = db.crate_graph();
8 crate_graph
9 .dependencies(self.crate_id)
10 .map(|dep| {
11 let krate = Crate { crate_id: dep.crate_id() };
12 let name = dep.as_name();
13 CrateDependency { krate, name }
14 })
15 .collect()
16 }
17 pub(crate) fn root_module_impl(&self, db: &impl DefDatabase) -> Option<Module> {
18 let module_id = db.crate_def_map(*self).root();
19 let module = Module { krate: *self, module_id };
20 Some(module)
21 }
22}
diff --git a/crates/ra_hir/src/code_model_impl/module.rs b/crates/ra_hir/src/code_model_impl/module.rs
deleted file mode 100644
index 5c2ea73ce..000000000
--- a/crates/ra_hir/src/code_model_impl/module.rs
+++ /dev/null
@@ -1,99 +0,0 @@
1use ra_db::FileId;
2use ra_syntax::{ast, TreeArc};
3
4use crate::{
5 Module, ModuleSource, Name, AstId,
6 nameres::CrateModuleId,
7 HirDatabase, DefDatabase,
8 HirFileId,
9};
10
11impl ModuleSource {
12 pub(crate) fn new(
13 db: &impl DefDatabase,
14 file_id: Option<FileId>,
15 decl_id: Option<AstId<ast::Module>>,
16 ) -> ModuleSource {
17 match (file_id, decl_id) {
18 (Some(file_id), _) => {
19 let source_file = db.parse(file_id);
20 ModuleSource::SourceFile(source_file)
21 }
22 (None, Some(item_id)) => {
23 let module = item_id.to_node(db);
24 assert!(module.item_list().is_some(), "expected inline module");
25 ModuleSource::Module(module.to_owned())
26 }
27 (None, None) => panic!(),
28 }
29 }
30}
31
32impl Module {
33 fn with_module_id(&self, module_id: CrateModuleId) -> Module {
34 Module { module_id, krate: self.krate }
35 }
36
37 pub(crate) fn name_impl(&self, db: &impl HirDatabase) -> Option<Name> {
38 let def_map = db.crate_def_map(self.krate);
39 let parent = def_map[self.module_id].parent?;
40 def_map[parent].children.iter().find_map(|(name, module_id)| {
41 if *module_id == self.module_id {
42 Some(name.clone())
43 } else {
44 None
45 }
46 })
47 }
48
49 pub(crate) fn definition_source_impl(
50 &self,
51 db: &impl DefDatabase,
52 ) -> (HirFileId, ModuleSource) {
53 let def_map = db.crate_def_map(self.krate);
54 let decl_id = def_map[self.module_id].declaration;
55 let file_id = def_map[self.module_id].definition;
56 let module_source = ModuleSource::new(db, file_id, decl_id);
57 let file_id = file_id.map(HirFileId::from).unwrap_or_else(|| decl_id.unwrap().file_id());
58 (file_id, module_source)
59 }
60
61 pub(crate) fn declaration_source_impl(
62 &self,
63 db: &impl HirDatabase,
64 ) -> Option<(HirFileId, TreeArc<ast::Module>)> {
65 let def_map = db.crate_def_map(self.krate);
66 let decl = def_map[self.module_id].declaration?;
67 let ast = decl.to_node(db);
68 Some((decl.file_id(), ast))
69 }
70
71 pub(crate) fn crate_root_impl(&self, db: &impl DefDatabase) -> Module {
72 let def_map = db.crate_def_map(self.krate);
73 self.with_module_id(def_map.root())
74 }
75
76 /// Finds a child module with the specified name.
77 pub(crate) fn child_impl(&self, db: &impl HirDatabase, name: &Name) -> Option<Module> {
78 let def_map = db.crate_def_map(self.krate);
79 let child_id = def_map[self.module_id].children.get(name)?;
80 Some(self.with_module_id(*child_id))
81 }
82
83 /// Iterates over all child modules.
84 pub(crate) fn children_impl(&self, db: &impl DefDatabase) -> impl Iterator<Item = Module> {
85 let def_map = db.crate_def_map(self.krate);
86 let children = def_map[self.module_id]
87 .children
88 .iter()
89 .map(|(_, module_id)| self.with_module_id(*module_id))
90 .collect::<Vec<_>>();
91 children.into_iter()
92 }
93
94 pub(crate) fn parent_impl(&self, db: &impl DefDatabase) -> Option<Module> {
95 let def_map = db.crate_def_map(self.krate);
96 let parent_id = def_map[self.module_id].parent?;
97 Some(self.with_module_id(parent_id))
98 }
99}
diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs
index 79a7fa23a..8effbbe35 100644
--- a/crates/ra_hir/src/generics.rs
+++ b/crates/ra_hir/src/generics.rs
@@ -9,7 +9,7 @@ use ra_syntax::ast::{self, NameOwner, TypeParamsOwner, TypeBoundsOwner, DefaultT
9 9
10use crate::{ 10use crate::{
11 db::{ HirDatabase, DefDatabase}, 11 db::{ HirDatabase, DefDatabase},
12 Name, AsName, Function, Struct, Enum, Trait, TypeAlias, ImplBlock, Container, path::Path, type_ref::TypeRef, AdtDef 12 Name, AsName, Function, Struct, Union, Enum, Trait, TypeAlias, ImplBlock, Container, path::Path, type_ref::TypeRef, AdtDef
13}; 13};
14 14
15/// Data about a generic parameter (to a function, struct, impl, ...). 15/// Data about a generic parameter (to a function, struct, impl, ...).
@@ -42,12 +42,13 @@ pub struct WherePredicate {
42pub enum GenericDef { 42pub enum GenericDef {
43 Function(Function), 43 Function(Function),
44 Struct(Struct), 44 Struct(Struct),
45 Union(Union),
45 Enum(Enum), 46 Enum(Enum),
46 Trait(Trait), 47 Trait(Trait),
47 TypeAlias(TypeAlias), 48 TypeAlias(TypeAlias),
48 ImplBlock(ImplBlock), 49 ImplBlock(ImplBlock),
49} 50}
50impl_froms!(GenericDef: Function, Struct, Enum, Trait, TypeAlias, ImplBlock); 51impl_froms!(GenericDef: Function, Struct, Union, Enum, Trait, TypeAlias, ImplBlock);
51 52
52impl GenericParams { 53impl GenericParams {
53 pub(crate) fn generic_params_query( 54 pub(crate) fn generic_params_query(
@@ -58,7 +59,10 @@ impl GenericParams {
58 let parent = match def { 59 let parent = match def {
59 GenericDef::Function(it) => it.container(db).map(GenericDef::from), 60 GenericDef::Function(it) => it.container(db).map(GenericDef::from),
60 GenericDef::TypeAlias(it) => it.container(db).map(GenericDef::from), 61 GenericDef::TypeAlias(it) => it.container(db).map(GenericDef::from),
61 GenericDef::Struct(_) | GenericDef::Enum(_) | GenericDef::Trait(_) => None, 62 GenericDef::Struct(_)
63 | GenericDef::Union(_)
64 | GenericDef::Enum(_)
65 | GenericDef::Trait(_) => None,
62 GenericDef::ImplBlock(_) => None, 66 GenericDef::ImplBlock(_) => None,
63 }; 67 };
64 generics.parent_params = parent.map(|p| db.generic_params(p)); 68 generics.parent_params = parent.map(|p| db.generic_params(p));
@@ -66,6 +70,7 @@ impl GenericParams {
66 match def { 70 match def {
67 GenericDef::Function(it) => generics.fill(&*it.source(db).1, start), 71 GenericDef::Function(it) => generics.fill(&*it.source(db).1, start),
68 GenericDef::Struct(it) => generics.fill(&*it.source(db).1, start), 72 GenericDef::Struct(it) => generics.fill(&*it.source(db).1, start),
73 GenericDef::Union(it) => generics.fill(&*it.source(db).1, start),
69 GenericDef::Enum(it) => generics.fill(&*it.source(db).1, start), 74 GenericDef::Enum(it) => generics.fill(&*it.source(db).1, start),
70 GenericDef::Trait(it) => { 75 GenericDef::Trait(it) => {
71 // traits get the Self type as an implicit first type parameter 76 // traits get the Self type as an implicit first type parameter
@@ -171,6 +176,7 @@ impl GenericDef {
171 match self { 176 match self {
172 GenericDef::Function(inner) => inner.resolver(db), 177 GenericDef::Function(inner) => inner.resolver(db),
173 GenericDef::Struct(inner) => inner.resolver(db), 178 GenericDef::Struct(inner) => inner.resolver(db),
179 GenericDef::Union(inner) => inner.resolver(db),
174 GenericDef::Enum(inner) => inner.resolver(db), 180 GenericDef::Enum(inner) => inner.resolver(db),
175 GenericDef::Trait(inner) => inner.resolver(db), 181 GenericDef::Trait(inner) => inner.resolver(db),
176 GenericDef::TypeAlias(inner) => inner.resolver(db), 182 GenericDef::TypeAlias(inner) => inner.resolver(db),
@@ -192,6 +198,7 @@ impl From<crate::adt::AdtDef> for GenericDef {
192 fn from(adt: crate::adt::AdtDef) -> Self { 198 fn from(adt: crate::adt::AdtDef) -> Self {
193 match adt { 199 match adt {
194 AdtDef::Struct(s) => s.into(), 200 AdtDef::Struct(s) => s.into(),
201 AdtDef::Union(u) => u.into(),
195 AdtDef::Enum(e) => e.into(), 202 AdtDef::Enum(e) => e.into(),
196 } 203 }
197 } 204 }
diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs
index 51fa491c3..637f6ab83 100644
--- a/crates/ra_hir/src/impl_block.rs
+++ b/crates/ra_hir/src/impl_block.rs
@@ -15,7 +15,7 @@ use crate::{
15 resolve::Resolver, 15 resolve::Resolver,
16 ty::Ty, 16 ty::Ty,
17 generics::HasGenericParams, 17 generics::HasGenericParams,
18 code_model_api::{Module, ModuleSource} 18 code_model::{Module, ModuleSource}
19}; 19};
20 20
21#[derive(Debug, Default, PartialEq, Eq)] 21#[derive(Debug, Default, PartialEq, Eq)]
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index 0c6d7c2b7..fe2d4adee 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -42,8 +42,7 @@ mod docs;
42mod resolve; 42mod resolve;
43pub mod diagnostics; 43pub mod diagnostics;
44 44
45mod code_model_api; 45mod code_model;
46mod code_model_impl;
47 46
48#[cfg(test)] 47#[cfg(test)]
49mod marks; 48mod marks;
@@ -73,11 +72,11 @@ pub use self::{
73 source_binder::{SourceAnalyzer, PathResolution, ScopeEntryWithSyntax,MacroByExampleDef}, 72 source_binder::{SourceAnalyzer, PathResolution, ScopeEntryWithSyntax,MacroByExampleDef},
74}; 73};
75 74
76pub use self::code_model_api::{ 75pub use self::code_model::{
77 Crate, CrateDependency, 76 Crate, CrateDependency,
78 DefWithBody, 77 DefWithBody,
79 Module, ModuleDef, ModuleSource, 78 Module, ModuleDef, ModuleSource,
80 Struct, Enum, EnumVariant, 79 Struct, Union, Enum, EnumVariant,
81 Function, FnSignature, 80 Function, FnSignature,
82 StructField, FieldSource, 81 StructField, FieldSource,
83 Static, Const, ConstSignature, 82 Static, Const, ConstSignature,
diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs
index c615d80c3..621236551 100644
--- a/crates/ra_hir/src/nameres/collector.rs
+++ b/crates/ra_hir/src/nameres/collector.rs
@@ -6,7 +6,7 @@ use ra_db::FileId;
6use ra_syntax::ast; 6use ra_syntax::ast;
7 7
8use crate::{ 8use crate::{
9 Function, Module, Struct, Enum, Const, Static, Trait, TypeAlias, 9 Function, Module, Struct, Union, Enum, Const, Static, Trait, TypeAlias,
10 DefDatabase, HirFileId, Name, Path, 10 DefDatabase, HirFileId, Name, Path,
11 KnownName, 11 KnownName,
12 nameres::{ 12 nameres::{
@@ -495,6 +495,10 @@ where
495 let s = def!(Struct, ast_id); 495 let s = def!(Struct, ast_id);
496 PerNs::both(s, s) 496 PerNs::both(s, s)
497 } 497 }
498 raw::DefKind::Union(ast_id) => {
499 let s = def!(Union, ast_id);
500 PerNs::both(s, s)
501 }
498 raw::DefKind::Enum(ast_id) => PerNs::types(def!(Enum, ast_id)), 502 raw::DefKind::Enum(ast_id) => PerNs::types(def!(Enum, ast_id)),
499 raw::DefKind::Const(ast_id) => PerNs::values(def!(Const, ast_id)), 503 raw::DefKind::Const(ast_id) => PerNs::values(def!(Const, ast_id)),
500 raw::DefKind::Static(ast_id) => PerNs::values(def!(Static, ast_id)), 504 raw::DefKind::Static(ast_id) => PerNs::values(def!(Static, ast_id)),
diff --git a/crates/ra_hir/src/nameres/raw.rs b/crates/ra_hir/src/nameres/raw.rs
index bd32b264b..1b4dcbb7a 100644
--- a/crates/ra_hir/src/nameres/raw.rs
+++ b/crates/ra_hir/src/nameres/raw.rs
@@ -1,7 +1,4 @@
1use std::{ 1use std::{sync::Arc, ops::Index};
2 sync::Arc,
3 ops::Index,
4};
5 2
6use test_utils::tested_by; 3use test_utils::tested_by;
7use ra_arena::{Arena, impl_arena_id, RawId, map::ArenaMap}; 4use ra_arena::{Arena, impl_arena_id, RawId, map::ArenaMap};
@@ -10,10 +7,7 @@ use ra_syntax::{
10 ast::{self, NameOwner, AttrsOwner}, 7 ast::{self, NameOwner, AttrsOwner},
11}; 8};
12 9
13use crate::{ 10use crate::{DefDatabase, Name, AsName, Path, HirFileId, ModuleSource, AstIdMap, FileAstId, Either};
14 DefDatabase, Name, AsName, Path, HirFileId, ModuleSource,
15 AstIdMap, FileAstId, Either,
16};
17 11
18/// `RawItems` is a set of top-level items in a file (except for impls). 12/// `RawItems` is a set of top-level items in a file (except for impls).
19/// 13///
@@ -161,6 +155,7 @@ pub(super) struct DefData {
161pub(super) enum DefKind { 155pub(super) enum DefKind {
162 Function(FileAstId<ast::FnDef>), 156 Function(FileAstId<ast::FnDef>),
163 Struct(FileAstId<ast::StructDef>), 157 Struct(FileAstId<ast::StructDef>),
158 Union(FileAstId<ast::StructDef>),
164 Enum(FileAstId<ast::EnumDef>), 159 Enum(FileAstId<ast::EnumDef>),
165 Const(FileAstId<ast::ConstDef>), 160 Const(FileAstId<ast::ConstDef>),
166 Static(FileAstId<ast::StaticDef>), 161 Static(FileAstId<ast::StaticDef>),
@@ -215,7 +210,13 @@ impl RawItemsCollector {
215 return; 210 return;
216 } 211 }
217 ast::ModuleItemKind::StructDef(it) => { 212 ast::ModuleItemKind::StructDef(it) => {
218 (DefKind::Struct(self.source_ast_id_map.ast_id(it)), it.name()) 213 let id = self.source_ast_id_map.ast_id(it);
214 let name = it.name();
215 if it.is_union() {
216 (DefKind::Union(id), name)
217 } else {
218 (DefKind::Struct(id), name)
219 }
219 } 220 }
220 ast::ModuleItemKind::EnumDef(it) => { 221 ast::ModuleItemKind::EnumDef(it) => {
221 (DefKind::Enum(self.source_ast_id_map.ast_id(it)), it.name()) 222 (DefKind::Enum(self.source_ast_id_map.ast_id(it)), it.name())
diff --git a/crates/ra_hir/src/resolve.rs b/crates/ra_hir/src/resolve.rs
index 3874e28bf..fedfe2fee 100644
--- a/crates/ra_hir/src/resolve.rs
+++ b/crates/ra_hir/src/resolve.rs
@@ -5,7 +5,7 @@ use rustc_hash::{FxHashMap, FxHashSet};
5 5
6use crate::{ 6use crate::{
7 ModuleDef, Trait, 7 ModuleDef, Trait,
8 code_model_api::Crate, 8 code_model::Crate,
9 MacroDefId, 9 MacroDefId,
10 db::HirDatabase, 10 db::HirDatabase,
11 name::{Name, KnownName}, 11 name::{Name, KnownName},
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs
index 3679a2242..76d34c12b 100644
--- a/crates/ra_hir/src/ty.rs
+++ b/crates/ra_hir/src/ty.rs
@@ -536,6 +536,7 @@ impl HirDisplay for ApplicationTy {
536 TypeCtor::Adt(def_id) => { 536 TypeCtor::Adt(def_id) => {
537 let name = match def_id { 537 let name = match def_id {
538 AdtDef::Struct(s) => s.name(f.db), 538 AdtDef::Struct(s) => s.name(f.db),
539 AdtDef::Union(u) => u.name(f.db),
539 AdtDef::Enum(e) => e.name(f.db), 540 AdtDef::Enum(e) => e.name(f.db),
540 } 541 }
541 .unwrap_or_else(Name::missing); 542 .unwrap_or_else(Name::missing);
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs
index a48272981..7d8250292 100644
--- a/crates/ra_hir/src/ty/infer.rs
+++ b/crates/ra_hir/src/ty/infer.rs
@@ -27,13 +27,13 @@ use ra_prof::profile;
27use test_utils::tested_by; 27use test_utils::tested_by;
28 28
29use crate::{ 29use crate::{
30 Function, StructField, Path, Name, 30 Function, StructField, Path, Name, FnSignature, AdtDef, ConstSignature, HirDatabase,
31 FnSignature, AdtDef,ConstSignature, 31 DefWithBody, ImplItem,
32 HirDatabase,
33 DefWithBody,
34 ImplItem,
35 type_ref::{TypeRef, Mutability}, 32 type_ref::{TypeRef, Mutability},
36 expr::{Body, Expr, BindingAnnotation, Literal, ExprId, Pat, PatId, UnaryOp, BinaryOp, Statement, FieldPat,Array, self}, 33 expr::{
34 Body, Expr, BindingAnnotation, Literal, ExprId, Pat, PatId, UnaryOp, BinaryOp, Statement,
35 FieldPat, Array, self,
36 },
37 generics::{GenericParams, HasGenericParams}, 37 generics::{GenericParams, HasGenericParams},
38 path::{GenericArgs, GenericArg}, 38 path::{GenericArgs, GenericArg},
39 ModuleDef, 39 ModuleDef,
@@ -644,7 +644,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
644 let ty = self.insert_type_vars(ty.apply_substs(substs)); 644 let ty = self.insert_type_vars(ty.apply_substs(substs));
645 (ty, Some(var.into())) 645 (ty, Some(var.into()))
646 } 646 }
647 TypableDef::TypeAlias(_) 647 TypableDef::Union(_)
648 | TypableDef::TypeAlias(_)
648 | TypableDef::Function(_) 649 | TypableDef::Function(_)
649 | TypableDef::Enum(_) 650 | TypableDef::Enum(_)
650 | TypableDef::Const(_) 651 | TypableDef::Const(_)
@@ -1407,7 +1408,11 @@ impl Expectation {
1407} 1408}
1408 1409
1409mod diagnostics { 1410mod diagnostics {
1410 use crate::{expr::ExprId, diagnostics::{DiagnosticSink, NoSuchField}, HirDatabase, Function}; 1411 use crate::{
1412 expr::ExprId,
1413 diagnostics::{DiagnosticSink, NoSuchField},
1414 HirDatabase, Function,
1415};
1411 1416
1412 #[derive(Debug, PartialEq, Eq, Clone)] 1417 #[derive(Debug, PartialEq, Eq, Clone)]
1413 pub(super) enum InferenceDiagnostic { 1418 pub(super) enum InferenceDiagnostic {
diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs
index a1a2d0f6b..7defa7a9b 100644
--- a/crates/ra_hir/src/ty/lower.rs
+++ b/crates/ra_hir/src/ty/lower.rs
@@ -9,7 +9,7 @@ use std::sync::Arc;
9use std::iter; 9use std::iter;
10 10
11use crate::{ 11use crate::{
12 Function, Struct, StructField, Enum, EnumVariant, Path, ModuleDef, TypeAlias, Const, Static, 12 Function, Struct, Union, StructField, Enum, EnumVariant, Path, ModuleDef, TypeAlias, Const, Static,
13 HirDatabase, 13 HirDatabase,
14 type_ref::TypeRef, 14 type_ref::TypeRef,
15 name::KnownName, 15 name::KnownName,
@@ -124,6 +124,7 @@ impl Ty {
124 let def_generic: Option<GenericDef> = match resolved { 124 let def_generic: Option<GenericDef> = match resolved {
125 TypableDef::Function(func) => Some(func.into()), 125 TypableDef::Function(func) => Some(func.into()),
126 TypableDef::Struct(s) => Some(s.into()), 126 TypableDef::Struct(s) => Some(s.into()),
127 TypableDef::Union(u) => Some(u.into()),
127 TypableDef::Enum(e) => Some(e.into()), 128 TypableDef::Enum(e) => Some(e.into()),
128 TypableDef::EnumVariant(var) => Some(var.parent_enum(db).into()), 129 TypableDef::EnumVariant(var) => Some(var.parent_enum(db).into()),
129 TypableDef::TypeAlias(t) => Some(t.into()), 130 TypableDef::TypeAlias(t) => Some(t.into()),
@@ -144,6 +145,7 @@ impl Ty {
144 let segment = match resolved { 145 let segment = match resolved {
145 TypableDef::Function(_) 146 TypableDef::Function(_)
146 | TypableDef::Struct(_) 147 | TypableDef::Struct(_)
148 | TypableDef::Union(_)
147 | TypableDef::Enum(_) 149 | TypableDef::Enum(_)
148 | TypableDef::Const(_) 150 | TypableDef::Const(_)
149 | TypableDef::Static(_) 151 | TypableDef::Static(_)
@@ -293,12 +295,14 @@ pub(crate) fn type_for_def(db: &impl HirDatabase, def: TypableDef, ns: Namespace
293 (TypableDef::Struct(s), Namespace::Values) => type_for_struct_constructor(db, s), 295 (TypableDef::Struct(s), Namespace::Values) => type_for_struct_constructor(db, s),
294 (TypableDef::Enum(e), Namespace::Types) => type_for_adt(db, e), 296 (TypableDef::Enum(e), Namespace::Types) => type_for_adt(db, e),
295 (TypableDef::EnumVariant(v), Namespace::Values) => type_for_enum_variant_constructor(db, v), 297 (TypableDef::EnumVariant(v), Namespace::Values) => type_for_enum_variant_constructor(db, v),
298 (TypableDef::Union(u), Namespace::Types) => type_for_adt(db, u),
296 (TypableDef::TypeAlias(t), Namespace::Types) => type_for_type_alias(db, t), 299 (TypableDef::TypeAlias(t), Namespace::Types) => type_for_type_alias(db, t),
297 (TypableDef::Const(c), Namespace::Values) => type_for_const(db, c), 300 (TypableDef::Const(c), Namespace::Values) => type_for_const(db, c),
298 (TypableDef::Static(c), Namespace::Values) => type_for_static(db, c), 301 (TypableDef::Static(c), Namespace::Values) => type_for_static(db, c),
299 302
300 // 'error' cases: 303 // 'error' cases:
301 (TypableDef::Function(_), Namespace::Types) => Ty::Unknown, 304 (TypableDef::Function(_), Namespace::Types) => Ty::Unknown,
305 (TypableDef::Union(_), Namespace::Values) => Ty::Unknown,
302 (TypableDef::Enum(_), Namespace::Values) => Ty::Unknown, 306 (TypableDef::Enum(_), Namespace::Values) => Ty::Unknown,
303 (TypableDef::EnumVariant(_), Namespace::Types) => Ty::Unknown, 307 (TypableDef::EnumVariant(_), Namespace::Types) => Ty::Unknown,
304 (TypableDef::TypeAlias(_), Namespace::Values) => Ty::Unknown, 308 (TypableDef::TypeAlias(_), Namespace::Values) => Ty::Unknown,
@@ -467,19 +471,21 @@ fn type_for_type_alias(db: &impl HirDatabase, t: TypeAlias) -> Ty {
467pub enum TypableDef { 471pub enum TypableDef {
468 Function(Function), 472 Function(Function),
469 Struct(Struct), 473 Struct(Struct),
474 Union(Union),
470 Enum(Enum), 475 Enum(Enum),
471 EnumVariant(EnumVariant), 476 EnumVariant(EnumVariant),
472 TypeAlias(TypeAlias), 477 TypeAlias(TypeAlias),
473 Const(Const), 478 Const(Const),
474 Static(Static), 479 Static(Static),
475} 480}
476impl_froms!(TypableDef: Function, Struct, Enum, EnumVariant, TypeAlias, Const, Static); 481impl_froms!(TypableDef: Function, Struct, Union, Enum, EnumVariant, TypeAlias, Const, Static);
477 482
478impl From<ModuleDef> for Option<TypableDef> { 483impl From<ModuleDef> for Option<TypableDef> {
479 fn from(def: ModuleDef) -> Option<TypableDef> { 484 fn from(def: ModuleDef) -> Option<TypableDef> {
480 let res = match def { 485 let res = match def {
481 ModuleDef::Function(f) => f.into(), 486 ModuleDef::Function(f) => f.into(),
482 ModuleDef::Struct(s) => s.into(), 487 ModuleDef::Struct(s) => s.into(),
488 ModuleDef::Union(u) => u.into(),
483 ModuleDef::Enum(e) => e.into(), 489 ModuleDef::Enum(e) => e.into(),
484 ModuleDef::EnumVariant(v) => v.into(), 490 ModuleDef::EnumVariant(v) => v.into(),
485 ModuleDef::TypeAlias(t) => t.into(), 491 ModuleDef::TypeAlias(t) => t.into(),