Merge pull request #5670 from calebcartwright/subtree-sync-2023-01-24
Subtree sync 2023-01-24
This commit is contained in:
commit
6eeb4fd230
36 changed files with 205 additions and 167 deletions
|
@ -51,7 +51,3 @@ git tag -s v1.2.3 -m "Release 1.2.3"
|
|||
`cargo publish`
|
||||
|
||||
## 5. Create a PR to rust-lang/rust to update the rustfmt submodule
|
||||
|
||||
Note that if you are updating `rustc-ap-*` crates, then you need to update **every** submodules in the rust-lang/rust repository that depend on the crates to use the same version of those.
|
||||
|
||||
As of 2019/05, there are two such crates: `rls` and `racer` (`racer` depends on `rustc-ap-syntax` and `rls` depends on `racer`, and `rls` is one of submodules of the rust-lang/rust repository).
|
||||
|
|
|
@ -135,7 +135,7 @@ completed without error (whether or not changes were made).
|
|||
* [Emacs](https://github.com/rust-lang/rust-mode)
|
||||
* [Sublime Text 3](https://packagecontrol.io/packages/RustFmt)
|
||||
* [Atom](atom.md)
|
||||
* Visual Studio Code using [vscode-rust](https://github.com/editor-rs/vscode-rust), [vsc-rustfmt](https://github.com/Connorcpu/vsc-rustfmt) or [rls_vscode](https://github.com/jonathandturner/rls_vscode) through RLS.
|
||||
* [Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer)
|
||||
* [IntelliJ or CLion](intellij.md)
|
||||
|
||||
|
||||
|
|
4
atom.md
4
atom.md
|
@ -1,8 +1,8 @@
|
|||
# Running Rustfmt from Atom
|
||||
|
||||
## RLS
|
||||
## rust-analyzer
|
||||
|
||||
Rustfmt is included with the Rust Language Server, itself provided by [ide-rust](https://atom.io/packages/ide-rust).
|
||||
Rustfmt can be utilized from [rust-analyzer](https://rust-analyzer.github.io/) which is provided by [ide-rust](https://atom.io/packages/ide-rust).
|
||||
|
||||
`apm install ide-rust`
|
||||
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
[toolchain]
|
||||
channel = "nightly-2022-08-06"
|
||||
components = ["rustc-dev"]
|
||||
channel = "nightly-2023-01-24"
|
||||
components = ["llvm-tools", "rustc-dev"]
|
||||
|
|
34
src/attr.rs
34
src/attr.rs
|
@ -49,10 +49,7 @@ pub(crate) fn get_span_without_attrs(stmt: &ast::Stmt) -> Span {
|
|||
}
|
||||
|
||||
/// Returns attributes that are within `outer_span`.
|
||||
pub(crate) fn filter_inline_attrs(
|
||||
attrs: &[ast::Attribute],
|
||||
outer_span: Span,
|
||||
) -> Vec<ast::Attribute> {
|
||||
pub(crate) fn filter_inline_attrs(attrs: &[ast::Attribute], outer_span: Span) -> ast::AttrVec {
|
||||
attrs
|
||||
.iter()
|
||||
.filter(|a| outer_span.lo() <= a.span.lo() && a.span.hi() <= outer_span.hi())
|
||||
|
@ -263,7 +260,9 @@ 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.as_token_lit(), l.span, shape)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -291,10 +290,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,
|
||||
|
@ -311,18 +310,18 @@ impl Rewrite for ast::MetaItem {
|
|||
}),
|
||||
)?
|
||||
}
|
||||
ast::MetaItemKind::NameValue(ref literal) => {
|
||||
let path = rewrite_path(context, PathContext::Type, None, &self.path, shape)?;
|
||||
ast::MetaItemKind::NameValue(ref lit) => {
|
||||
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
|
||||
// `rewrite_literal` returns `None` when `lit` exceeds max
|
||||
// width. Since a literal is basically unformattable unless it
|
||||
// is a string literal (and only if `format_strings` is set),
|
||||
// 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)
|
||||
.unwrap_or_else(|| context.snippet(literal.span).to_owned());
|
||||
let value = rewrite_literal(context, lit.as_token_lit(), lit.span, lit_shape)
|
||||
.unwrap_or_else(|| context.snippet(lit.span).to_owned());
|
||||
format!("{} = {}", path, value)
|
||||
}
|
||||
})
|
||||
|
@ -528,14 +527,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) {}
|
||||
}
|
||||
|
|
|
@ -199,8 +199,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 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()
|
||||
|
@ -217,8 +217,8 @@ impl ChainItemKind {
|
|||
} else {
|
||||
vec![]
|
||||
};
|
||||
let span = mk_sp(expressions[0].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) => {
|
||||
|
@ -307,7 +307,7 @@ impl ChainItem {
|
|||
format!("::<{}>", type_list.join(", "))
|
||||
};
|
||||
let callee_str = format!(".{}{}", rewrite_ident(context, method_name), type_str);
|
||||
rewrite_call(context, &callee_str, &args[1..], span, shape)
|
||||
rewrite_call(context, &callee_str, &args, span, shape)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -454,9 +454,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 expressions, _) => {
|
||||
Some(Self::convert_try(&expressions[0], 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)),
|
||||
|
|
|
@ -26,6 +26,7 @@ use crate::utils::{last_line_width, left_most_sub_expr, stmt_expr, NodeIdExt};
|
|||
|
||||
pub(crate) fn rewrite_closure(
|
||||
binder: &ast::ClosureBinder,
|
||||
constness: ast::Const,
|
||||
capture: ast::CaptureBy,
|
||||
is_async: &ast::Async,
|
||||
movability: ast::Movability,
|
||||
|
@ -38,7 +39,7 @@ pub(crate) fn rewrite_closure(
|
|||
debug!("rewrite_closure {:?}", body);
|
||||
|
||||
let (prefix, extra_offset) = rewrite_closure_fn_decl(
|
||||
binder, capture, is_async, movability, fn_decl, body, span, context, shape,
|
||||
binder, constness, capture, is_async, movability, fn_decl, body, span, context, shape,
|
||||
)?;
|
||||
// 1 = space between `|...|` and body.
|
||||
let body_shape = shape.offset_left(extra_offset)?;
|
||||
|
@ -230,6 +231,7 @@ fn rewrite_closure_block(
|
|||
// Return type is (prefix, extra_offset)
|
||||
fn rewrite_closure_fn_decl(
|
||||
binder: &ast::ClosureBinder,
|
||||
constness: ast::Const,
|
||||
capture: ast::CaptureBy,
|
||||
asyncness: &ast::Async,
|
||||
movability: ast::Movability,
|
||||
|
@ -250,6 +252,12 @@ fn rewrite_closure_fn_decl(
|
|||
ast::ClosureBinder::NotPresent => "".to_owned(),
|
||||
};
|
||||
|
||||
let const_ = if matches!(constness, ast::Const::Yes(_)) {
|
||||
"const "
|
||||
} else {
|
||||
""
|
||||
};
|
||||
|
||||
let immovable = if movability == ast::Movability::Static {
|
||||
"static "
|
||||
} else {
|
||||
|
@ -264,7 +272,7 @@ fn rewrite_closure_fn_decl(
|
|||
// 4 = "|| {".len(), which is overconservative when the closure consists of
|
||||
// a single expression.
|
||||
let nested_shape = shape
|
||||
.shrink_left(binder.len() + immovable.len() + is_async.len() + mover.len())?
|
||||
.shrink_left(binder.len() + const_.len() + immovable.len() + is_async.len() + mover.len())?
|
||||
.sub_width(4)?;
|
||||
|
||||
// 1 = |
|
||||
|
@ -302,7 +310,10 @@ fn rewrite_closure_fn_decl(
|
|||
.tactic(tactic)
|
||||
.preserve_newline(true);
|
||||
let list_str = write_list(&item_vec, &fmt)?;
|
||||
let mut prefix = format!("{}{}{}{}|{}|", binder, immovable, is_async, mover, list_str);
|
||||
let mut prefix = format!(
|
||||
"{}{}{}{}{}|{}|",
|
||||
binder, const_, immovable, is_async, mover, list_str
|
||||
);
|
||||
|
||||
if !ret_str.is_empty() {
|
||||
if prefix.contains('\n') {
|
||||
|
@ -326,16 +337,18 @@ 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,
|
||||
constness,
|
||||
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 +360,16 @@ 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,
|
||||
constness,
|
||||
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') {
|
||||
|
|
|
@ -5,7 +5,7 @@ use crate::config::options::{IgnoreList, WidthHeuristics};
|
|||
/// Trait for types that can be used in `Config`.
|
||||
pub(crate) trait ConfigType: Sized {
|
||||
/// Returns hint text for use in `Config::print_docs()`. For enum types, this is a
|
||||
/// pipe-separated list of variants; for other types it returns "<type>".
|
||||
/// pipe-separated list of variants; for other types it returns `<type>`.
|
||||
fn doc_hint() -> String;
|
||||
|
||||
/// Return `true` if the variant (i.e. value of this type) is stable.
|
||||
|
|
71
src/expr.rs
71
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.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,17 @@ 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.constness,
|
||||
cl.capture_clause,
|
||||
&cl.asyncness,
|
||||
cl.movability,
|
||||
&cl.fn_decl,
|
||||
&cl.body,
|
||||
expr.span,
|
||||
context,
|
||||
shape,
|
||||
),
|
||||
ast::ExprKind::Try(..)
|
||||
| ast::ExprKind::Field(..)
|
||||
|
@ -274,9 +275,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 +400,7 @@ pub(crate) fn format_expr(
|
|||
}
|
||||
}
|
||||
ast::ExprKind::Underscore => Some("_".to_owned()),
|
||||
ast::ExprKind::IncludedBytes(..) => unreachable!(),
|
||||
ast::ExprKind::Err => None,
|
||||
};
|
||||
|
||||
|
@ -659,7 +661,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 +1186,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 +1227,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.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,7 +1246,7 @@ fn rewrite_int_lit(context: &RewriteContext<'_>, lit: &ast::Lit, shape: Shape) -
|
|||
format!(
|
||||
"0x{}{}",
|
||||
hex_lit,
|
||||
lit.token.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,
|
||||
|
@ -1335,7 +1342,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)
|
||||
|
@ -1531,7 +1538,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],
|
||||
|
|
|
@ -116,7 +116,7 @@ pub(crate) struct UseTree {
|
|||
// Additional fields for top level use items.
|
||||
// Should we have another struct for top-level use items rather than reusing this?
|
||||
visibility: Option<ast::Visibility>,
|
||||
attrs: Option<Vec<ast::Attribute>>,
|
||||
attrs: Option<ast::AttrVec>,
|
||||
}
|
||||
|
||||
impl PartialEq for UseTree {
|
||||
|
@ -417,7 +417,7 @@ impl UseTree {
|
|||
list_item: Option<ListItem>,
|
||||
visibility: Option<ast::Visibility>,
|
||||
opt_lo: Option<BytePos>,
|
||||
attrs: Option<Vec<ast::Attribute>>,
|
||||
attrs: Option<ast::AttrVec>,
|
||||
) -> UseTree {
|
||||
let span = if let Some(lo) = opt_lo {
|
||||
mk_sp(lo, a.span.hi())
|
||||
|
@ -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`.
|
||||
|
|
12
src/items.rs
12
src/items.rs
|
@ -594,7 +594,7 @@ impl<'a> FmtVisitor<'a> {
|
|||
let both_type = |l: &TyOpt, r: &TyOpt| is_type(l) && is_type(r);
|
||||
let both_opaque = |l: &TyOpt, r: &TyOpt| is_opaque(l) && is_opaque(r);
|
||||
let need_empty_line = |a: &ast::AssocItemKind, b: &ast::AssocItemKind| match (a, b) {
|
||||
(TyAlias(lty), TyAlias(rty))
|
||||
(Type(lty), Type(rty))
|
||||
if both_type(<y.ty, &rty.ty) || both_opaque(<y.ty, &rty.ty) =>
|
||||
{
|
||||
false
|
||||
|
@ -612,7 +612,7 @@ impl<'a> FmtVisitor<'a> {
|
|||
}
|
||||
|
||||
buffer.sort_by(|(_, a), (_, b)| match (&a.kind, &b.kind) {
|
||||
(TyAlias(lty), TyAlias(rty))
|
||||
(Type(lty), Type(rty))
|
||||
if both_type(<y.ty, &rty.ty) || both_opaque(<y.ty, &rty.ty) =>
|
||||
{
|
||||
a.ident.as_str().cmp(b.ident.as_str())
|
||||
|
@ -621,10 +621,10 @@ impl<'a> FmtVisitor<'a> {
|
|||
a.ident.as_str().cmp(b.ident.as_str())
|
||||
}
|
||||
(Fn(..), Fn(..)) => a.span.lo().cmp(&b.span.lo()),
|
||||
(TyAlias(ty), _) if is_type(&ty.ty) => Ordering::Less,
|
||||
(_, TyAlias(ty)) if is_type(&ty.ty) => Ordering::Greater,
|
||||
(TyAlias(..), _) => Ordering::Less,
|
||||
(_, TyAlias(..)) => Ordering::Greater,
|
||||
(Type(ty), _) if is_type(&ty.ty) => Ordering::Less,
|
||||
(_, Type(ty)) if is_type(&ty.ty) => Ordering::Greater,
|
||||
(Type(..), _) => Ordering::Less,
|
||||
(_, Type(..)) => Ordering::Greater,
|
||||
(Const(..), _) => Ordering::Less,
|
||||
(_, Const(..)) => Ordering::Greater,
|
||||
(MacCall(..), _) => Ordering::Less,
|
||||
|
|
|
@ -23,6 +23,11 @@ extern crate rustc_parse;
|
|||
extern crate rustc_session;
|
||||
extern crate rustc_span;
|
||||
|
||||
// Necessary to pull in object code as the rest of the rustc crates are shipped only as rmeta
|
||||
// files.
|
||||
#[allow(unused_extern_crates)]
|
||||
extern crate rustc_driver;
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::collections::HashMap;
|
||||
use std::fmt;
|
||||
|
|
|
@ -209,7 +209,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 {
|
||||
|
@ -393,7 +393,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,
|
||||
|
@ -1088,7 +1088,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
|
||||
|
|
|
@ -26,7 +26,7 @@ type FileModMap<'ast> = BTreeMap<FileName, Module<'ast>>;
|
|||
pub(crate) struct Module<'a> {
|
||||
ast_mod_kind: Option<Cow<'a, ast::ModKind>>,
|
||||
pub(crate) items: Cow<'a, Vec<rustc_ast::ptr::P<ast::Item>>>,
|
||||
inner_attr: Vec<ast::Attribute>,
|
||||
inner_attr: ast::AttrVec,
|
||||
pub(crate) span: Span,
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ impl<'a> Module<'a> {
|
|||
mod_span: Span,
|
||||
ast_mod_kind: Option<Cow<'a, ast::ModKind>>,
|
||||
mod_items: Cow<'a, Vec<rustc_ast::ptr::P<ast::Item>>>,
|
||||
mod_attrs: Cow<'a, Vec<ast::Attribute>>,
|
||||
mod_attrs: Cow<'a, ast::AttrVec>,
|
||||
) -> Self {
|
||||
let inner_attr = mod_attrs
|
||||
.iter()
|
||||
|
@ -158,7 +158,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
|
|||
module_item.item.span,
|
||||
Some(Cow::Owned(sub_mod_kind.clone())),
|
||||
Cow::Owned(vec![]),
|
||||
Cow::Owned(vec![]),
|
||||
Cow::Owned(ast::AttrVec::new()),
|
||||
),
|
||||
)?;
|
||||
}
|
||||
|
@ -185,7 +185,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
|
|||
span,
|
||||
Some(Cow::Owned(sub_mod_kind.clone())),
|
||||
Cow::Owned(vec![]),
|
||||
Cow::Owned(vec![]),
|
||||
Cow::Owned(ast::AttrVec::new()),
|
||||
),
|
||||
)?;
|
||||
}
|
||||
|
|
|
@ -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!(),
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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![];
|
||||
|
|
|
@ -109,7 +109,7 @@ impl<'a> Parser<'a> {
|
|||
sess: &'a ParseSess,
|
||||
path: &Path,
|
||||
span: Span,
|
||||
) -> Result<(Vec<ast::Attribute>, Vec<ptr::P<ast::Item>>, Span), ParserError> {
|
||||
) -> Result<(ast::AttrVec, Vec<ptr::P<ast::Item>>, Span), ParserError> {
|
||||
let result = catch_unwind(AssertUnwindSafe(|| {
|
||||
let mut parser = new_parser_from_file(sess.inner(), path, Some(span));
|
||||
match parser.parse_mod(&TokenKind::Eof) {
|
||||
|
|
|
@ -3,6 +3,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
|
|||
|
||||
use rustc_data_structures::sync::{Lrc, Send};
|
||||
use rustc_errors::emitter::{Emitter, EmitterWriter};
|
||||
use rustc_errors::translation::Translate;
|
||||
use rustc_errors::{ColorConfig, Diagnostic, Handler, Level as DiagnosticLevel};
|
||||
use rustc_session::parse::ParseSess as RawParseSess;
|
||||
use rustc_span::{
|
||||
|
@ -28,17 +29,22 @@ pub(crate) struct ParseSess {
|
|||
/// Emitter which discards every error.
|
||||
struct SilentEmitter;
|
||||
|
||||
impl Translate for SilentEmitter {
|
||||
fn fluent_bundle(&self) -> Option<&Lrc<rustc_errors::FluentBundle>> {
|
||||
None
|
||||
}
|
||||
|
||||
fn fallback_fluent_bundle(&self) -> &rustc_errors::FluentBundle {
|
||||
panic!("silent emitter attempted to translate a diagnostic");
|
||||
}
|
||||
}
|
||||
|
||||
impl Emitter for SilentEmitter {
|
||||
fn source_map(&self) -> Option<&Lrc<SourceMap>> {
|
||||
None
|
||||
}
|
||||
|
||||
fn emit_diagnostic(&mut self, _db: &Diagnostic) {}
|
||||
fn fluent_bundle(&self) -> Option<&Lrc<rustc_errors::FluentBundle>> {
|
||||
None
|
||||
}
|
||||
fn fallback_fluent_bundle(&self) -> &rustc_errors::FluentBundle {
|
||||
panic!("silent emitter attempted to translate a diagnostic");
|
||||
}
|
||||
}
|
||||
|
||||
fn silent_emitter() -> Box<dyn Emitter + Send> {
|
||||
|
@ -62,10 +68,21 @@ impl SilentOnIgnoredFilesEmitter {
|
|||
}
|
||||
}
|
||||
|
||||
impl Translate for SilentOnIgnoredFilesEmitter {
|
||||
fn fluent_bundle(&self) -> Option<&Lrc<rustc_errors::FluentBundle>> {
|
||||
self.emitter.fluent_bundle()
|
||||
}
|
||||
|
||||
fn fallback_fluent_bundle(&self) -> &rustc_errors::FluentBundle {
|
||||
self.emitter.fallback_fluent_bundle()
|
||||
}
|
||||
}
|
||||
|
||||
impl Emitter for SilentOnIgnoredFilesEmitter {
|
||||
fn source_map(&self) -> Option<&Lrc<SourceMap>> {
|
||||
None
|
||||
}
|
||||
|
||||
fn emit_diagnostic(&mut self, db: &Diagnostic) {
|
||||
if db.level() == DiagnosticLevel::Fatal {
|
||||
return self.handle_non_ignoreable_error(db);
|
||||
|
@ -88,14 +105,6 @@ impl Emitter for SilentOnIgnoredFilesEmitter {
|
|||
}
|
||||
self.handle_non_ignoreable_error(db);
|
||||
}
|
||||
|
||||
fn fluent_bundle(&self) -> Option<&Lrc<rustc_errors::FluentBundle>> {
|
||||
self.emitter.fluent_bundle()
|
||||
}
|
||||
|
||||
fn fallback_fluent_bundle(&self) -> &rustc_errors::FluentBundle {
|
||||
self.emitter.fallback_fluent_bundle()
|
||||
}
|
||||
}
|
||||
|
||||
fn default_handler(
|
||||
|
@ -125,6 +134,7 @@ fn default_handler(
|
|||
false,
|
||||
None,
|
||||
false,
|
||||
false,
|
||||
))
|
||||
};
|
||||
Handler::with_emitter(
|
||||
|
@ -340,19 +350,24 @@ mod tests {
|
|||
num_emitted_errors: Lrc<AtomicU32>,
|
||||
}
|
||||
|
||||
impl Translate for TestEmitter {
|
||||
fn fluent_bundle(&self) -> Option<&Lrc<rustc_errors::FluentBundle>> {
|
||||
None
|
||||
}
|
||||
|
||||
fn fallback_fluent_bundle(&self) -> &rustc_errors::FluentBundle {
|
||||
panic!("test emitter attempted to translate a diagnostic");
|
||||
}
|
||||
}
|
||||
|
||||
impl Emitter for TestEmitter {
|
||||
fn source_map(&self) -> Option<&Lrc<SourceMap>> {
|
||||
None
|
||||
}
|
||||
|
||||
fn emit_diagnostic(&mut self, _db: &Diagnostic) {
|
||||
self.num_emitted_errors.fetch_add(1, Ordering::Release);
|
||||
}
|
||||
fn fluent_bundle(&self) -> Option<&Lrc<rustc_errors::FluentBundle>> {
|
||||
None
|
||||
}
|
||||
fn fallback_fluent_bundle(&self) -> &rustc_errors::FluentBundle {
|
||||
panic!("test emitter attempted to translate a diagnostic");
|
||||
}
|
||||
}
|
||||
|
||||
fn build_diagnostic(level: DiagnosticLevel, span: Option<MultiSpan>) -> Diagnostic {
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
use rustc_ast::ast::{self, BindingMode, Pat, PatField, PatKind, RangeEnd, RangeSyntax};
|
||||
use rustc_ast::ast::{
|
||||
self, BindingAnnotation, ByRef, Pat, PatField, PatKind, RangeEnd, RangeSyntax,
|
||||
};
|
||||
use rustc_ast::ptr;
|
||||
use rustc_span::{BytePos, Span};
|
||||
|
||||
|
@ -99,10 +101,10 @@ impl Rewrite for Pat {
|
|||
write_list(&items, &fmt)
|
||||
}
|
||||
PatKind::Box(ref pat) => rewrite_unary_prefix(context, "box ", &**pat, shape),
|
||||
PatKind::Ident(binding_mode, ident, ref sub_pat) => {
|
||||
let (prefix, mutability) = match binding_mode {
|
||||
BindingMode::ByRef(mutability) => ("ref", mutability),
|
||||
BindingMode::ByValue(mutability) => ("", mutability),
|
||||
PatKind::Ident(BindingAnnotation(by_ref, mutability), ident, ref sub_pat) => {
|
||||
let prefix = match by_ref {
|
||||
ByRef::Yes => "ref",
|
||||
ByRef::No => "",
|
||||
};
|
||||
let mut_infix = format_mutability(mutability).trim();
|
||||
let id_str = rewrite_ident(context, ident);
|
||||
|
@ -225,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),
|
||||
|
@ -269,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,
|
||||
|
@ -279,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));
|
||||
|
|
|
@ -109,8 +109,8 @@ fn get_skip_names(kind: &str, attrs: &[ast::Attribute]) -> Vec<String> {
|
|||
for attr in attrs {
|
||||
// rustc_ast::ast::Path is implemented partialEq
|
||||
// but it is designed for segments.len() == 1
|
||||
if let ast::AttrKind::Normal(attr_item, _) = &attr.kind {
|
||||
if pprust::path_to_string(&attr_item.path) != path {
|
||||
if let ast::AttrKind::Normal(normal) = &attr.kind {
|
||||
if pprust::path_to_string(&normal.item.path) != path {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
|
12
src/types.rs
12
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -688,7 +688,7 @@ impl Rewrite for ast::Ty {
|
|||
|
||||
rewrite_unary_prefix(context, prefix, &*mt.ty, shape)
|
||||
}
|
||||
ast::TyKind::Rptr(ref lifetime, ref mt) => {
|
||||
ast::TyKind::Ref(ref lifetime, ref mt) => {
|
||||
let mut_str = format_mutability(mt.mutbl);
|
||||
let mut_len = mut_str.len();
|
||||
let mut result = String::with_capacity(128);
|
||||
|
@ -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,
|
||||
|
@ -1094,7 +1094,7 @@ pub(crate) fn can_be_overflowed_type(
|
|||
) -> bool {
|
||||
match ty.kind {
|
||||
ast::TyKind::Tup(..) => context.use_block_indent() && len == 1,
|
||||
ast::TyKind::Rptr(_, ref mutty) | ast::TyKind::Ptr(ref mutty) => {
|
||||
ast::TyKind::Ref(_, ref mutty) | ast::TyKind::Ptr(ref mutty) => {
|
||||
can_be_overflowed_type(context, &*mutty.ty, len)
|
||||
}
|
||||
_ => false,
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -480,9 +480,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()
|
||||
|
@ -497,6 +497,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(..)
|
||||
|
|
|
@ -660,7 +660,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
|
|||
self.push_rewrite(ai.span, rewrite);
|
||||
}
|
||||
}
|
||||
(ast::AssocItemKind::TyAlias(ref ty_alias), _) => {
|
||||
(ast::AssocItemKind::Type(ref ty_alias), _) => {
|
||||
self.visit_ty_alias_kind(ty_alias, visitor_kind, ai.span);
|
||||
}
|
||||
(ast::AssocItemKind::MacCall(ref mac), _) => {
|
||||
|
@ -820,8 +820,8 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
|
|||
);
|
||||
} else {
|
||||
match &attr.kind {
|
||||
ast::AttrKind::Normal(ref attribute_item, _)
|
||||
if self.is_unknown_rustfmt_attr(&attribute_item.path.segments) =>
|
||||
ast::AttrKind::Normal(ref normal)
|
||||
if self.is_unknown_rustfmt_attr(&normal.item.path.segments) =>
|
||||
{
|
||||
let file_name = self.parse_sess.span_to_filename(attr.span);
|
||||
self.report.append(
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
test!(RunPassPretty {
|
||||
// comment
|
||||
path: "src/test/run-pass/pretty",
|
||||
path: "tests/run-pass/pretty",
|
||||
mode: "pretty",
|
||||
suite: "run-pass",
|
||||
default: false,
|
||||
|
@ -9,7 +9,7 @@ test!(RunPassPretty {
|
|||
|
||||
test!(RunPassPretty {
|
||||
// comment
|
||||
path: "src/test/run-pass/pretty",
|
||||
path: "tests/run-pass/pretty",
|
||||
mode: "pretty",
|
||||
suite: "run-pass",
|
||||
default: false,
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
#![feature(label_break_value)]
|
||||
|
||||
fn main() {
|
||||
let mut res = 0;
|
||||
's_39: { if res == 0i32 { println!("Hello, world!"); } }
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
#![feature(generic_associated_types)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
trait Trait<T> {
|
||||
type Type<'a> where T: 'a;
|
||||
fn foo(x: &T) -> Self::Type<'_>;
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#![feature(generic_associated_types)]
|
||||
#![feature(min_type_alias_impl_trait)]
|
||||
|
||||
impl SomeTrait for SomeType {
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
#![feature(generic_associated_types)]
|
||||
|
||||
impl SomeStruct {
|
||||
fn process<T>(v: T) -> <Self as GAT>::R<T>
|
||||
where Self: GAT<R<T> = T>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
test!(RunPassPretty {
|
||||
// comment
|
||||
path: "src/test/run-pass/pretty",
|
||||
path: "tests/run-pass/pretty",
|
||||
mode: "pretty",
|
||||
suite: "run-pass",
|
||||
default: false,
|
||||
|
@ -9,7 +9,7 @@ test!(RunPassPretty {
|
|||
|
||||
test!(RunPassPretty {
|
||||
// comment
|
||||
path: "src/test/run-pass/pretty",
|
||||
path: "tests/run-pass/pretty",
|
||||
mode: "pretty",
|
||||
suite: "run-pass",
|
||||
default: false,
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
#![feature(label_break_value)]
|
||||
|
||||
fn main() {
|
||||
let mut res = 0;
|
||||
's_39: {
|
||||
|
|
|
@ -20,6 +20,7 @@ fn bindings() {
|
|||
category,
|
||||
span,
|
||||
&format!("`{}`", name),
|
||||
"function",
|
||||
),
|
||||
(
|
||||
ref name,
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
#![feature(generic_associated_types)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
trait Trait<T> {
|
||||
type Type<'a>
|
||||
where
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#![feature(generic_associated_types)]
|
||||
#![feature(min_type_alias_impl_trait)]
|
||||
|
||||
impl SomeTrait for SomeType {
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
#![feature(generic_associated_types)]
|
||||
|
||||
impl SomeStruct {
|
||||
fn process<T>(v: T) -> <Self as GAT>::R<T>
|
||||
where
|
||||
|
|
Loading…
Add table
Reference in a new issue