From ca713e462b90afd650a5c07014e066d0aa4dbd69 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 29 Feb 2020 11:55:36 +0100 Subject: More orthogonal API for building paths --- crates/ra_assists/src/handlers/early_return.rs | 23 +++++++++++++---------- crates/ra_assists/src/handlers/move_bounds.rs | 6 +++++- 2 files changed, 18 insertions(+), 11 deletions(-) (limited to 'crates/ra_assists/src/handlers') 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 { Some((path, bound_ident)) => { // If-let. let match_expr = { - let happy_arm = make::match_arm( - once( - make::tuple_struct_pat( - path, - once(make::bind_pat(make::name("it")).into()), - ) - .into(), - ), - make::expr_path(make::path_from_name_ref(make::name_ref("it"))), - ); + let happy_arm = { + let pat = make::tuple_struct_pat( + path, + once(make::bind_pat(make::name("it")).into()), + ); + let expr = { + let name_ref = make::name_ref("it"); + let segment = make::path_segment(name_ref); + let path = make::path_unqalified(segment); + make::expr_path(path) + }; + make::match_arm(once(pat.into()), expr) + }; let sad_arm = make::match_arm( // 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 { } fn build_predicate(param: ast::TypeParam) -> Option { - let path = make::path_from_name_ref(make::name_ref(¶m.name()?.syntax().to_string())); + let path = { + let name_ref = make::name_ref(¶m.name()?.syntax().to_string()); + let segment = make::path_segment(name_ref); + make::path_unqalified(segment) + }; let predicate = make::where_pred(path, param.type_bound_list()?.bounds()); Some(predicate) } -- cgit v1.2.3