diff options
Diffstat (limited to 'crates/ra_hir_def')
-rw-r--r-- | crates/ra_hir_def/src/adt.rs | 18 | ||||
-rw-r--r-- | crates/ra_hir_def/src/attr.rs | 19 | ||||
-rw-r--r-- | crates/ra_hir_def/src/body.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir_def/src/body/lower.rs | 48 | ||||
-rw-r--r-- | crates/ra_hir_def/src/child_by_source.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_def/src/generics.rs | 14 | ||||
-rw-r--r-- | crates/ra_hir_def/src/item_tree.rs | 52 | ||||
-rw-r--r-- | crates/ra_hir_def/src/item_tree/lower.rs | 171 | ||||
-rw-r--r-- | crates/ra_hir_def/src/item_tree/tests.rs | 62 | ||||
-rw-r--r-- | crates/ra_hir_def/src/keys.rs | 26 | ||||
-rw-r--r-- | crates/ra_hir_def/src/lib.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/collector.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir_def/src/path.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_def/src/path/lower.rs | 10 | ||||
-rw-r--r-- | crates/ra_hir_def/src/path/lower/lower_use.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_def/src/type_ref.rs | 47 |
16 files changed, 235 insertions, 248 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 | }; |
10 | use ra_arena::{map::ArenaMap, Arena}; | 10 | use ra_arena::{map::ArenaMap, Arena}; |
11 | use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner, VisibilityOwner}; | 11 | use ra_syntax::ast::{self, NameOwner, VisibilityOwner}; |
12 | 12 | ||
13 | use crate::{ | 13 | use crate::{ |
14 | body::{CfgExpander, LowerCtx}, | 14 | body::{CfgExpander, LowerCtx}, |
@@ -112,7 +112,7 @@ impl EnumData { | |||
112 | 112 | ||
113 | impl HasChildSource for EnumId { | 113 | impl 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 | ||
124 | fn lower_enum( | 124 | fn 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 | ||
180 | impl HasChildSource for VariantId { | 180 | impl 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 { | |||
218 | fn lower_struct( | 218 | fn 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 { | |||
151 | impl Attr { | 151 | impl 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..827ced4ad 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs | |||
@@ -11,7 +11,7 @@ use ra_arena::Arena; | |||
11 | use ra_syntax::{ | 11 | use ra_syntax::{ |
12 | ast::{ | 12 | ast::{ |
13 | self, ArgListOwner, ArrayExprKind, LiteralKind, LoopBodyOwner, ModuleItemOwner, NameOwner, | 13 | self, ArgListOwner, ArrayExprKind, LiteralKind, LoopBodyOwner, ModuleItemOwner, NameOwner, |
14 | SlicePatComponents, TypeAscriptionOwner, | 14 | SlicePatComponents, |
15 | }, | 15 | }, |
16 | AstNode, AstPtr, | 16 | AstNode, AstPtr, |
17 | }; | 17 | }; |
@@ -379,10 +379,10 @@ impl ExprCollector<'_> { | |||
379 | let expr = e.expr().map(|e| self.collect_expr(e)); | 379 | let expr = e.expr().map(|e| self.collect_expr(e)); |
380 | self.alloc_expr(Expr::Return { expr }, syntax_ptr) | 380 | self.alloc_expr(Expr::Return { expr }, syntax_ptr) |
381 | } | 381 | } |
382 | ast::Expr::RecordLit(e) => { | 382 | ast::Expr::RecordExpr(e) => { |
383 | let path = e.path().and_then(|path| self.expander.parse_path(path)); | 383 | let path = e.path().and_then(|path| self.expander.parse_path(path)); |
384 | let mut field_ptrs = Vec::new(); | 384 | let mut field_ptrs = Vec::new(); |
385 | let record_lit = if let Some(nfl) = e.record_field_list() { | 385 | let record_lit = if let Some(nfl) = e.record_expr_field_list() { |
386 | let fields = nfl | 386 | let fields = nfl |
387 | .fields() | 387 | .fields() |
388 | .inspect(|field| field_ptrs.push(AstPtr::new(field))) | 388 | .inspect(|field| field_ptrs.push(AstPtr::new(field))) |
@@ -432,7 +432,7 @@ impl ExprCollector<'_> { | |||
432 | } | 432 | } |
433 | ast::Expr::CastExpr(e) => { | 433 | ast::Expr::CastExpr(e) => { |
434 | let expr = self.collect_expr_opt(e.expr()); | 434 | let expr = self.collect_expr_opt(e.expr()); |
435 | let type_ref = TypeRef::from_ast_opt(&self.ctx(), e.type_ref()); | 435 | let type_ref = TypeRef::from_ast_opt(&self.ctx(), e.ty()); |
436 | self.alloc_expr(Expr::Cast { expr, type_ref }, syntax_ptr) | 436 | self.alloc_expr(Expr::Cast { expr, type_ref }, syntax_ptr) |
437 | } | 437 | } |
438 | ast::Expr::RefExpr(e) => { | 438 | ast::Expr::RefExpr(e) => { |
@@ -466,16 +466,13 @@ impl ExprCollector<'_> { | |||
466 | if let Some(pl) = e.param_list() { | 466 | if let Some(pl) = e.param_list() { |
467 | for param in pl.params() { | 467 | for param in pl.params() { |
468 | let pat = self.collect_pat_opt(param.pat()); | 468 | let pat = self.collect_pat_opt(param.pat()); |
469 | let type_ref = | 469 | 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); | 470 | args.push(pat); |
472 | arg_types.push(type_ref); | 471 | arg_types.push(type_ref); |
473 | } | 472 | } |
474 | } | 473 | } |
475 | let ret_type = e | 474 | let ret_type = |
476 | .ret_type() | 475 | 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()); | 476 | let body = self.collect_expr_opt(e.body()); |
480 | self.alloc_expr(Expr::Lambda { args, arg_types, ret_type, body }, syntax_ptr) | 477 | self.alloc_expr(Expr::Lambda { args, arg_types, ret_type, body }, syntax_ptr) |
481 | } | 478 | } |
@@ -607,8 +604,7 @@ impl ExprCollector<'_> { | |||
607 | .map(|s| match s { | 604 | .map(|s| match s { |
608 | ast::Stmt::LetStmt(stmt) => { | 605 | ast::Stmt::LetStmt(stmt) => { |
609 | let pat = self.collect_pat_opt(stmt.pat()); | 606 | let pat = self.collect_pat_opt(stmt.pat()); |
610 | let type_ref = | 607 | let type_ref = stmt.ty().map(|it| TypeRef::from_ast(&self.ctx(), it)); |
611 | stmt.ascribed_type().map(|it| TypeRef::from_ast(&self.ctx(), it)); | ||
612 | let initializer = stmt.initializer().map(|e| self.collect_expr(e)); | 608 | let initializer = stmt.initializer().map(|e| self.collect_expr(e)); |
613 | Statement::Let { pat, type_ref, initializer } | 609 | Statement::Let { pat, type_ref, initializer } |
614 | } | 610 | } |
@@ -627,53 +623,53 @@ impl ExprCollector<'_> { | |||
627 | .items() | 623 | .items() |
628 | .filter_map(|item| { | 624 | .filter_map(|item| { |
629 | let (def, name): (ModuleDefId, Option<ast::Name>) = match item { | 625 | let (def, name): (ModuleDefId, Option<ast::Name>) = match item { |
630 | ast::ModuleItem::FnDef(def) => { | 626 | ast::Item::Fn(def) => { |
631 | let id = self.find_inner_item(&def)?; | 627 | let id = self.find_inner_item(&def)?; |
632 | ( | 628 | ( |
633 | FunctionLoc { container: container.into(), id }.intern(self.db).into(), | 629 | FunctionLoc { container: container.into(), id }.intern(self.db).into(), |
634 | def.name(), | 630 | def.name(), |
635 | ) | 631 | ) |
636 | } | 632 | } |
637 | ast::ModuleItem::TypeAliasDef(def) => { | 633 | ast::Item::TypeAlias(def) => { |
638 | let id = self.find_inner_item(&def)?; | 634 | let id = self.find_inner_item(&def)?; |
639 | ( | 635 | ( |
640 | TypeAliasLoc { container: container.into(), id }.intern(self.db).into(), | 636 | TypeAliasLoc { container: container.into(), id }.intern(self.db).into(), |
641 | def.name(), | 637 | def.name(), |
642 | ) | 638 | ) |
643 | } | 639 | } |
644 | ast::ModuleItem::ConstDef(def) => { | 640 | ast::Item::Const(def) => { |
645 | let id = self.find_inner_item(&def)?; | 641 | let id = self.find_inner_item(&def)?; |
646 | ( | 642 | ( |
647 | ConstLoc { container: container.into(), id }.intern(self.db).into(), | 643 | ConstLoc { container: container.into(), id }.intern(self.db).into(), |
648 | def.name(), | 644 | def.name(), |
649 | ) | 645 | ) |
650 | } | 646 | } |
651 | ast::ModuleItem::StaticDef(def) => { | 647 | ast::Item::Static(def) => { |
652 | let id = self.find_inner_item(&def)?; | 648 | let id = self.find_inner_item(&def)?; |
653 | (StaticLoc { container, id }.intern(self.db).into(), def.name()) | 649 | (StaticLoc { container, id }.intern(self.db).into(), def.name()) |
654 | } | 650 | } |
655 | ast::ModuleItem::StructDef(def) => { | 651 | ast::Item::Struct(def) => { |
656 | let id = self.find_inner_item(&def)?; | 652 | let id = self.find_inner_item(&def)?; |
657 | (StructLoc { container, id }.intern(self.db).into(), def.name()) | 653 | (StructLoc { container, id }.intern(self.db).into(), def.name()) |
658 | } | 654 | } |
659 | ast::ModuleItem::EnumDef(def) => { | 655 | ast::Item::Enum(def) => { |
660 | let id = self.find_inner_item(&def)?; | 656 | let id = self.find_inner_item(&def)?; |
661 | (EnumLoc { container, id }.intern(self.db).into(), def.name()) | 657 | (EnumLoc { container, id }.intern(self.db).into(), def.name()) |
662 | } | 658 | } |
663 | ast::ModuleItem::UnionDef(def) => { | 659 | ast::Item::Union(def) => { |
664 | let id = self.find_inner_item(&def)?; | 660 | let id = self.find_inner_item(&def)?; |
665 | (UnionLoc { container, id }.intern(self.db).into(), def.name()) | 661 | (UnionLoc { container, id }.intern(self.db).into(), def.name()) |
666 | } | 662 | } |
667 | ast::ModuleItem::TraitDef(def) => { | 663 | ast::Item::Trait(def) => { |
668 | let id = self.find_inner_item(&def)?; | 664 | let id = self.find_inner_item(&def)?; |
669 | (TraitLoc { container, id }.intern(self.db).into(), def.name()) | 665 | (TraitLoc { container, id }.intern(self.db).into(), def.name()) |
670 | } | 666 | } |
671 | ast::ModuleItem::ExternBlock(_) => return None, // FIXME: collect from extern blocks | 667 | ast::Item::ExternBlock(_) => return None, // FIXME: collect from extern blocks |
672 | ast::ModuleItem::ImplDef(_) | 668 | ast::Item::Impl(_) |
673 | | ast::ModuleItem::UseItem(_) | 669 | | ast::Item::Use(_) |
674 | | ast::ModuleItem::ExternCrateItem(_) | 670 | | ast::Item::ExternCrate(_) |
675 | | ast::ModuleItem::Module(_) | 671 | | ast::Item::Module(_) |
676 | | ast::ModuleItem::MacroCall(_) => return None, | 672 | | ast::Item::MacroCall(_) => return None, |
677 | }; | 673 | }; |
678 | 674 | ||
679 | Some((def, name)) | 675 | Some((def, name)) |
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..be0b45af3 100644 --- a/crates/ra_hir_def/src/generics.rs +++ b/crates/ra_hir_def/src/generics.rs | |||
@@ -12,7 +12,7 @@ use hir_expand::{ | |||
12 | use ra_arena::{map::ArenaMap, Arena}; | 12 | use ra_arena::{map::ArenaMap, Arena}; |
13 | use ra_db::FileId; | 13 | use ra_db::FileId; |
14 | use ra_prof::profile; | 14 | use ra_prof::profile; |
15 | use ra_syntax::ast::{self, NameOwner, TypeBoundsOwner, TypeParamsOwner}; | 15 | use ra_syntax::ast::{self, GenericParamsOwner, NameOwner, TypeBoundsOwner}; |
16 | 16 | ||
17 | use crate::{ | 17 | use crate::{ |
18 | body::LowerCtx, | 18 | body::LowerCtx, |
@@ -66,7 +66,7 @@ pub enum WherePredicateTarget { | |||
66 | TypeParam(LocalTypeParamId), | 66 | TypeParam(LocalTypeParamId), |
67 | } | 67 | } |
68 | 68 | ||
69 | type SourceMap = ArenaMap<LocalTypeParamId, Either<ast::TraitDef, ast::TypeParam>>; | 69 | type SourceMap = ArenaMap<LocalTypeParamId, Either<ast::Trait, ast::TypeParam>>; |
70 | 70 | ||
71 | impl GenericParams { | 71 | impl 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 | }; |
@@ -317,7 +317,7 @@ impl GenericParams { | |||
317 | 317 | ||
318 | impl HasChildSource for GenericDefId { | 318 | impl 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 | ||
16 | use ast::{AstNode, AttrsOwner, NameOwner, StructKind, TypeAscriptionOwner}; | 16 | use ast::{AstNode, AttrsOwner, NameOwner, StructKind}; |
17 | use either::Either; | 17 | use either::Either; |
18 | use hir_expand::{ | 18 | use hir_expand::{ |
19 | ast_id_map::FileAstId, | 19 | ast_id_map::FileAstId, |
@@ -70,7 +70,7 @@ impl GenericParamsId { | |||
70 | pub struct ItemTree { | 70 | pub 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. |
312 | pub trait ItemTreeNode: Clone { | 312 | pub 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 | ||
413 | mod_items! { | 413 | mod_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..b5d416acb 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 | ||
3 | use super::*; | 3 | use std::{collections::hash_map::Entry, mem, sync::Arc}; |
4 | use crate::{ | 4 | |
5 | attr::Attrs, | ||
6 | generics::{GenericParams, TypeParamData, TypeParamProvenance}, | ||
7 | }; | ||
8 | use hir_expand::{ast_id_map::AstIdMap, hygiene::Hygiene, HirFileId}; | 5 | use hir_expand::{ast_id_map::AstIdMap, hygiene::Hygiene, HirFileId}; |
9 | use ra_arena::map::ArenaMap; | 6 | use ra_arena::map::ArenaMap; |
10 | use ra_syntax::{ | 7 | use ra_syntax::{ |
@@ -12,7 +9,13 @@ use ra_syntax::{ | |||
12 | SyntaxNode, | 9 | SyntaxNode, |
13 | }; | 10 | }; |
14 | use smallvec::SmallVec; | 11 | use smallvec::SmallVec; |
15 | use std::{collections::hash_map::Entry, mem, sync::Arc}; | 12 | |
13 | use crate::{ | ||
14 | attr::Attrs, | ||
15 | generics::{GenericParams, TypeParamData, TypeParamProvenance}, | ||
16 | }; | ||
17 | |||
18 | use super::*; | ||
16 | 19 | ||
17 | fn id<N: ItemTreeNode>(index: Idx<N>) -> FileItemTreeId<N> { | 20 | fn 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,7 +445,7 @@ 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.target_trait().map(|tr| self.lower_type_ref(&tr)); |
@@ -458,9 +454,9 @@ impl Ctx { | |||
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 | ||
15 | pub type Key<K, V> = crate::dyn_map::Key<InFile<K>, V, AstPtrPolicy<K, V>>; | 15 | pub type Key<K, V> = crate::dyn_map::Key<InFile<K>, V, AstPtrPolicy<K, V>>; |
16 | 16 | ||
17 | pub const FUNCTION: Key<ast::FnDef, FunctionId> = Key::new(); | 17 | pub const FUNCTION: Key<ast::Fn, FunctionId> = Key::new(); |
18 | pub const CONST: Key<ast::ConstDef, ConstId> = Key::new(); | 18 | pub const CONST: Key<ast::Const, ConstId> = Key::new(); |
19 | pub const STATIC: Key<ast::StaticDef, StaticId> = Key::new(); | 19 | pub const STATIC: Key<ast::Static, StaticId> = Key::new(); |
20 | pub const TYPE_ALIAS: Key<ast::TypeAliasDef, TypeAliasId> = Key::new(); | 20 | pub const TYPE_ALIAS: Key<ast::TypeAlias, TypeAliasId> = Key::new(); |
21 | pub const IMPL: Key<ast::ImplDef, ImplId> = Key::new(); | 21 | pub const IMPL: Key<ast::Impl, ImplId> = Key::new(); |
22 | pub const TRAIT: Key<ast::TraitDef, TraitId> = Key::new(); | 22 | pub const TRAIT: Key<ast::Trait, TraitId> = Key::new(); |
23 | pub const STRUCT: Key<ast::StructDef, StructId> = Key::new(); | 23 | pub const STRUCT: Key<ast::Struct, StructId> = Key::new(); |
24 | pub const UNION: Key<ast::UnionDef, UnionId> = Key::new(); | 24 | pub const UNION: Key<ast::Union, UnionId> = Key::new(); |
25 | pub const ENUM: Key<ast::EnumDef, EnumId> = Key::new(); | 25 | pub const ENUM: Key<ast::Enum, EnumId> = Key::new(); |
26 | 26 | ||
27 | pub const ENUM_VARIANT: Key<ast::EnumVariant, EnumVariantId> = Key::new(); | 27 | pub const VARIANT: Key<ast::Variant, EnumVariantId> = Key::new(); |
28 | pub const TUPLE_FIELD: Key<ast::TupleFieldDef, FieldId> = Key::new(); | 28 | pub const TUPLE_FIELD: Key<ast::TupleField, FieldId> = Key::new(); |
29 | pub const RECORD_FIELD: Key<ast::RecordFieldDef, FieldId> = Key::new(); | 29 | pub const RECORD_FIELD: Key<ast::RecordField, FieldId> = Key::new(); |
30 | pub const TYPE_PARAM: Key<ast::TypeParam, TypeParamId> = Key::new(); | 30 | pub const TYPE_PARAM: Key<ast::TypeParam, TypeParamId> = Key::new(); |
31 | 31 | ||
32 | pub const MACRO: Key<ast::MacroCall, MacroDefId> = Key::new(); | 32 | pub 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 | ||
524 | impl AsMacroCall for AstIdWithPath<ast::ModuleItem> { | 524 | impl 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)] |
171 | struct DeriveDirective { | 171 | struct 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 | ||
176 | struct DefData<'a> { | 176 | struct 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..68b9f89c3 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 | ) { |
diff --git a/crates/ra_hir_def/src/path/lower.rs b/crates/ra_hir_def/src/path/lower.rs index 6a0c019fd..257f9a033 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 | }; |
12 | use ra_syntax::ast::{self, AstNode, TypeAscriptionOwner, TypeBoundsOwner}; | 12 | use ra_syntax::ast::{self, AstNode, TypeBoundsOwner}; |
13 | 13 | ||
14 | use super::AssociatedTypeBinding; | 14 | use super::AssociatedTypeBinding; |
15 | use crate::{ | 15 | use crate::{ |
@@ -152,7 +152,7 @@ pub(super) fn lower_generic_args( | |||
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() { | 154 | for type_arg in node.type_args() { |
155 | let type_ref = TypeRef::from_ast_opt(lower_ctx, type_arg.type_ref()); | 155 | let type_ref = TypeRef::from_ast_opt(lower_ctx, type_arg.ty()); |
156 | args.push(GenericArg::Type(type_ref)); | 156 | args.push(GenericArg::Type(type_ref)); |
157 | } | 157 | } |
158 | // lifetimes ignored for now | 158 | // lifetimes ignored for now |
@@ -161,7 +161,7 @@ pub(super) fn lower_generic_args( | |||
161 | let assoc_type_arg: ast::AssocTypeArg = assoc_type_arg; | 161 | let assoc_type_arg: ast::AssocTypeArg = assoc_type_arg; |
162 | if let Some(name_ref) = assoc_type_arg.name_ref() { | 162 | if let Some(name_ref) = assoc_type_arg.name_ref() { |
163 | let name = name_ref.as_name(); | 163 | let name = name_ref.as_name(); |
164 | let type_ref = assoc_type_arg.type_ref().map(|it| TypeRef::from_ast(lower_ctx, it)); | 164 | let type_ref = assoc_type_arg.ty().map(|it| TypeRef::from_ast(lower_ctx, it)); |
165 | let bounds = if let Some(l) = assoc_type_arg.type_bound_list() { | 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() | 166 | l.bounds().map(|it| TypeBound::from_ast(lower_ctx, it)).collect() |
167 | } else { | 167 | } else { |
@@ -189,14 +189,14 @@ fn lower_generic_args_from_fn_path( | |||
189 | if let Some(params) = params { | 189 | if let Some(params) = params { |
190 | let mut param_types = Vec::new(); | 190 | let mut param_types = Vec::new(); |
191 | for param in params.params() { | 191 | for param in params.params() { |
192 | let type_ref = TypeRef::from_ast_opt(&ctx, param.ascribed_type()); | 192 | let type_ref = TypeRef::from_ast_opt(&ctx, param.ty()); |
193 | param_types.push(type_ref); | 193 | param_types.push(type_ref); |
194 | } | 194 | } |
195 | let arg = GenericArg::Type(TypeRef::Tuple(param_types)); | 195 | let arg = GenericArg::Type(TypeRef::Tuple(param_types)); |
196 | args.push(arg); | 196 | args.push(arg); |
197 | } | 197 | } |
198 | if let Some(ret_type) = ret_type { | 198 | if let Some(ret_type) = ret_type { |
199 | let type_ref = TypeRef::from_ast_opt(&ctx, ret_type.type_ref()); | 199 | let type_ref = TypeRef::from_ast_opt(&ctx, ret_type.ty()); |
200 | bindings.push(AssociatedTypeBinding { | 200 | bindings.push(AssociatedTypeBinding { |
201 | name: name![Output], | 201 | name: name![Output], |
202 | type_ref: Some(type_ref), | 202 | 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..9386b91cb 100644 --- a/crates/ra_hir_def/src/type_ref.rs +++ b/crates/ra_hir_def/src/type_ref.rs | |||
@@ -1,7 +1,7 @@ | |||
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 | 3 | ||
4 | use ra_syntax::ast::{self, TypeAscriptionOwner, TypeBoundsOwner}; | 4 | use ra_syntax::ast::{self}; |
5 | 5 | ||
6 | use crate::{body::LowerCtx, path::Path}; | 6 | use crate::{body::LowerCtx, path::Path}; |
7 | 7 | ||
@@ -80,14 +80,14 @@ pub enum TypeBound { | |||
80 | 80 | ||
81 | impl TypeRef { | 81 | impl TypeRef { |
82 | /// Converts an `ast::TypeRef` to a `hir::TypeRef`. | 82 | /// Converts an `ast::TypeRef` to a `hir::TypeRef`. |
83 | pub(crate) fn from_ast(ctx: &LowerCtx, node: ast::TypeRef) -> Self { | 83 | pub(crate) fn from_ast(ctx: &LowerCtx, node: ast::Type) -> Self { |
84 | match node { | 84 | match node { |
85 | ast::TypeRef::ParenType(inner) => TypeRef::from_ast_opt(&ctx, inner.type_ref()), | 85 | ast::Type::ParenType(inner) => TypeRef::from_ast_opt(&ctx, inner.ty()), |
86 | ast::TypeRef::TupleType(inner) => { | 86 | ast::Type::TupleType(inner) => { |
87 | TypeRef::Tuple(inner.fields().map(|it| TypeRef::from_ast(ctx, it)).collect()) | 87 | TypeRef::Tuple(inner.fields().map(|it| TypeRef::from_ast(ctx, it)).collect()) |
88 | } | 88 | } |
89 | ast::TypeRef::NeverType(..) => TypeRef::Never, | 89 | ast::Type::NeverType(..) => TypeRef::Never, |
90 | ast::TypeRef::PathType(inner) => { | 90 | ast::Type::PathType(inner) => { |
91 | // FIXME: Use `Path::from_src` | 91 | // FIXME: Use `Path::from_src` |
92 | inner | 92 | inner |
93 | .path() | 93 | .path() |
@@ -95,27 +95,27 @@ impl TypeRef { | |||
95 | .map(TypeRef::Path) | 95 | .map(TypeRef::Path) |
96 | .unwrap_or(TypeRef::Error) | 96 | .unwrap_or(TypeRef::Error) |
97 | } | 97 | } |
98 | ast::TypeRef::PointerType(inner) => { | 98 | ast::Type::PointerType(inner) => { |
99 | let inner_ty = TypeRef::from_ast_opt(&ctx, inner.type_ref()); | 99 | let inner_ty = TypeRef::from_ast_opt(&ctx, inner.ty()); |
100 | let mutability = Mutability::from_mutable(inner.mut_token().is_some()); | 100 | let mutability = Mutability::from_mutable(inner.mut_token().is_some()); |
101 | TypeRef::RawPtr(Box::new(inner_ty), mutability) | 101 | TypeRef::RawPtr(Box::new(inner_ty), mutability) |
102 | } | 102 | } |
103 | ast::TypeRef::ArrayType(inner) => { | 103 | ast::Type::ArrayType(inner) => { |
104 | TypeRef::Array(Box::new(TypeRef::from_ast_opt(&ctx, inner.type_ref()))) | 104 | TypeRef::Array(Box::new(TypeRef::from_ast_opt(&ctx, inner.ty()))) |
105 | } | 105 | } |
106 | ast::TypeRef::SliceType(inner) => { | 106 | ast::Type::SliceType(inner) => { |
107 | TypeRef::Slice(Box::new(TypeRef::from_ast_opt(&ctx, inner.type_ref()))) | 107 | TypeRef::Slice(Box::new(TypeRef::from_ast_opt(&ctx, inner.ty()))) |
108 | } | 108 | } |
109 | ast::TypeRef::ReferenceType(inner) => { | 109 | ast::Type::ReferenceType(inner) => { |
110 | let inner_ty = TypeRef::from_ast_opt(&ctx, inner.type_ref()); | 110 | let inner_ty = TypeRef::from_ast_opt(&ctx, inner.ty()); |
111 | let mutability = Mutability::from_mutable(inner.mut_token().is_some()); | 111 | let mutability = Mutability::from_mutable(inner.mut_token().is_some()); |
112 | TypeRef::Reference(Box::new(inner_ty), mutability) | 112 | TypeRef::Reference(Box::new(inner_ty), mutability) |
113 | } | 113 | } |
114 | ast::TypeRef::PlaceholderType(_inner) => TypeRef::Placeholder, | 114 | ast::Type::PlaceholderType(_inner) => TypeRef::Placeholder, |
115 | ast::TypeRef::FnPointerType(inner) => { | 115 | ast::Type::FnPointerType(inner) => { |
116 | let ret_ty = inner | 116 | let ret_ty = inner |
117 | .ret_type() | 117 | .ret_type() |
118 | .and_then(|rt| rt.type_ref()) | 118 | .and_then(|rt| rt.ty()) |
119 | .map(|it| TypeRef::from_ast(ctx, it)) | 119 | .map(|it| TypeRef::from_ast(ctx, it)) |
120 | .unwrap_or_else(|| TypeRef::Tuple(Vec::new())); | 120 | .unwrap_or_else(|| TypeRef::Tuple(Vec::new())); |
121 | let mut is_varargs = false; | 121 | let mut is_varargs = false; |
@@ -124,10 +124,7 @@ impl TypeRef { | |||
124 | is_varargs = param.dotdotdot_token().is_some(); | 124 | is_varargs = param.dotdotdot_token().is_some(); |
125 | } | 125 | } |
126 | 126 | ||
127 | pl.params() | 127 | 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 { | 128 | } else { |
132 | Vec::new() | 129 | Vec::new() |
133 | }; | 130 | }; |
@@ -135,17 +132,17 @@ impl TypeRef { | |||
135 | TypeRef::Fn(params, is_varargs) | 132 | TypeRef::Fn(params, is_varargs) |
136 | } | 133 | } |
137 | // for types are close enough for our purposes to the inner type for now... | 134 | // 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()), | 135 | ast::Type::ForType(inner) => TypeRef::from_ast_opt(&ctx, inner.ty()), |
139 | ast::TypeRef::ImplTraitType(inner) => { | 136 | ast::Type::ImplTraitType(inner) => { |
140 | TypeRef::ImplTrait(type_bounds_from_ast(ctx, inner.type_bound_list())) | 137 | TypeRef::ImplTrait(type_bounds_from_ast(ctx, inner.type_bound_list())) |
141 | } | 138 | } |
142 | ast::TypeRef::DynTraitType(inner) => { | 139 | ast::Type::DynTraitType(inner) => { |
143 | TypeRef::DynTrait(type_bounds_from_ast(ctx, inner.type_bound_list())) | 140 | TypeRef::DynTrait(type_bounds_from_ast(ctx, inner.type_bound_list())) |
144 | } | 141 | } |
145 | } | 142 | } |
146 | } | 143 | } |
147 | 144 | ||
148 | pub(crate) fn from_ast_opt(ctx: &LowerCtx, node: Option<ast::TypeRef>) -> Self { | 145 | pub(crate) fn from_ast_opt(ctx: &LowerCtx, node: Option<ast::Type>) -> Self { |
149 | if let Some(node) = node { | 146 | if let Some(node) = node { |
150 | TypeRef::from_ast(ctx, node) | 147 | TypeRef::from_ast(ctx, node) |
151 | } else { | 148 | } else { |