forked from rust-lang/rust
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#99079 - compiler-errors:issue-99073, r=oli-obk
Check that RPITs constrained by a recursive call in a closure are compatible Fixes rust-lang#99073 Adapts a similar visitor pattern to `find_opaque_ty_constraints` (that we use to check TAITs), but with some changes: 0. Only walk the "OnlyBody" children, instead of all items in the RPIT's defining scope 1. Only walk through the body's children if we found a constraining usage 2. Don't actually do any inference, just do a comparison and error if they're mismatched ---- r? `@oli-obk` -- you know all this impl-trait stuff best... is this the right approach? I can explain the underlying issue better if you'd like, in case that might reveal a better solution. Not sure if it's possible to gather up the closure's defining usages of the RPIT while borrowck'ing the outer function, that might be a better place to put this check...
- Loading branch information
Showing
7 changed files
with
140 additions
and
72 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
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 |
---|---|---|
@@ -1,15 +1,14 @@ | ||
error[E0308]: mismatched types | ||
error: concrete type differs from previous defining opaque type use | ||
--> $DIR/issue-99073-2.rs:9:22 | ||
| | ||
LL | fn test<T: Display>(t: T, recurse: bool) -> impl Display { | ||
| ------------ the expected opaque type | ||
LL | let f = || { | ||
LL | let i: u32 = test::<i32>(-1, false); | ||
| ^^^^^^^^^^^^^^^^^^^^^^ types differ | ||
| ^^^^^^^^^^^^^^^^^^^^^^ expected `T`, got `u32` | ||
| | ||
= note: expected opaque type `impl std::fmt::Display` | ||
found type `u32` | ||
note: previous use here | ||
--> $DIR/issue-99073-2.rs:16:5 | ||
| | ||
LL | t | ||
| ^ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
fn main() { | ||
let _ = fix(|_: &dyn Fn()| {}); | ||
let _ = fix(|_: &dyn Fn()| {}); | ||
} | ||
|
||
fn fix<F: Fn(G), G: Fn()>(f: F) -> impl Fn() { | ||
move || f(fix(&f)) | ||
//~^ ERROR mismatched types | ||
move || f(fix(&f)) | ||
//~^ ERROR concrete type differs from previous defining opaque type use | ||
} |
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 |
---|---|---|
@@ -1,14 +1,14 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/issue-99073.rs:6:13 | ||
error: concrete type differs from previous defining opaque type use | ||
--> $DIR/issue-99073.rs:6:11 | ||
| | ||
LL | fn fix<F: Fn(G), G: Fn()>(f: F) -> impl Fn() { | ||
| --------- the expected opaque type | ||
LL | move || f(fix(&f)) | ||
| ^^^^^^^^^^ types differ | ||
LL | move || f(fix(&f)) | ||
| ^^^^^^^^^^ expected `[closure@$DIR/issue-99073.rs:6:3: 6:10]`, got `G` | ||
| | ||
= note: expected opaque type `impl Fn()` | ||
found type parameter `G` | ||
note: previous use here | ||
--> $DIR/issue-99073.rs:6:3 | ||
| | ||
LL | move || f(fix(&f)) | ||
| ^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0308`. |