Skip to content

Commit a362023

Browse files
bors[bot]matklad
andauthored
Merge #4521 #4522
4521: Use snippets in add_function r=matklad a=matklad bors r+ 🤖 4522: Explain the purpose of `ast::make` module more clearly r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
3 parents 28f6b5b + e6fc0bd + 4de2749 commit a362023

File tree

12 files changed

+205
-107
lines changed

12 files changed

+205
-107
lines changed

crates/ra_assists/src/handlers/add_explicit_type.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ pub(crate) fn add_explicit_type(acc: &mut Assists, ctx: &AssistContext) -> Optio
2525
let stmt = ctx.find_node_at_offset::<LetStmt>()?;
2626
let module = ctx.sema.scope(stmt.syntax()).module()?;
2727
let expr = stmt.initializer()?;
28-
let pat = stmt.pat()?;
2928
// Must be a binding
30-
let pat = match pat {
29+
let pat = match stmt.pat()? {
3130
ast::Pat::BindPat(bind_pat) => bind_pat,
3231
_ => return None,
3332
};
@@ -46,7 +45,7 @@ pub(crate) fn add_explicit_type(acc: &mut Assists, ctx: &AssistContext) -> Optio
4645
// Assist not applicable if the type has already been specified
4746
// and it has no placeholders
4847
let ascribed_ty = stmt.ascribed_type();
49-
if let Some(ref ty) = ascribed_ty {
48+
if let Some(ty) = &ascribed_ty {
5049
if ty.syntax().descendants().find_map(ast::PlaceholderType::cast).is_none() {
5150
return None;
5251
}

crates/ra_assists/src/handlers/add_from_impl_for_enum.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use ra_ide_db::RootDatabase;
22
use ra_syntax::ast::{self, AstNode, NameOwner};
3-
use stdx::format_to;
43
use test_utils::tested_by;
54

65
use crate::{utils::FamousDefs, AssistContext, AssistId, Assists};
@@ -35,7 +34,7 @@ pub(crate) fn add_from_impl_for_enum(acc: &mut Assists, ctx: &AssistContext) ->
3534
}
3635
let field_type = field_list.fields().next()?.type_ref()?;
3736
let path = match field_type {
38-
ast::TypeRef::PathType(p) => p,
37+
ast::TypeRef::PathType(it) => it,
3938
_ => return None,
4039
};
4140

@@ -51,9 +50,7 @@ pub(crate) fn add_from_impl_for_enum(acc: &mut Assists, ctx: &AssistContext) ->
5150
target,
5251
|edit| {
5352
let start_offset = variant.parent_enum().syntax().text_range().end();
54-
let mut buf = String::new();
55-
format_to!(
56-
buf,
53+
let buf = format!(
5754
r#"
5855
5956
impl From<{0}> for {1} {{

0 commit comments

Comments
 (0)