Skip to content

Commit 459e10e

Browse files
bors[bot]bnjjj
andauthored
Merge #7725
7725: fix(assist): display where predicates when we want to generate impl r=lnicola a=bnjjj close #7721 Co-authored-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2 parents ba3a5c5 + d855958 commit 459e10e

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

crates/assists/src/handlers/generate_impl.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,31 @@ mod tests {
122122
$0
123123
}"#,
124124
);
125+
126+
check_assist(
127+
generate_impl,
128+
r#"pub trait Trait {}
129+
struct Struct<T>$0
130+
where
131+
T: Trait,
132+
{
133+
inner: T,
134+
}"#,
135+
r#"pub trait Trait {}
136+
struct Struct<T>
137+
where
138+
T: Trait,
139+
{
140+
inner: T,
141+
}
142+
143+
impl<T> Struct<T>
144+
where
145+
T: Trait,
146+
{
147+
$0
148+
}"#,
149+
);
125150
}
126151

127152
#[test]

crates/assists/src/utils.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,14 @@ fn generate_impl_text_inner(adt: &ast::Adt, trait_text: Option<&str>, code: &str
421421
format_to!(buf, "<{}>", lifetime_params.chain(type_params).format(", "))
422422
}
423423

424-
format_to!(buf, " {{\n{}\n}}", code);
424+
match adt.where_clause() {
425+
Some(where_clause) => {
426+
format_to!(buf, "\n{}\n{{\n{}\n}}", where_clause, code);
427+
}
428+
None => {
429+
format_to!(buf, " {{\n{}\n}}", code);
430+
}
431+
}
425432

426433
buf
427434
}

0 commit comments

Comments
 (0)