mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 11:59:49 +00:00
Add newline to body when where clause is present
This commit is contained in:
parent
0519414c19
commit
f1293a8fc4
2 changed files with 19 additions and 5 deletions
|
@ -956,7 +956,8 @@ where
|
||||||
impl<T> AnotherTrait for S<T>
|
impl<T> AnotherTrait for S<T>
|
||||||
where
|
where
|
||||||
T: AnotherTrait,
|
T: AnotherTrait,
|
||||||
{}"#,
|
{
|
||||||
|
}"#,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1446,7 +1447,8 @@ where
|
||||||
impl<T> AnotherTrait for S<T>
|
impl<T> AnotherTrait for S<T>
|
||||||
where
|
where
|
||||||
T: AnotherTrait,
|
T: AnotherTrait,
|
||||||
{}"#,
|
{
|
||||||
|
}"#,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -248,8 +248,11 @@ pub fn impl_(
|
||||||
|
|
||||||
let gen_params = generic_params.map_or_else(String::new, |it| it.to_string());
|
let gen_params = generic_params.map_or_else(String::new, |it| it.to_string());
|
||||||
|
|
||||||
|
let body_newline =
|
||||||
|
if where_clause.is_some() && body.is_none() { "\n".to_string() } else { String::new() };
|
||||||
|
|
||||||
let where_clause = match where_clause {
|
let where_clause = match where_clause {
|
||||||
Some(pr) => pr.to_string(),
|
Some(pr) => format!("\n{pr}\n"),
|
||||||
None => " ".to_string(),
|
None => " ".to_string(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -258,7 +261,9 @@ pub fn impl_(
|
||||||
None => String::new(),
|
None => String::new(),
|
||||||
};
|
};
|
||||||
|
|
||||||
ast_from_text(&format!("impl{gen_params} {path_type}{gen_args}{where_clause}{{{body}}}"))
|
ast_from_text(&format!(
|
||||||
|
"impl{gen_params} {path_type}{gen_args}{where_clause}{{{body_newline}{body}}}"
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn impl_trait(
|
pub fn impl_trait(
|
||||||
|
@ -284,6 +289,13 @@ pub fn impl_trait(
|
||||||
|
|
||||||
let is_negative = if is_negative { "! " } else { "" };
|
let is_negative = if is_negative { "! " } else { "" };
|
||||||
|
|
||||||
|
let body_newline =
|
||||||
|
if (ty_where_clause.is_some() || trait_where_clause.is_some()) && body.is_none() {
|
||||||
|
"\n".to_string()
|
||||||
|
} else {
|
||||||
|
String::new()
|
||||||
|
};
|
||||||
|
|
||||||
let where_clause = merge_where_clause(ty_where_clause, trait_where_clause)
|
let where_clause = merge_where_clause(ty_where_clause, trait_where_clause)
|
||||||
.map_or_else(|| " ".to_string(), |wc| format!("\n{}\n", wc));
|
.map_or_else(|| " ".to_string(), |wc| format!("\n{}\n", wc));
|
||||||
|
|
||||||
|
@ -292,7 +304,7 @@ pub fn impl_trait(
|
||||||
None => String::new(),
|
None => String::new(),
|
||||||
};
|
};
|
||||||
|
|
||||||
ast_from_text(&format!("{is_unsafe}impl{gen_params} {is_negative}{path_type}{trait_gen_args} for {ty}{type_gen_args}{where_clause}{{{body}}}"))
|
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}}}"))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn impl_trait_type(bounds: ast::TypeBoundList) -> ast::ImplTraitType {
|
pub fn impl_trait_type(bounds: ast::TypeBoundList) -> ast::ImplTraitType {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue