Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-assists/src/handlers/replace_named_generic_with_impl.rs')
-rw-r--r--crates/ide-assists/src/handlers/replace_named_generic_with_impl.rs13
1 files changed, 12 insertions, 1 deletions
diff --git a/crates/ide-assists/src/handlers/replace_named_generic_with_impl.rs b/crates/ide-assists/src/handlers/replace_named_generic_with_impl.rs
index 17ef7727ec..4372683016 100644
--- a/crates/ide-assists/src/handlers/replace_named_generic_with_impl.rs
+++ b/crates/ide-assists/src/handlers/replace_named_generic_with_impl.rs
@@ -34,7 +34,7 @@ pub(crate) fn replace_named_generic_with_impl(
let type_param_name = type_param.name()?;
// The list of type bounds / traits: `AsRef<Path>`
- let type_bound_list = type_param.type_bound_list()?;
+ let type_bound_list = type_param.type_bound_list();
let fn_ = type_param.syntax().ancestors().find_map(ast::Fn::cast)?;
let param_list_text_range = fn_.param_list()?.syntax().text_range();
@@ -89,6 +89,8 @@ pub(crate) fn replace_named_generic_with_impl(
}
}
+ let type_bound_list = type_bound_list
+ .unwrap_or_else(|| make.type_bound_list([make.type_bound_text("Sized")]).unwrap());
let new_bounds = make.impl_trait_type(type_bound_list);
for path_type in path_types_to_replace.iter().rev() {
editor.replace(path_type.syntax(), new_bounds.syntax());
@@ -313,6 +315,15 @@ mod tests {
}
#[test]
+ fn replace_generic_without_bounds() {
+ check_assist(
+ replace_named_generic_with_impl,
+ r#"fn foo<T$0>(input: T) {}"#,
+ r#"fn foo(input: impl Sized) {}"#,
+ );
+ }
+
+ #[test]
fn replace_generic_with_multiple_trait_bounds() {
check_assist(
replace_named_generic_with_impl,