aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def/src')
-rw-r--r--crates/ra_hir_def/src/adt.rs18
-rw-r--r--crates/ra_hir_def/src/attr.rs19
-rw-r--r--crates/ra_hir_def/src/body.rs4
-rw-r--r--crates/ra_hir_def/src/body/lower.rs163
-rw-r--r--crates/ra_hir_def/src/child_by_source.rs2
-rw-r--r--crates/ra_hir_def/src/generics.rs16
-rw-r--r--crates/ra_hir_def/src/item_tree.rs52
-rw-r--r--crates/ra_hir_def/src/item_tree/lower.rs175
-rw-r--r--crates/ra_hir_def/src/item_tree/tests.rs62
-rw-r--r--crates/ra_hir_def/src/keys.rs26
-rw-r--r--crates/ra_hir_def/src/lib.rs2
-rw-r--r--crates/ra_hir_def/src/nameres/collector.rs4
-rw-r--r--crates/ra_hir_def/src/path.rs4
-rw-r--r--crates/ra_hir_def/src/path/lower.rs52
-rw-r--r--crates/ra_hir_def/src/path/lower/lower_use.rs2
-rw-r--r--crates/ra_hir_def/src/type_ref.rs48
16 files changed, 327 insertions, 322 deletions
diff --git a/crates/ra_hir_def/src/adt.rs b/crates/ra_hir_def/src/adt.rs
index 4994a2125..6cb56a1cd 100644
--- a/crates/ra_hir_def/src/adt.rs
+++ b/crates/ra_hir_def/src/adt.rs
@@ -8,7 +8,7 @@ use hir_expand::{
8 InFile, 8 InFile,
9}; 9};
10use ra_arena::{map::ArenaMap, Arena}; 10use ra_arena::{map::ArenaMap, Arena};
11use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner, VisibilityOwner}; 11use ra_syntax::ast::{self, NameOwner, VisibilityOwner};
12 12
13use crate::{ 13use crate::{
14 body::{CfgExpander, LowerCtx}, 14 body::{CfgExpander, LowerCtx},
@@ -112,7 +112,7 @@ impl EnumData {
112 112
113impl HasChildSource for EnumId { 113impl HasChildSource for EnumId {
114 type ChildId = LocalEnumVariantId; 114 type ChildId = LocalEnumVariantId;
115 type Value = ast::EnumVariant; 115 type Value = ast::Variant;
116 fn child_source(&self, db: &dyn DefDatabase) -> InFile<ArenaMap<Self::ChildId, Self::Value>> { 116 fn child_source(&self, db: &dyn DefDatabase) -> InFile<ArenaMap<Self::ChildId, Self::Value>> {
117 let src = self.lookup(db).source(db); 117 let src = self.lookup(db).source(db);
118 let mut trace = Trace::new_for_map(); 118 let mut trace = Trace::new_for_map();
@@ -123,8 +123,8 @@ impl HasChildSource for EnumId {
123 123
124fn lower_enum( 124fn lower_enum(
125 db: &dyn DefDatabase, 125 db: &dyn DefDatabase,
126 trace: &mut Trace<EnumVariantData, ast::EnumVariant>, 126 trace: &mut Trace<EnumVariantData, ast::Variant>,
127 ast: &InFile<ast::EnumDef>, 127 ast: &InFile<ast::Enum>,
128 module_id: ModuleId, 128 module_id: ModuleId,
129) { 129) {
130 let expander = CfgExpander::new(db, ast.file_id, module_id.krate); 130 let expander = CfgExpander::new(db, ast.file_id, module_id.krate);
@@ -179,7 +179,7 @@ impl VariantData {
179 179
180impl HasChildSource for VariantId { 180impl HasChildSource for VariantId {
181 type ChildId = LocalFieldId; 181 type ChildId = LocalFieldId;
182 type Value = Either<ast::TupleFieldDef, ast::RecordFieldDef>; 182 type Value = Either<ast::TupleField, ast::RecordField>;
183 183
184 fn child_source(&self, db: &dyn DefDatabase) -> InFile<ArenaMap<Self::ChildId, Self::Value>> { 184 fn child_source(&self, db: &dyn DefDatabase) -> InFile<ArenaMap<Self::ChildId, Self::Value>> {
185 let (src, module_id) = match self { 185 let (src, module_id) = match self {
@@ -194,7 +194,7 @@ impl HasChildSource for VariantId {
194 } 194 }
195 VariantId::UnionId(it) => ( 195 VariantId::UnionId(it) => (
196 it.lookup(db).source(db).map(|it| { 196 it.lookup(db).source(db).map(|it| {
197 it.record_field_def_list() 197 it.record_field_list()
198 .map(ast::StructKind::Record) 198 .map(ast::StructKind::Record)
199 .unwrap_or(ast::StructKind::Unit) 199 .unwrap_or(ast::StructKind::Unit)
200 }), 200 }),
@@ -218,7 +218,7 @@ pub enum StructKind {
218fn lower_struct( 218fn lower_struct(
219 db: &dyn DefDatabase, 219 db: &dyn DefDatabase,
220 expander: &mut CfgExpander, 220 expander: &mut CfgExpander,
221 trace: &mut Trace<FieldData, Either<ast::TupleFieldDef, ast::RecordFieldDef>>, 221 trace: &mut Trace<FieldData, Either<ast::TupleField, ast::RecordField>>,
222 ast: &InFile<ast::StructKind>, 222 ast: &InFile<ast::StructKind>,
223) -> StructKind { 223) -> StructKind {
224 let ctx = LowerCtx::new(db, ast.file_id); 224 let ctx = LowerCtx::new(db, ast.file_id);
@@ -234,7 +234,7 @@ fn lower_struct(
234 || Either::Left(fd.clone()), 234 || Either::Left(fd.clone()),
235 || FieldData { 235 || FieldData {
236 name: Name::new_tuple_field(i), 236 name: Name::new_tuple_field(i),
237 type_ref: TypeRef::from_ast_opt(&ctx, fd.type_ref()), 237 type_ref: TypeRef::from_ast_opt(&ctx, fd.ty()),
238 visibility: RawVisibility::from_ast(db, ast.with_value(fd.visibility())), 238 visibility: RawVisibility::from_ast(db, ast.with_value(fd.visibility())),
239 }, 239 },
240 ); 240 );
@@ -251,7 +251,7 @@ fn lower_struct(
251 || Either::Right(fd.clone()), 251 || Either::Right(fd.clone()),
252 || FieldData { 252 || FieldData {
253 name: fd.name().map(|n| n.as_name()).unwrap_or_else(Name::missing), 253 name: fd.name().map(|n| n.as_name()).unwrap_or_else(Name::missing),
254 type_ref: TypeRef::from_ast_opt(&ctx, fd.ascribed_type()), 254 type_ref: TypeRef::from_ast_opt(&ctx, fd.ty()),
255 visibility: RawVisibility::from_ast(db, ast.with_value(fd.visibility())), 255 visibility: RawVisibility::from_ast(db, ast.with_value(fd.visibility())),
256 }, 256 },
257 ); 257 );
diff --git a/crates/ra_hir_def/src/attr.rs b/crates/ra_hir_def/src/attr.rs
index 70ccd4305..050832ce0 100644
--- a/crates/ra_hir_def/src/attr.rs
+++ b/crates/ra_hir_def/src/attr.rs
@@ -151,18 +151,15 @@ pub enum AttrInput {
151impl Attr { 151impl Attr {
152 fn from_src(ast: ast::Attr, hygiene: &Hygiene) -> Option<Attr> { 152 fn from_src(ast: ast::Attr, hygiene: &Hygiene) -> Option<Attr> {
153 let path = ModPath::from_src(ast.path()?, hygiene)?; 153 let path = ModPath::from_src(ast.path()?, hygiene)?;
154 let input = match ast.input() { 154 let input = if let Some(lit) = ast.literal() {
155 None => None, 155 // FIXME: escape? raw string?
156 Some(ast::AttrInput::Literal(lit)) => { 156 let value = lit.syntax().first_token()?.text().trim_matches('"').into();
157 // FIXME: escape? raw string? 157 Some(AttrInput::Literal(value))
158 let value = lit.syntax().first_token()?.text().trim_matches('"').into(); 158 } else if let Some(tt) = ast.token_tree() {
159 Some(AttrInput::Literal(value)) 159 Some(AttrInput::TokenTree(ast_to_token_tree(&tt)?.0))
160 } 160 } else {
161 Some(ast::AttrInput::TokenTree(tt)) => { 161 None
162 Some(AttrInput::TokenTree(ast_to_token_tree(&tt)?.0))
163 }
164 }; 162 };
165
166 Some(Attr { path, input }) 163 Some(Attr { path, input })
167 } 164 }
168} 165}
diff --git a/crates/ra_hir_def/src/body.rs b/crates/ra_hir_def/src/body.rs
index 2fe04db2b..d5f18b920 100644
--- a/crates/ra_hir_def/src/body.rs
+++ b/crates/ra_hir_def/src/body.rs
@@ -216,7 +216,7 @@ pub struct BodySourceMap {
216 expr_map_back: ArenaMap<ExprId, Result<ExprSource, SyntheticSyntax>>, 216 expr_map_back: ArenaMap<ExprId, Result<ExprSource, SyntheticSyntax>>,
217 pat_map: FxHashMap<PatSource, PatId>, 217 pat_map: FxHashMap<PatSource, PatId>,
218 pat_map_back: ArenaMap<PatId, Result<PatSource, SyntheticSyntax>>, 218 pat_map_back: ArenaMap<PatId, Result<PatSource, SyntheticSyntax>>,
219 field_map: FxHashMap<(ExprId, usize), InFile<AstPtr<ast::RecordField>>>, 219 field_map: FxHashMap<(ExprId, usize), InFile<AstPtr<ast::RecordExprField>>>,
220 expansions: FxHashMap<InFile<AstPtr<ast::MacroCall>>, HirFileId>, 220 expansions: FxHashMap<InFile<AstPtr<ast::MacroCall>>, HirFileId>,
221} 221}
222 222
@@ -314,7 +314,7 @@ impl BodySourceMap {
314 self.pat_map.get(&src).cloned() 314 self.pat_map.get(&src).cloned()
315 } 315 }
316 316
317 pub fn field_syntax(&self, expr: ExprId, field: usize) -> InFile<AstPtr<ast::RecordField>> { 317 pub fn field_syntax(&self, expr: ExprId, field: usize) -> InFile<AstPtr<ast::RecordExprField>> {
318 self.field_map[&(expr, field)].clone() 318 self.field_map[&(expr, field)].clone()
319 } 319 }
320} 320}
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs
index c6bc85e2f..f5c37edb3 100644
--- a/crates/ra_hir_def/src/body/lower.rs
+++ b/crates/ra_hir_def/src/body/lower.rs
@@ -1,6 +1,8 @@
1//! Transforms `ast::Expr` into an equivalent `hir_def::expr::Expr` 1//! Transforms `ast::Expr` into an equivalent `hir_def::expr::Expr`
2//! representation. 2//! representation.
3 3
4use std::{any::type_name, sync::Arc};
5
4use either::Either; 6use either::Either;
5use hir_expand::{ 7use hir_expand::{
6 hygiene::Hygiene, 8 hygiene::Hygiene,
@@ -10,11 +12,12 @@ use hir_expand::{
10use ra_arena::Arena; 12use ra_arena::Arena;
11use ra_syntax::{ 13use ra_syntax::{
12 ast::{ 14 ast::{
13 self, ArgListOwner, ArrayExprKind, LiteralKind, LoopBodyOwner, ModuleItemOwner, NameOwner, 15 self, ArgListOwner, ArrayExprKind, AstChildren, LiteralKind, LoopBodyOwner, NameOwner,
14 SlicePatComponents, TypeAscriptionOwner, 16 SlicePatComponents,
15 }, 17 },
16 AstNode, AstPtr, 18 AstNode, AstPtr,
17}; 19};
20use rustc_hash::FxHashMap;
18use test_utils::mark; 21use test_utils::mark;
19 22
20use crate::{ 23use crate::{
@@ -35,9 +38,6 @@ use crate::{
35}; 38};
36 39
37use super::{ExprSource, PatSource}; 40use super::{ExprSource, PatSource};
38use ast::AstChildren;
39use rustc_hash::FxHashMap;
40use std::{any::type_name, sync::Arc};
41 41
42pub(crate) struct LowerCtx { 42pub(crate) struct LowerCtx {
43 hygiene: Hygiene, 43 hygiene: Hygiene,
@@ -224,9 +224,22 @@ impl ExprCollector<'_> {
224 self.alloc_expr(Expr::Unsafe { body }, syntax_ptr) 224 self.alloc_expr(Expr::Unsafe { body }, syntax_ptr)
225 } 225 }
226 // FIXME: we need to record these effects somewhere... 226 // FIXME: we need to record these effects somewhere...
227 ast::Effect::Async(_) | ast::Effect::Label(_) => { 227 ast::Effect::Label(label) => match e.block_expr() {
228 self.collect_block_opt(e.block_expr()) 228 Some(block) => {
229 } 229 let res = self.collect_block(block);
230 match &mut self.body.exprs[res] {
231 Expr::Block { label: block_label, .. } => {
232 *block_label =
233 label.lifetime_token().map(|t| Name::new_lifetime(&t))
234 }
235 _ => unreachable!(),
236 }
237 res
238 }
239 None => self.missing_expr(),
240 },
241 // FIXME: we need to record these effects somewhere...
242 ast::Effect::Async(_) => self.collect_block_opt(e.block_expr()),
230 }, 243 },
231 ast::Expr::BlockExpr(e) => self.collect_block(e), 244 ast::Expr::BlockExpr(e) => self.collect_block(e),
232 ast::Expr::LoopExpr(e) => { 245 ast::Expr::LoopExpr(e) => {
@@ -324,7 +337,7 @@ impl ExprCollector<'_> {
324 }; 337 };
325 let method_name = e.name_ref().map(|nr| nr.as_name()).unwrap_or_else(Name::missing); 338 let method_name = e.name_ref().map(|nr| nr.as_name()).unwrap_or_else(Name::missing);
326 let generic_args = 339 let generic_args =
327 e.type_arg_list().and_then(|it| GenericArgs::from_ast(&self.ctx(), it)); 340 e.generic_arg_list().and_then(|it| GenericArgs::from_ast(&self.ctx(), it));
328 self.alloc_expr( 341 self.alloc_expr(
329 Expr::MethodCall { receiver, method_name, args, generic_args }, 342 Expr::MethodCall { receiver, method_name, args, generic_args },
330 syntax_ptr, 343 syntax_ptr,
@@ -379,10 +392,10 @@ impl ExprCollector<'_> {
379 let expr = e.expr().map(|e| self.collect_expr(e)); 392 let expr = e.expr().map(|e| self.collect_expr(e));
380 self.alloc_expr(Expr::Return { expr }, syntax_ptr) 393 self.alloc_expr(Expr::Return { expr }, syntax_ptr)
381 } 394 }
382 ast::Expr::RecordLit(e) => { 395 ast::Expr::RecordExpr(e) => {
383 let path = e.path().and_then(|path| self.expander.parse_path(path)); 396 let path = e.path().and_then(|path| self.expander.parse_path(path));
384 let mut field_ptrs = Vec::new(); 397 let mut field_ptrs = Vec::new();
385 let record_lit = if let Some(nfl) = e.record_field_list() { 398 let record_lit = if let Some(nfl) = e.record_expr_field_list() {
386 let fields = nfl 399 let fields = nfl
387 .fields() 400 .fields()
388 .inspect(|field| field_ptrs.push(AstPtr::new(field))) 401 .inspect(|field| field_ptrs.push(AstPtr::new(field)))
@@ -432,7 +445,7 @@ impl ExprCollector<'_> {
432 } 445 }
433 ast::Expr::CastExpr(e) => { 446 ast::Expr::CastExpr(e) => {
434 let expr = self.collect_expr_opt(e.expr()); 447 let expr = self.collect_expr_opt(e.expr());
435 let type_ref = TypeRef::from_ast_opt(&self.ctx(), e.type_ref()); 448 let type_ref = TypeRef::from_ast_opt(&self.ctx(), e.ty());
436 self.alloc_expr(Expr::Cast { expr, type_ref }, syntax_ptr) 449 self.alloc_expr(Expr::Cast { expr, type_ref }, syntax_ptr)
437 } 450 }
438 ast::Expr::RefExpr(e) => { 451 ast::Expr::RefExpr(e) => {
@@ -460,22 +473,19 @@ impl ExprCollector<'_> {
460 self.alloc_expr(Expr::Missing, syntax_ptr) 473 self.alloc_expr(Expr::Missing, syntax_ptr)
461 } 474 }
462 } 475 }
463 ast::Expr::LambdaExpr(e) => { 476 ast::Expr::ClosureExpr(e) => {
464 let mut args = Vec::new(); 477 let mut args = Vec::new();
465 let mut arg_types = Vec::new(); 478 let mut arg_types = Vec::new();
466 if let Some(pl) = e.param_list() { 479 if let Some(pl) = e.param_list() {
467 for param in pl.params() { 480 for param in pl.params() {
468 let pat = self.collect_pat_opt(param.pat()); 481 let pat = self.collect_pat_opt(param.pat());
469 let type_ref = 482 let type_ref = param.ty().map(|it| TypeRef::from_ast(&self.ctx(), it));
470 param.ascribed_type().map(|it| TypeRef::from_ast(&self.ctx(), it));
471 args.push(pat); 483 args.push(pat);
472 arg_types.push(type_ref); 484 arg_types.push(type_ref);
473 } 485 }
474 } 486 }
475 let ret_type = e 487 let ret_type =
476 .ret_type() 488 e.ret_type().and_then(|r| r.ty()).map(|it| TypeRef::from_ast(&self.ctx(), it));
477 .and_then(|r| r.type_ref())
478 .map(|it| TypeRef::from_ast(&self.ctx(), it));
479 let body = self.collect_expr_opt(e.body()); 489 let body = self.collect_expr_opt(e.body());
480 self.alloc_expr(Expr::Lambda { args, arg_types, ret_type, body }, syntax_ptr) 490 self.alloc_expr(Expr::Lambda { args, arg_types, ret_type, body }, syntax_ptr)
481 } 491 }
@@ -486,7 +496,7 @@ impl ExprCollector<'_> {
486 self.alloc_expr(Expr::BinaryOp { lhs, rhs, op }, syntax_ptr) 496 self.alloc_expr(Expr::BinaryOp { lhs, rhs, op }, syntax_ptr)
487 } 497 }
488 ast::Expr::TupleExpr(e) => { 498 ast::Expr::TupleExpr(e) => {
489 let exprs = e.exprs().map(|expr| self.collect_expr(expr)).collect(); 499 let exprs = e.fields().map(|expr| self.collect_expr(expr)).collect();
490 self.alloc_expr(Expr::Tuple { exprs }, syntax_ptr) 500 self.alloc_expr(Expr::Tuple { exprs }, syntax_ptr)
491 } 501 }
492 ast::Expr::BoxExpr(e) => { 502 ast::Expr::BoxExpr(e) => {
@@ -559,9 +569,6 @@ impl ExprCollector<'_> {
559 } 569 }
560 } 570 }
561 } 571 }
562
563 // FIXME implement HIR for these:
564 ast::Expr::Label(_e) => self.alloc_expr(Expr::Missing, syntax_ptr),
565 } 572 }
566 } 573 }
567 574
@@ -604,76 +611,84 @@ impl ExprCollector<'_> {
604 self.collect_block_items(&block); 611 self.collect_block_items(&block);
605 let statements = block 612 let statements = block
606 .statements() 613 .statements()
607 .map(|s| match s { 614 .filter_map(|s| {
608 ast::Stmt::LetStmt(stmt) => { 615 let stmt = match s {
609 let pat = self.collect_pat_opt(stmt.pat()); 616 ast::Stmt::LetStmt(stmt) => {
610 let type_ref = 617 let pat = self.collect_pat_opt(stmt.pat());
611 stmt.ascribed_type().map(|it| TypeRef::from_ast(&self.ctx(), it)); 618 let type_ref = stmt.ty().map(|it| TypeRef::from_ast(&self.ctx(), it));
612 let initializer = stmt.initializer().map(|e| self.collect_expr(e)); 619 let initializer = stmt.initializer().map(|e| self.collect_expr(e));
613 Statement::Let { pat, type_ref, initializer } 620 Statement::Let { pat, type_ref, initializer }
614 } 621 }
615 ast::Stmt::ExprStmt(stmt) => Statement::Expr(self.collect_expr_opt(stmt.expr())), 622 ast::Stmt::ExprStmt(stmt) => {
623 Statement::Expr(self.collect_expr_opt(stmt.expr()))
624 }
625 ast::Stmt::Item(_) => return None,
626 };
627 Some(stmt)
616 }) 628 })
617 .collect(); 629 .collect();
618 let tail = block.expr().map(|e| self.collect_expr(e)); 630 let tail = block.expr().map(|e| self.collect_expr(e));
619 let label = block.label().and_then(|l| l.lifetime_token()).map(|t| Name::new_lifetime(&t)); 631 self.alloc_expr(Expr::Block { statements, tail, label: None }, syntax_node_ptr)
620 self.alloc_expr(Expr::Block { statements, tail, label }, syntax_node_ptr)
621 } 632 }
622 633
623 fn collect_block_items(&mut self, block: &ast::BlockExpr) { 634 fn collect_block_items(&mut self, block: &ast::BlockExpr) {
624 let container = ContainerId::DefWithBodyId(self.def); 635 let container = ContainerId::DefWithBodyId(self.def);
625 636
626 let items = block 637 let items = block
627 .items() 638 .statements()
639 .filter_map(|stmt| match stmt {
640 ast::Stmt::Item(it) => Some(it),
641 ast::Stmt::LetStmt(_) | ast::Stmt::ExprStmt(_) => None,
642 })
628 .filter_map(|item| { 643 .filter_map(|item| {
629 let (def, name): (ModuleDefId, Option<ast::Name>) = match item { 644 let (def, name): (ModuleDefId, Option<ast::Name>) = match item {
630 ast::ModuleItem::FnDef(def) => { 645 ast::Item::Fn(def) => {
631 let id = self.find_inner_item(&def)?; 646 let id = self.find_inner_item(&def)?;
632 ( 647 (
633 FunctionLoc { container: container.into(), id }.intern(self.db).into(), 648 FunctionLoc { container: container.into(), id }.intern(self.db).into(),
634 def.name(), 649 def.name(),
635 ) 650 )
636 } 651 }
637 ast::ModuleItem::TypeAliasDef(def) => { 652 ast::Item::TypeAlias(def) => {
638 let id = self.find_inner_item(&def)?; 653 let id = self.find_inner_item(&def)?;
639 ( 654 (
640 TypeAliasLoc { container: container.into(), id }.intern(self.db).into(), 655 TypeAliasLoc { container: container.into(), id }.intern(self.db).into(),
641 def.name(), 656 def.name(),
642 ) 657 )
643 } 658 }
644 ast::ModuleItem::ConstDef(def) => { 659 ast::Item::Const(def) => {
645 let id = self.find_inner_item(&def)?; 660 let id = self.find_inner_item(&def)?;
646 ( 661 (
647 ConstLoc { container: container.into(), id }.intern(self.db).into(), 662 ConstLoc { container: container.into(), id }.intern(self.db).into(),
648 def.name(), 663 def.name(),
649 ) 664 )
650 } 665 }
651 ast::ModuleItem::StaticDef(def) => { 666 ast::Item::Static(def) => {
652 let id = self.find_inner_item(&def)?; 667 let id = self.find_inner_item(&def)?;
653 (StaticLoc { container, id }.intern(self.db).into(), def.name()) 668 (StaticLoc { container, id }.intern(self.db).into(), def.name())
654 } 669 }
655 ast::ModuleItem::StructDef(def) => { 670 ast::Item::Struct(def) => {
656 let id = self.find_inner_item(&def)?; 671 let id = self.find_inner_item(&def)?;
657 (StructLoc { container, id }.intern(self.db).into(), def.name()) 672 (StructLoc { container, id }.intern(self.db).into(), def.name())
658 } 673 }
659 ast::ModuleItem::EnumDef(def) => { 674 ast::Item::Enum(def) => {
660 let id = self.find_inner_item(&def)?; 675 let id = self.find_inner_item(&def)?;
661 (EnumLoc { container, id }.intern(self.db).into(), def.name()) 676 (EnumLoc { container, id }.intern(self.db).into(), def.name())
662 } 677 }
663 ast::ModuleItem::UnionDef(def) => { 678 ast::Item::Union(def) => {
664 let id = self.find_inner_item(&def)?; 679 let id = self.find_inner_item(&def)?;
665 (UnionLoc { container, id }.intern(self.db).into(), def.name()) 680 (UnionLoc { container, id }.intern(self.db).into(), def.name())
666 } 681 }
667 ast::ModuleItem::TraitDef(def) => { 682 ast::Item::Trait(def) => {
668 let id = self.find_inner_item(&def)?; 683 let id = self.find_inner_item(&def)?;
669 (TraitLoc { container, id }.intern(self.db).into(), def.name()) 684 (TraitLoc { container, id }.intern(self.db).into(), def.name())
670 } 685 }
671 ast::ModuleItem::ExternBlock(_) => return None, // FIXME: collect from extern blocks 686 ast::Item::ExternBlock(_) => return None, // FIXME: collect from extern blocks
672 ast::ModuleItem::ImplDef(_) 687 ast::Item::Impl(_)
673 | ast::ModuleItem::UseItem(_) 688 | ast::Item::Use(_)
674 | ast::ModuleItem::ExternCrateItem(_) 689 | ast::Item::ExternCrate(_)
675 | ast::ModuleItem::Module(_) 690 | ast::Item::Module(_)
676 | ast::ModuleItem::MacroCall(_) => return None, 691 | ast::Item::MacroCall(_) => return None,
677 }; 692 };
678 693
679 Some((def, name)) 694 Some((def, name))
@@ -708,7 +723,7 @@ impl ExprCollector<'_> {
708 723
709 fn collect_pat(&mut self, pat: ast::Pat) -> PatId { 724 fn collect_pat(&mut self, pat: ast::Pat) -> PatId {
710 let pattern = match &pat { 725 let pattern = match &pat {
711 ast::Pat::BindPat(bp) => { 726 ast::Pat::IdentPat(bp) => {
712 let name = bp.name().map(|nr| nr.as_name()).unwrap_or_else(Name::missing); 727 let name = bp.name().map(|nr| nr.as_name()).unwrap_or_else(Name::missing);
713 let annotation = 728 let annotation =
714 BindingAnnotation::new(bp.mut_token().is_some(), bp.ref_token().is_some()); 729 BindingAnnotation::new(bp.mut_token().is_some(), bp.ref_token().is_some());
@@ -747,7 +762,7 @@ impl ExprCollector<'_> {
747 } 762 }
748 ast::Pat::TupleStructPat(p) => { 763 ast::Pat::TupleStructPat(p) => {
749 let path = p.path().and_then(|path| self.expander.parse_path(path)); 764 let path = p.path().and_then(|path| self.expander.parse_path(path));
750 let (args, ellipsis) = self.collect_tuple_pat(p.args()); 765 let (args, ellipsis) = self.collect_tuple_pat(p.fields());
751 Pat::TupleStruct { path, args, ellipsis } 766 Pat::TupleStruct { path, args, ellipsis }
752 } 767 }
753 ast::Pat::RefPat(p) => { 768 ast::Pat::RefPat(p) => {
@@ -765,40 +780,36 @@ impl ExprCollector<'_> {
765 } 780 }
766 ast::Pat::ParenPat(p) => return self.collect_pat_opt(p.pat()), 781 ast::Pat::ParenPat(p) => return self.collect_pat_opt(p.pat()),
767 ast::Pat::TuplePat(p) => { 782 ast::Pat::TuplePat(p) => {
768 let (args, ellipsis) = self.collect_tuple_pat(p.args()); 783 let (args, ellipsis) = self.collect_tuple_pat(p.fields());
769 Pat::Tuple { args, ellipsis } 784 Pat::Tuple { args, ellipsis }
770 } 785 }
771 ast::Pat::PlaceholderPat(_) => Pat::Wild, 786 ast::Pat::WildcardPat(_) => Pat::Wild,
772 ast::Pat::RecordPat(p) => { 787 ast::Pat::RecordPat(p) => {
773 let path = p.path().and_then(|path| self.expander.parse_path(path)); 788 let path = p.path().and_then(|path| self.expander.parse_path(path));
774 let record_field_pat_list = 789 let args: Vec<_> = p
775 p.record_field_pat_list().expect("every struct should have a field list"); 790 .record_pat_field_list()
776 let mut fields: Vec<_> = record_field_pat_list 791 .expect("every struct should have a field list")
777 .bind_pats() 792 .fields()
778 .filter_map(|bind_pat| { 793 .filter_map(|f| {
779 let ast_pat = 794 let ast_pat = f.pat()?;
780 ast::Pat::cast(bind_pat.syntax().clone()).expect("bind pat is a pat");
781 let pat = self.collect_pat(ast_pat); 795 let pat = self.collect_pat(ast_pat);
782 let name = bind_pat.name()?.as_name(); 796 let name = f.field_name()?.as_name();
783 Some(RecordFieldPat { name, pat }) 797 Some(RecordFieldPat { name, pat })
784 }) 798 })
785 .collect(); 799 .collect();
786 let iter = record_field_pat_list.record_field_pats().filter_map(|f| {
787 let ast_pat = f.pat()?;
788 let pat = self.collect_pat(ast_pat);
789 let name = f.field_name()?.as_name();
790 Some(RecordFieldPat { name, pat })
791 });
792 fields.extend(iter);
793 800
794 let ellipsis = record_field_pat_list.dotdot_token().is_some(); 801 let ellipsis = p
802 .record_pat_field_list()
803 .expect("every struct should have a field list")
804 .dotdot_token()
805 .is_some();
795 806
796 Pat::Record { path, args: fields, ellipsis } 807 Pat::Record { path, args, ellipsis }
797 } 808 }
798 ast::Pat::SlicePat(p) => { 809 ast::Pat::SlicePat(p) => {
799 let SlicePatComponents { prefix, slice, suffix } = p.components(); 810 let SlicePatComponents { prefix, slice, suffix } = p.components();
800 811
801 // FIXME properly handle `DotDotPat` 812 // FIXME properly handle `RestPat`
802 Pat::Slice { 813 Pat::Slice {
803 prefix: prefix.into_iter().map(|p| self.collect_pat(p)).collect(), 814 prefix: prefix.into_iter().map(|p| self.collect_pat(p)).collect(),
804 slice: slice.map(|p| self.collect_pat(p)), 815 slice: slice.map(|p| self.collect_pat(p)),
@@ -815,10 +826,10 @@ impl ExprCollector<'_> {
815 Pat::Missing 826 Pat::Missing
816 } 827 }
817 } 828 }
818 ast::Pat::DotDotPat(_) => { 829 ast::Pat::RestPat(_) => {
819 // `DotDotPat` requires special handling and should not be mapped 830 // `RestPat` requires special handling and should not be mapped
820 // to a Pat. Here we are using `Pat::Missing` as a fallback for 831 // to a Pat. Here we are using `Pat::Missing` as a fallback for
821 // when `DotDotPat` is mapped to `Pat`, which can easily happen 832 // when `RestPat` is mapped to `Pat`, which can easily happen
822 // when the source code being analyzed has a malformed pattern 833 // when the source code being analyzed has a malformed pattern
823 // which includes `..` in a place where it isn't valid. 834 // which includes `..` in a place where it isn't valid.
824 835
@@ -842,10 +853,10 @@ impl ExprCollector<'_> {
842 fn collect_tuple_pat(&mut self, args: AstChildren<ast::Pat>) -> (Vec<PatId>, Option<usize>) { 853 fn collect_tuple_pat(&mut self, args: AstChildren<ast::Pat>) -> (Vec<PatId>, Option<usize>) {
843 // Find the location of the `..`, if there is one. Note that we do not 854 // Find the location of the `..`, if there is one. Note that we do not
844 // consider the possiblity of there being multiple `..` here. 855 // consider the possiblity of there being multiple `..` here.
845 let ellipsis = args.clone().position(|p| matches!(p, ast::Pat::DotDotPat(_))); 856 let ellipsis = args.clone().position(|p| matches!(p, ast::Pat::RestPat(_)));
846 // We want to skip the `..` pattern here, since we account for it above. 857 // We want to skip the `..` pattern here, since we account for it above.
847 let args = args 858 let args = args
848 .filter(|p| !matches!(p, ast::Pat::DotDotPat(_))) 859 .filter(|p| !matches!(p, ast::Pat::RestPat(_)))
849 .map(|p| self.collect_pat(p)) 860 .map(|p| self.collect_pat(p))
850 .collect(); 861 .collect();
851 862
diff --git a/crates/ra_hir_def/src/child_by_source.rs b/crates/ra_hir_def/src/child_by_source.rs
index a885ec96d..dcb00a1d9 100644
--- a/crates/ra_hir_def/src/child_by_source.rs
+++ b/crates/ra_hir_def/src/child_by_source.rs
@@ -162,7 +162,7 @@ impl ChildBySource for EnumId {
162 let arena_map = arena_map.as_ref(); 162 let arena_map = arena_map.as_ref();
163 for (local_id, source) in arena_map.value.iter() { 163 for (local_id, source) in arena_map.value.iter() {
164 let id = EnumVariantId { parent: *self, local_id }; 164 let id = EnumVariantId { parent: *self, local_id };
165 res[keys::ENUM_VARIANT].insert(arena_map.with_value(source.clone()), id) 165 res[keys::VARIANT].insert(arena_map.with_value(source.clone()), id)
166 } 166 }
167 167
168 res 168 res
diff --git a/crates/ra_hir_def/src/generics.rs b/crates/ra_hir_def/src/generics.rs
index 6a0f493a7..699ba9c92 100644
--- a/crates/ra_hir_def/src/generics.rs
+++ b/crates/ra_hir_def/src/generics.rs
@@ -12,7 +12,7 @@ use hir_expand::{
12use ra_arena::{map::ArenaMap, Arena}; 12use ra_arena::{map::ArenaMap, Arena};
13use ra_db::FileId; 13use ra_db::FileId;
14use ra_prof::profile; 14use ra_prof::profile;
15use ra_syntax::ast::{self, NameOwner, TypeBoundsOwner, TypeParamsOwner}; 15use ra_syntax::ast::{self, GenericParamsOwner, NameOwner, TypeBoundsOwner};
16 16
17use crate::{ 17use crate::{
18 body::LowerCtx, 18 body::LowerCtx,
@@ -66,7 +66,7 @@ pub enum WherePredicateTarget {
66 TypeParam(LocalTypeParamId), 66 TypeParam(LocalTypeParamId),
67} 67}
68 68
69type SourceMap = ArenaMap<LocalTypeParamId, Either<ast::TraitDef, ast::TypeParam>>; 69type SourceMap = ArenaMap<LocalTypeParamId, Either<ast::Trait, ast::TypeParam>>;
70 70
71impl GenericParams { 71impl GenericParams {
72 pub(crate) fn generic_params_query( 72 pub(crate) fn generic_params_query(
@@ -205,9 +205,9 @@ impl GenericParams {
205 &mut self, 205 &mut self,
206 lower_ctx: &LowerCtx, 206 lower_ctx: &LowerCtx,
207 sm: &mut SourceMap, 207 sm: &mut SourceMap,
208 node: &dyn TypeParamsOwner, 208 node: &dyn GenericParamsOwner,
209 ) { 209 ) {
210 if let Some(params) = node.type_param_list() { 210 if let Some(params) = node.generic_param_list() {
211 self.fill_params(lower_ctx, sm, params) 211 self.fill_params(lower_ctx, sm, params)
212 } 212 }
213 if let Some(where_clause) = node.where_clause() { 213 if let Some(where_clause) = node.where_clause() {
@@ -232,7 +232,7 @@ impl GenericParams {
232 &mut self, 232 &mut self,
233 lower_ctx: &LowerCtx, 233 lower_ctx: &LowerCtx,
234 sm: &mut SourceMap, 234 sm: &mut SourceMap,
235 params: ast::TypeParamList, 235 params: ast::GenericParamList,
236 ) { 236 ) {
237 for type_param in params.type_params() { 237 for type_param in params.type_params() {
238 let name = type_param.name().map_or_else(Name::missing, |it| it.as_name()); 238 let name = type_param.name().map_or_else(Name::missing, |it| it.as_name());
@@ -253,7 +253,7 @@ impl GenericParams {
253 253
254 fn fill_where_predicates(&mut self, lower_ctx: &LowerCtx, where_clause: ast::WhereClause) { 254 fn fill_where_predicates(&mut self, lower_ctx: &LowerCtx, where_clause: ast::WhereClause) {
255 for pred in where_clause.predicates() { 255 for pred in where_clause.predicates() {
256 let type_ref = match pred.type_ref() { 256 let type_ref = match pred.ty() {
257 Some(type_ref) => type_ref, 257 Some(type_ref) => type_ref,
258 None => continue, 258 None => continue,
259 }; 259 };
@@ -270,7 +270,7 @@ impl GenericParams {
270 bound: ast::TypeBound, 270 bound: ast::TypeBound,
271 type_ref: TypeRef, 271 type_ref: TypeRef,
272 ) { 272 ) {
273 if bound.question_token().is_some() { 273 if bound.question_mark_token().is_some() {
274 // FIXME: remove this bound 274 // FIXME: remove this bound
275 return; 275 return;
276 } 276 }
@@ -317,7 +317,7 @@ impl GenericParams {
317 317
318impl HasChildSource for GenericDefId { 318impl HasChildSource for GenericDefId {
319 type ChildId = LocalTypeParamId; 319 type ChildId = LocalTypeParamId;
320 type Value = Either<ast::TraitDef, ast::TypeParam>; 320 type Value = Either<ast::Trait, ast::TypeParam>;
321 fn child_source(&self, db: &dyn DefDatabase) -> InFile<SourceMap> { 321 fn child_source(&self, db: &dyn DefDatabase) -> InFile<SourceMap> {
322 let (_, sm) = GenericParams::new(db, *self); 322 let (_, sm) = GenericParams::new(db, *self);
323 sm 323 sm
diff --git a/crates/ra_hir_def/src/item_tree.rs b/crates/ra_hir_def/src/item_tree.rs
index da79d8ffd..a67e75dac 100644
--- a/crates/ra_hir_def/src/item_tree.rs
+++ b/crates/ra_hir_def/src/item_tree.rs
@@ -13,7 +13,7 @@ use std::{
13 sync::Arc, 13 sync::Arc,
14}; 14};
15 15
16use ast::{AstNode, AttrsOwner, NameOwner, StructKind, TypeAscriptionOwner}; 16use ast::{AstNode, AttrsOwner, NameOwner, StructKind};
17use either::Either; 17use either::Either;
18use hir_expand::{ 18use hir_expand::{
19 ast_id_map::FileAstId, 19 ast_id_map::FileAstId,
@@ -70,7 +70,7 @@ impl GenericParamsId {
70pub struct ItemTree { 70pub struct ItemTree {
71 top_level: SmallVec<[ModItem; 1]>, 71 top_level: SmallVec<[ModItem; 1]>,
72 attrs: FxHashMap<AttrOwner, Attrs>, 72 attrs: FxHashMap<AttrOwner, Attrs>,
73 inner_items: FxHashMap<FileAstId<ast::ModuleItem>, SmallVec<[ModItem; 1]>>, 73 inner_items: FxHashMap<FileAstId<ast::Item>, SmallVec<[ModItem; 1]>>,
74 74
75 data: Option<Box<ItemTreeData>>, 75 data: Option<Box<ItemTreeData>>,
76} 76}
@@ -187,7 +187,7 @@ impl ItemTree {
187 /// 187 ///
188 /// Most AST items are lowered to a single `ModItem`, but some (eg. `use` items) may be lowered 188 /// Most AST items are lowered to a single `ModItem`, but some (eg. `use` items) may be lowered
189 /// to multiple items in the `ItemTree`. 189 /// to multiple items in the `ItemTree`.
190 pub fn inner_items(&self, ast: FileAstId<ast::ModuleItem>) -> &[ModItem] { 190 pub fn inner_items(&self, ast: FileAstId<ast::Item>) -> &[ModItem] {
191 &self.inner_items[&ast] 191 &self.inner_items[&ast]
192 } 192 }
193 193
@@ -310,7 +310,7 @@ from_attrs!(ModItem(ModItem), Variant(Idx<Variant>), Field(Idx<Field>));
310 310
311/// Trait implemented by all item nodes in the item tree. 311/// Trait implemented by all item nodes in the item tree.
312pub trait ItemTreeNode: Clone { 312pub trait ItemTreeNode: Clone {
313 type Source: AstNode + Into<ast::ModuleItem>; 313 type Source: AstNode + Into<ast::Item>;
314 314
315 fn ast_id(&self) -> FileAstId<Self::Source>; 315 fn ast_id(&self) -> FileAstId<Self::Source>;
316 316
@@ -411,17 +411,17 @@ macro_rules! mod_items {
411} 411}
412 412
413mod_items! { 413mod_items! {
414 Import in imports -> ast::UseItem, 414 Import in imports -> ast::Use,
415 ExternCrate in extern_crates -> ast::ExternCrateItem, 415 ExternCrate in extern_crates -> ast::ExternCrate,
416 Function in functions -> ast::FnDef, 416 Function in functions -> ast::Fn,
417 Struct in structs -> ast::StructDef, 417 Struct in structs -> ast::Struct,
418 Union in unions -> ast::UnionDef, 418 Union in unions -> ast::Union,
419 Enum in enums -> ast::EnumDef, 419 Enum in enums -> ast::Enum,
420 Const in consts -> ast::ConstDef, 420 Const in consts -> ast::Const,
421 Static in statics -> ast::StaticDef, 421 Static in statics -> ast::Static,
422 Trait in traits -> ast::TraitDef, 422 Trait in traits -> ast::Trait,
423 Impl in impls -> ast::ImplDef, 423 Impl in impls -> ast::Impl,
424 TypeAlias in type_aliases -> ast::TypeAliasDef, 424 TypeAlias in type_aliases -> ast::TypeAlias,
425 Mod in mods -> ast::Module, 425 Mod in mods -> ast::Module,
426 MacroCall in macro_calls -> ast::MacroCall, 426 MacroCall in macro_calls -> ast::MacroCall,
427} 427}
@@ -482,7 +482,7 @@ pub struct Import {
482 pub is_prelude: bool, 482 pub is_prelude: bool,
483 /// AST ID of the `use` or `extern crate` item this import was derived from. Note that many 483 /// AST ID of the `use` or `extern crate` item this import was derived from. Note that many
484 /// `Import`s can map to the same `use` item. 484 /// `Import`s can map to the same `use` item.
485 pub ast_id: FileAstId<ast::UseItem>, 485 pub ast_id: FileAstId<ast::Use>,
486} 486}
487 487
488#[derive(Debug, Clone, Eq, PartialEq)] 488#[derive(Debug, Clone, Eq, PartialEq)]
@@ -492,7 +492,7 @@ pub struct ExternCrate {
492 pub visibility: RawVisibilityId, 492 pub visibility: RawVisibilityId,
493 /// Whether this is a `#[macro_use] extern crate ...`. 493 /// Whether this is a `#[macro_use] extern crate ...`.
494 pub is_macro_use: bool, 494 pub is_macro_use: bool,
495 pub ast_id: FileAstId<ast::ExternCrateItem>, 495 pub ast_id: FileAstId<ast::ExternCrate>,
496} 496}
497 497
498#[derive(Debug, Clone, Eq, PartialEq)] 498#[derive(Debug, Clone, Eq, PartialEq)]
@@ -505,7 +505,7 @@ pub struct Function {
505 pub params: Box<[TypeRef]>, 505 pub params: Box<[TypeRef]>,
506 pub is_varargs: bool, 506 pub is_varargs: bool,
507 pub ret_type: TypeRef, 507 pub ret_type: TypeRef,
508 pub ast_id: FileAstId<ast::FnDef>, 508 pub ast_id: FileAstId<ast::Fn>,
509} 509}
510 510
511#[derive(Debug, Clone, Eq, PartialEq)] 511#[derive(Debug, Clone, Eq, PartialEq)]
@@ -514,7 +514,7 @@ pub struct Struct {
514 pub visibility: RawVisibilityId, 514 pub visibility: RawVisibilityId,
515 pub generic_params: GenericParamsId, 515 pub generic_params: GenericParamsId,
516 pub fields: Fields, 516 pub fields: Fields,
517 pub ast_id: FileAstId<ast::StructDef>, 517 pub ast_id: FileAstId<ast::Struct>,
518 pub kind: StructDefKind, 518 pub kind: StructDefKind,
519} 519}
520 520
@@ -534,7 +534,7 @@ pub struct Union {
534 pub visibility: RawVisibilityId, 534 pub visibility: RawVisibilityId,
535 pub generic_params: GenericParamsId, 535 pub generic_params: GenericParamsId,
536 pub fields: Fields, 536 pub fields: Fields,
537 pub ast_id: FileAstId<ast::UnionDef>, 537 pub ast_id: FileAstId<ast::Union>,
538} 538}
539 539
540#[derive(Debug, Clone, Eq, PartialEq)] 540#[derive(Debug, Clone, Eq, PartialEq)]
@@ -543,7 +543,7 @@ pub struct Enum {
543 pub visibility: RawVisibilityId, 543 pub visibility: RawVisibilityId,
544 pub generic_params: GenericParamsId, 544 pub generic_params: GenericParamsId,
545 pub variants: IdRange<Variant>, 545 pub variants: IdRange<Variant>,
546 pub ast_id: FileAstId<ast::EnumDef>, 546 pub ast_id: FileAstId<ast::Enum>,
547} 547}
548 548
549#[derive(Debug, Clone, Eq, PartialEq)] 549#[derive(Debug, Clone, Eq, PartialEq)]
@@ -552,7 +552,7 @@ pub struct Const {
552 pub name: Option<Name>, 552 pub name: Option<Name>,
553 pub visibility: RawVisibilityId, 553 pub visibility: RawVisibilityId,
554 pub type_ref: TypeRef, 554 pub type_ref: TypeRef,
555 pub ast_id: FileAstId<ast::ConstDef>, 555 pub ast_id: FileAstId<ast::Const>,
556} 556}
557 557
558#[derive(Debug, Clone, Eq, PartialEq)] 558#[derive(Debug, Clone, Eq, PartialEq)]
@@ -561,7 +561,7 @@ pub struct Static {
561 pub visibility: RawVisibilityId, 561 pub visibility: RawVisibilityId,
562 pub mutable: bool, 562 pub mutable: bool,
563 pub type_ref: TypeRef, 563 pub type_ref: TypeRef,
564 pub ast_id: FileAstId<ast::StaticDef>, 564 pub ast_id: FileAstId<ast::Static>,
565} 565}
566 566
567#[derive(Debug, Clone, Eq, PartialEq)] 567#[derive(Debug, Clone, Eq, PartialEq)]
@@ -571,7 +571,7 @@ pub struct Trait {
571 pub generic_params: GenericParamsId, 571 pub generic_params: GenericParamsId,
572 pub auto: bool, 572 pub auto: bool,
573 pub items: Box<[AssocItem]>, 573 pub items: Box<[AssocItem]>,
574 pub ast_id: FileAstId<ast::TraitDef>, 574 pub ast_id: FileAstId<ast::Trait>,
575} 575}
576 576
577#[derive(Debug, Clone, Eq, PartialEq)] 577#[derive(Debug, Clone, Eq, PartialEq)]
@@ -581,7 +581,7 @@ pub struct Impl {
581 pub target_type: TypeRef, 581 pub target_type: TypeRef,
582 pub is_negative: bool, 582 pub is_negative: bool,
583 pub items: Box<[AssocItem]>, 583 pub items: Box<[AssocItem]>,
584 pub ast_id: FileAstId<ast::ImplDef>, 584 pub ast_id: FileAstId<ast::Impl>,
585} 585}
586 586
587#[derive(Debug, Clone, PartialEq, Eq)] 587#[derive(Debug, Clone, PartialEq, Eq)]
@@ -592,7 +592,7 @@ pub struct TypeAlias {
592 pub bounds: Box<[TypeBound]>, 592 pub bounds: Box<[TypeBound]>,
593 pub generic_params: GenericParamsId, 593 pub generic_params: GenericParamsId,
594 pub type_ref: Option<TypeRef>, 594 pub type_ref: Option<TypeRef>,
595 pub ast_id: FileAstId<ast::TypeAliasDef>, 595 pub ast_id: FileAstId<ast::TypeAlias>,
596} 596}
597 597
598#[derive(Debug, Clone, Eq, PartialEq)] 598#[derive(Debug, Clone, Eq, PartialEq)]
diff --git a/crates/ra_hir_def/src/item_tree/lower.rs b/crates/ra_hir_def/src/item_tree/lower.rs
index f79b8fca3..450ef8798 100644
--- a/crates/ra_hir_def/src/item_tree/lower.rs
+++ b/crates/ra_hir_def/src/item_tree/lower.rs
@@ -1,10 +1,7 @@
1//! AST -> `ItemTree` lowering code. 1//! AST -> `ItemTree` lowering code.
2 2
3use super::*; 3use std::{collections::hash_map::Entry, mem, sync::Arc};
4use crate::{ 4
5 attr::Attrs,
6 generics::{GenericParams, TypeParamData, TypeParamProvenance},
7};
8use hir_expand::{ast_id_map::AstIdMap, hygiene::Hygiene, HirFileId}; 5use hir_expand::{ast_id_map::AstIdMap, hygiene::Hygiene, HirFileId};
9use ra_arena::map::ArenaMap; 6use ra_arena::map::ArenaMap;
10use ra_syntax::{ 7use ra_syntax::{
@@ -12,7 +9,13 @@ use ra_syntax::{
12 SyntaxNode, 9 SyntaxNode,
13}; 10};
14use smallvec::SmallVec; 11use smallvec::SmallVec;
15use std::{collections::hash_map::Entry, mem, sync::Arc}; 12
13use crate::{
14 attr::Attrs,
15 generics::{GenericParams, TypeParamData, TypeParamProvenance},
16};
17
18use super::*;
16 19
17fn id<N: ItemTreeNode>(index: Idx<N>) -> FileItemTreeId<N> { 20fn id<N: ItemTreeNode>(index: Idx<N>) -> FileItemTreeId<N> {
18 FileItemTreeId { index, _p: PhantomData } 21 FileItemTreeId { index, _p: PhantomData }
@@ -70,19 +73,19 @@ impl Ctx {
70 self.tree.data_mut() 73 self.tree.data_mut()
71 } 74 }
72 75
73 fn lower_mod_item(&mut self, item: &ast::ModuleItem, inner: bool) -> Option<ModItems> { 76 fn lower_mod_item(&mut self, item: &ast::Item, inner: bool) -> Option<ModItems> {
74 assert!(inner || self.inner_items.is_empty()); 77 assert!(inner || self.inner_items.is_empty());
75 78
76 // Collect inner items for 1-to-1-lowered items. 79 // Collect inner items for 1-to-1-lowered items.
77 match item { 80 match item {
78 ast::ModuleItem::StructDef(_) 81 ast::Item::Struct(_)
79 | ast::ModuleItem::UnionDef(_) 82 | ast::Item::Union(_)
80 | ast::ModuleItem::EnumDef(_) 83 | ast::Item::Enum(_)
81 | ast::ModuleItem::FnDef(_) 84 | ast::Item::Fn(_)
82 | ast::ModuleItem::TypeAliasDef(_) 85 | ast::Item::TypeAlias(_)
83 | ast::ModuleItem::ConstDef(_) 86 | ast::Item::Const(_)
84 | ast::ModuleItem::StaticDef(_) 87 | ast::Item::Static(_)
85 | ast::ModuleItem::MacroCall(_) => { 88 | ast::Item::MacroCall(_) => {
86 // Skip this if we're already collecting inner items. We'll descend into all nodes 89 // Skip this if we're already collecting inner items. We'll descend into all nodes
87 // already. 90 // already.
88 if !inner { 91 if !inner {
@@ -92,34 +95,30 @@ impl Ctx {
92 95
93 // These are handled in their respective `lower_X` method (since we can't just blindly 96 // These are handled in their respective `lower_X` method (since we can't just blindly
94 // walk them). 97 // walk them).
95 ast::ModuleItem::TraitDef(_) 98 ast::Item::Trait(_) | ast::Item::Impl(_) | ast::Item::ExternBlock(_) => {}
96 | ast::ModuleItem::ImplDef(_)
97 | ast::ModuleItem::ExternBlock(_) => {}
98 99
99 // These don't have inner items. 100 // These don't have inner items.
100 ast::ModuleItem::Module(_) 101 ast::Item::Module(_) | ast::Item::ExternCrate(_) | ast::Item::Use(_) => {}
101 | ast::ModuleItem::ExternCrateItem(_)
102 | ast::ModuleItem::UseItem(_) => {}
103 }; 102 };
104 103
105 let attrs = Attrs::new(item, &self.hygiene); 104 let attrs = Attrs::new(item, &self.hygiene);
106 let items = match item { 105 let items = match item {
107 ast::ModuleItem::StructDef(ast) => self.lower_struct(ast).map(Into::into), 106 ast::Item::Struct(ast) => self.lower_struct(ast).map(Into::into),
108 ast::ModuleItem::UnionDef(ast) => self.lower_union(ast).map(Into::into), 107 ast::Item::Union(ast) => self.lower_union(ast).map(Into::into),
109 ast::ModuleItem::EnumDef(ast) => self.lower_enum(ast).map(Into::into), 108 ast::Item::Enum(ast) => self.lower_enum(ast).map(Into::into),
110 ast::ModuleItem::FnDef(ast) => self.lower_function(ast).map(Into::into), 109 ast::Item::Fn(ast) => self.lower_function(ast).map(Into::into),
111 ast::ModuleItem::TypeAliasDef(ast) => self.lower_type_alias(ast).map(Into::into), 110 ast::Item::TypeAlias(ast) => self.lower_type_alias(ast).map(Into::into),
112 ast::ModuleItem::StaticDef(ast) => self.lower_static(ast).map(Into::into), 111 ast::Item::Static(ast) => self.lower_static(ast).map(Into::into),
113 ast::ModuleItem::ConstDef(ast) => Some(self.lower_const(ast).into()), 112 ast::Item::Const(ast) => Some(self.lower_const(ast).into()),
114 ast::ModuleItem::Module(ast) => self.lower_module(ast).map(Into::into), 113 ast::Item::Module(ast) => self.lower_module(ast).map(Into::into),
115 ast::ModuleItem::TraitDef(ast) => self.lower_trait(ast).map(Into::into), 114 ast::Item::Trait(ast) => self.lower_trait(ast).map(Into::into),
116 ast::ModuleItem::ImplDef(ast) => self.lower_impl(ast).map(Into::into), 115 ast::Item::Impl(ast) => self.lower_impl(ast).map(Into::into),
117 ast::ModuleItem::UseItem(ast) => Some(ModItems( 116 ast::Item::Use(ast) => Some(ModItems(
118 self.lower_use(ast).into_iter().map(Into::into).collect::<SmallVec<_>>(), 117 self.lower_use(ast).into_iter().map(Into::into).collect::<SmallVec<_>>(),
119 )), 118 )),
120 ast::ModuleItem::ExternCrateItem(ast) => self.lower_extern_crate(ast).map(Into::into), 119 ast::Item::ExternCrate(ast) => self.lower_extern_crate(ast).map(Into::into),
121 ast::ModuleItem::MacroCall(ast) => self.lower_macro_call(ast).map(Into::into), 120 ast::Item::MacroCall(ast) => self.lower_macro_call(ast).map(Into::into),
122 ast::ModuleItem::ExternBlock(ast) => { 121 ast::Item::ExternBlock(ast) => {
123 Some(ModItems(self.lower_extern_block(ast).into_iter().collect::<SmallVec<_>>())) 122 Some(ModItems(self.lower_extern_block(ast).into_iter().collect::<SmallVec<_>>()))
124 } 123 }
125 }; 124 };
@@ -147,27 +146,26 @@ impl Ctx {
147 fn collect_inner_items(&mut self, container: &SyntaxNode) { 146 fn collect_inner_items(&mut self, container: &SyntaxNode) {
148 let forced_vis = self.forced_visibility.take(); 147 let forced_vis = self.forced_visibility.take();
149 let mut inner_items = mem::take(&mut self.tree.inner_items); 148 let mut inner_items = mem::take(&mut self.tree.inner_items);
150 inner_items.extend( 149 inner_items.extend(container.descendants().skip(1).filter_map(ast::Item::cast).filter_map(
151 container.descendants().skip(1).filter_map(ast::ModuleItem::cast).filter_map(|item| { 150 |item| {
152 let ast_id = self.source_ast_id_map.ast_id(&item); 151 let ast_id = self.source_ast_id_map.ast_id(&item);
153 Some((ast_id, self.lower_mod_item(&item, true)?.0)) 152 Some((ast_id, self.lower_mod_item(&item, true)?.0))
154 }), 153 },
155 ); 154 ));
156 self.tree.inner_items = inner_items; 155 self.tree.inner_items = inner_items;
157 self.forced_visibility = forced_vis; 156 self.forced_visibility = forced_vis;
158 } 157 }
159 158
160 fn lower_assoc_item(&mut self, item: &ast::ModuleItem) -> Option<AssocItem> { 159 fn lower_assoc_item(&mut self, item: &ast::AssocItem) -> Option<AssocItem> {
161 match item { 160 match item {
162 ast::ModuleItem::FnDef(ast) => self.lower_function(ast).map(Into::into), 161 ast::AssocItem::Fn(ast) => self.lower_function(ast).map(Into::into),
163 ast::ModuleItem::TypeAliasDef(ast) => self.lower_type_alias(ast).map(Into::into), 162 ast::AssocItem::TypeAlias(ast) => self.lower_type_alias(ast).map(Into::into),
164 ast::ModuleItem::ConstDef(ast) => Some(self.lower_const(ast).into()), 163 ast::AssocItem::Const(ast) => Some(self.lower_const(ast).into()),
165 ast::ModuleItem::MacroCall(ast) => self.lower_macro_call(ast).map(Into::into), 164 ast::AssocItem::MacroCall(ast) => self.lower_macro_call(ast).map(Into::into),
166 _ => None,
167 } 165 }
168 } 166 }
169 167
170 fn lower_struct(&mut self, strukt: &ast::StructDef) -> Option<FileItemTreeId<Struct>> { 168 fn lower_struct(&mut self, strukt: &ast::Struct) -> Option<FileItemTreeId<Struct>> {
171 let visibility = self.lower_visibility(strukt); 169 let visibility = self.lower_visibility(strukt);
172 let name = strukt.name()?.as_name(); 170 let name = strukt.name()?.as_name();
173 let generic_params = self.lower_generic_params(GenericsOwner::Struct, strukt); 171 let generic_params = self.lower_generic_params(GenericsOwner::Struct, strukt);
@@ -196,7 +194,7 @@ impl Ctx {
196 } 194 }
197 } 195 }
198 196
199 fn lower_record_fields(&mut self, fields: &ast::RecordFieldDefList) -> IdRange<Field> { 197 fn lower_record_fields(&mut self, fields: &ast::RecordFieldList) -> IdRange<Field> {
200 let start = self.next_field_idx(); 198 let start = self.next_field_idx();
201 for field in fields.fields() { 199 for field in fields.fields() {
202 if let Some(data) = self.lower_record_field(&field) { 200 if let Some(data) = self.lower_record_field(&field) {
@@ -208,15 +206,15 @@ impl Ctx {
208 IdRange::new(start..end) 206 IdRange::new(start..end)
209 } 207 }
210 208
211 fn lower_record_field(&mut self, field: &ast::RecordFieldDef) -> Option<Field> { 209 fn lower_record_field(&mut self, field: &ast::RecordField) -> Option<Field> {
212 let name = field.name()?.as_name(); 210 let name = field.name()?.as_name();
213 let visibility = self.lower_visibility(field); 211 let visibility = self.lower_visibility(field);
214 let type_ref = self.lower_type_ref_opt(field.ascribed_type()); 212 let type_ref = self.lower_type_ref_opt(field.ty());
215 let res = Field { name, type_ref, visibility }; 213 let res = Field { name, type_ref, visibility };
216 Some(res) 214 Some(res)
217 } 215 }
218 216
219 fn lower_tuple_fields(&mut self, fields: &ast::TupleFieldDefList) -> IdRange<Field> { 217 fn lower_tuple_fields(&mut self, fields: &ast::TupleFieldList) -> IdRange<Field> {
220 let start = self.next_field_idx(); 218 let start = self.next_field_idx();
221 for (i, field) in fields.fields().enumerate() { 219 for (i, field) in fields.fields().enumerate() {
222 let data = self.lower_tuple_field(i, &field); 220 let data = self.lower_tuple_field(i, &field);
@@ -227,22 +225,20 @@ impl Ctx {
227 IdRange::new(start..end) 225 IdRange::new(start..end)
228 } 226 }
229 227
230 fn lower_tuple_field(&mut self, idx: usize, field: &ast::TupleFieldDef) -> Field { 228 fn lower_tuple_field(&mut self, idx: usize, field: &ast::TupleField) -> Field {
231 let name = Name::new_tuple_field(idx); 229 let name = Name::new_tuple_field(idx);
232 let visibility = self.lower_visibility(field); 230 let visibility = self.lower_visibility(field);
233 let type_ref = self.lower_type_ref_opt(field.type_ref()); 231 let type_ref = self.lower_type_ref_opt(field.ty());
234 let res = Field { name, type_ref, visibility }; 232 let res = Field { name, type_ref, visibility };
235 res 233 res
236 } 234 }
237 235
238 fn lower_union(&mut self, union: &ast::UnionDef) -> Option<FileItemTreeId<Union>> { 236 fn lower_union(&mut self, union: &ast::Union) -> Option<FileItemTreeId<Union>> {
239 let visibility = self.lower_visibility(union); 237 let visibility = self.lower_visibility(union);
240 let name = union.name()?.as_name(); 238 let name = union.name()?.as_name();
241 let generic_params = self.lower_generic_params(GenericsOwner::Union, union); 239 let generic_params = self.lower_generic_params(GenericsOwner::Union, union);
242 let fields = match union.record_field_def_list() { 240 let fields = match union.record_field_list() {
243 Some(record_field_def_list) => { 241 Some(record_field_list) => self.lower_fields(&StructKind::Record(record_field_list)),
244 self.lower_fields(&StructKind::Record(record_field_def_list))
245 }
246 None => Fields::Record(IdRange::new(self.next_field_idx()..self.next_field_idx())), 242 None => Fields::Record(IdRange::new(self.next_field_idx()..self.next_field_idx())),
247 }; 243 };
248 let ast_id = self.source_ast_id_map.ast_id(union); 244 let ast_id = self.source_ast_id_map.ast_id(union);
@@ -250,7 +246,7 @@ impl Ctx {
250 Some(id(self.data().unions.alloc(res))) 246 Some(id(self.data().unions.alloc(res)))
251 } 247 }
252 248
253 fn lower_enum(&mut self, enum_: &ast::EnumDef) -> Option<FileItemTreeId<Enum>> { 249 fn lower_enum(&mut self, enum_: &ast::Enum) -> Option<FileItemTreeId<Enum>> {
254 let visibility = self.lower_visibility(enum_); 250 let visibility = self.lower_visibility(enum_);
255 let name = enum_.name()?.as_name(); 251 let name = enum_.name()?.as_name();
256 let generic_params = self.lower_generic_params(GenericsOwner::Enum, enum_); 252 let generic_params = self.lower_generic_params(GenericsOwner::Enum, enum_);
@@ -263,7 +259,7 @@ impl Ctx {
263 Some(id(self.data().enums.alloc(res))) 259 Some(id(self.data().enums.alloc(res)))
264 } 260 }
265 261
266 fn lower_variants(&mut self, variants: &ast::EnumVariantList) -> IdRange<Variant> { 262 fn lower_variants(&mut self, variants: &ast::VariantList) -> IdRange<Variant> {
267 let start = self.next_variant_idx(); 263 let start = self.next_variant_idx();
268 for variant in variants.variants() { 264 for variant in variants.variants() {
269 if let Some(data) = self.lower_variant(&variant) { 265 if let Some(data) = self.lower_variant(&variant) {
@@ -275,14 +271,14 @@ impl Ctx {
275 IdRange::new(start..end) 271 IdRange::new(start..end)
276 } 272 }
277 273
278 fn lower_variant(&mut self, variant: &ast::EnumVariant) -> Option<Variant> { 274 fn lower_variant(&mut self, variant: &ast::Variant) -> Option<Variant> {
279 let name = variant.name()?.as_name(); 275 let name = variant.name()?.as_name();
280 let fields = self.lower_fields(&variant.kind()); 276 let fields = self.lower_fields(&variant.kind());
281 let res = Variant { name, fields }; 277 let res = Variant { name, fields };
282 Some(res) 278 Some(res)
283 } 279 }
284 280
285 fn lower_function(&mut self, func: &ast::FnDef) -> Option<FileItemTreeId<Function>> { 281 fn lower_function(&mut self, func: &ast::Fn) -> Option<FileItemTreeId<Function>> {
286 let visibility = self.lower_visibility(func); 282 let visibility = self.lower_visibility(func);
287 let name = func.name()?.as_name(); 283 let name = func.name()?.as_name();
288 284
@@ -290,7 +286,7 @@ impl Ctx {
290 let mut has_self_param = false; 286 let mut has_self_param = false;
291 if let Some(param_list) = func.param_list() { 287 if let Some(param_list) = func.param_list() {
292 if let Some(self_param) = param_list.self_param() { 288 if let Some(self_param) = param_list.self_param() {
293 let self_type = match self_param.ascribed_type() { 289 let self_type = match self_param.ty() {
294 Some(type_ref) => TypeRef::from_ast(&self.body_ctx, type_ref), 290 Some(type_ref) => TypeRef::from_ast(&self.body_ctx, type_ref),
295 None => { 291 None => {
296 let self_type = TypeRef::Path(name![Self].into()); 292 let self_type = TypeRef::Path(name![Self].into());
@@ -309,7 +305,7 @@ impl Ctx {
309 has_self_param = true; 305 has_self_param = true;
310 } 306 }
311 for param in param_list.params() { 307 for param in param_list.params() {
312 let type_ref = TypeRef::from_ast_opt(&self.body_ctx, param.ascribed_type()); 308 let type_ref = TypeRef::from_ast_opt(&self.body_ctx, param.ty());
313 params.push(type_ref); 309 params.push(type_ref);
314 } 310 }
315 } 311 }
@@ -321,7 +317,7 @@ impl Ctx {
321 } 317 }
322 } 318 }
323 319
324 let ret_type = match func.ret_type().and_then(|rt| rt.type_ref()) { 320 let ret_type = match func.ret_type().and_then(|rt| rt.ty()) {
325 Some(type_ref) => TypeRef::from_ast(&self.body_ctx, type_ref), 321 Some(type_ref) => TypeRef::from_ast(&self.body_ctx, type_ref),
326 _ => TypeRef::unit(), 322 _ => TypeRef::unit(),
327 }; 323 };
@@ -353,10 +349,10 @@ impl Ctx {
353 349
354 fn lower_type_alias( 350 fn lower_type_alias(
355 &mut self, 351 &mut self,
356 type_alias: &ast::TypeAliasDef, 352 type_alias: &ast::TypeAlias,
357 ) -> Option<FileItemTreeId<TypeAlias>> { 353 ) -> Option<FileItemTreeId<TypeAlias>> {
358 let name = type_alias.name()?.as_name(); 354 let name = type_alias.name()?.as_name();
359 let type_ref = type_alias.type_ref().map(|it| self.lower_type_ref(&it)); 355 let type_ref = type_alias.ty().map(|it| self.lower_type_ref(&it));
360 let visibility = self.lower_visibility(type_alias); 356 let visibility = self.lower_visibility(type_alias);
361 let bounds = self.lower_type_bounds(type_alias); 357 let bounds = self.lower_type_bounds(type_alias);
362 let generic_params = self.lower_generic_params(GenericsOwner::TypeAlias, type_alias); 358 let generic_params = self.lower_generic_params(GenericsOwner::TypeAlias, type_alias);
@@ -372,9 +368,9 @@ impl Ctx {
372 Some(id(self.data().type_aliases.alloc(res))) 368 Some(id(self.data().type_aliases.alloc(res)))
373 } 369 }
374 370
375 fn lower_static(&mut self, static_: &ast::StaticDef) -> Option<FileItemTreeId<Static>> { 371 fn lower_static(&mut self, static_: &ast::Static) -> Option<FileItemTreeId<Static>> {
376 let name = static_.name()?.as_name(); 372 let name = static_.name()?.as_name();
377 let type_ref = self.lower_type_ref_opt(static_.ascribed_type()); 373 let type_ref = self.lower_type_ref_opt(static_.ty());
378 let visibility = self.lower_visibility(static_); 374 let visibility = self.lower_visibility(static_);
379 let mutable = static_.mut_token().is_some(); 375 let mutable = static_.mut_token().is_some();
380 let ast_id = self.source_ast_id_map.ast_id(static_); 376 let ast_id = self.source_ast_id_map.ast_id(static_);
@@ -382,9 +378,9 @@ impl Ctx {
382 Some(id(self.data().statics.alloc(res))) 378 Some(id(self.data().statics.alloc(res)))
383 } 379 }
384 380
385 fn lower_const(&mut self, konst: &ast::ConstDef) -> FileItemTreeId<Const> { 381 fn lower_const(&mut self, konst: &ast::Const) -> FileItemTreeId<Const> {
386 let name = konst.name().map(|it| it.as_name()); 382 let name = konst.name().map(|it| it.as_name());
387 let type_ref = self.lower_type_ref_opt(konst.ascribed_type()); 383 let type_ref = self.lower_type_ref_opt(konst.ty());
388 let visibility = self.lower_visibility(konst); 384 let visibility = self.lower_visibility(konst);
389 let ast_id = self.source_ast_id_map.ast_id(konst); 385 let ast_id = self.source_ast_id_map.ast_id(konst);
390 let res = Const { name, visibility, type_ref, ast_id }; 386 let res = Const { name, visibility, type_ref, ast_id };
@@ -417,15 +413,15 @@ impl Ctx {
417 Some(id(self.data().mods.alloc(res))) 413 Some(id(self.data().mods.alloc(res)))
418 } 414 }
419 415
420 fn lower_trait(&mut self, trait_def: &ast::TraitDef) -> Option<FileItemTreeId<Trait>> { 416 fn lower_trait(&mut self, trait_def: &ast::Trait) -> Option<FileItemTreeId<Trait>> {
421 let name = trait_def.name()?.as_name(); 417 let name = trait_def.name()?.as_name();
422 let visibility = self.lower_visibility(trait_def); 418 let visibility = self.lower_visibility(trait_def);
423 let generic_params = 419 let generic_params =
424 self.lower_generic_params_and_inner_items(GenericsOwner::Trait(trait_def), trait_def); 420 self.lower_generic_params_and_inner_items(GenericsOwner::Trait(trait_def), trait_def);
425 let auto = trait_def.auto_token().is_some(); 421 let auto = trait_def.auto_token().is_some();
426 let items = trait_def.item_list().map(|list| { 422 let items = trait_def.assoc_item_list().map(|list| {
427 self.with_inherited_visibility(visibility, |this| { 423 self.with_inherited_visibility(visibility, |this| {
428 list.items() 424 list.assoc_items()
429 .filter_map(|item| { 425 .filter_map(|item| {
430 let attrs = Attrs::new(&item, &this.hygiene); 426 let attrs = Attrs::new(&item, &this.hygiene);
431 this.collect_inner_items(item.syntax()); 427 this.collect_inner_items(item.syntax());
@@ -449,18 +445,18 @@ impl Ctx {
449 Some(id(self.data().traits.alloc(res))) 445 Some(id(self.data().traits.alloc(res)))
450 } 446 }
451 447
452 fn lower_impl(&mut self, impl_def: &ast::ImplDef) -> Option<FileItemTreeId<Impl>> { 448 fn lower_impl(&mut self, impl_def: &ast::Impl) -> Option<FileItemTreeId<Impl>> {
453 let generic_params = 449 let generic_params =
454 self.lower_generic_params_and_inner_items(GenericsOwner::Impl, impl_def); 450 self.lower_generic_params_and_inner_items(GenericsOwner::Impl, impl_def);
455 let target_trait = impl_def.target_trait().map(|tr| self.lower_type_ref(&tr)); 451 let target_trait = impl_def.trait_().map(|tr| self.lower_type_ref(&tr));
456 let target_type = self.lower_type_ref(&impl_def.target_type()?); 452 let target_type = self.lower_type_ref(&impl_def.self_ty()?);
457 let is_negative = impl_def.excl_token().is_some(); 453 let is_negative = impl_def.excl_token().is_some();
458 454
459 // We cannot use `assoc_items()` here as that does not include macro calls. 455 // We cannot use `assoc_items()` here as that does not include macro calls.
460 let items = impl_def 456 let items = impl_def
461 .item_list() 457 .assoc_item_list()
462 .into_iter() 458 .into_iter()
463 .flat_map(|it| it.items()) 459 .flat_map(|it| it.assoc_items())
464 .filter_map(|item| { 460 .filter_map(|item| {
465 self.collect_inner_items(item.syntax()); 461 self.collect_inner_items(item.syntax());
466 let assoc = self.lower_assoc_item(&item)?; 462 let assoc = self.lower_assoc_item(&item)?;
@@ -474,7 +470,7 @@ impl Ctx {
474 Some(id(self.data().impls.alloc(res))) 470 Some(id(self.data().impls.alloc(res)))
475 } 471 }
476 472
477 fn lower_use(&mut self, use_item: &ast::UseItem) -> Vec<FileItemTreeId<Import>> { 473 fn lower_use(&mut self, use_item: &ast::Use) -> Vec<FileItemTreeId<Import>> {
478 // FIXME: cfg_attr 474 // FIXME: cfg_attr
479 let is_prelude = use_item.has_atom_attr("prelude_import"); 475 let is_prelude = use_item.has_atom_attr("prelude_import");
480 let visibility = self.lower_visibility(use_item); 476 let visibility = self.lower_visibility(use_item);
@@ -503,10 +499,10 @@ impl Ctx {
503 499
504 fn lower_extern_crate( 500 fn lower_extern_crate(
505 &mut self, 501 &mut self,
506 extern_crate: &ast::ExternCrateItem, 502 extern_crate: &ast::ExternCrate,
507 ) -> Option<FileItemTreeId<ExternCrate>> { 503 ) -> Option<FileItemTreeId<ExternCrate>> {
508 let path = ModPath::from_name_ref(&extern_crate.name_ref()?); 504 let path = ModPath::from_name_ref(&extern_crate.name_ref()?);
509 let alias = extern_crate.alias().map(|a| { 505 let alias = extern_crate.rename().map(|a| {
510 a.name().map(|it| it.as_name()).map_or(ImportAlias::Underscore, ImportAlias::Alias) 506 a.name().map(|it| it.as_name()).map_or(ImportAlias::Underscore, ImportAlias::Alias)
511 }); 507 });
512 let visibility = self.lower_visibility(extern_crate); 508 let visibility = self.lower_visibility(extern_crate);
@@ -552,15 +548,16 @@ impl Ctx {
552 self.collect_inner_items(item.syntax()); 548 self.collect_inner_items(item.syntax());
553 let attrs = Attrs::new(&item, &self.hygiene); 549 let attrs = Attrs::new(&item, &self.hygiene);
554 let id: ModItem = match item { 550 let id: ModItem = match item {
555 ast::ExternItem::FnDef(ast) => { 551 ast::ExternItem::Fn(ast) => {
556 let func = self.lower_function(&ast)?; 552 let func = self.lower_function(&ast)?;
557 self.data().functions[func.index].is_unsafe = true; 553 self.data().functions[func.index].is_unsafe = true;
558 func.into() 554 func.into()
559 } 555 }
560 ast::ExternItem::StaticDef(ast) => { 556 ast::ExternItem::Static(ast) => {
561 let statik = self.lower_static(&ast)?; 557 let statik = self.lower_static(&ast)?;
562 statik.into() 558 statik.into()
563 } 559 }
560 ast::ExternItem::MacroCall(_) => return None,
564 }; 561 };
565 self.add_attrs(id.into(), attrs); 562 self.add_attrs(id.into(), attrs);
566 Some(id) 563 Some(id)
@@ -573,10 +570,10 @@ impl Ctx {
573 fn lower_generic_params_and_inner_items( 570 fn lower_generic_params_and_inner_items(
574 &mut self, 571 &mut self,
575 owner: GenericsOwner<'_>, 572 owner: GenericsOwner<'_>,
576 node: &impl ast::TypeParamsOwner, 573 node: &impl ast::GenericParamsOwner,
577 ) -> GenericParamsId { 574 ) -> GenericParamsId {
578 // Generics are part of item headers and may contain inner items we need to collect. 575 // Generics are part of item headers and may contain inner items we need to collect.
579 if let Some(params) = node.type_param_list() { 576 if let Some(params) = node.generic_param_list() {
580 self.collect_inner_items(params.syntax()); 577 self.collect_inner_items(params.syntax());
581 } 578 }
582 if let Some(clause) = node.where_clause() { 579 if let Some(clause) = node.where_clause() {
@@ -589,7 +586,7 @@ impl Ctx {
589 fn lower_generic_params( 586 fn lower_generic_params(
590 &mut self, 587 &mut self,
591 owner: GenericsOwner<'_>, 588 owner: GenericsOwner<'_>,
592 node: &impl ast::TypeParamsOwner, 589 node: &impl ast::GenericParamsOwner,
593 ) -> GenericParamsId { 590 ) -> GenericParamsId {
594 let mut sm = &mut ArenaMap::default(); 591 let mut sm = &mut ArenaMap::default();
595 let mut generics = GenericParams::default(); 592 let mut generics = GenericParams::default();
@@ -651,10 +648,10 @@ impl Ctx {
651 self.data().vis.alloc(vis) 648 self.data().vis.alloc(vis)
652 } 649 }
653 650
654 fn lower_type_ref(&self, type_ref: &ast::TypeRef) -> TypeRef { 651 fn lower_type_ref(&self, type_ref: &ast::Type) -> TypeRef {
655 TypeRef::from_ast(&self.body_ctx, type_ref.clone()) 652 TypeRef::from_ast(&self.body_ctx, type_ref.clone())
656 } 653 }
657 fn lower_type_ref_opt(&self, type_ref: Option<ast::TypeRef>) -> TypeRef { 654 fn lower_type_ref_opt(&self, type_ref: Option<ast::Type>) -> TypeRef {
658 type_ref.map(|ty| self.lower_type_ref(&ty)).unwrap_or(TypeRef::Error) 655 type_ref.map(|ty| self.lower_type_ref(&ty)).unwrap_or(TypeRef::Error)
659 } 656 }
660 657
@@ -702,7 +699,7 @@ enum GenericsOwner<'a> {
702 Enum, 699 Enum,
703 Union, 700 Union,
704 /// The `TraitDef` is needed to fill the source map for the implicit `Self` parameter. 701 /// The `TraitDef` is needed to fill the source map for the implicit `Self` parameter.
705 Trait(&'a ast::TraitDef), 702 Trait(&'a ast::Trait),
706 TypeAlias, 703 TypeAlias,
707 Impl, 704 Impl,
708} 705}
diff --git a/crates/ra_hir_def/src/item_tree/tests.rs b/crates/ra_hir_def/src/item_tree/tests.rs
index f26982985..a81497fa8 100644
--- a/crates/ra_hir_def/src/item_tree/tests.rs
+++ b/crates/ra_hir_def/src/item_tree/tests.rs
@@ -21,7 +21,7 @@ fn test_inner_items(ra_fixture: &str) {
21 let mut outer_items = FxHashSet::default(); 21 let mut outer_items = FxHashSet::default();
22 let mut worklist = tree.top_level_items().to_vec(); 22 let mut worklist = tree.top_level_items().to_vec();
23 while let Some(item) = worklist.pop() { 23 while let Some(item) = worklist.pop() {
24 let node: ast::ModuleItem = match item { 24 let node: ast::Item = match item {
25 ModItem::Import(it) => tree.source(&db, InFile::new(file_id, it)).into(), 25 ModItem::Import(it) => tree.source(&db, InFile::new(file_id, it)).into(),
26 ModItem::ExternCrate(it) => tree.source(&db, InFile::new(file_id, it)).into(), 26 ModItem::ExternCrate(it) => tree.source(&db, InFile::new(file_id, it)).into(),
27 ModItem::Function(it) => tree.source(&db, InFile::new(file_id, it)).into(), 27 ModItem::Function(it) => tree.source(&db, InFile::new(file_id, it)).into(),
@@ -53,7 +53,7 @@ fn test_inner_items(ra_fixture: &str) {
53 53
54 // Now descend the root node and check that all `ast::ModuleItem`s are either recorded above, or 54 // Now descend the root node and check that all `ast::ModuleItem`s are either recorded above, or
55 // registered as inner items. 55 // registered as inner items.
56 for item in root.descendants().skip(1).filter_map(ast::ModuleItem::cast) { 56 for item in root.descendants().skip(1).filter_map(ast::Item::cast) {
57 if outer_items.contains(&item) { 57 if outer_items.contains(&item) {
58 continue; 58 continue;
59 } 59 }
@@ -228,31 +228,31 @@ fn smoke() {
228 228
229 top-level items: 229 top-level items:
230 #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_on_use"))] }, input: None }]) }] 230 #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_on_use"))] }, input: None }]) }]
231 Import { path: ModPath { kind: Plain, segments: [Name(Text("a"))] }, alias: None, visibility: RawVisibilityId("pub(self)"), is_glob: false, is_prelude: false, ast_id: FileAstId::<ra_syntax::ast::generated::nodes::UseItem>(0) } 231 Import { path: ModPath { kind: Plain, segments: [Name(Text("a"))] }, alias: None, visibility: RawVisibilityId("pub(self)"), is_glob: false, is_prelude: false, ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Use>(0) }
232 #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_on_use"))] }, input: None }]) }] 232 #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_on_use"))] }, input: None }]) }]
233 Import { path: ModPath { kind: Plain, segments: [Name(Text("b"))] }, alias: None, visibility: RawVisibilityId("pub(self)"), is_glob: true, is_prelude: false, ast_id: FileAstId::<ra_syntax::ast::generated::nodes::UseItem>(0) } 233 Import { path: ModPath { kind: Plain, segments: [Name(Text("b"))] }, alias: None, visibility: RawVisibilityId("pub(self)"), is_glob: true, is_prelude: false, ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Use>(0) }
234 #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("ext_crate"))] }, input: None }]) }] 234 #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("ext_crate"))] }, input: None }]) }]
235 ExternCrate { path: ModPath { kind: Plain, segments: [Name(Text("krate"))] }, alias: None, visibility: RawVisibilityId("pub(self)"), is_macro_use: false, ast_id: FileAstId::<ra_syntax::ast::generated::nodes::ExternCrateItem>(1) } 235 ExternCrate { path: ModPath { kind: Plain, segments: [Name(Text("krate"))] }, alias: None, visibility: RawVisibilityId("pub(self)"), is_macro_use: false, ast_id: FileAstId::<ra_syntax::ast::generated::nodes::ExternCrate>(1) }
236 #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("on_trait"))] }, input: None }]) }] 236 #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("on_trait"))] }, input: None }]) }]
237 Trait { name: Name(Text("Tr")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(0), auto: false, items: [TypeAlias(Idx::<TypeAlias>(0)), Const(Idx::<Const>(0)), Function(Idx::<Function>(0)), Function(Idx::<Function>(1))], ast_id: FileAstId::<ra_syntax::ast::generated::nodes::TraitDef>(2) } 237 Trait { name: Name(Text("Tr")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(0), auto: false, items: [TypeAlias(Idx::<TypeAlias>(0)), Const(Idx::<Const>(0)), Function(Idx::<Function>(0)), Function(Idx::<Function>(1))], ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Trait>(2) }
238 > #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("assoc_ty"))] }, input: None }]) }] 238 > #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("assoc_ty"))] }, input: None }]) }]
239 > TypeAlias { name: Name(Text("AssocTy")), visibility: RawVisibilityId("pub(self)"), bounds: [Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("Tr"))] }, generic_args: [Some(GenericArgs { args: [Type(Tuple([]))], has_self_type: false, bindings: [] })] })], generic_params: GenericParamsId(4294967295), type_ref: None, ast_id: FileAstId::<ra_syntax::ast::generated::nodes::TypeAliasDef>(8) } 239 > TypeAlias { name: Name(Text("AssocTy")), visibility: RawVisibilityId("pub(self)"), bounds: [Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("Tr"))] }, generic_args: [Some(GenericArgs { args: [Type(Tuple([]))], has_self_type: false, bindings: [] })] })], generic_params: GenericParamsId(4294967295), type_ref: None, ast_id: FileAstId::<ra_syntax::ast::generated::nodes::TypeAlias>(8) }
240 > #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("assoc_const"))] }, input: None }]) }] 240 > #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("assoc_const"))] }, input: None }]) }]
241 > Const { name: Some(Name(Text("CONST"))), visibility: RawVisibilityId("pub(self)"), type_ref: Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("u8"))] }, generic_args: [None] }), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::ConstDef>(9) } 241 > Const { name: Some(Name(Text("CONST"))), visibility: RawVisibilityId("pub(self)"), type_ref: Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("u8"))] }, generic_args: [None] }), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Const>(9) }
242 > #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("assoc_method"))] }, input: None }]) }] 242 > #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("assoc_method"))] }, input: None }]) }]
243 > Function { name: Name(Text("method")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: true, is_unsafe: false, params: [Reference(Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("Self"))] }, generic_args: [None] }), Shared)], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::FnDef>(10) } 243 > Function { name: Name(Text("method")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: true, is_unsafe: false, params: [Reference(Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("Self"))] }, generic_args: [None] }), Shared)], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Fn>(10) }
244 > #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("assoc_dfl_method"))] }, input: None }]) }] 244 > #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("assoc_dfl_method"))] }, input: None }]) }]
245 > Function { name: Name(Text("dfl_method")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: true, is_unsafe: false, params: [Reference(Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("Self"))] }, generic_args: [None] }), Mut)], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::FnDef>(11) } 245 > Function { name: Name(Text("dfl_method")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: true, is_unsafe: false, params: [Reference(Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("Self"))] }, generic_args: [None] }), Mut)], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Fn>(11) }
246 #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("struct0"))] }, input: None }]) }] 246 #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("struct0"))] }, input: None }]) }]
247 Struct { name: Name(Text("Struct0")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(1), fields: Unit, ast_id: FileAstId::<ra_syntax::ast::generated::nodes::StructDef>(3), kind: Unit } 247 Struct { name: Name(Text("Struct0")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(1), fields: Unit, ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Struct>(3), kind: Unit }
248 #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("struct1"))] }, input: None }]) }] 248 #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("struct1"))] }, input: None }]) }]
249 Struct { name: Name(Text("Struct1")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(2), fields: Tuple(IdRange::<ra_hir_def::item_tree::Field>(0..1)), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::StructDef>(4), kind: Tuple } 249 Struct { name: Name(Text("Struct1")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(2), fields: Tuple(IdRange::<ra_hir_def::item_tree::Field>(0..1)), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Struct>(4), kind: Tuple }
250 #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("struct2"))] }, input: None }]) }] 250 #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("struct2"))] }, input: None }]) }]
251 Struct { name: Name(Text("Struct2")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(3), fields: Record(IdRange::<ra_hir_def::item_tree::Field>(1..2)), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::StructDef>(5), kind: Record } 251 Struct { name: Name(Text("Struct2")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(3), fields: Record(IdRange::<ra_hir_def::item_tree::Field>(1..2)), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Struct>(5), kind: Record }
252 #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("en"))] }, input: None }]) }] 252 #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("en"))] }, input: None }]) }]
253 Enum { name: Name(Text("En")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), variants: IdRange::<ra_hir_def::item_tree::Variant>(0..1), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::EnumDef>(6) } 253 Enum { name: Name(Text("En")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), variants: IdRange::<ra_hir_def::item_tree::Variant>(0..1), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Enum>(6) }
254 #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("un"))] }, input: None }]) }] 254 #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("un"))] }, input: None }]) }]
255 Union { name: Name(Text("Un")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), fields: Record(IdRange::<ra_hir_def::item_tree::Field>(3..4)), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::UnionDef>(7) } 255 Union { name: Name(Text("Un")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), fields: Record(IdRange::<ra_hir_def::item_tree::Field>(3..4)), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Union>(7) }
256 "##]], 256 "##]],
257 ); 257 );
258} 258}
@@ -274,13 +274,13 @@ fn simple_inner_items() {
274 inner attrs: Attrs { entries: None } 274 inner attrs: Attrs { entries: None }
275 275
276 top-level items: 276 top-level items:
277 Impl { generic_params: GenericParamsId(0), target_trait: Some(Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("D"))] }, generic_args: [None] })), target_type: Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("Response"))] }, generic_args: [Some(GenericArgs { args: [Type(Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("T"))] }, generic_args: [None] }))], has_self_type: false, bindings: [] })] }), is_negative: false, items: [Function(Idx::<Function>(1))], ast_id: FileAstId::<ra_syntax::ast::generated::nodes::ImplDef>(0) } 277 Impl { generic_params: GenericParamsId(0), target_trait: Some(Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("D"))] }, generic_args: [None] })), target_type: Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("Response"))] }, generic_args: [Some(GenericArgs { args: [Type(Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("T"))] }, generic_args: [None] }))], has_self_type: false, bindings: [] })] }), is_negative: false, items: [Function(Idx::<Function>(1))], ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Impl>(0) }
278 > Function { name: Name(Text("foo")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::FnDef>(1) } 278 > Function { name: Name(Text("foo")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Fn>(1) }
279 279
280 inner items: 280 inner items:
281 281
282 for AST FileAstId::<ra_syntax::ast::generated::nodes::ModuleItem>(2): 282 for AST FileAstId::<ra_syntax::ast::generated::nodes::Item>(2):
283 Function { name: Name(Text("end")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(1), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::FnDef>(2) } 283 Function { name: Name(Text("end")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(1), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Fn>(2) }
284 284
285 "#]], 285 "#]],
286 ); 286 );
@@ -303,9 +303,9 @@ fn extern_attrs() {
303 303
304 top-level items: 304 top-level items:
305 #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_a"))] }, input: None }, Attr { path: ModPath { kind: Plain, segments: [Name(Text("block_attr"))] }, input: None }]) }] 305 #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_a"))] }, input: None }, Attr { path: ModPath { kind: Plain, segments: [Name(Text("block_attr"))] }, input: None }]) }]
306 Function { name: Name(Text("a")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: true, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::FnDef>(1) } 306 Function { name: Name(Text("a")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: true, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Fn>(1) }
307 #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_b"))] }, input: None }, Attr { path: ModPath { kind: Plain, segments: [Name(Text("block_attr"))] }, input: None }]) }] 307 #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_b"))] }, input: None }, Attr { path: ModPath { kind: Plain, segments: [Name(Text("block_attr"))] }, input: None }]) }]
308 Function { name: Name(Text("b")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: true, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::FnDef>(2) } 308 Function { name: Name(Text("b")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: true, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Fn>(2) }
309 "##]], 309 "##]],
310 ); 310 );
311} 311}
@@ -327,11 +327,11 @@ fn trait_attrs() {
327 327
328 top-level items: 328 top-level items:
329 #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("trait_attr"))] }, input: None }]) }] 329 #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("trait_attr"))] }, input: None }]) }]
330 Trait { name: Name(Text("Tr")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(0), auto: false, items: [Function(Idx::<Function>(0)), Function(Idx::<Function>(1))], ast_id: FileAstId::<ra_syntax::ast::generated::nodes::TraitDef>(0) } 330 Trait { name: Name(Text("Tr")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(0), auto: false, items: [Function(Idx::<Function>(0)), Function(Idx::<Function>(1))], ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Trait>(0) }
331 > #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_a"))] }, input: None }]) }] 331 > #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_a"))] }, input: None }]) }]
332 > Function { name: Name(Text("a")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::FnDef>(1) } 332 > Function { name: Name(Text("a")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Fn>(1) }
333 > #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_b"))] }, input: None }]) }] 333 > #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_b"))] }, input: None }]) }]
334 > Function { name: Name(Text("b")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::FnDef>(2) } 334 > Function { name: Name(Text("b")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Fn>(2) }
335 "##]], 335 "##]],
336 ); 336 );
337} 337}
@@ -353,11 +353,11 @@ fn impl_attrs() {
353 353
354 top-level items: 354 top-level items:
355 #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("impl_attr"))] }, input: None }]) }] 355 #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("impl_attr"))] }, input: None }]) }]
356 Impl { generic_params: GenericParamsId(4294967295), target_trait: None, target_type: Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("Ty"))] }, generic_args: [None] }), is_negative: false, items: [Function(Idx::<Function>(0)), Function(Idx::<Function>(1))], ast_id: FileAstId::<ra_syntax::ast::generated::nodes::ImplDef>(0) } 356 Impl { generic_params: GenericParamsId(4294967295), target_trait: None, target_type: Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("Ty"))] }, generic_args: [None] }), is_negative: false, items: [Function(Idx::<Function>(0)), Function(Idx::<Function>(1))], ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Impl>(0) }
357 > #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_a"))] }, input: None }]) }] 357 > #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_a"))] }, input: None }]) }]
358 > Function { name: Name(Text("a")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::FnDef>(1) } 358 > Function { name: Name(Text("a")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Fn>(1) }
359 > #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_b"))] }, input: None }]) }] 359 > #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_b"))] }, input: None }]) }]
360 > Function { name: Name(Text("b")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::FnDef>(2) } 360 > Function { name: Name(Text("b")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Fn>(2) }
361 "##]], 361 "##]],
362 ); 362 );
363} 363}
@@ -408,13 +408,13 @@ fn inner_item_attrs() {
408 inner attrs: Attrs { entries: None } 408 inner attrs: Attrs { entries: None }
409 409
410 top-level items: 410 top-level items:
411 Function { name: Name(Text("foo")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::FnDef>(0) } 411 Function { name: Name(Text("foo")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Fn>(0) }
412 412
413 inner items: 413 inner items:
414 414
415 for AST FileAstId::<ra_syntax::ast::generated::nodes::ModuleItem>(1): 415 for AST FileAstId::<ra_syntax::ast::generated::nodes::Item>(1):
416 #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("on_inner"))] }, input: None }]) }] 416 #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("on_inner"))] }, input: None }]) }]
417 Function { name: Name(Text("inner")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::FnDef>(1) } 417 Function { name: Name(Text("inner")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Fn>(1) }
418 418
419 "##]], 419 "##]],
420 ); 420 );
@@ -432,7 +432,7 @@ fn assoc_item_macros() {
432 inner attrs: Attrs { entries: None } 432 inner attrs: Attrs { entries: None }
433 433
434 top-level items: 434 top-level items:
435 Impl { generic_params: GenericParamsId(4294967295), target_trait: None, target_type: Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("S"))] }, generic_args: [None] }), is_negative: false, items: [MacroCall(Idx::<MacroCall>(0))], ast_id: FileAstId::<ra_syntax::ast::generated::nodes::ImplDef>(0) } 435 Impl { generic_params: GenericParamsId(4294967295), target_trait: None, target_type: Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("S"))] }, generic_args: [None] }), is_negative: false, items: [MacroCall(Idx::<MacroCall>(0))], ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Impl>(0) }
436 > MacroCall { name: None, path: ModPath { kind: Plain, segments: [Name(Text("items"))] }, is_export: false, is_local_inner: false, is_builtin: false, ast_id: FileAstId::<ra_syntax::ast::generated::nodes::MacroCall>(1) } 436 > MacroCall { name: None, path: ModPath { kind: Plain, segments: [Name(Text("items"))] }, is_export: false, is_local_inner: false, is_builtin: false, ast_id: FileAstId::<ra_syntax::ast::generated::nodes::MacroCall>(1) }
437 "#]], 437 "#]],
438 ); 438 );
diff --git a/crates/ra_hir_def/src/keys.rs b/crates/ra_hir_def/src/keys.rs
index a7349a21d..441bdbead 100644
--- a/crates/ra_hir_def/src/keys.rs
+++ b/crates/ra_hir_def/src/keys.rs
@@ -14,19 +14,19 @@ use crate::{
14 14
15pub type Key<K, V> = crate::dyn_map::Key<InFile<K>, V, AstPtrPolicy<K, V>>; 15pub type Key<K, V> = crate::dyn_map::Key<InFile<K>, V, AstPtrPolicy<K, V>>;
16 16
17pub const FUNCTION: Key<ast::FnDef, FunctionId> = Key::new(); 17pub const FUNCTION: Key<ast::Fn, FunctionId> = Key::new();
18pub const CONST: Key<ast::ConstDef, ConstId> = Key::new(); 18pub const CONST: Key<ast::Const, ConstId> = Key::new();
19pub const STATIC: Key<ast::StaticDef, StaticId> = Key::new(); 19pub const STATIC: Key<ast::Static, StaticId> = Key::new();
20pub const TYPE_ALIAS: Key<ast::TypeAliasDef, TypeAliasId> = Key::new(); 20pub const TYPE_ALIAS: Key<ast::TypeAlias, TypeAliasId> = Key::new();
21pub const IMPL: Key<ast::ImplDef, ImplId> = Key::new(); 21pub const IMPL: Key<ast::Impl, ImplId> = Key::new();
22pub const TRAIT: Key<ast::TraitDef, TraitId> = Key::new(); 22pub const TRAIT: Key<ast::Trait, TraitId> = Key::new();
23pub const STRUCT: Key<ast::StructDef, StructId> = Key::new(); 23pub const STRUCT: Key<ast::Struct, StructId> = Key::new();
24pub const UNION: Key<ast::UnionDef, UnionId> = Key::new(); 24pub const UNION: Key<ast::Union, UnionId> = Key::new();
25pub const ENUM: Key<ast::EnumDef, EnumId> = Key::new(); 25pub const ENUM: Key<ast::Enum, EnumId> = Key::new();
26 26
27pub const ENUM_VARIANT: Key<ast::EnumVariant, EnumVariantId> = Key::new(); 27pub const VARIANT: Key<ast::Variant, EnumVariantId> = Key::new();
28pub const TUPLE_FIELD: Key<ast::TupleFieldDef, FieldId> = Key::new(); 28pub const TUPLE_FIELD: Key<ast::TupleField, FieldId> = Key::new();
29pub const RECORD_FIELD: Key<ast::RecordFieldDef, FieldId> = Key::new(); 29pub const RECORD_FIELD: Key<ast::RecordField, FieldId> = Key::new();
30pub const TYPE_PARAM: Key<ast::TypeParam, TypeParamId> = Key::new(); 30pub const TYPE_PARAM: Key<ast::TypeParam, TypeParamId> = Key::new();
31 31
32pub const MACRO: Key<ast::MacroCall, MacroDefId> = Key::new(); 32pub const MACRO: Key<ast::MacroCall, MacroDefId> = Key::new();
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs
index 87000fe98..237b1038a 100644
--- a/crates/ra_hir_def/src/lib.rs
+++ b/crates/ra_hir_def/src/lib.rs
@@ -521,7 +521,7 @@ impl AsMacroCall for AstIdWithPath<ast::MacroCall> {
521 } 521 }
522} 522}
523 523
524impl AsMacroCall for AstIdWithPath<ast::ModuleItem> { 524impl AsMacroCall for AstIdWithPath<ast::Item> {
525 fn as_call_id( 525 fn as_call_id(
526 &self, 526 &self,
527 db: &dyn db::DefDatabase, 527 db: &dyn db::DefDatabase,
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs
index a030cab47..28b7a20c5 100644
--- a/crates/ra_hir_def/src/nameres/collector.rs
+++ b/crates/ra_hir_def/src/nameres/collector.rs
@@ -170,7 +170,7 @@ struct MacroDirective {
170#[derive(Clone, Debug, Eq, PartialEq)] 170#[derive(Clone, Debug, Eq, PartialEq)]
171struct DeriveDirective { 171struct DeriveDirective {
172 module_id: LocalModuleId, 172 module_id: LocalModuleId,
173 ast_id: AstIdWithPath<ast::ModuleItem>, 173 ast_id: AstIdWithPath<ast::Item>,
174} 174}
175 175
176struct DefData<'a> { 176struct DefData<'a> {
@@ -1100,7 +1100,7 @@ impl ModCollector<'_, '_> {
1100 res 1100 res
1101 } 1101 }
1102 1102
1103 fn collect_derives(&mut self, attrs: &Attrs, ast_id: FileAstId<ast::ModuleItem>) { 1103 fn collect_derives(&mut self, attrs: &Attrs, ast_id: FileAstId<ast::Item>) {
1104 for derive_subtree in attrs.by_key("derive").tt_values() { 1104 for derive_subtree in attrs.by_key("derive").tt_values() {
1105 // for #[derive(Copy, Clone)], `derive_subtree` is the `(Copy, Clone)` subtree 1105 // for #[derive(Copy, Clone)], `derive_subtree` is the `(Copy, Clone)` subtree
1106 for tt in &derive_subtree.token_trees { 1106 for tt in &derive_subtree.token_trees {
diff --git a/crates/ra_hir_def/src/path.rs b/crates/ra_hir_def/src/path.rs
index 190d6d98d..cc1726e9e 100644
--- a/crates/ra_hir_def/src/path.rs
+++ b/crates/ra_hir_def/src/path.rs
@@ -67,7 +67,7 @@ impl ModPath {
67 67
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: InFile<ast::UseItem>, 70 item_src: InFile<ast::Use>,
71 hygiene: &Hygiene, 71 hygiene: &Hygiene,
72 mut cb: impl FnMut(ModPath, &ast::UseTree, /* is_glob */ bool, Option<ImportAlias>), 72 mut cb: impl FnMut(ModPath, &ast::UseTree, /* is_glob */ bool, Option<ImportAlias>),
73 ) { 73 ) {
@@ -258,7 +258,7 @@ impl<'a> PathSegments<'a> {
258} 258}
259 259
260impl GenericArgs { 260impl GenericArgs {
261 pub(crate) fn from_ast(lower_ctx: &LowerCtx, node: ast::TypeArgList) -> Option<GenericArgs> { 261 pub(crate) fn from_ast(lower_ctx: &LowerCtx, node: ast::GenericArgList) -> Option<GenericArgs> {
262 lower::lower_generic_args(lower_ctx, node) 262 lower::lower_generic_args(lower_ctx, node)
263 } 263 }
264 264
diff --git a/crates/ra_hir_def/src/path/lower.rs b/crates/ra_hir_def/src/path/lower.rs
index 6a0c019fd..d09fc66e4 100644
--- a/crates/ra_hir_def/src/path/lower.rs
+++ b/crates/ra_hir_def/src/path/lower.rs
@@ -9,7 +9,7 @@ use hir_expand::{
9 hygiene::Hygiene, 9 hygiene::Hygiene,
10 name::{name, AsName}, 10 name::{name, AsName},
11}; 11};
12use ra_syntax::ast::{self, AstNode, TypeAscriptionOwner, TypeBoundsOwner}; 12use ra_syntax::ast::{self, AstNode, TypeBoundsOwner};
13 13
14use super::AssociatedTypeBinding; 14use super::AssociatedTypeBinding;
15use crate::{ 15use crate::{
@@ -41,7 +41,7 @@ pub(super) fn lower_path(mut path: ast::Path, hygiene: &Hygiene) -> Option<Path>
41 match hygiene.name_ref_to_name(name_ref) { 41 match hygiene.name_ref_to_name(name_ref) {
42 Either::Left(name) => { 42 Either::Left(name) => {
43 let args = segment 43 let args = segment
44 .type_arg_list() 44 .generic_arg_list()
45 .and_then(|it| lower_generic_args(&ctx, it)) 45 .and_then(|it| lower_generic_args(&ctx, it))
46 .or_else(|| { 46 .or_else(|| {
47 lower_generic_args_from_fn_path( 47 lower_generic_args_from_fn_path(
@@ -148,33 +148,37 @@ pub(super) fn lower_path(mut path: ast::Path, hygiene: &Hygiene) -> Option<Path>
148 148
149pub(super) fn lower_generic_args( 149pub(super) fn lower_generic_args(
150 lower_ctx: &LowerCtx, 150 lower_ctx: &LowerCtx,
151 node: ast::TypeArgList, 151 node: ast::GenericArgList,
152) -> Option<GenericArgs> { 152) -> Option<GenericArgs> {
153 let mut args = Vec::new(); 153 let mut args = Vec::new();
154 for type_arg in node.type_args() {
155 let type_ref = TypeRef::from_ast_opt(lower_ctx, type_arg.type_ref());
156 args.push(GenericArg::Type(type_ref));
157 }
158 // lifetimes ignored for now
159 let mut bindings = Vec::new(); 154 let mut bindings = Vec::new();
160 for assoc_type_arg in node.assoc_type_args() { 155 for generic_arg in node.generic_args() {
161 let assoc_type_arg: ast::AssocTypeArg = assoc_type_arg; 156 match generic_arg {
162 if let Some(name_ref) = assoc_type_arg.name_ref() { 157 ast::GenericArg::TypeArg(type_arg) => {
163 let name = name_ref.as_name(); 158 let type_ref = TypeRef::from_ast_opt(lower_ctx, type_arg.ty());
164 let type_ref = assoc_type_arg.type_ref().map(|it| TypeRef::from_ast(lower_ctx, it)); 159 args.push(GenericArg::Type(type_ref));
165 let bounds = if let Some(l) = assoc_type_arg.type_bound_list() { 160 }
166 l.bounds().map(|it| TypeBound::from_ast(lower_ctx, it)).collect() 161 ast::GenericArg::AssocTypeArg(assoc_type_arg) => {
167 } else { 162 if let Some(name_ref) = assoc_type_arg.name_ref() {
168 Vec::new() 163 let name = name_ref.as_name();
169 }; 164 let type_ref = assoc_type_arg.ty().map(|it| TypeRef::from_ast(lower_ctx, it));
170 bindings.push(AssociatedTypeBinding { name, type_ref, bounds }); 165 let bounds = if let Some(l) = assoc_type_arg.type_bound_list() {
166 l.bounds().map(|it| TypeBound::from_ast(lower_ctx, it)).collect()
167 } else {
168 Vec::new()
169 };
170 bindings.push(AssociatedTypeBinding { name, type_ref, bounds });
171 }
172 }
173 // Lifetimes and constants are ignored for now.
174 ast::GenericArg::LifetimeArg(_) | ast::GenericArg::ConstArg(_) => (),
171 } 175 }
172 } 176 }
177
173 if args.is_empty() && bindings.is_empty() { 178 if args.is_empty() && bindings.is_empty() {
174 None 179 return None;
175 } else {
176 Some(GenericArgs { args, has_self_type: false, bindings })
177 } 180 }
181 Some(GenericArgs { args, has_self_type: false, bindings })
178} 182}
179 183
180/// Collect `GenericArgs` from the parts of a fn-like path, i.e. `Fn(X, Y) 184/// Collect `GenericArgs` from the parts of a fn-like path, i.e. `Fn(X, Y)
@@ -189,14 +193,14 @@ fn lower_generic_args_from_fn_path(
189 if let Some(params) = params { 193 if let Some(params) = params {
190 let mut param_types = Vec::new(); 194 let mut param_types = Vec::new();
191 for param in params.params() { 195 for param in params.params() {
192 let type_ref = TypeRef::from_ast_opt(&ctx, param.ascribed_type()); 196 let type_ref = TypeRef::from_ast_opt(&ctx, param.ty());
193 param_types.push(type_ref); 197 param_types.push(type_ref);
194 } 198 }
195 let arg = GenericArg::Type(TypeRef::Tuple(param_types)); 199 let arg = GenericArg::Type(TypeRef::Tuple(param_types));
196 args.push(arg); 200 args.push(arg);
197 } 201 }
198 if let Some(ret_type) = ret_type { 202 if let Some(ret_type) = ret_type {
199 let type_ref = TypeRef::from_ast_opt(&ctx, ret_type.type_ref()); 203 let type_ref = TypeRef::from_ast_opt(&ctx, ret_type.ty());
200 bindings.push(AssociatedTypeBinding { 204 bindings.push(AssociatedTypeBinding {
201 name: name![Output], 205 name: name![Output],
202 type_ref: Some(type_ref), 206 type_ref: Some(type_ref),
diff --git a/crates/ra_hir_def/src/path/lower/lower_use.rs b/crates/ra_hir_def/src/path/lower/lower_use.rs
index 7cc655487..794be45e8 100644
--- a/crates/ra_hir_def/src/path/lower/lower_use.rs
+++ b/crates/ra_hir_def/src/path/lower/lower_use.rs
@@ -31,7 +31,7 @@ pub(crate) fn lower_use_tree(
31 lower_use_tree(prefix.clone(), child_tree, hygiene, cb); 31 lower_use_tree(prefix.clone(), child_tree, hygiene, cb);
32 } 32 }
33 } else { 33 } else {
34 let alias = tree.alias().map(|a| { 34 let alias = tree.rename().map(|a| {
35 a.name().map(|it| it.as_name()).map_or(ImportAlias::Underscore, ImportAlias::Alias) 35 a.name().map(|it| it.as_name()).map_or(ImportAlias::Underscore, ImportAlias::Alias)
36 }); 36 });
37 let is_glob = tree.star_token().is_some(); 37 let is_glob = tree.star_token().is_some();
diff --git a/crates/ra_hir_def/src/type_ref.rs b/crates/ra_hir_def/src/type_ref.rs
index e90b2a0b9..6f7884ffe 100644
--- a/crates/ra_hir_def/src/type_ref.rs
+++ b/crates/ra_hir_def/src/type_ref.rs
@@ -1,7 +1,6 @@
1//! HIR for references to types. Paths in these are not yet resolved. They can 1//! HIR for references to types. Paths in these are not yet resolved. They can
2//! be directly created from an ast::TypeRef, without further queries. 2//! be directly created from an ast::TypeRef, without further queries.
3 3use ra_syntax::ast::{self};
4use ra_syntax::ast::{self, TypeAscriptionOwner, TypeBoundsOwner};
5 4
6use crate::{body::LowerCtx, path::Path}; 5use crate::{body::LowerCtx, path::Path};
7 6
@@ -80,14 +79,14 @@ pub enum TypeBound {
80 79
81impl TypeRef { 80impl TypeRef {
82 /// Converts an `ast::TypeRef` to a `hir::TypeRef`. 81 /// Converts an `ast::TypeRef` to a `hir::TypeRef`.
83 pub(crate) fn from_ast(ctx: &LowerCtx, node: ast::TypeRef) -> Self { 82 pub(crate) fn from_ast(ctx: &LowerCtx, node: ast::Type) -> Self {
84 match node { 83 match node {
85 ast::TypeRef::ParenType(inner) => TypeRef::from_ast_opt(&ctx, inner.type_ref()), 84 ast::Type::ParenType(inner) => TypeRef::from_ast_opt(&ctx, inner.ty()),
86 ast::TypeRef::TupleType(inner) => { 85 ast::Type::TupleType(inner) => {
87 TypeRef::Tuple(inner.fields().map(|it| TypeRef::from_ast(ctx, it)).collect()) 86 TypeRef::Tuple(inner.fields().map(|it| TypeRef::from_ast(ctx, it)).collect())
88 } 87 }
89 ast::TypeRef::NeverType(..) => TypeRef::Never, 88 ast::Type::NeverType(..) => TypeRef::Never,
90 ast::TypeRef::PathType(inner) => { 89 ast::Type::PathType(inner) => {
91 // FIXME: Use `Path::from_src` 90 // FIXME: Use `Path::from_src`
92 inner 91 inner
93 .path() 92 .path()
@@ -95,27 +94,27 @@ impl TypeRef {
95 .map(TypeRef::Path) 94 .map(TypeRef::Path)
96 .unwrap_or(TypeRef::Error) 95 .unwrap_or(TypeRef::Error)
97 } 96 }
98 ast::TypeRef::PointerType(inner) => { 97 ast::Type::PtrType(inner) => {
99 let inner_ty = TypeRef::from_ast_opt(&ctx, inner.type_ref()); 98 let inner_ty = TypeRef::from_ast_opt(&ctx, inner.ty());
100 let mutability = Mutability::from_mutable(inner.mut_token().is_some()); 99 let mutability = Mutability::from_mutable(inner.mut_token().is_some());
101 TypeRef::RawPtr(Box::new(inner_ty), mutability) 100 TypeRef::RawPtr(Box::new(inner_ty), mutability)
102 } 101 }
103 ast::TypeRef::ArrayType(inner) => { 102 ast::Type::ArrayType(inner) => {
104 TypeRef::Array(Box::new(TypeRef::from_ast_opt(&ctx, inner.type_ref()))) 103 TypeRef::Array(Box::new(TypeRef::from_ast_opt(&ctx, inner.ty())))
105 } 104 }
106 ast::TypeRef::SliceType(inner) => { 105 ast::Type::SliceType(inner) => {
107 TypeRef::Slice(Box::new(TypeRef::from_ast_opt(&ctx, inner.type_ref()))) 106 TypeRef::Slice(Box::new(TypeRef::from_ast_opt(&ctx, inner.ty())))
108 } 107 }
109 ast::TypeRef::ReferenceType(inner) => { 108 ast::Type::RefType(inner) => {
110 let inner_ty = TypeRef::from_ast_opt(&ctx, inner.type_ref()); 109 let inner_ty = TypeRef::from_ast_opt(&ctx, inner.ty());
111 let mutability = Mutability::from_mutable(inner.mut_token().is_some()); 110 let mutability = Mutability::from_mutable(inner.mut_token().is_some());
112 TypeRef::Reference(Box::new(inner_ty), mutability) 111 TypeRef::Reference(Box::new(inner_ty), mutability)
113 } 112 }
114 ast::TypeRef::PlaceholderType(_inner) => TypeRef::Placeholder, 113 ast::Type::InferType(_inner) => TypeRef::Placeholder,
115 ast::TypeRef::FnPointerType(inner) => { 114 ast::Type::FnPtrType(inner) => {
116 let ret_ty = inner 115 let ret_ty = inner
117 .ret_type() 116 .ret_type()
118 .and_then(|rt| rt.type_ref()) 117 .and_then(|rt| rt.ty())
119 .map(|it| TypeRef::from_ast(ctx, it)) 118 .map(|it| TypeRef::from_ast(ctx, it))
120 .unwrap_or_else(|| TypeRef::Tuple(Vec::new())); 119 .unwrap_or_else(|| TypeRef::Tuple(Vec::new()));
121 let mut is_varargs = false; 120 let mut is_varargs = false;
@@ -124,10 +123,7 @@ impl TypeRef {
124 is_varargs = param.dotdotdot_token().is_some(); 123 is_varargs = param.dotdotdot_token().is_some();
125 } 124 }
126 125
127 pl.params() 126 pl.params().map(|p| p.ty()).map(|it| TypeRef::from_ast_opt(&ctx, it)).collect()
128 .map(|p| p.ascribed_type())
129 .map(|it| TypeRef::from_ast_opt(&ctx, it))
130 .collect()
131 } else { 127 } else {
132 Vec::new() 128 Vec::new()
133 }; 129 };
@@ -135,17 +131,17 @@ impl TypeRef {
135 TypeRef::Fn(params, is_varargs) 131 TypeRef::Fn(params, is_varargs)
136 } 132 }
137 // for types are close enough for our purposes to the inner type for now... 133 // for types are close enough for our purposes to the inner type for now...
138 ast::TypeRef::ForType(inner) => TypeRef::from_ast_opt(&ctx, inner.type_ref()), 134 ast::Type::ForType(inner) => TypeRef::from_ast_opt(&ctx, inner.ty()),
139 ast::TypeRef::ImplTraitType(inner) => { 135 ast::Type::ImplTraitType(inner) => {
140 TypeRef::ImplTrait(type_bounds_from_ast(ctx, inner.type_bound_list())) 136 TypeRef::ImplTrait(type_bounds_from_ast(ctx, inner.type_bound_list()))
141 } 137 }
142 ast::TypeRef::DynTraitType(inner) => { 138 ast::Type::DynTraitType(inner) => {
143 TypeRef::DynTrait(type_bounds_from_ast(ctx, inner.type_bound_list())) 139 TypeRef::DynTrait(type_bounds_from_ast(ctx, inner.type_bound_list()))
144 } 140 }
145 } 141 }
146 } 142 }
147 143
148 pub(crate) fn from_ast_opt(ctx: &LowerCtx, node: Option<ast::TypeRef>) -> Self { 144 pub(crate) fn from_ast_opt(ctx: &LowerCtx, node: Option<ast::Type>) -> Self {
149 if let Some(node) = node { 145 if let Some(node) = node {
150 TypeRef::from_ast(ctx, node) 146 TypeRef::from_ast(ctx, node)
151 } else { 147 } else {