diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-02-07 11:15:26 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-02-07 11:15:26 +0000 |
commit | 336909b63a14b801520c6627d90d750babcfe280 (patch) | |
tree | b5b73fc760b261fafda58a3e20e04b8e74559c60 | |
parent | 75a87ec198b25c5938c651ef087f9ebf923c34f8 (diff) | |
parent | 7022ea52b5f2a0262c2cd96b290ddb8ec0af0df9 (diff) |
Merge #7587
7587: AdtDef -> Adt r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
-rw-r--r-- | Cargo.lock | 4 | ||||
-rw-r--r-- | crates/assists/src/handlers/add_lifetime_to_type.rs | 10 | ||||
-rw-r--r-- | crates/assists/src/handlers/generate_derive.rs | 4 | ||||
-rw-r--r-- | crates/assists/src/handlers/generate_enum_match_method.rs | 2 | ||||
-rw-r--r-- | crates/assists/src/handlers/generate_impl.rs | 2 | ||||
-rw-r--r-- | crates/assists/src/handlers/generate_new.rs | 2 | ||||
-rw-r--r-- | crates/assists/src/utils.rs | 8 | ||||
-rw-r--r-- | crates/ide/src/goto_implementation.rs | 10 | ||||
-rw-r--r-- | crates/syntax/src/ast/generated/nodes.rs | 38 |
9 files changed, 40 insertions, 40 deletions
diff --git a/Cargo.lock b/Cargo.lock index 4b1ecd099..894fadcb2 100644 --- a/Cargo.lock +++ b/Cargo.lock | |||
@@ -1816,9 +1816,9 @@ checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c" | |||
1816 | 1816 | ||
1817 | [[package]] | 1817 | [[package]] |
1818 | name = "ungrammar" | 1818 | name = "ungrammar" |
1819 | version = "1.10.0" | 1819 | version = "1.11.0" |
1820 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1820 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1821 | checksum = "ce24866975a8858d3a35eba845efc6b42962c5067afd2bc1a07b9ce0108d335c" | 1821 | checksum = "84c629795d377049f2a1dc5f42cf505dc5ba8b28a5df0a03f4183a24480e4a6a" |
1822 | 1822 | ||
1823 | [[package]] | 1823 | [[package]] |
1824 | name = "unicase" | 1824 | name = "unicase" |
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 | |||
26 | return None; | 26 | return None; |
27 | } | 27 | } |
28 | 28 | ||
29 | let node = ctx.find_node_at_offset::<ast::AdtDef>()?; | 29 | let node = ctx.find_node_at_offset::<ast::Adt>()?; |
30 | let has_lifetime = node | 30 | let has_lifetime = node |
31 | .generic_param_list() | 31 | .generic_param_list() |
32 | .map(|gen_list| gen_list.lifetime_params().count() > 0) | 32 | .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 | |||
66 | ) | 66 | ) |
67 | } | 67 | } |
68 | 68 | ||
69 | fn fetch_borrowed_types(node: &ast::AdtDef) -> Option<Vec<RefType>> { | 69 | fn fetch_borrowed_types(node: &ast::Adt) -> Option<Vec<RefType>> { |
70 | let ref_types: Vec<RefType> = match node { | 70 | let ref_types: Vec<RefType> = match node { |
71 | ast::AdtDef::Enum(enum_) => { | 71 | ast::Adt::Enum(enum_) => { |
72 | let variant_list = enum_.variant_list()?; | 72 | let variant_list = enum_.variant_list()?; |
73 | variant_list | 73 | variant_list |
74 | .variants() | 74 | .variants() |
@@ -80,11 +80,11 @@ fn fetch_borrowed_types(node: &ast::AdtDef) -> Option<Vec<RefType>> { | |||
80 | .flatten() | 80 | .flatten() |
81 | .collect() | 81 | .collect() |
82 | } | 82 | } |
83 | ast::AdtDef::Struct(strukt) => { | 83 | ast::Adt::Struct(strukt) => { |
84 | let field_list = strukt.field_list()?; | 84 | let field_list = strukt.field_list()?; |
85 | find_ref_types_from_field_list(&field_list)? | 85 | find_ref_types_from_field_list(&field_list)? |
86 | } | 86 | } |
87 | ast::AdtDef::Union(un) => { | 87 | ast::Adt::Union(un) => { |
88 | let record_field_list = un.record_field_list()?; | 88 | let record_field_list = un.record_field_list()?; |
89 | record_field_list | 89 | record_field_list |
90 | .fields() | 90 | .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}; | |||
26 | // ``` | 26 | // ``` |
27 | pub(crate) fn generate_derive(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { | 27 | pub(crate) fn generate_derive(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { |
28 | let cap = ctx.config.snippet_cap?; | 28 | let cap = ctx.config.snippet_cap?; |
29 | let nominal = ctx.find_node_at_offset::<ast::AdtDef>()?; | 29 | let nominal = ctx.find_node_at_offset::<ast::Adt>()?; |
30 | let node_start = derive_insertion_offset(&nominal)?; | 30 | let node_start = derive_insertion_offset(&nominal)?; |
31 | let target = nominal.syntax().text_range(); | 31 | let target = nominal.syntax().text_range(); |
32 | acc.add( | 32 | acc.add( |
@@ -58,7 +58,7 @@ pub(crate) fn generate_derive(acc: &mut Assists, ctx: &AssistContext) -> Option< | |||
58 | } | 58 | } |
59 | 59 | ||
60 | // Insert `derive` after doc comments. | 60 | // Insert `derive` after doc comments. |
61 | fn derive_insertion_offset(nominal: &ast::AdtDef) -> Option<TextSize> { | 61 | fn derive_insertion_offset(nominal: &ast::Adt) -> Option<TextSize> { |
62 | let non_ws_child = nominal | 62 | let non_ws_child = nominal |
63 | .syntax() | 63 | .syntax() |
64 | .children_with_tokens() | 64 | .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) | |||
49 | // Return early if we've found an existing new fn | 49 | // Return early if we've found an existing new fn |
50 | let impl_def = find_struct_impl( | 50 | let impl_def = find_struct_impl( |
51 | &ctx, | 51 | &ctx, |
52 | &ast::AdtDef::Enum(parent_enum.clone()), | 52 | &ast::Adt::Enum(parent_enum.clone()), |
53 | format!("is_{}", fn_name).as_str(), | 53 | format!("is_{}", fn_name).as_str(), |
54 | )?; | 54 | )?; |
55 | 55 | ||
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}; | |||
27 | // } | 27 | // } |
28 | // ``` | 28 | // ``` |
29 | pub(crate) fn generate_impl(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { | 29 | pub(crate) fn generate_impl(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { |
30 | let nominal = ctx.find_node_at_offset::<ast::AdtDef>()?; | 30 | let nominal = ctx.find_node_at_offset::<ast::Adt>()?; |
31 | let name = nominal.name()?; | 31 | let name = nominal.name()?; |
32 | let target = nominal.syntax().text_range(); | 32 | let target = nominal.syntax().text_range(); |
33 | 33 | ||
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<()> | |||
40 | }; | 40 | }; |
41 | 41 | ||
42 | // Return early if we've found an existing new fn | 42 | // Return early if we've found an existing new fn |
43 | let impl_def = find_struct_impl(&ctx, &ast::AdtDef::Struct(strukt.clone()), "new")?; | 43 | let impl_def = find_struct_impl(&ctx, &ast::Adt::Struct(strukt.clone()), "new")?; |
44 | 44 | ||
45 | let target = strukt.syntax().text_range(); | 45 | let target = strukt.syntax().text_range(); |
46 | acc.add(AssistId("generate_new", AssistKind::Generate), "Generate `new`", target, |builder| { | 46 | 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 { | |||
281 | // FIXME: this partially overlaps with `find_impl_block` | 281 | // FIXME: this partially overlaps with `find_impl_block` |
282 | pub(crate) fn find_struct_impl( | 282 | pub(crate) fn find_struct_impl( |
283 | ctx: &AssistContext, | 283 | ctx: &AssistContext, |
284 | strukt: &ast::AdtDef, | 284 | strukt: &ast::Adt, |
285 | name: &str, | 285 | name: &str, |
286 | ) -> Option<Option<ast::Impl>> { | 286 | ) -> Option<Option<ast::Impl>> { |
287 | let db = ctx.db(); | 287 | let db = ctx.db(); |
@@ -290,9 +290,9 @@ pub(crate) fn find_struct_impl( | |||
290 | })?; | 290 | })?; |
291 | 291 | ||
292 | let struct_def = match strukt { | 292 | let struct_def = match strukt { |
293 | ast::AdtDef::Enum(e) => Adt::Enum(ctx.sema.to_def(e)?), | 293 | ast::Adt::Enum(e) => Adt::Enum(ctx.sema.to_def(e)?), |
294 | ast::AdtDef::Struct(s) => Adt::Struct(ctx.sema.to_def(s)?), | 294 | ast::Adt::Struct(s) => Adt::Struct(ctx.sema.to_def(s)?), |
295 | ast::AdtDef::Union(u) => Adt::Union(ctx.sema.to_def(u)?), | 295 | ast::Adt::Union(u) => Adt::Union(ctx.sema.to_def(u)?), |
296 | }; | 296 | }; |
297 | 297 | ||
298 | let block = module.descendants().filter_map(ast::Impl::cast).find_map(|impl_blk| { | 298 | 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( | |||
23 | 23 | ||
24 | let krate = sema.to_module_def(position.file_id)?.krate(); | 24 | let krate = sema.to_module_def(position.file_id)?.krate(); |
25 | 25 | ||
26 | if let Some(nominal_def) = find_node_at_offset::<ast::AdtDef>(&syntax, position.offset) { | 26 | if let Some(nominal_def) = find_node_at_offset::<ast::Adt>(&syntax, position.offset) { |
27 | return Some(RangeInfo::new( | 27 | return Some(RangeInfo::new( |
28 | nominal_def.syntax().text_range(), | 28 | nominal_def.syntax().text_range(), |
29 | impls_for_def(&sema, &nominal_def, krate)?, | 29 | impls_for_def(&sema, &nominal_def, krate)?, |
@@ -40,13 +40,13 @@ pub(crate) fn goto_implementation( | |||
40 | 40 | ||
41 | fn impls_for_def( | 41 | fn impls_for_def( |
42 | sema: &Semantics<RootDatabase>, | 42 | sema: &Semantics<RootDatabase>, |
43 | node: &ast::AdtDef, | 43 | node: &ast::Adt, |
44 | krate: Crate, | 44 | krate: Crate, |
45 | ) -> Option<Vec<NavigationTarget>> { | 45 | ) -> Option<Vec<NavigationTarget>> { |
46 | let ty = match node { | 46 | let ty = match node { |
47 | ast::AdtDef::Struct(def) => sema.to_def(def)?.ty(sema.db), | 47 | ast::Adt::Struct(def) => sema.to_def(def)?.ty(sema.db), |
48 | ast::AdtDef::Enum(def) => sema.to_def(def)?.ty(sema.db), | 48 | ast::Adt::Enum(def) => sema.to_def(def)?.ty(sema.db), |
49 | ast::AdtDef::Union(def) => sema.to_def(def)?.ty(sema.db), | 49 | ast::Adt::Union(def) => sema.to_def(def)?.ty(sema.db), |
50 | }; | 50 | }; |
51 | 51 | ||
52 | let impls = Impl::all_in_crate(sema.db, krate); | 52 | 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 { | |||
1401 | TupleFieldList(TupleFieldList), | 1401 | TupleFieldList(TupleFieldList), |
1402 | } | 1402 | } |
1403 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1403 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1404 | pub enum AdtDef { | 1404 | pub enum Adt { |
1405 | Enum(Enum), | 1405 | Enum(Enum), |
1406 | Struct(Struct), | 1406 | Struct(Struct), |
1407 | Union(Union), | 1407 | Union(Union), |
1408 | } | 1408 | } |
1409 | impl ast::AttrsOwner for AdtDef {} | 1409 | impl ast::AttrsOwner for Adt {} |
1410 | impl ast::GenericParamsOwner for AdtDef {} | 1410 | impl ast::GenericParamsOwner for Adt {} |
1411 | impl ast::NameOwner for AdtDef {} | 1411 | impl ast::NameOwner for Adt {} |
1412 | impl ast::VisibilityOwner for AdtDef {} | 1412 | impl ast::VisibilityOwner for Adt {} |
1413 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1413 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1414 | pub enum AssocItem { | 1414 | pub enum AssocItem { |
1415 | Const(Const), | 1415 | Const(Const), |
@@ -3394,16 +3394,16 @@ impl AstNode for FieldList { | |||
3394 | } | 3394 | } |
3395 | } | 3395 | } |
3396 | } | 3396 | } |
3397 | impl From<Enum> for AdtDef { | 3397 | impl From<Enum> for Adt { |
3398 | fn from(node: Enum) -> AdtDef { AdtDef::Enum(node) } | 3398 | fn from(node: Enum) -> Adt { Adt::Enum(node) } |
3399 | } | 3399 | } |
3400 | impl From<Struct> for AdtDef { | 3400 | impl From<Struct> for Adt { |
3401 | fn from(node: Struct) -> AdtDef { AdtDef::Struct(node) } | 3401 | fn from(node: Struct) -> Adt { Adt::Struct(node) } |
3402 | } | 3402 | } |
3403 | impl From<Union> for AdtDef { | 3403 | impl From<Union> for Adt { |
3404 | fn from(node: Union) -> AdtDef { AdtDef::Union(node) } | 3404 | fn from(node: Union) -> Adt { Adt::Union(node) } |
3405 | } | 3405 | } |
3406 | impl AstNode for AdtDef { | 3406 | impl AstNode for Adt { |
3407 | fn can_cast(kind: SyntaxKind) -> bool { | 3407 | fn can_cast(kind: SyntaxKind) -> bool { |
3408 | match kind { | 3408 | match kind { |
3409 | ENUM | STRUCT | UNION => true, | 3409 | ENUM | STRUCT | UNION => true, |
@@ -3412,18 +3412,18 @@ impl AstNode for AdtDef { | |||
3412 | } | 3412 | } |
3413 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 3413 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
3414 | let res = match syntax.kind() { | 3414 | let res = match syntax.kind() { |
3415 | ENUM => AdtDef::Enum(Enum { syntax }), | 3415 | ENUM => Adt::Enum(Enum { syntax }), |
3416 | STRUCT => AdtDef::Struct(Struct { syntax }), | 3416 | STRUCT => Adt::Struct(Struct { syntax }), |
3417 | UNION => AdtDef::Union(Union { syntax }), | 3417 | UNION => Adt::Union(Union { syntax }), |
3418 | _ => return None, | 3418 | _ => return None, |
3419 | }; | 3419 | }; |
3420 | Some(res) | 3420 | Some(res) |
3421 | } | 3421 | } |
3422 | fn syntax(&self) -> &SyntaxNode { | 3422 | fn syntax(&self) -> &SyntaxNode { |
3423 | match self { | 3423 | match self { |
3424 | AdtDef::Enum(it) => &it.syntax, | 3424 | Adt::Enum(it) => &it.syntax, |
3425 | AdtDef::Struct(it) => &it.syntax, | 3425 | Adt::Struct(it) => &it.syntax, |
3426 | AdtDef::Union(it) => &it.syntax, | 3426 | Adt::Union(it) => &it.syntax, |
3427 | } | 3427 | } |
3428 | } | 3428 | } |
3429 | } | 3429 | } |
@@ -3571,7 +3571,7 @@ impl std::fmt::Display for FieldList { | |||
3571 | std::fmt::Display::fmt(self.syntax(), f) | 3571 | std::fmt::Display::fmt(self.syntax(), f) |
3572 | } | 3572 | } |
3573 | } | 3573 | } |
3574 | impl std::fmt::Display for AdtDef { | 3574 | impl std::fmt::Display for Adt { |
3575 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 3575 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
3576 | std::fmt::Display::fmt(self.syntax(), f) | 3576 | std::fmt::Display::fmt(self.syntax(), f) |
3577 | } | 3577 | } |