mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 15:23:46 +00:00
Tweak typecheck to enforce covariance on higher-order function arguments
This commit is contained in:
parent
342a400e79
commit
391e12124b
@ -2004,8 +2004,11 @@ mod unify {
|
||||
(ures_err(terr_mode_mismatch(expected_input.mode,
|
||||
actual_input.mode)));
|
||||
} else { expected_input.mode };
|
||||
// The variance changes (flips basically) when descending
|
||||
// into arguments of function types
|
||||
let result = unify_step(
|
||||
cx, expected_input.ty, actual_input.ty, variance);
|
||||
cx, expected_input.ty, actual_input.ty,
|
||||
variance_transform(variance, contravariant));
|
||||
alt result {
|
||||
ures_ok(rty) { result_ins += [{mode: result_mode, ty: rty}]; }
|
||||
_ { ret fn_common_res_err(result); }
|
||||
|
14
src/test/compile-fail/block-coerce-no-2.rs
Normal file
14
src/test/compile-fail/block-coerce-no-2.rs
Normal file
@ -0,0 +1,14 @@
|
||||
// error-pattern: mismatched types
|
||||
|
||||
// Make sure that fn-to-block coercion isn't incorrectly lifted over
|
||||
// other tycons.
|
||||
|
||||
fn main() {
|
||||
fn f(f: fn(fn(fn()))) {
|
||||
}
|
||||
|
||||
fn g(f: fn(block())) {
|
||||
}
|
||||
|
||||
f(g);
|
||||
}
|
Loading…
Reference in New Issue
Block a user