From de074fe6368aca7435256925ee749f5664d49b69 Mon Sep 17 00:00:00 2001 From: Dawer <7803845+iDawer@users.noreply.github.com> Date: Wed, 11 Aug 2021 22:09:32 +0500 Subject: [PATCH] Accept ambiguous unsize coercion only if it has definite guidance. --- crates/hir_ty/src/infer/coerce.rs | 8 ++++---- crates/hir_ty/src/tests/coercion.rs | 13 +++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/crates/hir_ty/src/infer/coerce.rs b/crates/hir_ty/src/infer/coerce.rs index 0e6b474486..9543404114 100644 --- a/crates/hir_ty/src/infer/coerce.rs +++ b/crates/hir_ty/src/infer/coerce.rs @@ -575,11 +575,11 @@ impl<'a> InferenceContext<'a> { }, ); } - Solution::Ambig(guidance) => { - if let Guidance::Definite(subst) = guidance { - canonicalized.apply_solution(&mut self.table, subst); - } + Solution::Ambig(Guidance::Definite(subst)) => { + canonicalized.apply_solution(&mut self.table, subst) } + // FIXME: should we accept ambiguous results here? + _ => return Err(TypeError), }; let unsize = Adjustment { kind: Adjust::Pointer(PointerCast::Unsize), target: to_ty.clone() }; diff --git a/crates/hir_ty/src/tests/coercion.rs b/crates/hir_ty/src/tests/coercion.rs index cef1ffe9c9..4e761a6b47 100644 --- a/crates/hir_ty/src/tests/coercion.rs +++ b/crates/hir_ty/src/tests/coercion.rs @@ -559,3 +559,16 @@ fn test() { "#, ); } + +#[test] +fn coerce_type_var() { + check_types( + r#" +//- minicore: from, coerce_unsized +fn test() { + let x = (); + let _: &() = &x.into(); +} //^^^^^^^^ () +"#, + ) +}