Skip to content

Commit de074fe

Browse files
committed
Accept ambiguous unsize coercion only if it has definite guidance.
1 parent e89ad9f commit de074fe

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

crates/hir_ty/src/infer/coerce.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -575,11 +575,11 @@ impl<'a> InferenceContext<'a> {
575575
},
576576
);
577577
}
578-
Solution::Ambig(guidance) => {
579-
if let Guidance::Definite(subst) = guidance {
580-
canonicalized.apply_solution(&mut self.table, subst);
581-
}
578+
Solution::Ambig(Guidance::Definite(subst)) => {
579+
canonicalized.apply_solution(&mut self.table, subst)
582580
}
581+
// FIXME: should we accept ambiguous results here?
582+
_ => return Err(TypeError),
583583
};
584584
let unsize =
585585
Adjustment { kind: Adjust::Pointer(PointerCast::Unsize), target: to_ty.clone() };

crates/hir_ty/src/tests/coercion.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,3 +559,16 @@ fn test() {
559559
"#,
560560
);
561561
}
562+
563+
#[test]
564+
fn coerce_type_var() {
565+
check_types(
566+
r#"
567+
//- minicore: from, coerce_unsized
568+
fn test() {
569+
let x = ();
570+
let _: &() = &x.into();
571+
} //^^^^^^^^ ()
572+
"#,
573+
)
574+
}

0 commit comments

Comments
 (0)