-
Notifications
You must be signed in to change notification settings - Fork 144
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 raw borrow #3020
Parse raw borrow #3020
Conversation
00f00eb
to
922e7fc
Compare
The raw ref operator is an unstable feature required to obtain a pointer to unaligned adresses (mainly unaligned struct fields) without UB. gcc/rust/ChangeLog: * ast/rust-ast-builder.cc (Builder::ref): Adapt constructor to the new API. * ast/rust-ast-collector.cc (TokenCollector::visit): Emit a raw weak keyword when required. * ast/rust-ast.cc (BorrowExpr::as_string): Change as_string representation to handle raw ref operator. * ast/rust-expr.h (class BorrowExpr): Add raw discriminant. * expand/rust-macro-builtins-include.cc: Adapt constructor to the new API. * parse/rust-parse-impl.h: Handle the raw weak keyword. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
We do not handle those kind of references yet, we shall not let them pass as a regular reference. gcc/rust/ChangeLog: * ast/rust-expr.h: Add a getter for mutability. * hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Panic when a raw reference is met. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Raw ref operators are still experimental and shall not slip within stable rust, they should therefore be feature gated. gcc/rust/ChangeLog: * checks/errors/rust-feature-gate.cc (FeatureGate::visit): Gate raw borrow. * checks/errors/rust-feature-gate.h: Update function prototype. * checks/errors/rust-feature.cc: Add raw_ref_op gate. * checks/errors/rust-feature.h: Likewise. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Add a test for the feature gate, as well as some test to ensure the raw keyword stays weak. Also add some tests to check whether the raw_ref_op syntax is parsed correctly. gcc/testsuite/ChangeLog: * rust/compile/not_raw_ref_op.rs: New test. * rust/compile/raw_ref_op.rs: New test. * rust/compile/raw_ref_op_feature_gate.rs: New test. * rust/compile/raw_ref_op_invalid.rs: New test. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
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.
great work, the testcases are good, edge cases are handled, well done ❤️
rust_error_at (lexer.peek_token ()->get_locus (), | ||
"raw borrow should be either const or mut"); |
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 can't remember so feel free to disregard, but shouldn't we do something like add_error(Error(...))
here? so that parser errors are only emitted if we want them to be?
Raw borrow syntax was not parsed correctly.
Requires #3014
Requires #3012
Content:
https://github.com/Rust-GCC/gccrs/compare/3c311a9c33340382fd0ea043f365ddfef9068a8f..922e7fc3aaff968a25b6543c37b62f15c2da3b7e