Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions crates/ra_assists/src/handlers/early_return.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,19 @@ pub(crate) fn convert_to_guarded_return(ctx: AssistCtx) -> Option<Assist> {
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
Expand Down
6 changes: 5 additions & 1 deletion crates/ra_assists/src/handlers/move_bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ pub(crate) fn move_bounds_to_where_clause(ctx: AssistCtx) -> Option<Assist> {
}

fn build_predicate(param: ast::TypeParam) -> Option<ast::WherePred> {
let path = make::path_from_name_ref(make::name_ref(&param.name()?.syntax().to_string()));
let path = {
let name_ref = make::name_ref(&param.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)
}
Expand Down
11 changes: 7 additions & 4 deletions crates/ra_syntax/src/ast/make.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ pub fn name_ref(text: &str) -> ast::NameRef {
ast_from_text(&format!("fn f() {{ {}; }}", text))
}

pub fn path_from_name_ref(name_ref: ast::NameRef) -> ast::Path {
path_from_text(&name_ref.syntax().to_string())
pub fn path_segment(name_ref: ast::NameRef) -> ast::PathSegment {
ast_from_text(&format!("use {};", name_ref.syntax()))
}
pub fn path_qualified(qual: ast::Path, name_ref: ast::NameRef) -> ast::Path {
path_from_text(&format!("{}::{}", qual.syntax(), name_ref.syntax()))
pub fn path_unqalified(segment: ast::PathSegment) -> ast::Path {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: unqualified 😅

path_from_text(&format!("use {}", segment.syntax()))
}
pub fn path_qualified(qual: ast::Path, segment: ast::PathSegment) -> ast::Path {
path_from_text(&format!("{}::{}", qual.syntax(), segment.syntax()))
}
fn path_from_text(text: &str) -> ast::Path {
ast_from_text(text)
Expand Down