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

Handle async qualifier inside trait #2779

Merged
merged 2 commits into from
Dec 27, 2023

Conversation

braw-lee
Copy link
Contributor

@braw-lee braw-lee commented Dec 15, 2023

Fixes #2778

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_trait_impl_item): Handled `async` similar to `const` (Parser::parse_pattern): clang-format.

Thank you for making Rust GCC better!

If your PR fixes an issue, you can add "Fixes #issue_number" into this
PR description and the git commit message. This way the issue will be
automatically closed when your PR is merged. If your change addresses
an issue but does not fully fix it please mark it as "Addresses #issue_number"
in the git commit message.

Here is a checklist to help you with your PR.

Note that you can skip the above if you are just opening a WIP PR in
order to get feedback.

*Please write a comment explaining your change. This is the message
that will be part of the merge commit.

@braw-lee braw-lee force-pushed the unhandledAsync branch 2 times, most recently from 0187d64 to 72c7e45 Compare December 15, 2023 19:34
@braw-lee
Copy link
Contributor Author

second commit fixes #2767

@braw-lee
Copy link
Contributor Author

@philberty review pls

Copy link
Member

@CohenArthur CohenArthur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the testcase is great, and if you fix the comment I've added this looks good to me for merging :) thanks for working on this!

@@ -5784,6 +5785,7 @@ Parser<ManagedTokenSource>::parse_trait_impl_item ()
// function or method
return parse_trait_impl_function_or_method (visibility,
std::move (outer_attrs));
case ASYNC:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const is handled this way because inside a trait, you could have a const variable or a constant function:

impl Foo for u32 {
    const TRAIT_ASSOC_CST: u32 = 15;
    
    const fn constant_fn() -> u32 { 14 }
}

for async, we can only have async functions - so we don't need to bundle the cases for CONST and ASYNC together.

Instead, this is what I would like to see:

Suggested change
case ASYNC:
case ASYNC:
return parse_async_item (visibility, std::move(outer_attrs))
case CONST:
/* snip */

Comment on lines +110 to +113
// may change soon
if (qualifiers.is_async () && context.back () == Context::TRAIT_IMPL)
rust_error_at (function.get_locus (), ErrorCode::E0706,
"functions in traits cannot be declared %<async%>");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is great :)

@braw-lee braw-lee force-pushed the unhandledAsync branch 2 times, most recently from 4c00228 to a8dd9ff Compare December 27, 2023 02:19
Fixes Rust-GCC#2778

gcc/rust/ChangeLog:

	* parse/rust-parse-impl.h (Parser::parse_trait_impl_item):
	Handled `async` items

Signed-off-by: Kushal Pal <[email protected]>
Fixes Rust-GCC#2767

gcc/rust/ChangeLog:

	* checks/errors/rust-ast-validation.cc (ASTValidation::visit):
	Added check for `async` function inside trait.

gcc/testsuite/ChangeLog:

	* rust/compile/issue-2767.rs: New test.

Signed-off-by: Kushal Pal <[email protected]>
@braw-lee
Copy link
Contributor Author

fixed suggested changes, thanks for review @CohenArthur

Copy link
Member

@CohenArthur CohenArthur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! If you'd like @braw-lee you could implement the same sort of pattern for trait functions and parsing of async functions for regular impls

@CohenArthur CohenArthur added this pull request to the merge queue Dec 27, 2023
Merged via the queue into Rust-GCC:master with commit 7bb5d5c Dec 27, 2023
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unhandled async while parsing items inside trait
2 participants