diff options
Diffstat (limited to 'crates/ide_assists/src/utils.rs')
-rw-r--r-- | crates/ide_assists/src/utils.rs | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/crates/ide_assists/src/utils.rs b/crates/ide_assists/src/utils.rs index 62f959082..d67524937 100644 --- a/crates/ide_assists/src/utils.rs +++ b/crates/ide_assists/src/utils.rs | |||
@@ -246,7 +246,7 @@ fn invert_special_case(sema: &Semantics<RootDatabase>, expr: &ast::Expr) -> Opti | |||
246 | let method = mce.name_ref()?; | 246 | let method = mce.name_ref()?; |
247 | let arg_list = mce.arg_list()?; | 247 | let arg_list = mce.arg_list()?; |
248 | 248 | ||
249 | let method = match method.text() { | 249 | let method = match method.text().as_str() { |
250 | "is_some" => "is_none", | 250 | "is_some" => "is_none", |
251 | "is_none" => "is_some", | 251 | "is_none" => "is_some", |
252 | "is_ok" => "is_err", | 252 | "is_ok" => "is_err", |
@@ -338,11 +338,11 @@ pub(crate) fn find_struct_impl( | |||
338 | // (we currently use the wrong type parameter) | 338 | // (we currently use the wrong type parameter) |
339 | // also we wouldn't want to use e.g. `impl S<u32>` | 339 | // also we wouldn't want to use e.g. `impl S<u32>` |
340 | 340 | ||
341 | let same_ty = match blk.target_ty(db).as_adt() { | 341 | let same_ty = match blk.self_ty(db).as_adt() { |
342 | Some(def) => def == struct_def, | 342 | Some(def) => def == struct_def, |
343 | None => false, | 343 | None => false, |
344 | }; | 344 | }; |
345 | let not_trait_impl = blk.target_trait(db).is_none(); | 345 | let not_trait_impl = blk.trait_(db).is_none(); |
346 | 346 | ||
347 | if !(same_ty && not_trait_impl) { | 347 | if !(same_ty && not_trait_impl) { |
348 | None | 348 | None |
@@ -434,7 +434,8 @@ fn generate_impl_text_inner(adt: &ast::Adt, trait_text: Option<&str>, code: &str | |||
434 | } | 434 | } |
435 | buf | 435 | buf |
436 | }); | 436 | }); |
437 | let generics = lifetimes.chain(type_params).format(", "); | 437 | let const_params = generic_params.const_params().map(|t| t.syntax().to_string()); |
438 | let generics = lifetimes.chain(type_params).chain(const_params).format(", "); | ||
438 | format_to!(buf, "<{}>", generics); | 439 | format_to!(buf, "<{}>", generics); |
439 | } | 440 | } |
440 | buf.push(' '); | 441 | buf.push(' '); |
@@ -442,7 +443,7 @@ fn generate_impl_text_inner(adt: &ast::Adt, trait_text: Option<&str>, code: &str | |||
442 | buf.push_str(trait_text); | 443 | buf.push_str(trait_text); |
443 | buf.push_str(" for "); | 444 | buf.push_str(" for "); |
444 | } | 445 | } |
445 | buf.push_str(adt.name().unwrap().text()); | 446 | buf.push_str(&adt.name().unwrap().text()); |
446 | if let Some(generic_params) = generic_params { | 447 | if let Some(generic_params) = generic_params { |
447 | let lifetime_params = generic_params | 448 | let lifetime_params = generic_params |
448 | .lifetime_params() | 449 | .lifetime_params() |
@@ -452,7 +453,11 @@ fn generate_impl_text_inner(adt: &ast::Adt, trait_text: Option<&str>, code: &str | |||
452 | .type_params() | 453 | .type_params() |
453 | .filter_map(|it| it.name()) | 454 | .filter_map(|it| it.name()) |
454 | .map(|it| SmolStr::from(it.text())); | 455 | .map(|it| SmolStr::from(it.text())); |
455 | format_to!(buf, "<{}>", lifetime_params.chain(type_params).format(", ")) | 456 | let const_params = generic_params |
457 | .const_params() | ||
458 | .filter_map(|it| it.name()) | ||
459 | .map(|it| SmolStr::from(it.text())); | ||
460 | format_to!(buf, "<{}>", lifetime_params.chain(type_params).chain(const_params).format(", ")) | ||
456 | } | 461 | } |
457 | 462 | ||
458 | match adt.where_clause() { | 463 | match adt.where_clause() { |