From c83467796b6c7365ea4f41900d74444384a9e618 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 18:17:28 +0200 Subject: Finalize Trait grammar --- crates/ra_hir_def/src/body/lower.rs | 2 +- crates/ra_hir_def/src/generics.rs | 4 ++-- crates/ra_hir_def/src/item_tree.rs | 4 ++-- crates/ra_hir_def/src/item_tree/lower.rs | 8 ++++---- crates/ra_hir_def/src/item_tree/tests.rs | 4 ++-- crates/ra_hir_def/src/keys.rs | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) (limited to 'crates/ra_hir_def/src') diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index 4a26e6397..0d0242173 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -664,7 +664,7 @@ impl ExprCollector<'_> { let id = self.find_inner_item(&def)?; (UnionLoc { container, id }.intern(self.db).into(), def.name()) } - ast::Item::TraitDef(def) => { + ast::Item::Trait(def) => { let id = self.find_inner_item(&def)?; (TraitLoc { container, id }.intern(self.db).into(), def.name()) } diff --git a/crates/ra_hir_def/src/generics.rs b/crates/ra_hir_def/src/generics.rs index 5fa2fbb3f..8ea61fcf2 100644 --- a/crates/ra_hir_def/src/generics.rs +++ b/crates/ra_hir_def/src/generics.rs @@ -66,7 +66,7 @@ pub enum WherePredicateTarget { TypeParam(LocalTypeParamId), } -type SourceMap = ArenaMap>; +type SourceMap = ArenaMap>; impl GenericParams { pub(crate) fn generic_params_query( @@ -317,7 +317,7 @@ impl GenericParams { impl HasChildSource for GenericDefId { type ChildId = LocalTypeParamId; - type Value = Either; + type Value = Either; fn child_source(&self, db: &dyn DefDatabase) -> InFile { let (_, sm) = GenericParams::new(db, *self); sm diff --git a/crates/ra_hir_def/src/item_tree.rs b/crates/ra_hir_def/src/item_tree.rs index c478a9909..11002b1ad 100644 --- a/crates/ra_hir_def/src/item_tree.rs +++ b/crates/ra_hir_def/src/item_tree.rs @@ -419,7 +419,7 @@ mod_items! { Enum in enums -> ast::Enum, Const in consts -> ast::Const, Static in statics -> ast::Static, - Trait in traits -> ast::TraitDef, + Trait in traits -> ast::Trait, Impl in impls -> ast::ImplDef, TypeAlias in type_aliases -> ast::TypeAlias, Mod in mods -> ast::Module, @@ -571,7 +571,7 @@ pub struct Trait { pub generic_params: GenericParamsId, pub auto: bool, pub items: Box<[AssocItem]>, - pub ast_id: FileAstId, + pub ast_id: FileAstId, } #[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 a94548e5d..aaf3cfd3a 100644 --- a/crates/ra_hir_def/src/item_tree/lower.rs +++ b/crates/ra_hir_def/src/item_tree/lower.rs @@ -95,7 +95,7 @@ impl Ctx { // These are handled in their respective `lower_X` method (since we can't just blindly // walk them). - ast::Item::TraitDef(_) | ast::Item::ImplDef(_) | ast::Item::ExternBlock(_) => {} + ast::Item::Trait(_) | ast::Item::ImplDef(_) | ast::Item::ExternBlock(_) => {} // These don't have inner items. ast::Item::Module(_) | ast::Item::ExternCrate(_) | ast::Item::Use(_) => {} @@ -111,7 +111,7 @@ impl Ctx { ast::Item::Static(ast) => self.lower_static(ast).map(Into::into), ast::Item::Const(ast) => Some(self.lower_const(ast).into()), ast::Item::Module(ast) => self.lower_module(ast).map(Into::into), - ast::Item::TraitDef(ast) => self.lower_trait(ast).map(Into::into), + ast::Item::Trait(ast) => self.lower_trait(ast).map(Into::into), ast::Item::ImplDef(ast) => self.lower_impl(ast).map(Into::into), ast::Item::Use(ast) => Some(ModItems( self.lower_use(ast).into_iter().map(Into::into).collect::>(), @@ -413,7 +413,7 @@ impl Ctx { Some(id(self.data().mods.alloc(res))) } - fn lower_trait(&mut self, trait_def: &ast::TraitDef) -> Option> { + fn lower_trait(&mut self, trait_def: &ast::Trait) -> Option> { let name = trait_def.name()?.as_name(); let visibility = self.lower_visibility(trait_def); let generic_params = @@ -698,7 +698,7 @@ enum GenericsOwner<'a> { Enum, Union, /// The `TraitDef` is needed to fill the source map for the implicit `Self` parameter. - Trait(&'a ast::TraitDef), + Trait(&'a ast::Trait), TypeAlias, Impl, } diff --git a/crates/ra_hir_def/src/item_tree/tests.rs b/crates/ra_hir_def/src/item_tree/tests.rs index e61ce58bc..40a9bd53d 100644 --- a/crates/ra_hir_def/src/item_tree/tests.rs +++ b/crates/ra_hir_def/src/item_tree/tests.rs @@ -234,7 +234,7 @@ fn smoke() { #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("ext_crate"))] }, input: None }]) }] ExternCrate { path: ModPath { kind: Plain, segments: [Name(Text("krate"))] }, alias: None, visibility: RawVisibilityId("pub(self)"), is_macro_use: false, ast_id: FileAstId::(1) } #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("on_trait"))] }, input: None }]) }] - Trait { name: Name(Text("Tr")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(0), auto: false, items: [TypeAlias(Idx::(0)), Const(Idx::(0)), Function(Idx::(0)), Function(Idx::(1))], ast_id: FileAstId::(2) } + Trait { name: Name(Text("Tr")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(0), auto: false, items: [TypeAlias(Idx::(0)), Const(Idx::(0)), Function(Idx::(0)), Function(Idx::(1))], ast_id: FileAstId::(2) } > #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("assoc_ty"))] }, input: None }]) }] > 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::(8) } > #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("assoc_const"))] }, input: None }]) }] @@ -327,7 +327,7 @@ fn trait_attrs() { top-level items: #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("trait_attr"))] }, input: None }]) }] - Trait { name: Name(Text("Tr")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(0), auto: false, items: [Function(Idx::(0)), Function(Idx::(1))], ast_id: FileAstId::(0) } + Trait { name: Name(Text("Tr")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(0), auto: false, items: [Function(Idx::(0)), Function(Idx::(1))], ast_id: FileAstId::(0) } > #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_a"))] }, input: None }]) }] > 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::(1) } > #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_b"))] }, input: None }]) }] diff --git a/crates/ra_hir_def/src/keys.rs b/crates/ra_hir_def/src/keys.rs index f75e3bb50..0bed08875 100644 --- a/crates/ra_hir_def/src/keys.rs +++ b/crates/ra_hir_def/src/keys.rs @@ -19,7 +19,7 @@ pub const CONST: Key = Key::new(); pub const STATIC: Key = Key::new(); pub const TYPE_ALIAS: Key = Key::new(); pub const IMPL: Key = Key::new(); -pub const TRAIT: Key = Key::new(); +pub const TRAIT: Key = Key::new(); pub const STRUCT: Key = Key::new(); pub const UNION: Key = Key::new(); pub const ENUM: Key = Key::new(); -- cgit v1.2.3 From c5798c4d75aa807aec47208a49101bdec3affcca Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 18:28:28 +0200 Subject: Finalize impl Grammar --- crates/ra_hir_def/src/body/lower.rs | 2 +- crates/ra_hir_def/src/item_tree.rs | 4 ++-- crates/ra_hir_def/src/item_tree/lower.rs | 6 +++--- crates/ra_hir_def/src/item_tree/tests.rs | 6 +++--- crates/ra_hir_def/src/keys.rs | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) (limited to 'crates/ra_hir_def/src') diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index 0d0242173..78f6da5b8 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -669,7 +669,7 @@ impl ExprCollector<'_> { (TraitLoc { container, id }.intern(self.db).into(), def.name()) } ast::Item::ExternBlock(_) => return None, // FIXME: collect from extern blocks - ast::Item::ImplDef(_) + ast::Item::Impl(_) | ast::Item::Use(_) | ast::Item::ExternCrate(_) | ast::Item::Module(_) diff --git a/crates/ra_hir_def/src/item_tree.rs b/crates/ra_hir_def/src/item_tree.rs index 11002b1ad..63b56405c 100644 --- a/crates/ra_hir_def/src/item_tree.rs +++ b/crates/ra_hir_def/src/item_tree.rs @@ -420,7 +420,7 @@ mod_items! { Const in consts -> ast::Const, Static in statics -> ast::Static, Trait in traits -> ast::Trait, - Impl in impls -> ast::ImplDef, + Impl in impls -> ast::Impl, TypeAlias in type_aliases -> ast::TypeAlias, Mod in mods -> ast::Module, MacroCall in macro_calls -> ast::MacroCall, @@ -581,7 +581,7 @@ pub struct Impl { pub target_type: TypeRef, pub is_negative: bool, pub items: Box<[AssocItem]>, - pub ast_id: FileAstId, + pub ast_id: FileAstId, } #[derive(Debug, Clone, PartialEq, Eq)] diff --git a/crates/ra_hir_def/src/item_tree/lower.rs b/crates/ra_hir_def/src/item_tree/lower.rs index aaf3cfd3a..b0cf94956 100644 --- a/crates/ra_hir_def/src/item_tree/lower.rs +++ b/crates/ra_hir_def/src/item_tree/lower.rs @@ -95,7 +95,7 @@ impl Ctx { // These are handled in their respective `lower_X` method (since we can't just blindly // walk them). - ast::Item::Trait(_) | ast::Item::ImplDef(_) | ast::Item::ExternBlock(_) => {} + ast::Item::Trait(_) | ast::Item::Impl(_) | ast::Item::ExternBlock(_) => {} // These don't have inner items. ast::Item::Module(_) | ast::Item::ExternCrate(_) | ast::Item::Use(_) => {} @@ -112,7 +112,7 @@ impl Ctx { ast::Item::Const(ast) => Some(self.lower_const(ast).into()), ast::Item::Module(ast) => self.lower_module(ast).map(Into::into), ast::Item::Trait(ast) => self.lower_trait(ast).map(Into::into), - ast::Item::ImplDef(ast) => self.lower_impl(ast).map(Into::into), + ast::Item::Impl(ast) => self.lower_impl(ast).map(Into::into), ast::Item::Use(ast) => Some(ModItems( self.lower_use(ast).into_iter().map(Into::into).collect::>(), )), @@ -445,7 +445,7 @@ impl Ctx { Some(id(self.data().traits.alloc(res))) } - fn lower_impl(&mut self, impl_def: &ast::ImplDef) -> Option> { + fn lower_impl(&mut self, impl_def: &ast::Impl) -> Option> { let generic_params = self.lower_generic_params_and_inner_items(GenericsOwner::Impl, impl_def); let target_trait = impl_def.target_trait().map(|tr| self.lower_type_ref(&tr)); diff --git a/crates/ra_hir_def/src/item_tree/tests.rs b/crates/ra_hir_def/src/item_tree/tests.rs index 40a9bd53d..a81497fa8 100644 --- a/crates/ra_hir_def/src/item_tree/tests.rs +++ b/crates/ra_hir_def/src/item_tree/tests.rs @@ -274,7 +274,7 @@ fn simple_inner_items() { inner attrs: Attrs { entries: None } top-level items: - 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::(1))], ast_id: FileAstId::(0) } + 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::(1))], ast_id: FileAstId::(0) } > 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::(1) } inner items: @@ -353,7 +353,7 @@ fn impl_attrs() { top-level items: #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("impl_attr"))] }, input: None }]) }] - 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::(0)), Function(Idx::(1))], ast_id: FileAstId::(0) } + 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::(0)), Function(Idx::(1))], ast_id: FileAstId::(0) } > #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_a"))] }, input: None }]) }] > 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::(1) } > #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_b"))] }, input: None }]) }] @@ -432,7 +432,7 @@ fn assoc_item_macros() { inner attrs: Attrs { entries: None } top-level items: - 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::(0))], ast_id: FileAstId::(0) } + 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::(0))], ast_id: FileAstId::(0) } > MacroCall { name: None, path: ModPath { kind: Plain, segments: [Name(Text("items"))] }, is_export: false, is_local_inner: false, is_builtin: false, ast_id: FileAstId::(1) } "#]], ); diff --git a/crates/ra_hir_def/src/keys.rs b/crates/ra_hir_def/src/keys.rs index 0bed08875..441bdbead 100644 --- a/crates/ra_hir_def/src/keys.rs +++ b/crates/ra_hir_def/src/keys.rs @@ -18,7 +18,7 @@ pub const FUNCTION: Key = Key::new(); pub const CONST: Key = Key::new(); pub const STATIC: Key = Key::new(); pub const TYPE_ALIAS: Key = Key::new(); -pub const IMPL: Key = Key::new(); +pub const IMPL: Key = Key::new(); pub const TRAIT: Key = Key::new(); pub const STRUCT: Key = Key::new(); pub const UNION: Key = Key::new(); -- cgit v1.2.3