Skip to content
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

Merged
merged 1 commit into from
Apr 2, 2020

Conversation

Centril
Copy link
Contributor

@Centril Centril commented Mar 26, 2020

Recover on const fn() and async fn() function pointers, suggesting to remove the qualifier.
For example:

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

r? @estebank

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 26, 2020
@Centril
Copy link
Contributor Author

Centril commented Mar 26, 2020

cc also @petrochenkov

Copy link
Contributor

@estebank estebank left a 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 fns actually are. If you don't feel that's worth it, r=me.

src/test/ui/parser/issue-63116.stderr Show resolved Hide resolved
Comment on lines +28 to +35
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
Copy link
Contributor

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 = ()>`

Copy link
Contributor Author

@Centril Centril Apr 2, 2020

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).

Comment on lines +316 to 327
/// 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();
}
Copy link
Contributor

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?

Copy link
Contributor Author

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. :)

@Centril
Copy link
Contributor Author

Centril commented Apr 2, 2020

@bors r=estebank

@bors
Copy link
Contributor

bors commented Apr 2, 2020

📌 Commit af1146b has been approved by estebank

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 2, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 2, 2020
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
@bors bors merged commit 03591e8 into rust-lang:master Apr 2, 2020
@Centril Centril deleted the recover-const-async-fn-ptr branch April 2, 2020 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants