diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-03-16 13:56:53 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-03-16 13:56:53 +0000 |
commit | b4ed3e1551f828d44dcd8e0caf08420438e5eb1a (patch) | |
tree | a7a53cb60960d6f83fee09d9333047256e02b08c | |
parent | da5328a01be27a73378f4c4bac161e8fd43781e3 (diff) | |
parent | 81f51fcd654f961af97133c6995fe802e9913f05 (diff) |
Merge #8052
8052: minor style fixes per feedback on #8036 r=JoshMcguigan a=JoshMcguigan
cc @matklad - this PR addresses your comments in #8036.
changelog fixup #8036
Co-authored-by: Josh Mcguigan <[email protected]>
-rw-r--r-- | crates/ide_completion/src/render.rs | 48 |
1 files changed, 21 insertions, 27 deletions
diff --git a/crates/ide_completion/src/render.rs b/crates/ide_completion/src/render.rs index 36655667c..4e4923e0d 100644 --- a/crates/ide_completion/src/render.rs +++ b/crates/ide_completion/src/render.rs | |||
@@ -307,12 +307,13 @@ impl<'a> Render<'a> { | |||
307 | } | 307 | } |
308 | 308 | ||
309 | fn compute_exact_type_match(ctx: &CompletionContext, completion_ty: &hir::Type) -> bool { | 309 | fn compute_exact_type_match(ctx: &CompletionContext, completion_ty: &hir::Type) -> bool { |
310 | if let Some(expected_type) = ctx.expected_type.as_ref() { | 310 | match ctx.expected_type.as_ref() { |
311 | // We don't ever consider unit type to be an exact type match, since | 311 | Some(expected_type) => { |
312 | // nearly always this is not meaningful to the user. | 312 | // We don't ever consider unit type to be an exact type match, since |
313 | completion_ty == expected_type && !expected_type.is_unit() | 313 | // nearly always this is not meaningful to the user. |
314 | } else { | 314 | completion_ty == expected_type && !expected_type.is_unit() |
315 | false | 315 | } |
316 | None => false, | ||
316 | } | 317 | } |
317 | } | 318 | } |
318 | 319 | ||
@@ -323,27 +324,20 @@ fn compute_exact_name_match(ctx: &CompletionContext, completion_name: impl Into< | |||
323 | } | 324 | } |
324 | 325 | ||
325 | fn compute_ref_match(ctx: &CompletionContext, completion_ty: &hir::Type) -> Option<Mutability> { | 326 | fn compute_ref_match(ctx: &CompletionContext, completion_ty: &hir::Type) -> Option<Mutability> { |
326 | let mut ref_match = None; | 327 | let expected_type = ctx.expected_type.as_ref()?; |
327 | if let Some(expected_type) = &ctx.expected_type { | 328 | if completion_ty != expected_type { |
328 | if completion_ty != expected_type { | 329 | let expected_type_without_ref = expected_type.remove_ref()?; |
329 | if let Some(expected_type_without_ref) = expected_type.remove_ref() { | 330 | if completion_ty.autoderef(ctx.db).any(|deref_ty| deref_ty == expected_type_without_ref) { |
330 | if completion_ty == &expected_type_without_ref | 331 | cov_mark::hit!(suggest_ref); |
331 | || completion_ty | 332 | let mutability = if expected_type.is_mutable_reference() { |
332 | .autoderef(ctx.db) | 333 | Mutability::Mut |
333 | .any(|deref_ty| deref_ty == expected_type_without_ref) | 334 | } else { |
334 | { | 335 | Mutability::Shared |
335 | cov_mark::hit!(suggest_ref); | 336 | }; |
336 | let mutability = if expected_type.is_mutable_reference() { | 337 | return Some(mutability); |
337 | Mutability::Mut | 338 | }; |
338 | } else { | 339 | } |
339 | Mutability::Shared | 340 | None |
340 | }; | ||
341 | ref_match = Some(mutability); | ||
342 | } | ||
343 | } | ||
344 | } | ||
345 | }; | ||
346 | ref_match | ||
347 | } | 341 | } |
348 | 342 | ||
349 | #[cfg(test)] | 343 | #[cfg(test)] |