forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#123531 - compiler-errors:closure-wf, r=oli-obk
Enforce closure args + return type are WF I found this out when investigating rust-lang#123461 (comment). Turns out we don't register WF obligations for closure args and return types, leading to the ICE. ~~I think this is a useful thing to check for, but I'd like to check what the fallout is.~~ crater is complete. ~~Worst case, I think we should enforce this across an edition boundary (and possibly eventually migrate this for all editions) -- this should be super easy to do, since this is a check in HIR wfcheck, so it can be made edition dependent.~~ I believe the regressions are manageable enough to not necessitate edition-specific behavior. Fixes rust-lang#123461
- Loading branch information
Showing
16 changed files
with
126 additions
and
44 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 was deleted.
Oops, something went wrong.
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,20 @@ | ||
error[E0277]: the trait bound `usize: Fsm` is not satisfied | ||
--> $DIR/issue-80409.rs:36:31 | ||
| | ||
LL | builder.state().on_entry(|_| {}); | ||
| ^ the trait `Fsm` is not implemented for `usize` | ||
| | ||
help: this trait has no implementations, consider adding one | ||
--> $DIR/issue-80409.rs:26:1 | ||
| | ||
LL | trait Fsm { | ||
| ^^^^^^^^^ | ||
note: required by a bound in `StateContext` | ||
--> $DIR/issue-80409.rs:30:31 | ||
| | ||
LL | struct StateContext<'a, TFsm: Fsm> { | ||
| ^^^ required by this bound in `StateContext` | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
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,20 @@ | ||
error: internal compiler error: error performing operation: fully_perform | ||
--> $DIR/issue-80409.rs:49:30 | ||
error[E0277]: the trait bound `usize: Fsm` is not satisfied | ||
--> $DIR/issue-80409.rs:36:31 | ||
| | ||
LL | builder.state().on_entry(|_| {}); | ||
| ^^^ | ||
| ^ the trait `Fsm` is not implemented for `usize` | ||
| | ||
note: | ||
--> $DIR/issue-80409.rs:49:30 | ||
help: this trait has no implementations, consider adding one | ||
--> $DIR/issue-80409.rs:26:1 | ||
| | ||
LL | builder.state().on_entry(|_| {}); | ||
| ^^^ | ||
LL | trait Fsm { | ||
| ^^^^^^^^^ | ||
note: required by a bound in `StateContext` | ||
--> $DIR/issue-80409.rs:30:31 | ||
| | ||
LL | struct StateContext<'a, TFsm: Fsm> { | ||
| ^^^ required by this bound in `StateContext` | ||
|
||
error: aborting due to 1 previous error | ||
|
||
query stack during panic: | ||
end of query stack | ||
For more information about this error, try `rustc --explain E0277`. |
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
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,11 @@ | ||
// Minimized test for <https://github.com/rust-lang/rust/issues/123461>. | ||
|
||
struct Unconstrained<T>(T); | ||
|
||
fn main() { | ||
unsafe { std::mem::transmute::<_, ()>(|o_b: Unconstrained<_>| {}) }; | ||
//~^ ERROR type annotations needed | ||
// We unfortunately don't check `Wf(Unconstrained<_>)`, so we won't | ||
// hit an ambiguity error before checking the transmute. That means | ||
// we still may have inference variables in our transmute src. | ||
} |
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,9 @@ | ||
error[E0282]: type annotations needed | ||
--> $DIR/ambiguity-in-closure-arg.rs:6:44 | ||
| | ||
LL | unsafe { std::mem::transmute::<_, ()>(|o_b: Unconstrained<_>| {}) }; | ||
| ^^^^^^^^^^^^^^^^^^^^^ cannot infer type | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0282`. |
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,11 @@ | ||
trait Bound {} | ||
struct NeedsBound<T: Bound>(T); | ||
|
||
// Checks that we enforce that closure args are WF. | ||
|
||
fn constrain_inner<T, F: for<'a> FnOnce(&'a (), NeedsBound<T>)>(_: T, _: F) {} | ||
|
||
fn main() { | ||
constrain_inner(1u32, |&(), _| ()); | ||
//~^ ERROR the trait bound `u32: Bound` is not satisfied | ||
} |
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,20 @@ | ||
error[E0277]: the trait bound `u32: Bound` is not satisfied | ||
--> $DIR/closure-wf.rs:9:33 | ||
| | ||
LL | constrain_inner(1u32, |&(), _| ()); | ||
| ^ the trait `Bound` is not implemented for `u32` | ||
| | ||
help: this trait has no implementations, consider adding one | ||
--> $DIR/closure-wf.rs:1:1 | ||
| | ||
LL | trait Bound {} | ||
| ^^^^^^^^^^^ | ||
note: required by a bound in `NeedsBound` | ||
--> $DIR/closure-wf.rs:2:22 | ||
| | ||
LL | struct NeedsBound<T: Bound>(T); | ||
| ^^^^^ required by this bound in `NeedsBound` | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0277`. |