diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-02-29 10:56:10 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-02-29 10:56:10 +0000 |
commit | b53ff214aa9fe30eeedb64f78cc89561060c0083 (patch) | |
tree | f78e3650b3cd4ca1f13a7fdc90b9f4f60e0c6ce0 | |
parent | 7cf710c66f5645193a765ededfed77eaec9a19a9 (diff) | |
parent | ca713e462b90afd650a5c07014e066d0aa4dbd69 (diff) |
Merge #3374
3374: More orthogonal API for building paths r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
-rw-r--r-- | crates/ra_assists/src/handlers/early_return.rs | 23 | ||||
-rw-r--r-- | crates/ra_assists/src/handlers/move_bounds.rs | 6 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/make.rs | 11 |
3 files changed, 25 insertions, 15 deletions
diff --git a/crates/ra_assists/src/handlers/early_return.rs b/crates/ra_assists/src/handlers/early_return.rs index 22f88884f..f57ecd07a 100644 --- a/crates/ra_assists/src/handlers/early_return.rs +++ b/crates/ra_assists/src/handlers/early_return.rs | |||
@@ -112,16 +112,19 @@ pub(crate) fn convert_to_guarded_return(ctx: AssistCtx) -> Option<Assist> { | |||
112 | Some((path, bound_ident)) => { | 112 | Some((path, bound_ident)) => { |
113 | // If-let. | 113 | // If-let. |
114 | let match_expr = { | 114 | let match_expr = { |
115 | let happy_arm = make::match_arm( | 115 | let happy_arm = { |
116 | once( | 116 | let pat = make::tuple_struct_pat( |
117 | make::tuple_struct_pat( | 117 | path, |
118 | path, | 118 | once(make::bind_pat(make::name("it")).into()), |
119 | once(make::bind_pat(make::name("it")).into()), | 119 | ); |
120 | ) | 120 | let expr = { |
121 | .into(), | 121 | let name_ref = make::name_ref("it"); |
122 | ), | 122 | let segment = make::path_segment(name_ref); |
123 | make::expr_path(make::path_from_name_ref(make::name_ref("it"))), | 123 | let path = make::path_unqalified(segment); |
124 | ); | 124 | make::expr_path(path) |
125 | }; | ||
126 | make::match_arm(once(pat.into()), expr) | ||
127 | }; | ||
125 | 128 | ||
126 | let sad_arm = make::match_arm( | 129 | let sad_arm = make::match_arm( |
127 | // FIXME: would be cool to use `None` or `Err(_)` if appropriate | 130 | // FIXME: would be cool to use `None` or `Err(_)` if appropriate |
diff --git a/crates/ra_assists/src/handlers/move_bounds.rs b/crates/ra_assists/src/handlers/move_bounds.rs index 90793b5fc..616b95770 100644 --- a/crates/ra_assists/src/handlers/move_bounds.rs +++ b/crates/ra_assists/src/handlers/move_bounds.rs | |||
@@ -72,7 +72,11 @@ pub(crate) fn move_bounds_to_where_clause(ctx: AssistCtx) -> Option<Assist> { | |||
72 | } | 72 | } |
73 | 73 | ||
74 | fn build_predicate(param: ast::TypeParam) -> Option<ast::WherePred> { | 74 | fn build_predicate(param: ast::TypeParam) -> Option<ast::WherePred> { |
75 | let path = make::path_from_name_ref(make::name_ref(¶m.name()?.syntax().to_string())); | 75 | let path = { |
76 | let name_ref = make::name_ref(¶m.name()?.syntax().to_string()); | ||
77 | let segment = make::path_segment(name_ref); | ||
78 | make::path_unqalified(segment) | ||
79 | }; | ||
76 | let predicate = make::where_pred(path, param.type_bound_list()?.bounds()); | 80 | let predicate = make::where_pred(path, param.type_bound_list()?.bounds()); |
77 | Some(predicate) | 81 | Some(predicate) |
78 | } | 82 | } |
diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs index 7c20fcc10..60cd9d260 100644 --- a/crates/ra_syntax/src/ast/make.rs +++ b/crates/ra_syntax/src/ast/make.rs | |||
@@ -12,11 +12,14 @@ pub fn name_ref(text: &str) -> ast::NameRef { | |||
12 | ast_from_text(&format!("fn f() {{ {}; }}", text)) | 12 | ast_from_text(&format!("fn f() {{ {}; }}", text)) |
13 | } | 13 | } |
14 | 14 | ||
15 | pub fn path_from_name_ref(name_ref: ast::NameRef) -> ast::Path { | 15 | pub fn path_segment(name_ref: ast::NameRef) -> ast::PathSegment { |
16 | path_from_text(&name_ref.syntax().to_string()) | 16 | ast_from_text(&format!("use {};", name_ref.syntax())) |
17 | } | 17 | } |
18 | pub fn path_qualified(qual: ast::Path, name_ref: ast::NameRef) -> ast::Path { | 18 | pub fn path_unqalified(segment: ast::PathSegment) -> ast::Path { |
19 | path_from_text(&format!("{}::{}", qual.syntax(), name_ref.syntax())) | 19 | path_from_text(&format!("use {}", segment.syntax())) |
20 | } | ||
21 | pub fn path_qualified(qual: ast::Path, segment: ast::PathSegment) -> ast::Path { | ||
22 | path_from_text(&format!("{}::{}", qual.syntax(), segment.syntax())) | ||
20 | } | 23 | } |
21 | fn path_from_text(text: &str) -> ast::Path { | 24 | fn path_from_text(text: &str) -> ast::Path { |
22 | ast_from_text(text) | 25 | ast_from_text(text) |