Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The bug was revealed by the behavior of the old-lub-glb-hr-noteq1.rs test. The old-lub-glb-hr-noteq2 test shows the current 'order dependent' behavior of coercions around higher-ranked functions, at least when running with `-Zborrowck=mir`. Also, run compare-mode=nll.
- Loading branch information
1 parent
c88a76e
commit 6929013
Showing
30 changed files
with
472 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/test/ui/associated-types/associated-types-eq-hr.nll.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
error[E0271]: type mismatch resolving `for<'x> <UintStruct as TheTrait<&'x isize>>::A == &'x isize` | ||
--> $DIR/associated-types-eq-hr.rs:87:5 | ||
| | ||
LL | fn foo<T>() | ||
| --- required by a bound in this | ||
LL | where | ||
LL | T: for<'x> TheTrait<&'x isize, A = &'x isize>, | ||
| ------------- required by this bound in `foo` | ||
... | ||
LL | foo::<UintStruct>(); | ||
| ^^^^^^^^^^^^^^^^^ expected `isize`, found `usize` | ||
| | ||
= note: expected reference `&isize` | ||
found reference `&usize` | ||
|
||
error[E0271]: type mismatch resolving `for<'x> <IntStruct as TheTrait<&'x isize>>::A == &'x usize` | ||
--> $DIR/associated-types-eq-hr.rs:91:5 | ||
| | ||
LL | fn bar<T>() | ||
| --- required by a bound in this | ||
LL | where | ||
LL | T: for<'x> TheTrait<&'x isize, A = &'x usize>, | ||
| ------------- required by this bound in `bar` | ||
... | ||
LL | bar::<IntStruct>(); | ||
| ^^^^^^^^^^^^^^^^ expected `usize`, found `isize` | ||
| | ||
= note: expected reference `&usize` | ||
found reference `&isize` | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0271`. |
8 changes: 8 additions & 0 deletions
8
src/test/ui/associated-types/higher-ranked-projection.bad.nll.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
error: higher-ranked subtype error | ||
--> $DIR/higher-ranked-projection.rs:25:5 | ||
| | ||
LL | foo(()); | ||
| ^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
error: higher-ranked subtype error | ||
--> $DIR/resume-arg-late-bound.rs:15:5 | ||
| | ||
LL | test(gen); | ||
| ^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
14 changes: 14 additions & 0 deletions
14
src/test/ui/hr-subtype/hr-subtype.bound_a_b_ret_a_vs_bound_a_ret_a.nll.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
error: higher-ranked subtype error | ||
--> $DIR/hr-subtype.rs:45:13 | ||
| | ||
LL | gimme::<$t1>(None::<$t2>); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
... | ||
LL | / check! { bound_a_b_ret_a_vs_bound_a_ret_a: (for<'a,'b> fn(&'a u32, &'b u32) -> &'a u32, | ||
LL | | for<'a> fn(&'a u32, &'a u32) -> &'a u32) } | ||
| |_____________________________________________- in this macro invocation | ||
| | ||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: aborting due to previous error | ||
|
14 changes: 14 additions & 0 deletions
14
src/test/ui/hr-subtype/hr-subtype.bound_a_vs_free_x.nll.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
error: higher-ranked subtype error | ||
--> $DIR/hr-subtype.rs:45:13 | ||
| | ||
LL | gimme::<$t1>(None::<$t2>); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
... | ||
LL | / check! { bound_a_vs_free_x: (for<'a> fn(&'a u32), | ||
LL | | fn(&'x u32)) } | ||
| |______________- in this macro invocation | ||
| | ||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: aborting due to previous error | ||
|
26 changes: 26 additions & 0 deletions
26
src/test/ui/hr-subtype/hr-subtype.bound_inv_a_b_vs_bound_inv_a.nll.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
error: higher-ranked subtype error | ||
--> $DIR/hr-subtype.rs:45:13 | ||
| | ||
LL | gimme::<$t1>(None::<$t2>); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
... | ||
LL | / check! { bound_inv_a_b_vs_bound_inv_a: (for<'a,'b> fn(Inv<'a>, Inv<'b>), | ||
LL | | for<'a> fn(Inv<'a>, Inv<'a>)) } | ||
| |__________________________________- in this macro invocation | ||
| | ||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: higher-ranked subtype error | ||
--> $DIR/hr-subtype.rs:45:13 | ||
| | ||
LL | gimme::<$t1>(None::<$t2>); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
... | ||
LL | / check! { bound_inv_a_b_vs_bound_inv_a: (for<'a,'b> fn(Inv<'a>, Inv<'b>), | ||
LL | | for<'a> fn(Inv<'a>, Inv<'a>)) } | ||
| |__________________________________- in this macro invocation | ||
| | ||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: aborting due to 2 previous errors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
error: higher-ranked subtype error | ||
--> $DIR/hrtb-conflate-regions.rs:27:10 | ||
| | ||
LL | fn b() { want_foo2::<SomeStruct>(); } | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: higher-ranked subtype error | ||
--> $DIR/hrtb-conflate-regions.rs:27:10 | ||
| | ||
LL | fn b() { want_foo2::<SomeStruct>(); } | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
error: higher-ranked subtype error | ||
--> $DIR/hrtb-exists-forall-fn.rs:17:12 | ||
| | ||
LL | let _: for<'b> fn(&'b u32) = foo(); | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
8 changes: 8 additions & 0 deletions
8
src/test/ui/hrtb/hrtb-exists-forall-trait-contravariant.nll.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
error: higher-ranked subtype error | ||
--> $DIR/hrtb-exists-forall-trait-contravariant.rs:34:5 | ||
| | ||
LL | foo::<()>(); | ||
| ^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
8 changes: 8 additions & 0 deletions
8
src/test/ui/hrtb/hrtb-exists-forall-trait-invariant.nll.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
error: higher-ranked subtype error | ||
--> $DIR/hrtb-exists-forall-trait-invariant.rs:28:5 | ||
| | ||
LL | foo::<()>(); | ||
| ^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
error: higher-ranked subtype error | ||
--> $DIR/hrtb-just-for-static.rs:24:5 | ||
| | ||
LL | want_hrtb::<StaticInt>() | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: lifetime may not live long enough | ||
--> $DIR/hrtb-just-for-static.rs:30:5 | ||
| | ||
LL | fn give_some<'a>() { | ||
| -- lifetime `'a` defined here | ||
LL | want_hrtb::<&'a u32>() | ||
| ^^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static` | ||
| | ||
= help: consider replacing `'a` with `'static` | ||
|
||
error: higher-ranked subtype error | ||
--> $DIR/hrtb-just-for-static.rs:30:5 | ||
| | ||
LL | want_hrtb::<&'a u32>() | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 3 previous errors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
error: higher-ranked subtype error | ||
--> $DIR/issue-46989.rs:38:5 | ||
| | ||
LL | assert_foo::<fn(&i32)>(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
error: higher-ranked subtype error | ||
--> $DIR/issue-40000.rs:6:9 | ||
| | ||
LL | foo(bar); | ||
| ^^^ | ||
|
||
error: aborting due to previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Test that we give a note when the old LUB/GLB algorithm would have | ||
// succeeded but the new code (which requires equality) gives an | ||
// error. However, now that we handle subtyping correctly, we no | ||
// longer get an error, because we recognize these two types as | ||
// equivalent! | ||
// | ||
// check-pass | ||
|
||
fn foo(x: fn(&u8, &u8), y: for<'a> fn(&'a u8, &'a u8)) { | ||
// The two types above are actually equivalent. With the older | ||
// leak check, though, we didn't consider them as equivalent, and | ||
// hence we gave errors. But now we've fixed that. | ||
let z = match 22 { | ||
0 => x, | ||
_ => y, | ||
}; | ||
} | ||
|
||
fn foo_cast(x: fn(&u8, &u8), y: for<'a> fn(&'a u8, &'a u8)) { | ||
let z = match 22 { | ||
// No error with an explicit cast: | ||
0 => x as for<'a> fn(&'a u8, &'a u8), | ||
_ => y, | ||
}; | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
error: higher-ranked subtype error | ||
--> $DIR/old-lub-glb-hr-noteq1.rs:11:14 | ||
| | ||
LL | _ => y, | ||
| ^ | ||
|
||
error: aborting due to previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Test taking the LUB of two function types that are not equatable but where one is more | ||
// general than the other. Test the case where the more general type (`x`) is the first | ||
// match arm specifically. | ||
|
||
fn foo(x: for<'a, 'b> fn(&'a u8, &'b u8) -> &'a u8, y: for<'a> fn(&'a u8, &'a u8) -> &'a u8) { | ||
// The two types above are not equivalent. With the older LUB/GLB | ||
// algorithm, this may have worked (I don't remember), but now it | ||
// doesn't because we require equality. | ||
let z = match 22 { | ||
0 => x, | ||
_ => y, //~ ERROR `match` arms have incompatible types | ||
}; | ||
} | ||
|
||
fn foo_cast(x: for<'a, 'b> fn(&'a u8, &'b u8) -> &'a u8, y: for<'a> fn(&'a u8, &'a u8) -> &'a u8) { | ||
// But we can *upcast* explicitly the type of `x` and figure | ||
// things out: | ||
let z = match 22 { | ||
0 => x as for<'a> fn(&'a u8, &'a u8) -> &'a u8, | ||
_ => y, | ||
}; | ||
} | ||
|
||
fn main() {} |
2 changes: 1 addition & 1 deletion
2
src/test/ui/lub-glb/old-lub-glb-hr.stderr → ...t/ui/lub-glb/old-lub-glb-hr-noteq1.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Test taking the LUB of two function types that are not equatable but where | ||
// one is more general than the other. Test the case where the more general type | ||
// (`x`) is the second match arm specifically. | ||
// | ||
// Skip for compare-mode because the pure NLL checker accepts this test. (Note | ||
// that it still errors in old-lub-glb-hr-noteq1.rs). What happens is that, due | ||
// to the ordering of the match arms, we pick the correct "more general" fn | ||
// type, and we ignore the errors from the non-NLL type checker that requires | ||
// equality. The NLL type checker only requires a subtyping relationship, and | ||
// that holds. | ||
// | ||
// ignore-compare-mode-nll | ||
|
||
fn foo(x: for<'a, 'b> fn(&'a u8, &'b u8) -> &'a u8, y: for<'a> fn(&'a u8, &'a u8) -> &'a u8) { | ||
// The two types above are not equivalent. With the older LUB/GLB | ||
// algorithm, this may have worked (I don't remember), but now it | ||
// doesn't because we require equality. | ||
let z = match 22 { | ||
0 => y, | ||
_ => x, //~ ERROR `match` arms have incompatible types | ||
}; | ||
} | ||
|
||
fn foo_cast(x: for<'a, 'b> fn(&'a u8, &'b u8) -> &'a u8, y: for<'a> fn(&'a u8, &'a u8) -> &'a u8) { | ||
// But we can *upcast* explicitly the type of `x` and figure | ||
// things out: | ||
let z = match 22 { | ||
0 => x as for<'a> fn(&'a u8, &'a u8) -> &'a u8, | ||
_ => y, | ||
}; | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
error[E0308]: `match` arms have incompatible types | ||
--> $DIR/old-lub-glb-hr-noteq2.rs:20:14 | ||
| | ||
LL | let z = match 22 { | ||
| _____________- | ||
LL | | 0 => y, | ||
| | - this is found to be of type `for<'a> fn(&'a u8, &'a u8) -> &'a u8` | ||
LL | | _ => x, | ||
| | ^ one type is more general than the other | ||
LL | | }; | ||
| |_____- `match` arms have incompatible types | ||
| | ||
= note: expected fn pointer `for<'a> fn(&'a u8, &'a u8) -> &'a u8` | ||
found fn pointer `for<'a, 'b> fn(&'a u8, &'b u8) -> &'a u8` | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
Oops, something went wrong.