Skip to content

Commit b58d6e5

Browse files
authored
Merge pull request #22148 from A4-Tacks/filter-default-bounds
minor: filter default bounds for introduce_named_type_parameter
2 parents e0bdaee + 5e48ae4 commit b58d6e5

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ pub(crate) fn introduce_named_type_parameter(
4848
)
4949
.for_impl_trait_as_generic(&impl_trait_type);
5050

51-
let type_param = make.type_param(make.name(&type_param_name), Some(type_bound_list));
51+
let type_bound_list = non_default_bounds(&type_bound_list).then_some(type_bound_list);
52+
let type_param = make.type_param(make.name(&type_param_name), type_bound_list);
5253
let new_ty = make.ty(&type_param_name);
5354

5455
editor.replace(impl_trait_type.syntax(), new_ty.syntax());
@@ -63,6 +64,10 @@ pub(crate) fn introduce_named_type_parameter(
6364
)
6465
}
6566

67+
fn non_default_bounds(bounds: &ast::TypeBoundList) -> bool {
68+
bounds.bounds().collect_array().is_none_or(|[bound]| bound.syntax().text() != "Sized")
69+
}
70+
6671
#[cfg(test)]
6772
mod tests {
6873
use super::*;
@@ -168,6 +173,15 @@ fn foo<
168173
);
169174
}
170175

176+
#[test]
177+
fn replace_impl_default_bounds() {
178+
check_assist(
179+
introduce_named_type_parameter,
180+
r#"fn foo(bar: $0impl Sized) {}"#,
181+
r#"fn foo<$0S>(bar: S) {}"#,
182+
);
183+
}
184+
171185
#[test]
172186
fn replace_impl_with_mut() {
173187
check_assist(

0 commit comments

Comments
 (0)