From cf7f802d7d138d1d5af0ad8e9f05b2129b81bb18 Mon Sep 17 00:00:00 2001 From: Caleb Cartwright Date: Tue, 11 Feb 2020 20:13:31 -0600 Subject: [PATCH] feat: support raw ref operator --- rustfmt-core/rustfmt-lib/src/expr.rs | 10 ++++++---- rustfmt-core/rustfmt-lib/tests/source/expr.rs | 4 ++++ rustfmt-core/rustfmt-lib/tests/target/expr.rs | 4 ++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/rustfmt-core/rustfmt-lib/src/expr.rs b/rustfmt-core/rustfmt-lib/src/expr.rs index 2ef3cf69834..46279c0af59 100644 --- a/rustfmt-core/rustfmt-lib/src/expr.rs +++ b/rustfmt-core/rustfmt-lib/src/expr.rs @@ -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 { - 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) } diff --git a/rustfmt-core/rustfmt-lib/tests/source/expr.rs b/rustfmt-core/rustfmt-lib/tests/source/expr.rs index 05af07f231b..1339f51c12d 100644 --- a/rustfmt-core/rustfmt-lib/tests/source/expr.rs +++ b/rustfmt-core/rustfmt-lib/tests/source/expr.rs @@ -218,6 +218,10 @@ fn returns() { fn addrof() { & mut(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa+bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb); & (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa+bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb); + + // raw reference operator + & raw const a; + & raw mut b; } fn casts() { diff --git a/rustfmt-core/rustfmt-lib/tests/target/expr.rs b/rustfmt-core/rustfmt-lib/tests/target/expr.rs index fe5b21dc163..6f228084e50 100644 --- a/rustfmt-core/rustfmt-lib/tests/target/expr.rs +++ b/rustfmt-core/rustfmt-lib/tests/target/expr.rs @@ -251,6 +251,10 @@ fn addrof() { + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb); &(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb); + + // raw reference operator + &raw const a; + &raw mut b; } fn casts() {