aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_completion
diff options
context:
space:
mode:
authorJosh Mcguigan <[email protected]>2021-03-16 13:54:17 +0000
committerJosh Mcguigan <[email protected]>2021-03-16 13:54:17 +0000
commit81f51fcd654f961af97133c6995fe802e9913f05 (patch)
tree2e135e40193932da0743c3229343325c75088974 /crates/ide_completion
parentc49b5b7468a9954af86fd1724276261f396aba5d (diff)
minor style fixes per feedback on #8036
Diffstat (limited to 'crates/ide_completion')
-rw-r--r--crates/ide_completion/src/render.rs48
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
309fn compute_exact_type_match(ctx: &CompletionContext, completion_ty: &hir::Type) -> bool { 309fn 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
325fn compute_ref_match(ctx: &CompletionContext, completion_ty: &hir::Type) -> Option<Mutability> { 326fn 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)]