-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Open
Labels
A-closuresArea: Closures (`|…| { … }`)Area: Closures (`|…| { … }`)A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.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.
Description
Code
use std::fmt::Display;
struct S;
impl S {
fn call(&self, _: impl Display) {}
}
fn main() {
S.call(|| "hello");
}
Current output
error[E0277]: `{closure@src/main.rs:9:12: 9:14}` doesn't implement `std::fmt::Display`
--> src/main.rs:9:12
|
9 | S.call(|| "hello");
| ---- ^^^^^^^^^^ the trait `std::fmt::Display` is not implemented for closure `{closure@src/main.rs:9:12: 9:14}`
| |
| required by a bound introduced by this call
|
note: required by a bound in `S::call`
--> src/main.rs:5:28
|
5 | fn call(&self, _: impl Display) {}
| ^^^^^^^ required by this bound in `S::call`
help: use parentheses to call this closure
|
9 | S.call(|| "hello"());
| ++
Desired output
9 | S.call((|| "hello")());
Rationale and extra context
The suggestion doesn't compile because it fails to take account of precedence.
Other cases
#144401 may be related?
Rust Version
Rust playground, stable, today.
Anything else?
Metadata
Metadata
Assignees
Labels
A-closuresArea: Closures (`|…| { … }`)Area: Closures (`|…| { … }`)A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.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.