Accept ambiguous unsize coercion only if it has definite guidance.

This commit is contained in:
Dawer 2021-08-11 22:09:32 +05:00
parent e89ad9f345
commit de074fe636
2 changed files with 17 additions and 4 deletions

View file

@ -575,11 +575,11 @@ impl<'a> InferenceContext<'a> {
}, },
); );
} }
Solution::Ambig(guidance) => { Solution::Ambig(Guidance::Definite(subst)) => {
if let Guidance::Definite(subst) = guidance { canonicalized.apply_solution(&mut self.table, subst)
canonicalized.apply_solution(&mut self.table, subst);
}
} }
// FIXME: should we accept ambiguous results here?
_ => return Err(TypeError),
}; };
let unsize = let unsize =
Adjustment { kind: Adjust::Pointer(PointerCast::Unsize), target: to_ty.clone() }; Adjustment { kind: Adjust::Pointer(PointerCast::Unsize), target: to_ty.clone() };

View file

@ -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();
} //^^^^^^^^ ()
"#,
)
}