Skip to content

support raw reference operator #4046

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

Merged
merged 1 commit into from
Feb 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions rustfmt-core/rustfmt-lib/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2039,14 +2039,16 @@ pub(crate) fn prefer_next_line(

fn rewrite_expr_addrof(
context: &RewriteContext<'_>,
_borrow_kind: ast::BorrowKind,
borrow_kind: ast::BorrowKind,
mutability: ast::Mutability,
expr: &ast::Expr,
shape: Shape,
) -> Option<String> {
let operator_str = match mutability {
ast::Mutability::Not => "&",
ast::Mutability::Mut => "&mut ",
let operator_str = match (mutability, borrow_kind) {
(ast::Mutability::Not, ast::BorrowKind::Ref) => "&",
(ast::Mutability::Not, ast::BorrowKind::Raw) => "&raw const ",
(ast::Mutability::Mut, ast::BorrowKind::Ref) => "&mut ",
(ast::Mutability::Mut, ast::BorrowKind::Raw) => "&raw mut ",
};
rewrite_unary_prefix(context, operator_str, expr, shape)
}
Expand Down
4 changes: 4 additions & 0 deletions rustfmt-core/rustfmt-lib/tests/source/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ fn returns() {
fn addrof() {
& mut(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa+bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb);
& (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa+bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb);

// raw reference operator
& raw const a;
& raw mut b;
}

fn casts() {
Expand Down
4 changes: 4 additions & 0 deletions rustfmt-core/rustfmt-lib/tests/target/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ fn addrof() {
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb);
&(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb);

// raw reference operator
&raw const a;
&raw mut b;
}

fn casts() {
Expand Down