]> git.lizzy.rs Git - rust.git/commitdiff
Fix tests
authorAleksei Sidorov <gorthauer87@yandex.ru>
Fri, 4 Sep 2020 14:55:27 +0000 (17:55 +0300)
committerAleksei Sidorov <gorthauer87@yandex.ru>
Fri, 4 Sep 2020 14:55:27 +0000 (17:55 +0300)
crates/assists/src/handlers/replace_impl_trait_with_generic.rs
crates/assists/src/tests/generated.rs
crates/syntax/src/ast/make.rs

index 612c48466e4f004c6c719155f09b69b74beb2cb2..748c528d45acb263c73b28391b818d866ba8c2f9 100644 (file)
@@ -7,11 +7,11 @@
 // Replaces `impl Trait` function argument with the named generic.
 //
 // ```
-// fn foo<G>(bar: <|>impl Bar) {}
+// fn foo(bar: <|>impl Bar) {}
 // ```
 // ->
 // ```
-// fn foo<B: Bar>(bar: B) {}
+// fn foo<B: Bar,>(bar: B) {}
 // ```
 pub(crate) fn replace_impl_trait_with_generic(
     acc: &mut Assists,
@@ -21,13 +21,7 @@ pub(crate) fn replace_impl_trait_with_generic(
     let type_param = type_impl_trait.syntax().parent().and_then(ast::Param::cast)?;
     let type_fn = type_param.syntax().ancestors().find_map(ast::Fn::cast)?;
 
-    let impl_trait_ty = type_impl_trait
-        .syntax()
-        .descendants()
-        .last()
-        .and_then(ast::NameRef::cast)?
-        .text()
-        .to_string();
+    let impl_trait_ty = type_impl_trait.type_bound_list()?;
 
     let target = type_fn.syntax().text_range();
     acc.add(
@@ -35,7 +29,7 @@ pub(crate) fn replace_impl_trait_with_generic(
         "Replace impl trait with generic",
         target,
         |edit| {
-            let generic_letter = impl_trait_ty.chars().next().unwrap().to_string();
+            let generic_letter = impl_trait_ty.to_string().chars().next().unwrap().to_string();
 
             let generic_param_list = type_fn
                 .generic_param_list()
@@ -65,7 +59,7 @@ fn replace_impl_trait_with_generic_params() {
             fn foo<G>(bar: <|>impl Bar) {}
             "#,
             r#"
-            fn foo<G, B: Bar>(bar: B) {}
+            fn foo<G, B: Bar,>(bar: B) {}
             "#,
         );
     }
@@ -78,7 +72,7 @@ fn replace_impl_trait_without_generic_params() {
             fn foo(bar: <|>impl Bar) {}
             "#,
             r#"
-            fn foo<B: Bar>(bar: B) {}
+            fn foo<B: Bar,>(bar: B) {}
             "#,
         );
     }
@@ -91,7 +85,7 @@ fn replace_two_impl_trait_with_generic_params() {
             fn foo<G>(foo: impl Foo, bar: <|>impl Bar) {}
             "#,
             r#"
-            fn foo<G, B: Bar>(foo: impl Foo, bar: B) {}
+            fn foo<G, B: Bar,>(foo: impl Foo, bar: B) {}
             "#,
         );
     }
@@ -104,7 +98,7 @@ fn replace_impl_trait_with_empty_generic_params() {
             fn foo<>(bar: <|>impl Bar) {}
             "#,
             r#"
-            fn foo<B: Bar>(bar: B) {}
+            fn foo<B: Bar,>(bar: B) {}
             "#,
         );
     }
@@ -133,7 +127,7 @@ fn replace_impl_trait_with_exist_generic_letter() {
             fn foo<B>(bar: <|>impl Bar) {}
             "#,
             r#"
-            fn foo<B, C: Bar>(bar: C) {}
+            fn foo<B, C: Bar,>(bar: C) {}
             "#,
         );
     }
@@ -158,4 +152,17 @@ fn foo<
             "#,
         );
     }
+
+    #[test]
+    fn replace_impl_trait_multiple() {
+        check_assist(
+            replace_impl_trait_with_generic,
+            r#"
+            fn foo(bar: <|>impl Foo + Bar) {}
+            "#,
+            r#"
+            fn foo<F: Foo + Bar,>(bar: F) {}
+            "#,
+        );
+    }
 }
index 3963136d82406a0cef889252e2252d2560d338a9..4e5ca38251b5ed25907728ca02ee1ddb461304f3 100644 (file)
@@ -819,10 +819,10 @@ fn doctest_replace_impl_trait_with_generic() {
     check_doc_test(
         "replace_impl_trait_with_generic",
         r#####"
-fn foo<G>(bar: <|>impl Bar) {}
+fn foo(bar: <|>impl Bar) {}
 "#####,
         r#####"
-fn foo<B: Bar>(bar: B) {}
+fn foo<B: Bar,>(bar: B) {}
 "#####,
     )
 }
index 7329e3039c5c46afce6ebff57ab320e6b62da575..dac4174cd96a23b03fd42ea0b1084a5f590879a3 100644 (file)
@@ -294,7 +294,7 @@ pub fn param_list(pats: impl IntoIterator<Item = ast::Param>) -> ast::ParamList
     ast_from_text(&format!("fn f({}) {{ }}", args))
 }
 
-pub fn generic_param(name: String, ty: Option<String>) -> ast::GenericParam {
+pub fn generic_param(name: String, ty: Option<ast::TypeBoundList>) -> ast::GenericParam {
     let bound = match ty {
         Some(it) => format!(": {}", it),
         None => String::new(),