Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit f1293a8

Browse files
committed
Add newline to body when where clause is present
1 parent 0519414 commit f1293a8

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

crates/ide-assists/src/handlers/generate_delegate_trait.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,8 @@ where
956956
impl<T> AnotherTrait for S<T>
957957
where
958958
T: AnotherTrait,
959-
{}"#,
959+
{
960+
}"#,
960961
);
961962
}
962963

@@ -1446,7 +1447,8 @@ where
14461447
impl<T> AnotherTrait for S<T>
14471448
where
14481449
T: AnotherTrait,
1449-
{}"#,
1450+
{
1451+
}"#,
14501452
);
14511453
}
14521454

crates/syntax/src/ast/make.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,11 @@ pub fn impl_(
248248

249249
let gen_params = generic_params.map_or_else(String::new, |it| it.to_string());
250250

251+
let body_newline =
252+
if where_clause.is_some() && body.is_none() { "\n".to_string() } else { String::new() };
253+
251254
let where_clause = match where_clause {
252-
Some(pr) => pr.to_string(),
255+
Some(pr) => format!("\n{pr}\n"),
253256
None => " ".to_string(),
254257
};
255258

@@ -258,7 +261,9 @@ pub fn impl_(
258261
None => String::new(),
259262
};
260263

261-
ast_from_text(&format!("impl{gen_params} {path_type}{gen_args}{where_clause}{{{body}}}"))
264+
ast_from_text(&format!(
265+
"impl{gen_params} {path_type}{gen_args}{where_clause}{{{body_newline}{body}}}"
266+
))
262267
}
263268

264269
pub fn impl_trait(
@@ -284,6 +289,13 @@ pub fn impl_trait(
284289

285290
let is_negative = if is_negative { "! " } else { "" };
286291

292+
let body_newline =
293+
if (ty_where_clause.is_some() || trait_where_clause.is_some()) && body.is_none() {
294+
"\n".to_string()
295+
} else {
296+
String::new()
297+
};
298+
287299
let where_clause = merge_where_clause(ty_where_clause, trait_where_clause)
288300
.map_or_else(|| " ".to_string(), |wc| format!("\n{}\n", wc));
289301

@@ -292,7 +304,7 @@ pub fn impl_trait(
292304
None => String::new(),
293305
};
294306

295-
ast_from_text(&format!("{is_unsafe}impl{gen_params} {is_negative}{path_type}{trait_gen_args} for {ty}{type_gen_args}{where_clause}{{{body}}}"))
307+
ast_from_text(&format!("{is_unsafe}impl{gen_params} {is_negative}{path_type}{trait_gen_args} for {ty}{type_gen_args}{where_clause}{{{body_newline}{body}}}"))
296308
}
297309

298310
pub fn impl_trait_type(bounds: ast::TypeBoundList) -> ast::ImplTraitType {

0 commit comments

Comments
 (0)