5940: Implement "Replace `impl Trait` function argument with the named generic" assist. r=matklad a=alekseysidorov

Fixes #5085 

Co-authored-by: Aleksei Sidorov <gorthauer87@yandex.ru>
This commit is contained in:
bors[bot] 2020-09-04 21:54:42 +00:00 committed by GitHub
commit 0275b08d15
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 267 additions and 1 deletions

View file

@ -294,6 +294,21 @@ 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<ast::TypeBoundList>) -> ast::GenericParam {
let bound = match ty {
Some(it) => format!(": {}", it),
None => String::new(),
};
ast_from_text(&format!("fn f<{}{}>() {{ }}", name, bound))
}
pub fn generic_param_list(
pats: impl IntoIterator<Item = ast::GenericParam>,
) -> ast::GenericParamList {
let args = pats.into_iter().join(", ");
ast_from_text(&format!("fn f<{}>() {{ }}", args))
}
pub fn visibility_pub_crate() -> ast::Visibility {
ast_from_text("pub(crate) struct S")
}