-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
parse: recover on const fn()
/ async fn()
#70421
Conversation
cc also @petrochenkov |
17875f2
to
af1146b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a small nitpick to maybe take the chance to teach what async fn
s actually are. If you don't feel that's worth it, r=me.
error: an `fn` pointer type cannot be `async` | ||
--> $DIR/recover-const-async-fn-ptr.rs:6:11 | ||
| | ||
LL | type T3 = async fn(); | ||
| -----^^^^^ | ||
| | | ||
| `async` because of this | ||
| help: remove the `async` qualifier |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you feel it would make sense to add some explanation of what async
does to functions in the first place? Something along the lines of
error: an `fn` pointer type cannot be `async`
--> $DIR/recover-const-async-fn-ptr.rs:6:11
|
LL | type T3 = async fn();
| -----^^^^^
| |
| `async` because of this
| help: remove the `async` qualifier
= note: `async` functions only modify the return type of the function to be wrapped in a `std::future::Future<Output = ReturnType>`, an `async fn()` would be the same as `fn() -> Future<Output = ()>`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would have to be fn() -> Box<dyn Future<Output = ()>>
or some such as fn() -> impl A
is not valid. I think I'd prefer to keep things simple now, as I did this PR mostly as a refactoring (improving diagnostics is secondary).
/// Emit an error for the given bad function pointer qualifier. | ||
fn error_fn_ptr_bad_qualifier(&self, span: Span, qual_span: Span, qual: &str) { | ||
self.struct_span_err(span, &format!("an `fn` pointer type cannot be `{}`", qual)) | ||
.span_label(qual_span, format!("`{}` because of this", qual)) | ||
.span_suggestion_short( | ||
qual_span, | ||
&format!("remove the `{}` qualifier", qual), | ||
String::new(), | ||
Applicability::MaybeIncorrect, | ||
) | ||
.emit(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we move this to parser/diagnostics.rs
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I generally prefer to keep parsing of various things more self-contained, and diagnostics.rs
is larger than ty.rs
in any case. :)
@bors r=estebank |
📌 Commit af1146b has been approved by |
Rollup of 8 pull requests Successful merges: - rust-lang#70281 (Implement Hash for Infallible) - rust-lang#70421 (parse: recover on `const fn()` / `async fn()`) - rust-lang#70615 (Renamed `PerDefTables` to `Tables`) - rust-lang#70631 (Update cargo) - rust-lang#70634 (Remove some reexports in `rustc_middle`) - rust-lang#70658 (add `STILL_FURTHER_SPECIALIZABLE` flag) - rust-lang#70678 (Add missing markdown rust annotation) - rust-lang#70681 (Handle unterminated raw strings with no #s properly) Failed merges: r? @ghost
Recover on
const fn()
andasync fn()
function pointers, suggesting to remove the qualifier.For example:
r? @estebank