File tree Expand file tree Collapse file tree
crates/ide-assists/src/handlers Expand file tree Collapse file tree Original file line number Diff line number Diff 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) ]
6772mod 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 (
You can’t perform that action at this time.
0 commit comments