]> git.lizzy.rs Git - rust.git/blobdiff - src/expr.rs
fix: don't force a newline after an empty where clause
[rust.git] / src / expr.rs
index 6a581e6c0547ab4c2eb3792f099d51080a00a05e..1ba879ccc1d315d1180bb1e8af612bf05574f36c 100644 (file)
@@ -2,9 +2,9 @@
 use std::cmp::min;
 
 use itertools::Itertools;
+use rustc_ast::token::{DelimToken, LitKind};
+use rustc_ast::{ast, ptr};
 use rustc_span::{BytePos, Span};
-use syntax::token::{DelimToken, LitKind};
-use syntax::{ast, ptr};
 
 use crate::chains::rewrite_chain;
 use crate::closures;
@@ -124,6 +124,9 @@ pub(crate) fn format_expr(
         | ast::ExprKind::Loop(..)
         | ast::ExprKind::While(..) => to_control_flow(expr, expr_type)
             .and_then(|control_flow| control_flow.rewrite(context, shape)),
+        ast::ExprKind::ConstBlock(ref anon_const) => {
+            Some(format!("const {}", anon_const.rewrite(context, shape)?))
+        }
         ast::ExprKind::Block(ref block, opt_label) => {
             match expr_type {
                 ExprType::Statement => {
@@ -322,7 +325,11 @@ fn needs_space_after_range(rhs: &ast::Expr) -> bool {
         }
         // We do not format these expressions yet, but they should still
         // satisfy our width restrictions.
-        ast::ExprKind::InlineAsm(..) => Some(context.snippet(expr.span).to_owned()),
+        // Style Guide RFC for InlineAsm variant pending
+        // https://github.com/rust-dev-tools/fmt-rfcs/issues/152
+        ast::ExprKind::LlvmInlineAsm(..) | ast::ExprKind::InlineAsm(..) => {
+            Some(context.snippet(expr.span).to_owned())
+        }
         ast::ExprKind::TryBlock(ref block) => {
             if let rw @ Some(_) =
                 rewrite_single_line_block(context, "try ", block, Some(&expr.attrs), None, shape)
@@ -1314,7 +1321,7 @@ pub(crate) fn can_be_overflowed_expr(
         }
         ast::ExprKind::MacCall(ref mac) => {
             match (
-                syntax::ast::MacDelimiter::from_token(mac.args.delim()),
+                rustc_ast::ast::MacDelimiter::from_token(mac.args.delim()),
                 context.config.overflow_delimited_expr(),
             ) {
                 (Some(ast::MacDelimiter::Bracket), true)
@@ -1988,14 +1995,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)
 }