Use equality when relating formal and expected type in arg checking
This commit is contained in:
parent
d571ae851d
commit
c3f9c4f4d4
@ -292,21 +292,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
let coerce_error =
|
||||
self.coerce(provided_arg, checked_ty, coerced_ty, AllowTwoPhase::Yes, None).err();
|
||||
|
||||
if coerce_error.is_some() {
|
||||
return Compatibility::Incompatible(coerce_error);
|
||||
}
|
||||
|
||||
// 3. Check if the formal type is a supertype of the checked one
|
||||
// and register any such obligations for future type checks
|
||||
let supertype_error = self.at(&self.misc(provided_arg.span), self.param_env).sup(
|
||||
// 3. Check if the formal type is actually equal to the checked one
|
||||
// and register any such obligations for future type checks.
|
||||
let formal_ty_error = self.at(&self.misc(provided_arg.span), self.param_env).eq(
|
||||
DefineOpaqueTypes::Yes,
|
||||
formal_input_ty,
|
||||
coerced_ty,
|
||||
);
|
||||
|
||||
// If neither check failed, the types are compatible
|
||||
match supertype_error {
|
||||
match formal_ty_error {
|
||||
Ok(InferOk { obligations, value: () }) => {
|
||||
self.register_predicates(obligations);
|
||||
Compatibility::Compatible
|
||||
|
19
tests/ui/coercion/constrain-expectation-in-arg.rs
Normal file
19
tests/ui/coercion/constrain-expectation-in-arg.rs
Normal file
@ -0,0 +1,19 @@
|
||||
//@ check-pass
|
||||
|
||||
trait Trait {
|
||||
type Item;
|
||||
}
|
||||
|
||||
struct Struct<A: Trait<Item = B>, B> {
|
||||
pub field: A,
|
||||
}
|
||||
|
||||
fn identity<T>(x: T) -> T {
|
||||
x
|
||||
}
|
||||
|
||||
fn test<A: Trait<Item = B>, B>(x: &Struct<A, B>) {
|
||||
let x: &Struct<_, _> = identity(x);
|
||||
}
|
||||
|
||||
fn main() {}
|
Loading…
x
Reference in New Issue
Block a user