Skip to content

Commit 3268907

Browse files
committed
implement feedback from review
1 parent d6b788a commit 3268907

File tree

5 files changed

+19
-14
lines changed

5 files changed

+19
-14
lines changed

crates/ide_assists/src/handlers/add_missing_impl_members.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use syntax::ast::{self, make, AstNode};
55
use crate::{
66
assist_context::{AssistContext, Assists},
77
utils::{
8-
add_trait_assoc_items_to_impl, filter_assoc_items, gen_trait_body, render_snippet, Cursor,
9-
DefaultMethods,
8+
add_trait_assoc_items_to_impl, filter_assoc_items, gen_trait_fn_body, render_snippet,
9+
Cursor, DefaultMethods,
1010
},
1111
AssistId, AssistKind,
1212
};
@@ -156,10 +156,10 @@ fn try_gen_trait_body(
156156
trait_: &hir::Trait,
157157
impl_def: &ast::Impl,
158158
) -> Option<()> {
159-
let trait_path = make::path_from_text(&trait_.name(ctx.db()).to_string());
159+
let trait_path = make::ext::ident_path(&trait_.name(ctx.db()).to_string());
160160
let hir_ty = ctx.sema.resolve_type(&impl_def.self_ty()?)?;
161161
let adt = hir_ty.as_adt()?.source(ctx.db())?;
162-
gen_trait_body(func, &trait_path, &adt.value)
162+
gen_trait_fn_body(func, &trait_path, &adt.value)
163163
}
164164

165165
#[cfg(test)]

crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ use syntax::{
77
SyntaxKind::{IDENT, WHITESPACE},
88
};
99

10-
use crate::utils::gen_trait_body;
1110
use crate::{
1211
assist_context::{AssistBuilder, AssistContext, Assists},
1312
utils::{
14-
add_trait_assoc_items_to_impl, filter_assoc_items, generate_trait_impl_text,
15-
render_snippet, Cursor, DefaultMethods,
13+
add_trait_assoc_items_to_impl, filter_assoc_items, gen_trait_fn_body,
14+
generate_trait_impl_text, render_snippet, Cursor, DefaultMethods,
1615
},
1716
AssistId, AssistKind,
1817
};
@@ -168,7 +167,7 @@ fn impl_def_from_trait(
168167

169168
// Generate a default `impl` function body for the derived trait.
170169
if let ast::AssocItem::Fn(ref func) = first_assoc_item {
171-
let _ = gen_trait_body(func, trait_path, adt);
170+
let _ = gen_trait_fn_body(func, trait_path, adt);
172171
};
173172

174173
Some((impl_def, first_assoc_item))

crates/ide_assists/src/utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Assorted functions shared by several assists.
22
33
pub(crate) mod suggest_name;
4-
mod gen_trait_body;
4+
mod gen_trait_fn_body;
55

66
use std::ops;
77

@@ -26,7 +26,7 @@ use syntax::{
2626

2727
use crate::assist_context::{AssistBuilder, AssistContext};
2828

29-
pub(crate) use gen_trait_body::gen_trait_body;
29+
pub(crate) use gen_trait_fn_body::gen_trait_fn_body;
3030

3131
pub(crate) fn unwrap_trivial_block(block: ast::BlockExpr) -> ast::Expr {
3232
extract_trivial_expression(&block)

crates/ide_assists/src/utils/gen_trait_body.rs renamed to crates/ide_assists/src/utils/gen_trait_fn_body.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
//! This module contains functions to generate default trait impl function bodies where possible.
22
3-
use syntax::ast::{self, edit::AstNodeEdit, make, AstNode, NameOwner};
4-
use syntax::ted;
3+
use syntax::{
4+
ast::{self, edit::AstNodeEdit, make, AstNode, NameOwner},
5+
ted,
6+
};
57

68
/// Generate custom trait bodies where possible.
79
///
810
/// Returns `Option` so that we can use `?` rather than `if let Some`. Returning
911
/// `None` means that generating a custom trait body failed, and the body will remain
1012
/// as `todo!` instead.
11-
pub(crate) fn gen_trait_body(func: &ast::Fn, trait_path: &ast::Path, adt: &ast::Adt) -> Option<()> {
13+
pub(crate) fn gen_trait_fn_body(
14+
func: &ast::Fn,
15+
trait_path: &ast::Path,
16+
adt: &ast::Adt,
17+
) -> Option<()> {
1218
match trait_path.segment()?.name_ref()?.text().as_str() {
1319
"Debug" => gen_debug_impl(adt, func),
1420
"Default" => gen_default_impl(adt, func),

crates/rust-analyzer/tests/slow-tests/tidy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ fn check_todo(path: &Path, text: &str) {
280280
"ast/make.rs",
281281
// The documentation in string literals may contain anything for its own purposes
282282
"ide_db/src/helpers/generated_lints.rs",
283-
"ide_assists/src/utils/gen_trait_body.rs",
283+
"ide_assists/src/utils/gen_trait_fn_body.rs",
284284
"ide_assists/src/tests/generated.rs",
285285
];
286286
if need_todo.iter().any(|p| path.ends_with(p)) {

0 commit comments

Comments
 (0)