-
Notifications
You must be signed in to change notification settings - Fork 165
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
Conversation
0187d64
to
72c7e45
Compare
second commit fixes #2767 |
@philberty review pls |
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.
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: |
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.
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:
case ASYNC: | |
case ASYNC: | |
return parse_async_item (visibility, std::move(outer_attrs)) | |
case CONST: | |
/* snip */ |
// 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%>"); |
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.
this is great :)
4c00228
to
a8dd9ff
Compare
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]>
a8dd9ff
to
f5f0f3a
Compare
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]>
f5f0f3a
to
e97a817
Compare
fixed suggested changes, thanks for review @CohenArthur |
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.
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
Fixes #2778
gcc/rust/ChangeLog:
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.
make check-rust
passes locallyclang-format
gcc/testsuite/rust/
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.