summaryrefslogtreecommitdiffstats
path: root/src/tools/rustfmt
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:18:32 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:18:32 +0000
commit4547b622d8d29df964fa2914213088b148c498fc (patch)
tree9fc6b25f3c3add6b745be9a2400a6e96140046e9 /src/tools/rustfmt
parentReleasing progress-linux version 1.66.0+dfsg1-1~progress7.99u1. (diff)
downloadrustc-4547b622d8d29df964fa2914213088b148c498fc.tar.xz
rustc-4547b622d8d29df964fa2914213088b148c498fc.zip
Merging upstream version 1.67.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--src/tools/rustfmt/src/attr.rs21
-rw-r--r--src/tools/rustfmt/src/chains.rs12
-rw-r--r--src/tools/rustfmt/src/closures.rs31
-rw-r--r--src/tools/rustfmt/src/expr.rs72
-rw-r--r--src/tools/rustfmt/src/imports.rs2
-rw-r--r--src/tools/rustfmt/src/macros.rs6
-rw-r--r--src/tools/rustfmt/src/modules/visitor.rs12
-rw-r--r--src/tools/rustfmt/src/overflow.rs4
-rw-r--r--src/tools/rustfmt/src/parse/macros/asm.rs2
-rw-r--r--src/tools/rustfmt/src/parse/macros/cfg_if.rs2
-rw-r--r--src/tools/rustfmt/src/parse/session.rs1
-rw-r--r--src/tools/rustfmt/src/patterns.rs9
-rw-r--r--src/tools/rustfmt/src/types.rs8
-rw-r--r--src/tools/rustfmt/src/utils.rs5
14 files changed, 104 insertions, 83 deletions
diff --git a/src/tools/rustfmt/src/attr.rs b/src/tools/rustfmt/src/attr.rs
index f5c1ee5fd..2ac703b95 100644
--- a/src/tools/rustfmt/src/attr.rs
+++ b/src/tools/rustfmt/src/attr.rs
@@ -260,7 +260,7 @@ impl Rewrite for ast::NestedMetaItem {
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
match self {
ast::NestedMetaItem::MetaItem(ref meta_item) => meta_item.rewrite(context, shape),
- ast::NestedMetaItem::Literal(ref l) => rewrite_literal(context, l, shape),
+ ast::NestedMetaItem::Lit(ref l) => rewrite_literal(context, l.token_lit, l.span, shape),
}
}
}
@@ -288,10 +288,10 @@ impl Rewrite for ast::MetaItem {
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
Some(match self.kind {
ast::MetaItemKind::Word => {
- rewrite_path(context, PathContext::Type, None, &self.path, shape)?
+ rewrite_path(context, PathContext::Type, &None, &self.path, shape)?
}
ast::MetaItemKind::List(ref list) => {
- let path = rewrite_path(context, PathContext::Type, None, &self.path, shape)?;
+ let path = rewrite_path(context, PathContext::Type, &None, &self.path, shape)?;
let has_trailing_comma = crate::expr::span_ends_with_comma(context, self.span);
overflow::rewrite_with_parens(
context,
@@ -309,7 +309,7 @@ impl Rewrite for ast::MetaItem {
)?
}
ast::MetaItemKind::NameValue(ref literal) => {
- let path = rewrite_path(context, PathContext::Type, None, &self.path, shape)?;
+ let path = rewrite_path(context, PathContext::Type, &None, &self.path, shape)?;
// 3 = ` = `
let lit_shape = shape.shrink_left(path.len() + 3)?;
// `rewrite_literal` returns `None` when `literal` exceeds max
@@ -318,7 +318,7 @@ impl Rewrite for ast::MetaItem {
// we might be better off ignoring the fact that the attribute
// is longer than the max width and continue on formatting.
// See #2479 for example.
- let value = rewrite_literal(context, literal, lit_shape)
+ let value = rewrite_literal(context, literal.token_lit, literal.span, lit_shape)
.unwrap_or_else(|| context.snippet(literal.span).to_owned());
format!("{} = {}", path, value)
}
@@ -525,14 +525,19 @@ pub(crate) trait MetaVisitor<'ast> {
fn visit_meta_word(&mut self, _meta_item: &'ast ast::MetaItem) {}
- fn visit_meta_name_value(&mut self, _meta_item: &'ast ast::MetaItem, _lit: &'ast ast::Lit) {}
+ fn visit_meta_name_value(
+ &mut self,
+ _meta_item: &'ast ast::MetaItem,
+ _lit: &'ast ast::MetaItemLit,
+ ) {
+ }
fn visit_nested_meta_item(&mut self, nm: &'ast ast::NestedMetaItem) {
match nm {
ast::NestedMetaItem::MetaItem(ref meta_item) => self.visit_meta_item(meta_item),
- ast::NestedMetaItem::Literal(ref lit) => self.visit_literal(lit),
+ ast::NestedMetaItem::Lit(ref lit) => self.visit_meta_item_lit(lit),
}
}
- fn visit_literal(&mut self, _lit: &'ast ast::Lit) {}
+ fn visit_meta_item_lit(&mut self, _lit: &'ast ast::MetaItemLit) {}
}
diff --git a/src/tools/rustfmt/src/chains.rs b/src/tools/rustfmt/src/chains.rs
index fcc02eca4..a1a73cf4b 100644
--- a/src/tools/rustfmt/src/chains.rs
+++ b/src/tools/rustfmt/src/chains.rs
@@ -145,8 +145,8 @@ impl ChainItemKind {
fn from_ast(context: &RewriteContext<'_>, expr: &ast::Expr) -> (ChainItemKind, Span) {
let (kind, span) = match expr.kind {
- ast::ExprKind::MethodCall(ref segment, ref receiver, ref expressions, _) => {
- let types = if let Some(ref generic_args) = segment.args {
+ ast::ExprKind::MethodCall(ref call) => {
+ let types = if let Some(ref generic_args) = call.seg.args {
if let ast::GenericArgs::AngleBracketed(ref data) = **generic_args {
data.args
.iter()
@@ -163,8 +163,8 @@ impl ChainItemKind {
} else {
vec![]
};
- let span = mk_sp(receiver.span.hi(), expr.span.hi());
- let kind = ChainItemKind::MethodCall(segment.clone(), types, expressions.clone());
+ let span = mk_sp(call.receiver.span.hi(), expr.span.hi());
+ let kind = ChainItemKind::MethodCall(call.seg.clone(), types, call.args.clone());
(kind, span)
}
ast::ExprKind::Field(ref nested, field) => {
@@ -400,9 +400,7 @@ impl Chain {
// is a try! macro, we'll convert it to shorthand when the option is set.
fn pop_expr_chain(expr: &ast::Expr, context: &RewriteContext<'_>) -> Option<ast::Expr> {
match expr.kind {
- ast::ExprKind::MethodCall(_, ref receiver, _, _) => {
- Some(Self::convert_try(&receiver, context))
- }
+ ast::ExprKind::MethodCall(ref call) => Some(Self::convert_try(&call.receiver, context)),
ast::ExprKind::Field(ref subexpr, _)
| ast::ExprKind::Try(ref subexpr)
| ast::ExprKind::Await(ref subexpr) => Some(Self::convert_try(subexpr, context)),
diff --git a/src/tools/rustfmt/src/closures.rs b/src/tools/rustfmt/src/closures.rs
index 88a6bebb6..244d4427c 100644
--- a/src/tools/rustfmt/src/closures.rs
+++ b/src/tools/rustfmt/src/closures.rs
@@ -326,16 +326,17 @@ pub(crate) fn rewrite_last_closure(
expr: &ast::Expr,
shape: Shape,
) -> Option<String> {
- if let ast::ExprKind::Closure(
- ref binder,
- capture,
- ref is_async,
- movability,
- ref fn_decl,
- ref body,
- _,
- ) = expr.kind
- {
+ if let ast::ExprKind::Closure(ref closure) = expr.kind {
+ let ast::Closure {
+ ref binder,
+ capture_clause,
+ ref asyncness,
+ movability,
+ ref fn_decl,
+ ref body,
+ fn_decl_span: _,
+ fn_arg_span: _,
+ } = **closure;
let body = match body.kind {
ast::ExprKind::Block(ref block, _)
if !is_unsafe_block(block)
@@ -347,7 +348,15 @@ pub(crate) fn rewrite_last_closure(
_ => body,
};
let (prefix, extra_offset) = rewrite_closure_fn_decl(
- binder, capture, is_async, movability, fn_decl, body, expr.span, context, shape,
+ binder,
+ capture_clause,
+ asyncness,
+ movability,
+ fn_decl,
+ body,
+ expr.span,
+ context,
+ shape,
)?;
// If the closure goes multi line before its body, do not overflow the closure.
if prefix.contains('\n') {
diff --git a/src/tools/rustfmt/src/expr.rs b/src/tools/rustfmt/src/expr.rs
index 3105882e2..414e76769 100644
--- a/src/tools/rustfmt/src/expr.rs
+++ b/src/tools/rustfmt/src/expr.rs
@@ -3,7 +3,7 @@ use std::cmp::min;
use itertools::Itertools;
use rustc_ast::token::{Delimiter, LitKind};
-use rustc_ast::{ast, ptr};
+use rustc_ast::{ast, ptr, token};
use rustc_span::{BytePos, Span};
use crate::chains::rewrite_chain;
@@ -75,12 +75,12 @@ pub(crate) fn format_expr(
choose_separator_tactic(context, expr.span),
None,
),
- ast::ExprKind::Lit(ref l) => {
- if let Some(expr_rw) = rewrite_literal(context, l, shape) {
+ ast::ExprKind::Lit(token_lit) => {
+ if let Some(expr_rw) = rewrite_literal(context, token_lit, expr.span, shape) {
Some(expr_rw)
} else {
- if let LitKind::StrRaw(_) = l.token_lit.kind {
- Some(context.snippet(l.span).trim().into())
+ if let LitKind::StrRaw(_) = token_lit.kind {
+ Some(context.snippet(expr.span).trim().into())
} else {
None
}
@@ -116,7 +116,7 @@ pub(crate) fn format_expr(
rewrite_struct_lit(
context,
path,
- qself.as_ref(),
+ qself,
fields,
rest,
&expr.attrs,
@@ -169,7 +169,7 @@ pub(crate) fn format_expr(
rewrite_match(context, cond, arms, shape, expr.span, &expr.attrs)
}
ast::ExprKind::Path(ref qself, ref path) => {
- rewrite_path(context, PathContext::Expr, qself.as_ref(), path, shape)
+ rewrite_path(context, PathContext::Expr, qself, path, shape)
}
ast::ExprKind::Assign(ref lhs, ref rhs, _) => {
rewrite_assignment(context, lhs, rhs, None, shape)
@@ -203,16 +203,16 @@ pub(crate) fn format_expr(
Some("yield".to_string())
}
}
- ast::ExprKind::Closure(
- ref binder,
- capture,
- ref is_async,
- movability,
- ref fn_decl,
- ref body,
- _,
- ) => closures::rewrite_closure(
- binder, capture, is_async, movability, fn_decl, body, expr.span, context, shape,
+ ast::ExprKind::Closure(ref cl) => closures::rewrite_closure(
+ &cl.binder,
+ cl.capture_clause,
+ &cl.asyncness,
+ cl.movability,
+ &cl.fn_decl,
+ &cl.body,
+ expr.span,
+ context,
+ shape,
),
ast::ExprKind::Try(..)
| ast::ExprKind::Field(..)
@@ -274,9 +274,9 @@ pub(crate) fn format_expr(
fn needs_space_before_range(context: &RewriteContext<'_>, lhs: &ast::Expr) -> bool {
match lhs.kind {
- ast::ExprKind::Lit(ref lit) => match lit.kind {
- ast::LitKind::Float(_, ast::LitFloatType::Unsuffixed) => {
- context.snippet(lit.span).ends_with('.')
+ ast::ExprKind::Lit(token_lit) => match token_lit.kind {
+ token::LitKind::Float if token_lit.suffix.is_none() => {
+ context.snippet(lhs.span).ends_with('.')
}
_ => false,
},
@@ -399,6 +399,7 @@ pub(crate) fn format_expr(
}
}
ast::ExprKind::Underscore => Some("_".to_owned()),
+ ast::ExprKind::IncludedBytes(..) => unreachable!(),
ast::ExprKind::Err => None,
};
@@ -659,7 +660,7 @@ fn to_control_flow(expr: &ast::Expr, expr_type: ExprType) -> Option<ControlFlow<
ast::ExprKind::ForLoop(ref pat, ref cond, ref block, label) => {
Some(ControlFlow::new_for(pat, cond, block, label, expr.span))
}
- ast::ExprKind::Loop(ref block, label) => {
+ ast::ExprKind::Loop(ref block, label, _) => {
Some(ControlFlow::new_loop(block, label, expr.span))
}
ast::ExprKind::While(ref cond, ref block, label) => {
@@ -1184,14 +1185,15 @@ pub(crate) fn is_unsafe_block(block: &ast::Block) -> bool {
pub(crate) fn rewrite_literal(
context: &RewriteContext<'_>,
- l: &ast::Lit,
+ token_lit: token::Lit,
+ span: Span,
shape: Shape,
) -> Option<String> {
- match l.kind {
- ast::LitKind::Str(_, ast::StrStyle::Cooked) => rewrite_string_lit(context, l.span, shape),
- ast::LitKind::Int(..) => rewrite_int_lit(context, l, shape),
+ match token_lit.kind {
+ token::LitKind::Str => rewrite_string_lit(context, span, shape),
+ token::LitKind::Integer => rewrite_int_lit(context, token_lit, span, shape),
_ => wrap_str(
- context.snippet(l.span).to_owned(),
+ context.snippet(span).to_owned(),
context.config.max_width(),
shape,
),
@@ -1224,9 +1226,13 @@ fn rewrite_string_lit(context: &RewriteContext<'_>, span: Span, shape: Shape) ->
)
}
-fn rewrite_int_lit(context: &RewriteContext<'_>, lit: &ast::Lit, shape: Shape) -> Option<String> {
- let span = lit.span;
- let symbol = lit.token_lit.symbol.as_str();
+fn rewrite_int_lit(
+ context: &RewriteContext<'_>,
+ token_lit: token::Lit,
+ span: Span,
+ shape: Shape,
+) -> Option<String> {
+ let symbol = token_lit.symbol.as_str();
if let Some(symbol_stripped) = symbol.strip_prefix("0x") {
let hex_lit = match context.config.hex_literal_case() {
@@ -1239,9 +1245,7 @@ fn rewrite_int_lit(context: &RewriteContext<'_>, lit: &ast::Lit, shape: Shape) -
format!(
"0x{}{}",
hex_lit,
- lit.token_lit
- .suffix
- .map_or(String::new(), |s| s.to_string())
+ token_lit.suffix.map_or(String::new(), |s| s.to_string())
),
context.config.max_width(),
shape,
@@ -1337,7 +1341,7 @@ pub(crate) fn can_be_overflowed_expr(
}
ast::ExprKind::MacCall(ref mac) => {
match (
- rustc_ast::ast::MacDelimiter::from_token(mac.args.delim().unwrap()),
+ rustc_ast::ast::MacDelimiter::from_token(mac.args.delim.to_token()),
context.config.overflow_delimited_expr(),
) {
(Some(ast::MacDelimiter::Bracket), true)
@@ -1533,7 +1537,7 @@ fn struct_lit_can_be_aligned(fields: &[ast::ExprField], has_base: bool) -> bool
fn rewrite_struct_lit<'a>(
context: &RewriteContext<'_>,
path: &ast::Path,
- qself: Option<&ast::QSelf>,
+ qself: &Option<ptr::P<ast::QSelf>>,
fields: &'a [ast::ExprField],
struct_rest: &ast::StructRest,
attrs: &[ast::Attribute],
diff --git a/src/tools/rustfmt/src/imports.rs b/src/tools/rustfmt/src/imports.rs
index b6530c692..d9dc8d004 100644
--- a/src/tools/rustfmt/src/imports.rs
+++ b/src/tools/rustfmt/src/imports.rs
@@ -490,7 +490,7 @@ impl UseTree {
);
result.path.push(UseSegment { kind, version });
}
- UseTreeKind::Simple(ref rename, ..) => {
+ UseTreeKind::Simple(ref rename) => {
// If the path has leading double colons and is composed of only 2 segments, then we
// bypass the call to path_to_imported_ident which would get only the ident and
// lose the path root, e.g., `that` in `::that`.
diff --git a/src/tools/rustfmt/src/macros.rs b/src/tools/rustfmt/src/macros.rs
index 3a641fab5..df9493880 100644
--- a/src/tools/rustfmt/src/macros.rs
+++ b/src/tools/rustfmt/src/macros.rs
@@ -208,7 +208,7 @@ fn rewrite_macro_inner(
original_style
};
- let ts = mac.args.inner_tokens();
+ let ts = mac.args.tokens.clone();
let has_comment = contains_comment(context.snippet(mac.span()));
if ts.is_empty() && !has_comment {
return match style {
@@ -392,7 +392,7 @@ pub(crate) fn rewrite_macro_def(
return snippet;
}
- let ts = def.body.inner_tokens();
+ let ts = def.body.tokens.clone();
let mut parser = MacroParser::new(ts.into_trees());
let parsed_def = match parser.parse() {
Some(def) => def,
@@ -1087,7 +1087,7 @@ pub(crate) fn convert_try_mac(
) -> Option<ast::Expr> {
let path = &pprust::path_to_string(&mac.path);
if path == "try" || path == "r#try" {
- let ts = mac.args.inner_tokens();
+ let ts = mac.args.tokens.clone();
Some(ast::Expr {
id: ast::NodeId::root(), // dummy value
diff --git a/src/tools/rustfmt/src/modules/visitor.rs b/src/tools/rustfmt/src/modules/visitor.rs
index ea67977c1..484316933 100644
--- a/src/tools/rustfmt/src/modules/visitor.rs
+++ b/src/tools/rustfmt/src/modules/visitor.rs
@@ -84,15 +84,19 @@ impl PathVisitor {
}
impl<'ast> MetaVisitor<'ast> for PathVisitor {
- fn visit_meta_name_value(&mut self, meta_item: &'ast ast::MetaItem, lit: &'ast ast::Lit) {
+ fn visit_meta_name_value(
+ &mut self,
+ meta_item: &'ast ast::MetaItem,
+ lit: &'ast ast::MetaItemLit,
+ ) {
if meta_item.has_name(Symbol::intern("path")) && lit.kind.is_str() {
- self.paths.push(lit_to_str(lit));
+ self.paths.push(meta_item_lit_to_str(lit));
}
}
}
#[cfg(not(windows))]
-fn lit_to_str(lit: &ast::Lit) -> String {
+fn meta_item_lit_to_str(lit: &ast::MetaItemLit) -> String {
match lit.kind {
ast::LitKind::Str(symbol, ..) => symbol.to_string(),
_ => unreachable!(),
@@ -100,7 +104,7 @@ fn lit_to_str(lit: &ast::Lit) -> String {
}
#[cfg(windows)]
-fn lit_to_str(lit: &ast::Lit) -> String {
+fn meta_item_lit_to_str(lit: &ast::MetaItemLit) -> String {
match lit.kind {
ast::LitKind::Str(symbol, ..) => symbol.as_str().replace("/", "\\"),
_ => unreachable!(),
diff --git a/src/tools/rustfmt/src/overflow.rs b/src/tools/rustfmt/src/overflow.rs
index 6bf8cd0c7..af0b95430 100644
--- a/src/tools/rustfmt/src/overflow.rs
+++ b/src/tools/rustfmt/src/overflow.rs
@@ -125,7 +125,7 @@ impl<'a> OverflowableItem<'a> {
OverflowableItem::MacroArg(MacroArg::Keyword(..)) => true,
OverflowableItem::MacroArg(MacroArg::Expr(expr)) => is_simple_expr(expr),
OverflowableItem::NestedMetaItem(nested_meta_item) => match nested_meta_item {
- ast::NestedMetaItem::Literal(..) => true,
+ ast::NestedMetaItem::Lit(..) => true,
ast::NestedMetaItem::MetaItem(ref meta_item) => {
matches!(meta_item.kind, ast::MetaItemKind::Word)
}
@@ -169,7 +169,7 @@ impl<'a> OverflowableItem<'a> {
},
OverflowableItem::NestedMetaItem(nested_meta_item) if len == 1 => {
match nested_meta_item {
- ast::NestedMetaItem::Literal(..) => false,
+ ast::NestedMetaItem::Lit(..) => false,
ast::NestedMetaItem::MetaItem(..) => true,
}
}
diff --git a/src/tools/rustfmt/src/parse/macros/asm.rs b/src/tools/rustfmt/src/parse/macros/asm.rs
index cc9fb5072..01edfab36 100644
--- a/src/tools/rustfmt/src/parse/macros/asm.rs
+++ b/src/tools/rustfmt/src/parse/macros/asm.rs
@@ -5,7 +5,7 @@ use crate::rewrite::RewriteContext;
#[allow(dead_code)]
pub(crate) fn parse_asm(context: &RewriteContext<'_>, mac: &ast::MacCall) -> Option<AsmArgs> {
- let ts = mac.args.inner_tokens();
+ let ts = mac.args.tokens.clone();
let mut parser = super::build_parser(context, ts);
parse_asm_args(&mut parser, context.parse_sess.inner(), mac.span(), false).ok()
}
diff --git a/src/tools/rustfmt/src/parse/macros/cfg_if.rs b/src/tools/rustfmt/src/parse/macros/cfg_if.rs
index 09b3e32df..ace1a76b3 100644
--- a/src/tools/rustfmt/src/parse/macros/cfg_if.rs
+++ b/src/tools/rustfmt/src/parse/macros/cfg_if.rs
@@ -23,7 +23,7 @@ fn parse_cfg_if_inner<'a>(
sess: &'a ParseSess,
mac: &'a ast::MacCall,
) -> Result<Vec<ast::Item>, &'static str> {
- let ts = mac.args.inner_tokens();
+ let ts = mac.args.tokens.clone();
let mut parser = build_stream_parser(sess.inner(), ts);
let mut items = vec![];
diff --git a/src/tools/rustfmt/src/parse/session.rs b/src/tools/rustfmt/src/parse/session.rs
index 6efeee98f..6bfec79cd 100644
--- a/src/tools/rustfmt/src/parse/session.rs
+++ b/src/tools/rustfmt/src/parse/session.rs
@@ -134,6 +134,7 @@ fn default_handler(
false,
None,
false,
+ false,
))
};
Handler::with_emitter(
diff --git a/src/tools/rustfmt/src/patterns.rs b/src/tools/rustfmt/src/patterns.rs
index e2fe92b28..3f3351725 100644
--- a/src/tools/rustfmt/src/patterns.rs
+++ b/src/tools/rustfmt/src/patterns.rs
@@ -227,11 +227,10 @@ impl Rewrite for Pat {
}
PatKind::Tuple(ref items) => rewrite_tuple_pat(items, None, self.span, context, shape),
PatKind::Path(ref q_self, ref path) => {
- rewrite_path(context, PathContext::Expr, q_self.as_ref(), path, shape)
+ rewrite_path(context, PathContext::Expr, q_self, path, shape)
}
PatKind::TupleStruct(ref q_self, ref path, ref pat_vec) => {
- let path_str =
- rewrite_path(context, PathContext::Expr, q_self.as_ref(), path, shape)?;
+ let path_str = rewrite_path(context, PathContext::Expr, q_self, path, shape)?;
rewrite_tuple_pat(pat_vec, Some(path_str), self.span, context, shape)
}
PatKind::Lit(ref expr) => expr.rewrite(context, shape),
@@ -271,7 +270,7 @@ impl Rewrite for Pat {
}
fn rewrite_struct_pat(
- qself: &Option<ast::QSelf>,
+ qself: &Option<ptr::P<ast::QSelf>>,
path: &ast::Path,
fields: &[ast::PatField],
ellipsis: bool,
@@ -281,7 +280,7 @@ fn rewrite_struct_pat(
) -> Option<String> {
// 2 = ` {`
let path_shape = shape.sub_width(2)?;
- let path_str = rewrite_path(context, PathContext::Expr, qself.as_ref(), path, path_shape)?;
+ let path_str = rewrite_path(context, PathContext::Expr, qself, path, path_shape)?;
if fields.is_empty() && !ellipsis {
return Some(format!("{} {{}}", path_str));
diff --git a/src/tools/rustfmt/src/types.rs b/src/tools/rustfmt/src/types.rs
index 2627886db..d5177a205 100644
--- a/src/tools/rustfmt/src/types.rs
+++ b/src/tools/rustfmt/src/types.rs
@@ -38,11 +38,11 @@ pub(crate) enum PathContext {
pub(crate) fn rewrite_path(
context: &RewriteContext<'_>,
path_context: PathContext,
- qself: Option<&ast::QSelf>,
+ qself: &Option<ptr::P<ast::QSelf>>,
path: &ast::Path,
shape: Shape,
) -> Option<String> {
- let skip_count = qself.map_or(0, |x| x.position);
+ let skip_count = qself.as_ref().map_or(0, |x| x.position);
let mut result = if path.is_global() && qself.is_none() && path_context != PathContext::Import {
"::".to_owned()
@@ -655,7 +655,7 @@ impl Rewrite for ast::PolyTraitRef {
impl Rewrite for ast::TraitRef {
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
- rewrite_path(context, PathContext::Type, None, &self.path, shape)
+ rewrite_path(context, PathContext::Type, &None, &self.path, shape)
}
}
@@ -800,7 +800,7 @@ impl Rewrite for ast::Ty {
rewrite_tuple(context, items.iter(), self.span, shape, items.len() == 1)
}
ast::TyKind::Path(ref q_self, ref path) => {
- rewrite_path(context, PathContext::Type, q_self.as_ref(), path, shape)
+ rewrite_path(context, PathContext::Type, q_self, path, shape)
}
ast::TyKind::Array(ref ty, ref repeats) => rewrite_pair(
&**ty,
diff --git a/src/tools/rustfmt/src/utils.rs b/src/tools/rustfmt/src/utils.rs
index cd8528556..3e884419f 100644
--- a/src/tools/rustfmt/src/utils.rs
+++ b/src/tools/rustfmt/src/utils.rs
@@ -263,7 +263,7 @@ fn is_skip(meta_item: &MetaItem) -> bool {
fn is_skip_nested(meta_item: &NestedMetaItem) -> bool {
match meta_item {
NestedMetaItem::MetaItem(ref mi) => is_skip(mi),
- NestedMetaItem::Literal(_) => false,
+ NestedMetaItem::Lit(_) => false,
}
}
@@ -479,9 +479,9 @@ pub(crate) fn is_block_expr(context: &RewriteContext<'_>, expr: &ast::Expr, repr
| ast::ExprKind::Binary(_, _, ref expr)
| ast::ExprKind::Index(_, ref expr)
| ast::ExprKind::Unary(_, ref expr)
- | ast::ExprKind::Closure(_, _, _, _, _, ref expr, _)
| ast::ExprKind::Try(ref expr)
| ast::ExprKind::Yield(Some(ref expr)) => is_block_expr(context, expr, repr),
+ ast::ExprKind::Closure(ref closure) => is_block_expr(context, &closure.body, repr),
// This can only be a string lit
ast::ExprKind::Lit(_) => {
repr.contains('\n') && trimmed_last_line_width(repr) <= context.config.tab_spaces()
@@ -496,6 +496,7 @@ pub(crate) fn is_block_expr(context: &RewriteContext<'_>, expr: &ast::Expr, repr
| ast::ExprKind::Continue(..)
| ast::ExprKind::Err
| ast::ExprKind::Field(..)
+ | ast::ExprKind::IncludedBytes(..)
| ast::ExprKind::InlineAsm(..)
| ast::ExprKind::Let(..)
| ast::ExprKind::Path(..)