-
-
Notifications
You must be signed in to change notification settings - Fork 15k
Type inference doesn't properly handle closures that don't return #111539
Copy link
Copy link
Open
Labels
A-closuresArea: Closures (`|…| { … }`)Area: Closures (`|…| { … }`)A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-inferenceArea: Type inferenceArea: Type inferenceC-bugCategory: This is a bug.Category: This is a bug.D-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team
Metadata
Metadata
Assignees
Labels
A-closuresArea: Closures (`|…| { … }`)Area: Closures (`|…| { … }`)A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-inferenceArea: Type inferenceArea: Type inferenceC-bugCategory: This is a bug.Category: This is a bug.D-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team
Type
Fields
Give feedbackNo fields configured for issues without a type.
In the code below, both of the
demo_*functions provoke type inference errors that I believe should not happen.The errors I observe are (suggestions omitted for space):
I believe these errors to be incorrect, because:
std::process::exit, which does not return. The return type of the closure indemo_oneshould therefore have been inferred to be!, matching the closure indemo_two. (Note: whether that call has a;afterward does not make any difference.)!coerces to any type, therefore a callable which never returns ought to be compatible with a caller expecting any return type.Meta
rustc --version --verbose:Identical behavior observed from nightly (playground link).