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 /crates/assists/src | |
parent | 75a87ec198b25c5938c651ef087f9ebf923c34f8 (diff) | |
parent | 7022ea52b5f2a0262c2cd96b290ddb8ec0af0df9 (diff) |
Merge #7587
7587: AdtDef -> Adt r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/assists/src')
-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 |
6 files changed, 14 insertions, 14 deletions
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| { |