Skip to content

Commit f4349ff

Browse files
rmehri01Veykril
authored andcommitted
fix: preserve where clause in delegate method
1 parent 934358e commit f4349ff

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

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

+48-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ pub(crate) fn generate_delegate_methods(acc: &mut Assists, ctx: &AssistContext<'
134134
vis,
135135
fn_name,
136136
type_params,
137-
None,
137+
method_source.where_clause(),
138138
params,
139139
body,
140140
ret_type,
@@ -464,6 +464,53 @@ impl Person {
464464
);
465465
}
466466

467+
#[test]
468+
fn test_preserve_where_clause() {
469+
check_assist(
470+
generate_delegate_methods,
471+
r#"
472+
struct Inner<T>(T);
473+
impl<T> Inner<T> {
474+
fn get(&self) -> T
475+
where
476+
T: Copy,
477+
T: PartialEq,
478+
{
479+
self.0
480+
}
481+
}
482+
483+
struct Struct<T> {
484+
$0field: Inner<T>,
485+
}
486+
"#,
487+
r#"
488+
struct Inner<T>(T);
489+
impl<T> Inner<T> {
490+
fn get(&self) -> T
491+
where
492+
T: Copy,
493+
T: PartialEq,
494+
{
495+
self.0
496+
}
497+
}
498+
499+
struct Struct<T> {
500+
field: Inner<T>,
501+
}
502+
503+
impl<T> Struct<T> {
504+
$0fn get(&self) -> T where
505+
T: Copy,
506+
T: PartialEq, {
507+
self.field.get()
508+
}
509+
}
510+
"#,
511+
);
512+
}
513+
467514
#[test]
468515
fn test_fixes_basic_self_references() {
469516
check_assist(

0 commit comments

Comments
 (0)