From 81359af733f7b13e0bd2196191f2ab294e1b57aa Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 31 Jul 2020 20:22:20 +0200 Subject: Simplify trait gramamr --- crates/ra_syntax/src/ast/generated/nodes.rs | 1 - xtask/src/codegen/gen_syntax.rs | 2 ++ xtask/src/codegen/rust.ungram | 11 +++++------ 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs index 231a0f727..01aefb60d 100644 --- a/crates/ra_syntax/src/ast/generated/nodes.rs +++ b/crates/ra_syntax/src/ast/generated/nodes.rs @@ -267,7 +267,6 @@ impl Impl { pub fn unsafe_token(&self) -> Option { support::token(&self.syntax, T![unsafe]) } pub fn impl_token(&self) -> Option { support::token(&self.syntax, T![impl]) } pub fn const_token(&self) -> Option { support::token(&self.syntax, T![const]) } - pub fn ty(&self) -> Option { support::child(&self.syntax) } pub fn excl_token(&self) -> Option { support::token(&self.syntax, T![!]) } pub fn for_token(&self) -> Option { support::token(&self.syntax, T![for]) } pub fn assoc_item_list(&self) -> Option { support::child(&self.syntax) } diff --git a/xtask/src/codegen/gen_syntax.rs b/xtask/src/codegen/gen_syntax.rs index e6231ece2..4602ff1d7 100644 --- a/xtask/src/codegen/gen_syntax.rs +++ b/xtask/src/codegen/gen_syntax.rs @@ -591,6 +591,8 @@ fn lower_rule(acc: &mut Vec, grammar: &Grammar, label: Option<&String>, r | "index" | "base" | "value" + | "target_type" + | "target_trait" ); if manually_implemented { return; diff --git a/xtask/src/codegen/rust.ungram b/xtask/src/codegen/rust.ungram index 7685f4f06..25d6f7a20 100644 --- a/xtask/src/codegen/rust.ungram +++ b/xtask/src/codegen/rust.ungram @@ -194,12 +194,11 @@ AssocItem = | TypeAlias Impl = - Attr* Visibility? - 'default'? 'unsafe'? 'impl' 'const'? GenericParamList? ( - Type - | '!'? Type 'for' Type - ) WhereClause? - AssocItemList + Attr* Visibility? + 'default'? 'unsafe'? 'impl' 'const'? GenericParamList? + ('!'? target_trait:Type 'for')? target_type:Type + WhereClause? + AssocItemList ExternBlock = Attr* Abi ExternItemList -- cgit v1.2.3 From af53d5f4b081ad50d8fe08fc1e107aa6025b2491 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 31 Jul 2020 20:23:52 +0200 Subject: Rename --- crates/ra_assists/src/ast_transform.rs | 2 +- crates/ra_assists/src/utils.rs | 7 ++----- crates/ra_hir_def/src/item_tree/lower.rs | 4 ++-- crates/ra_ide/src/display/navigation_target.rs | 2 +- crates/ra_ide/src/file_structure.rs | 4 ++-- crates/ra_ide/src/references/rename.rs | 2 +- crates/ra_syntax/src/ast/node_ext.rs | 4 ++-- crates/ra_syntax/src/validation.rs | 2 +- 8 files changed, 12 insertions(+), 15 deletions(-) diff --git a/crates/ra_assists/src/ast_transform.rs b/crates/ra_assists/src/ast_transform.rs index 0a7be87a0..28f3f3546 100644 --- a/crates/ra_assists/src/ast_transform.rs +++ b/crates/ra_assists/src/ast_transform.rs @@ -81,7 +81,7 @@ impl<'a> SubstituteTypeParams<'a> { // FIXME: It would probably be nicer if we could get this via HIR (i.e. get the // trait ref, and then go from the types in the substs back to the syntax). fn get_syntactic_substs(impl_def: ast::Impl) -> Option> { - let target_trait = impl_def.target_trait()?; + let target_trait = impl_def.trait_()?; let path_type = match target_trait { ast::Type::PathType(path) => path, _ => return None, diff --git a/crates/ra_assists/src/utils.rs b/crates/ra_assists/src/utils.rs index bb16ebd4e..373de273c 100644 --- a/crates/ra_assists/src/utils.rs +++ b/crates/ra_assists/src/utils.rs @@ -111,11 +111,8 @@ pub(crate) fn resolve_target_trait( sema: &Semantics, impl_def: &ast::Impl, ) -> Option { - let ast_path = impl_def - .target_trait() - .map(|it| it.syntax().clone()) - .and_then(ast::PathType::cast)? - .path()?; + let ast_path = + impl_def.trait_().map(|it| it.syntax().clone()).and_then(ast::PathType::cast)?.path()?; match sema.resolve_path(&ast_path) { Some(hir::PathResolution::Def(hir::ModuleDef::Trait(def))) => Some(def), diff --git a/crates/ra_hir_def/src/item_tree/lower.rs b/crates/ra_hir_def/src/item_tree/lower.rs index b5d416acb..450ef8798 100644 --- a/crates/ra_hir_def/src/item_tree/lower.rs +++ b/crates/ra_hir_def/src/item_tree/lower.rs @@ -448,8 +448,8 @@ impl Ctx { 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)); - let target_type = self.lower_type_ref(&impl_def.target_type()?); + let target_trait = impl_def.trait_().map(|tr| self.lower_type_ref(&tr)); + let target_type = self.lower_type_ref(&impl_def.self_ty()?); let is_negative = impl_def.excl_token().is_some(); // We cannot use `assoc_items()` here as that does not include macro calls. diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs index d70e33e72..fdbf75abd 100644 --- a/crates/ra_ide/src/display/navigation_target.rs +++ b/crates/ra_ide/src/display/navigation_target.rs @@ -253,7 +253,7 @@ impl ToNav for hir::ImplDef { let focus_range = if derive_attr.is_some() { None } else { - src.value.target_type().map(|ty| original_range(db, src.with_value(ty.syntax())).range) + src.value.self_ty().map(|ty| original_range(db, src.with_value(ty.syntax())).range) }; NavigationTarget::from_syntax( diff --git a/crates/ra_ide/src/file_structure.rs b/crates/ra_ide/src/file_structure.rs index ef368651a..87cab4503 100644 --- a/crates/ra_ide/src/file_structure.rs +++ b/crates/ra_ide/src/file_structure.rs @@ -130,8 +130,8 @@ fn structure_node(node: &SyntaxNode) -> Option { ast::Const(it) => decl_with_type_ref(&it, it.ty()), ast::Static(it) => decl_with_type_ref(&it, it.ty()), ast::Impl(it) => { - let target_type = it.target_type()?; - let target_trait = it.target_trait(); + let target_type = it.self_ty()?; + let target_trait = it.trait_(); let label = match target_trait { None => format!("impl {}", target_type.syntax().text()), Some(t) => { diff --git a/crates/ra_ide/src/references/rename.rs b/crates/ra_ide/src/references/rename.rs index 96aed7cc7..3cd6c815b 100644 --- a/crates/ra_ide/src/references/rename.rs +++ b/crates/ra_ide/src/references/rename.rs @@ -194,7 +194,7 @@ fn text_edit_from_self_param( new_name: &str, ) -> Option { fn target_type_name(impl_def: &ast::Impl) -> Option { - if let Some(ast::Type::PathType(p)) = impl_def.target_type() { + if let Some(ast::Type::PathType(p)) = impl_def.self_ty() { return Some(p.path()?.segment()?.name_ref()?.text().to_string()); } None diff --git a/crates/ra_syntax/src/ast/node_ext.rs b/crates/ra_syntax/src/ast/node_ext.rs index 4b4a72375..af5a93d1d 100644 --- a/crates/ra_syntax/src/ast/node_ext.rs +++ b/crates/ra_syntax/src/ast/node_ext.rs @@ -136,14 +136,14 @@ impl ast::UseTreeList { } impl ast::Impl { - pub fn target_type(&self) -> Option { + pub fn self_ty(&self) -> Option { match self.target() { (Some(t), None) | (_, Some(t)) => Some(t), _ => None, } } - pub fn target_trait(&self) -> Option { + pub fn trait_(&self) -> Option { match self.target() { (Some(t), Some(_)) => Some(t), _ => None, diff --git a/crates/ra_syntax/src/validation.rs b/crates/ra_syntax/src/validation.rs index 0325ab0b4..2dddaf09a 100644 --- a/crates/ra_syntax/src/validation.rs +++ b/crates/ra_syntax/src/validation.rs @@ -208,7 +208,7 @@ fn validate_visibility(vis: ast::Visibility, errors: &mut Vec) { Some(it) => it, None => return, }; - if impl_def.target_trait().is_some() { + if impl_def.trait_().is_some() { errors.push(SyntaxError::new("Unnecessary visibility qualifier", vis.syntax.text_range())); } } -- cgit v1.2.3