From 7022ea52b5f2a0262c2cd96b290ddb8ec0af0df9 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 7 Feb 2021 14:15:02 +0300 Subject: AdtDef -> Adt --- .../assists/src/handlers/add_lifetime_to_type.rs | 10 +++--- crates/assists/src/handlers/generate_derive.rs | 4 +-- .../src/handlers/generate_enum_match_method.rs | 2 +- crates/assists/src/handlers/generate_impl.rs | 2 +- crates/assists/src/handlers/generate_new.rs | 2 +- crates/assists/src/utils.rs | 8 ++--- crates/ide/src/goto_implementation.rs | 10 +++--- crates/syntax/src/ast/generated/nodes.rs | 38 +++++++++++----------- 8 files changed, 38 insertions(+), 38 deletions(-) (limited to 'crates') diff --git a/crates/assists/src/handlers/add_lifetime_to_type.rs b/crates/assists/src/handlers/add_lifetime_to_type.rs index c1603e972..2edf7b204 100644 --- a/crates/assists/src/handlers/add_lifetime_to_type.rs +++ b/crates/assists/src/handlers/add_lifetime_to_type.rs @@ -26,7 +26,7 @@ pub(crate) fn add_lifetime_to_type(acc: &mut Assists, ctx: &AssistContext) -> Op return None; } - let node = ctx.find_node_at_offset::()?; + let node = ctx.find_node_at_offset::()?; let has_lifetime = node .generic_param_list() .map(|gen_list| gen_list.lifetime_params().count() > 0) @@ -66,9 +66,9 @@ pub(crate) fn add_lifetime_to_type(acc: &mut Assists, ctx: &AssistContext) -> Op ) } -fn fetch_borrowed_types(node: &ast::AdtDef) -> Option> { +fn fetch_borrowed_types(node: &ast::Adt) -> Option> { let ref_types: Vec = match node { - ast::AdtDef::Enum(enum_) => { + ast::Adt::Enum(enum_) => { let variant_list = enum_.variant_list()?; variant_list .variants() @@ -80,11 +80,11 @@ fn fetch_borrowed_types(node: &ast::AdtDef) -> Option> { .flatten() .collect() } - ast::AdtDef::Struct(strukt) => { + ast::Adt::Struct(strukt) => { let field_list = strukt.field_list()?; find_ref_types_from_field_list(&field_list)? } - ast::AdtDef::Union(un) => { + ast::Adt::Union(un) => { let record_field_list = un.record_field_list()?; record_field_list .fields() diff --git a/crates/assists/src/handlers/generate_derive.rs b/crates/assists/src/handlers/generate_derive.rs index f876b7684..adae8ab7e 100644 --- a/crates/assists/src/handlers/generate_derive.rs +++ b/crates/assists/src/handlers/generate_derive.rs @@ -26,7 +26,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; // ``` pub(crate) fn generate_derive(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { let cap = ctx.config.snippet_cap?; - let nominal = ctx.find_node_at_offset::()?; + let nominal = ctx.find_node_at_offset::()?; let node_start = derive_insertion_offset(&nominal)?; let target = nominal.syntax().text_range(); acc.add( @@ -58,7 +58,7 @@ pub(crate) fn generate_derive(acc: &mut Assists, ctx: &AssistContext) -> Option< } // Insert `derive` after doc comments. -fn derive_insertion_offset(nominal: &ast::AdtDef) -> Option { +fn derive_insertion_offset(nominal: &ast::Adt) -> Option { let non_ws_child = nominal .syntax() .children_with_tokens() diff --git a/crates/assists/src/handlers/generate_enum_match_method.rs b/crates/assists/src/handlers/generate_enum_match_method.rs index 4cf66b5d5..9d6b161c9 100644 --- a/crates/assists/src/handlers/generate_enum_match_method.rs +++ b/crates/assists/src/handlers/generate_enum_match_method.rs @@ -49,7 +49,7 @@ pub(crate) fn generate_enum_match_method(acc: &mut Assists, ctx: &AssistContext) // Return early if we've found an existing new fn let impl_def = find_struct_impl( &ctx, - &ast::AdtDef::Enum(parent_enum.clone()), + &ast::Adt::Enum(parent_enum.clone()), format!("is_{}", fn_name).as_str(), )?; diff --git a/crates/assists/src/handlers/generate_impl.rs b/crates/assists/src/handlers/generate_impl.rs index 827477272..61d1bd25c 100644 --- a/crates/assists/src/handlers/generate_impl.rs +++ b/crates/assists/src/handlers/generate_impl.rs @@ -27,7 +27,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; // } // ``` pub(crate) fn generate_impl(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { - let nominal = ctx.find_node_at_offset::()?; + let nominal = ctx.find_node_at_offset::()?; let name = nominal.name()?; let target = nominal.syntax().text_range(); diff --git a/crates/assists/src/handlers/generate_new.rs b/crates/assists/src/handlers/generate_new.rs index 307f2e228..a9203d33f 100644 --- a/crates/assists/src/handlers/generate_new.rs +++ b/crates/assists/src/handlers/generate_new.rs @@ -40,7 +40,7 @@ pub(crate) fn generate_new(acc: &mut Assists, ctx: &AssistContext) -> Option<()> }; // Return early if we've found an existing new fn - let impl_def = find_struct_impl(&ctx, &ast::AdtDef::Struct(strukt.clone()), "new")?; + let impl_def = find_struct_impl(&ctx, &ast::Adt::Struct(strukt.clone()), "new")?; let target = strukt.syntax().text_range(); acc.add(AssistId("generate_new", AssistKind::Generate), "Generate `new`", target, |builder| { diff --git a/crates/assists/src/utils.rs b/crates/assists/src/utils.rs index 8045aac40..cd80c2958 100644 --- a/crates/assists/src/utils.rs +++ b/crates/assists/src/utils.rs @@ -281,7 +281,7 @@ pub(crate) fn does_pat_match_variant(pat: &ast::Pat, var: &ast::Pat) -> bool { // FIXME: this partially overlaps with `find_impl_block` pub(crate) fn find_struct_impl( ctx: &AssistContext, - strukt: &ast::AdtDef, + strukt: &ast::Adt, name: &str, ) -> Option> { let db = ctx.db(); @@ -290,9 +290,9 @@ pub(crate) fn find_struct_impl( })?; let struct_def = match strukt { - ast::AdtDef::Enum(e) => Adt::Enum(ctx.sema.to_def(e)?), - ast::AdtDef::Struct(s) => Adt::Struct(ctx.sema.to_def(s)?), - ast::AdtDef::Union(u) => Adt::Union(ctx.sema.to_def(u)?), + ast::Adt::Enum(e) => Adt::Enum(ctx.sema.to_def(e)?), + ast::Adt::Struct(s) => Adt::Struct(ctx.sema.to_def(s)?), + ast::Adt::Union(u) => Adt::Union(ctx.sema.to_def(u)?), }; let block = module.descendants().filter_map(ast::Impl::cast).find_map(|impl_blk| { diff --git a/crates/ide/src/goto_implementation.rs b/crates/ide/src/goto_implementation.rs index 761a98b2c..3990305fc 100644 --- a/crates/ide/src/goto_implementation.rs +++ b/crates/ide/src/goto_implementation.rs @@ -23,7 +23,7 @@ pub(crate) fn goto_implementation( let krate = sema.to_module_def(position.file_id)?.krate(); - if let Some(nominal_def) = find_node_at_offset::(&syntax, position.offset) { + if let Some(nominal_def) = find_node_at_offset::(&syntax, position.offset) { return Some(RangeInfo::new( nominal_def.syntax().text_range(), impls_for_def(&sema, &nominal_def, krate)?, @@ -40,13 +40,13 @@ pub(crate) fn goto_implementation( fn impls_for_def( sema: &Semantics, - node: &ast::AdtDef, + node: &ast::Adt, krate: Crate, ) -> Option> { let ty = match node { - ast::AdtDef::Struct(def) => sema.to_def(def)?.ty(sema.db), - ast::AdtDef::Enum(def) => sema.to_def(def)?.ty(sema.db), - ast::AdtDef::Union(def) => sema.to_def(def)?.ty(sema.db), + ast::Adt::Struct(def) => sema.to_def(def)?.ty(sema.db), + ast::Adt::Enum(def) => sema.to_def(def)?.ty(sema.db), + ast::Adt::Union(def) => sema.to_def(def)?.ty(sema.db), }; let impls = Impl::all_in_crate(sema.db, krate); diff --git a/crates/syntax/src/ast/generated/nodes.rs b/crates/syntax/src/ast/generated/nodes.rs index 5baa54a3f..064931aec 100644 --- a/crates/syntax/src/ast/generated/nodes.rs +++ b/crates/syntax/src/ast/generated/nodes.rs @@ -1401,15 +1401,15 @@ pub enum FieldList { TupleFieldList(TupleFieldList), } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub enum AdtDef { +pub enum Adt { Enum(Enum), Struct(Struct), Union(Union), } -impl ast::AttrsOwner for AdtDef {} -impl ast::GenericParamsOwner for AdtDef {} -impl ast::NameOwner for AdtDef {} -impl ast::VisibilityOwner for AdtDef {} +impl ast::AttrsOwner for Adt {} +impl ast::GenericParamsOwner for Adt {} +impl ast::NameOwner for Adt {} +impl ast::VisibilityOwner for Adt {} #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum AssocItem { Const(Const), @@ -3394,16 +3394,16 @@ impl AstNode for FieldList { } } } -impl From for AdtDef { - fn from(node: Enum) -> AdtDef { AdtDef::Enum(node) } +impl From for Adt { + fn from(node: Enum) -> Adt { Adt::Enum(node) } } -impl From for AdtDef { - fn from(node: Struct) -> AdtDef { AdtDef::Struct(node) } +impl From for Adt { + fn from(node: Struct) -> Adt { Adt::Struct(node) } } -impl From for AdtDef { - fn from(node: Union) -> AdtDef { AdtDef::Union(node) } +impl From for Adt { + fn from(node: Union) -> Adt { Adt::Union(node) } } -impl AstNode for AdtDef { +impl AstNode for Adt { fn can_cast(kind: SyntaxKind) -> bool { match kind { ENUM | STRUCT | UNION => true, @@ -3412,18 +3412,18 @@ impl AstNode for AdtDef { } fn cast(syntax: SyntaxNode) -> Option { let res = match syntax.kind() { - ENUM => AdtDef::Enum(Enum { syntax }), - STRUCT => AdtDef::Struct(Struct { syntax }), - UNION => AdtDef::Union(Union { syntax }), + ENUM => Adt::Enum(Enum { syntax }), + STRUCT => Adt::Struct(Struct { syntax }), + UNION => Adt::Union(Union { syntax }), _ => return None, }; Some(res) } fn syntax(&self) -> &SyntaxNode { match self { - AdtDef::Enum(it) => &it.syntax, - AdtDef::Struct(it) => &it.syntax, - AdtDef::Union(it) => &it.syntax, + Adt::Enum(it) => &it.syntax, + Adt::Struct(it) => &it.syntax, + Adt::Union(it) => &it.syntax, } } } @@ -3571,7 +3571,7 @@ impl std::fmt::Display for FieldList { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for AdtDef { +impl std::fmt::Display for Adt { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } -- cgit v1.2.3