fix: preserve where clause in delegate method

This commit is contained in:
Ryan Mehri 2023-10-05 12:45:26 -07:00 committed by Lukas Wirth
parent 934358e95c
commit f4349ff26e

View File

@ -134,7 +134,7 @@ pub(crate) fn generate_delegate_methods(acc: &mut Assists, ctx: &AssistContext<'
vis,
fn_name,
type_params,
None,
method_source.where_clause(),
params,
body,
ret_type,
@ -464,6 +464,53 @@ impl Person {
);
}
#[test]
fn test_preserve_where_clause() {
check_assist(
generate_delegate_methods,
r#"
struct Inner<T>(T);
impl<T> Inner<T> {
fn get(&self) -> T
where
T: Copy,
T: PartialEq,
{
self.0
}
}
struct Struct<T> {
$0field: Inner<T>,
}
"#,
r#"
struct Inner<T>(T);
impl<T> Inner<T> {
fn get(&self) -> T
where
T: Copy,
T: PartialEq,
{
self.0
}
}
struct Struct<T> {
field: Inner<T>,
}
impl<T> Struct<T> {
$0fn get(&self) -> T where
T: Copy,
T: PartialEq, {
self.field.get()
}
}
"#,
);
}
#[test]
fn test_fixes_basic_self_references() {
check_assist(