Update deps (#3788)
This commit is contained in:
parent
6fec3a69ec
commit
ceca01465a
612
Cargo.lock
generated
612
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
13
Cargo.toml
13
Cargo.toml
@ -34,7 +34,6 @@ rustfmt-format-diff = []
|
||||
generic-simd = ["bytecount/generic-simd"]
|
||||
|
||||
[dependencies]
|
||||
atty = "0.2"
|
||||
itertools = "0.8"
|
||||
toml = "0.5"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
@ -48,19 +47,19 @@ env_logger = "0.6"
|
||||
getopts = "0.2"
|
||||
derive-new = "0.5"
|
||||
cargo_metadata = "0.8"
|
||||
rustc-ap-rustc_target = "581.0.0"
|
||||
rustc-ap-syntax = "581.0.0"
|
||||
rustc-ap-syntax_pos = "581.0.0"
|
||||
rustc-ap-rustc_target = "583.0.0"
|
||||
rustc-ap-syntax = "583.0.0"
|
||||
rustc-ap-syntax_pos = "583.0.0"
|
||||
failure = "0.1.3"
|
||||
bytecount = "0.5"
|
||||
bytecount = "0.6"
|
||||
unicode-width = "0.1.5"
|
||||
unicode_categories = "0.1.1"
|
||||
dirs = "2.0.1"
|
||||
ignore = "0.4.6"
|
||||
annotate-snippets = { version = "0.6", features = ["ansi_term"] }
|
||||
structopt = "0.2.18"
|
||||
structopt = "0.3"
|
||||
|
||||
rustfmt-config_proc_macro = { version = "0.1.2", path = "config_proc_macro" }
|
||||
rustfmt-config_proc_macro = { version = "0.2", path = "config_proc_macro" }
|
||||
|
||||
# A noop dependency that changes in the Rust repository, it's a bit of a hack.
|
||||
# See the `src/tools/rustc-workspace-hack/README.md` file in `rust-lang/rust`
|
||||
|
50
config_proc_macro/Cargo.lock
generated
50
config_proc_macro/Cargo.lock
generated
@ -2,67 +2,67 @@
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "0.4.27"
|
||||
version = "1.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "0.6.11"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"proc-macro2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustfmt-config_proc_macro"
|
||||
version = "0.1.2"
|
||||
dependencies = [
|
||||
"proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"proc-macro2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.89"
|
||||
version = "1.0.99"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.89"
|
||||
version = "1.0.99"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"proc-macro2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "0.15.29"
|
||||
version = "1.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"proc-macro2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.1.0"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[metadata]
|
||||
"checksum proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)" = "4d317f9caece796be1980837fd5cb3dfec5613ebdb04ad0956deea83ce168915"
|
||||
"checksum quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)" = "cdd8e04bd9c52e0342b406469d494fcb033be4bdbe5c606016defbb1681411e1"
|
||||
"checksum serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)" = "92514fb95f900c9b5126e32d020f5c6d40564c27a5ea6d1d7d9f157a96623560"
|
||||
"checksum serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)" = "bb6eabf4b5914e88e24eea240bb7c9f9a2cbc1bbbe8d961d381975ec3c6b806c"
|
||||
"checksum syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)" = "1825685f977249735d510a242a6727b46efe914bb67e38d30c071b1b72b1d5c2"
|
||||
"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
|
||||
"checksum proc-macro2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e98a83a9f9b331f54b924e68a66acb1bb35cb01fb0a23645139967abefb697e8"
|
||||
"checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe"
|
||||
"checksum serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)" = "fec2851eb56d010dc9a21b89ca53ee75e6528bab60c11e89d38390904982da9f"
|
||||
"checksum serde_derive 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)" = "cb4dc18c61206b08dc98216c98faa0232f4337e1e1b8574551d5bad29ea1b425"
|
||||
"checksum syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "66850e97125af79138385e9b88339cbcd037e3f28ceab8c5ad98e64f0f1f80bf"
|
||||
"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "rustfmt-config_proc_macro"
|
||||
version = "0.1.2"
|
||||
version = "0.2.0"
|
||||
authors = ["topecongiro <seuchida@gmail.com>"]
|
||||
edition = "2018"
|
||||
description = "A collection of procedural macros for rustfmt"
|
||||
@ -12,9 +12,9 @@ repository = "https://github.com/rust-lang/rustfmt"
|
||||
proc-macro = true
|
||||
|
||||
[dependencies]
|
||||
proc-macro2 = "0.4"
|
||||
quote = "0.6"
|
||||
syn = { version = "0.15", features = ["full", "visit"] }
|
||||
proc-macro2 = "1.0"
|
||||
quote = "1.0"
|
||||
syn = { version = "1.0", features = ["full", "visit"] }
|
||||
|
||||
[dev-dependencies]
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
|
@ -39,19 +39,19 @@ pub fn is_config_value(attr: &syn::Attribute) -> bool {
|
||||
}
|
||||
|
||||
fn is_attr_name_value(attr: &syn::Attribute, name: &str) -> bool {
|
||||
attr.interpret_meta().map_or(false, |meta| match meta {
|
||||
syn::Meta::NameValue(syn::MetaNameValue { ref ident, .. }) if ident == name => true,
|
||||
attr.parse_meta().ok().map_or(false, |meta| match meta {
|
||||
syn::Meta::NameValue(syn::MetaNameValue { ref path, .. }) if path.is_ident(name) => true,
|
||||
_ => false,
|
||||
})
|
||||
}
|
||||
|
||||
fn get_name_value_str_lit(attr: &syn::Attribute, name: &str) -> Option<String> {
|
||||
attr.interpret_meta().and_then(|meta| match meta {
|
||||
attr.parse_meta().ok().and_then(|meta| match meta {
|
||||
syn::Meta::NameValue(syn::MetaNameValue {
|
||||
ref ident,
|
||||
ref path,
|
||||
lit: syn::Lit::Str(ref lit_str),
|
||||
..
|
||||
}) if ident == name => Some(lit_str.value()),
|
||||
}) if path.is_ident(name) => Some(lit_str.value()),
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
|
@ -20,7 +20,6 @@ use structopt::StructOpt;
|
||||
#[derive(StructOpt, Debug)]
|
||||
#[structopt(
|
||||
bin_name = "cargo fmt",
|
||||
author = "",
|
||||
about = "This utility formats all bin and lib files of \
|
||||
the current crate using rustfmt."
|
||||
)]
|
||||
@ -51,7 +50,7 @@ pub struct Opts {
|
||||
|
||||
/// Options passed to rustfmt
|
||||
// 'raw = true' to make `--` explicit.
|
||||
#[structopt(name = "rustfmt_options", raw(raw = "true"))]
|
||||
#[structopt(name = "rustfmt_options", raw(true))]
|
||||
rustfmt_options: Vec<String>,
|
||||
|
||||
/// Format all packages (only usable in workspaces)
|
||||
|
@ -2,7 +2,6 @@ use std::collections::{hash_set, HashSet};
|
||||
use std::fmt;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use atty;
|
||||
use itertools::Itertools;
|
||||
use rustfmt_config_proc_macro::config_type;
|
||||
use serde::de::{SeqAccess, Visitor};
|
||||
@ -147,7 +146,7 @@ pub enum Color {
|
||||
pub enum Version {
|
||||
/// 1.x.y. When specified, rustfmt will format in the same style as 1.0.0.
|
||||
One,
|
||||
/// 2.x.y. When specified, rustfmt will formatin the the latest style.
|
||||
/// 2.x.y. When specified, rustfmt will format in the the latest style.
|
||||
Two,
|
||||
}
|
||||
|
||||
@ -155,9 +154,8 @@ impl Color {
|
||||
/// Whether we should use a coloured terminal.
|
||||
pub fn use_colored_tty(self) -> bool {
|
||||
match self {
|
||||
Color::Always => true,
|
||||
Color::Always | Color::Auto => true,
|
||||
Color::Never => false,
|
||||
Color::Auto => atty::is(atty::Stream::Stdout),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
90
src/expr.rs
90
src/expr.rs
@ -16,13 +16,12 @@ use crate::config::lists::*;
|
||||
use crate::config::{Config, ControlBraceStyle, IndentStyle, Version};
|
||||
use crate::lists::{
|
||||
definitive_tactic, itemize_list, shape_for_tactic, struct_lit_formatting, struct_lit_shape,
|
||||
struct_lit_tactic, write_list, ListFormatting, ListItem, Separator,
|
||||
struct_lit_tactic, write_list, ListFormatting, Separator,
|
||||
};
|
||||
use crate::macros::{rewrite_macro, MacroPosition};
|
||||
use crate::matches::rewrite_match;
|
||||
use crate::overflow::{self, IntoOverflowableItem, OverflowableItem};
|
||||
use crate::pairs::{rewrite_all_pairs, rewrite_pair, PairParts};
|
||||
use crate::patterns::is_short_pattern;
|
||||
use crate::rewrite::{Rewrite, RewriteContext};
|
||||
use crate::shape::{Indent, Shape};
|
||||
use crate::source_map::{LineRangeUtils, SpanUtils};
|
||||
@ -31,8 +30,8 @@ use crate::string::{rewrite_string, StringFormat};
|
||||
use crate::types::{rewrite_path, PathContext};
|
||||
use crate::utils::{
|
||||
colon_spaces, contains_skip, count_newlines, first_line_ends_with, inner_attributes,
|
||||
last_line_extendable, last_line_width, mk_sp, outer_attributes, ptr_vec_to_ref_vec,
|
||||
semicolon_for_expr, unicode_str_width, wrap_str,
|
||||
last_line_extendable, last_line_width, mk_sp, outer_attributes, semicolon_for_expr,
|
||||
unicode_str_width, wrap_str,
|
||||
};
|
||||
use crate::vertical::rewrite_with_alignment;
|
||||
use crate::visitor::FmtVisitor;
|
||||
@ -587,7 +586,7 @@ struct ControlFlow<'a> {
|
||||
block: &'a ast::Block,
|
||||
else_block: Option<&'a ast::Expr>,
|
||||
label: Option<ast::Label>,
|
||||
pats: Vec<&'a ast::Pat>,
|
||||
pat: Option<&'a ast::Pat>,
|
||||
keyword: &'a str,
|
||||
matcher: &'a str,
|
||||
connector: &'a str,
|
||||
@ -597,10 +596,10 @@ struct ControlFlow<'a> {
|
||||
span: Span,
|
||||
}
|
||||
|
||||
fn extract_pats_and_cond(expr: &ast::Expr) -> (Vec<&ast::Pat>, &ast::Expr) {
|
||||
fn extract_pats_and_cond(expr: &ast::Expr) -> (Option<&ast::Pat>, &ast::Expr) {
|
||||
match expr.node {
|
||||
ast::ExprKind::Let(ref pats, ref cond) => (ptr_vec_to_ref_vec(pats), cond),
|
||||
_ => (vec![], expr),
|
||||
ast::ExprKind::Let(ref pat, ref cond) => (Some(pat), cond),
|
||||
_ => (None, expr),
|
||||
}
|
||||
}
|
||||
|
||||
@ -608,10 +607,10 @@ fn extract_pats_and_cond(expr: &ast::Expr) -> (Vec<&ast::Pat>, &ast::Expr) {
|
||||
fn to_control_flow(expr: &ast::Expr, expr_type: ExprType) -> Option<ControlFlow<'_>> {
|
||||
match expr.node {
|
||||
ast::ExprKind::If(ref cond, ref if_block, ref else_block) => {
|
||||
let (pats, cond) = extract_pats_and_cond(cond);
|
||||
let (pat, cond) = extract_pats_and_cond(cond);
|
||||
Some(ControlFlow::new_if(
|
||||
cond,
|
||||
pats,
|
||||
pat,
|
||||
if_block,
|
||||
else_block.as_ref().map(|e| &**e),
|
||||
expr_type == ExprType::SubExpression,
|
||||
@ -626,34 +625,34 @@ fn to_control_flow(expr: &ast::Expr, expr_type: ExprType) -> Option<ControlFlow<
|
||||
Some(ControlFlow::new_loop(block, label, expr.span))
|
||||
}
|
||||
ast::ExprKind::While(ref cond, ref block, label) => {
|
||||
let (pats, cond) = extract_pats_and_cond(cond);
|
||||
Some(ControlFlow::new_while(pats, cond, block, label, expr.span))
|
||||
let (pat, cond) = extract_pats_and_cond(cond);
|
||||
Some(ControlFlow::new_while(pat, cond, block, label, expr.span))
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn choose_matcher(pats: &[&ast::Pat]) -> &'static str {
|
||||
if pats.is_empty() { "" } else { "let" }
|
||||
fn choose_matcher(pat: Option<&ast::Pat>) -> &'static str {
|
||||
pat.map_or("", |_| "let")
|
||||
}
|
||||
|
||||
impl<'a> ControlFlow<'a> {
|
||||
fn new_if(
|
||||
cond: &'a ast::Expr,
|
||||
pats: Vec<&'a ast::Pat>,
|
||||
pat: Option<&'a ast::Pat>,
|
||||
block: &'a ast::Block,
|
||||
else_block: Option<&'a ast::Expr>,
|
||||
allow_single_line: bool,
|
||||
nested_if: bool,
|
||||
span: Span,
|
||||
) -> ControlFlow<'a> {
|
||||
let matcher = choose_matcher(&pats);
|
||||
let matcher = choose_matcher(pat);
|
||||
ControlFlow {
|
||||
cond: Some(cond),
|
||||
block,
|
||||
else_block,
|
||||
label: None,
|
||||
pats,
|
||||
pat,
|
||||
keyword: "if",
|
||||
matcher,
|
||||
connector: " =",
|
||||
@ -669,7 +668,7 @@ impl<'a> ControlFlow<'a> {
|
||||
block,
|
||||
else_block: None,
|
||||
label,
|
||||
pats: vec![],
|
||||
pat: None,
|
||||
keyword: "loop",
|
||||
matcher: "",
|
||||
connector: "",
|
||||
@ -680,19 +679,19 @@ impl<'a> ControlFlow<'a> {
|
||||
}
|
||||
|
||||
fn new_while(
|
||||
pats: Vec<&'a ast::Pat>,
|
||||
pat: Option<&'a ast::Pat>,
|
||||
cond: &'a ast::Expr,
|
||||
block: &'a ast::Block,
|
||||
label: Option<ast::Label>,
|
||||
span: Span,
|
||||
) -> ControlFlow<'a> {
|
||||
let matcher = choose_matcher(&pats);
|
||||
let matcher = choose_matcher(pat);
|
||||
ControlFlow {
|
||||
cond: Some(cond),
|
||||
block,
|
||||
else_block: None,
|
||||
label,
|
||||
pats,
|
||||
pat,
|
||||
keyword: "while",
|
||||
matcher,
|
||||
connector: " =",
|
||||
@ -714,7 +713,7 @@ impl<'a> ControlFlow<'a> {
|
||||
block,
|
||||
else_block: None,
|
||||
label,
|
||||
pats: vec![pat],
|
||||
pat: Some(pat),
|
||||
keyword: "for",
|
||||
matcher: "",
|
||||
connector: " in",
|
||||
@ -790,10 +789,10 @@ impl<'a> ControlFlow<'a> {
|
||||
shape: Shape,
|
||||
offset: usize,
|
||||
) -> Option<String> {
|
||||
debug!("rewrite_pat_expr {:?} {:?} {:?}", shape, self.pats, expr);
|
||||
debug!("rewrite_pat_expr {:?} {:?} {:?}", shape, self.pat, expr);
|
||||
|
||||
let cond_shape = shape.offset_left(offset)?;
|
||||
if !self.pats.is_empty() {
|
||||
if !self.pat.is_none() {
|
||||
let matcher = if self.matcher.is_empty() {
|
||||
self.matcher.to_owned()
|
||||
} else {
|
||||
@ -802,7 +801,11 @@ impl<'a> ControlFlow<'a> {
|
||||
let pat_shape = cond_shape
|
||||
.offset_left(matcher.len())?
|
||||
.sub_width(self.connector.len())?;
|
||||
let pat_string = rewrite_multiple_patterns(context, &self.pats, pat_shape)?;
|
||||
let pat_string = if let Some(pat) = self.pat {
|
||||
pat.rewrite(context, pat_shape)?
|
||||
} else {
|
||||
"".to_owned()
|
||||
};
|
||||
let result = format!("{}{}{}", matcher, pat_string, self.connector);
|
||||
return rewrite_assign_rhs(context, result, expr, cond_shape);
|
||||
}
|
||||
@ -906,10 +909,10 @@ impl<'a> ControlFlow<'a> {
|
||||
context
|
||||
.snippet_provider
|
||||
.span_after(mk_sp(lo, self.span.hi()), self.keyword.trim()),
|
||||
if self.pats.is_empty() {
|
||||
if self.pat.is_none() {
|
||||
cond_span.lo()
|
||||
} else if self.matcher.is_empty() {
|
||||
self.pats[0].span.lo()
|
||||
self.pat.unwrap().span.lo()
|
||||
} else {
|
||||
context
|
||||
.snippet_provider
|
||||
@ -1145,39 +1148,6 @@ pub(crate) fn is_unsafe_block(block: &ast::Block) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn rewrite_multiple_patterns(
|
||||
context: &RewriteContext<'_>,
|
||||
pats: &[&ast::Pat],
|
||||
shape: Shape,
|
||||
) -> Option<String> {
|
||||
let pat_strs = pats
|
||||
.iter()
|
||||
.map(|p| p.rewrite(context, shape))
|
||||
.collect::<Option<Vec<_>>>()?;
|
||||
|
||||
let use_mixed_layout = pats
|
||||
.iter()
|
||||
.zip(pat_strs.iter())
|
||||
.all(|(pat, pat_str)| is_short_pattern(pat, pat_str));
|
||||
let items: Vec<_> = pat_strs.into_iter().map(ListItem::from_str).collect();
|
||||
let tactic = if use_mixed_layout {
|
||||
DefinitiveListTactic::Mixed
|
||||
} else {
|
||||
definitive_tactic(
|
||||
&items,
|
||||
ListTactic::HorizontalVertical,
|
||||
Separator::VerticalBar,
|
||||
shape.width,
|
||||
)
|
||||
};
|
||||
let fmt = ListFormatting::new(shape, context.config)
|
||||
.tactic(tactic)
|
||||
.separator(" |")
|
||||
.separator_place(context.config.binop_separator())
|
||||
.ends_with_newline(false);
|
||||
write_list(&items, &fmt)
|
||||
}
|
||||
|
||||
pub(crate) fn rewrite_literal(
|
||||
context: &RewriteContext<'_>,
|
||||
l: &ast::Lit,
|
||||
|
@ -58,10 +58,8 @@ impl From<io::Error> for FormatDiffError {
|
||||
#[derive(StructOpt, Debug)]
|
||||
#[structopt(
|
||||
name = "rustfmt-format-diff",
|
||||
author = "",
|
||||
about = "",
|
||||
raw(setting = "AppSettings::DisableVersion"),
|
||||
raw(setting = "AppSettings::NextLineHelp")
|
||||
setting = AppSettings::DisableVersion,
|
||||
setting = AppSettings::NextLineHelp
|
||||
)]
|
||||
pub struct Opts {
|
||||
/// Skip the smallest prefix containing NUMBER slashes
|
||||
@ -78,7 +76,7 @@ pub struct Opts {
|
||||
short = "f",
|
||||
long = "filter",
|
||||
value_name = "PATTERN",
|
||||
raw(default_value = "DEFAULT_PATTERN")
|
||||
default_value = DEFAULT_PATTERN
|
||||
)]
|
||||
filter: String,
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ use crate::config::lists::*;
|
||||
use crate::config::{Config, ControlBraceStyle, IndentStyle, Version};
|
||||
use crate::expr::{
|
||||
format_expr, is_empty_block, is_simple_block, is_unsafe_block, prefer_next_line, rewrite_cond,
|
||||
rewrite_multiple_patterns, ExprType, RhsTactics,
|
||||
ExprType, RhsTactics,
|
||||
};
|
||||
use crate::lists::{itemize_list, write_list, ListFormatting};
|
||||
use crate::rewrite::{Rewrite, RewriteContext};
|
||||
@ -19,7 +19,7 @@ use crate::source_map::SpanUtils;
|
||||
use crate::spanned::Spanned;
|
||||
use crate::utils::{
|
||||
contains_skip, extra_offset, first_line_width, inner_attributes, last_line_extendable, mk_sp,
|
||||
ptr_vec_to_ref_vec, semicolon_for_expr, trimmed_last_line_width, unicode_str_width,
|
||||
semicolon_for_expr, trimmed_last_line_width, unicode_str_width,
|
||||
};
|
||||
|
||||
/// A simple wrapper type against `ast::Arm`. Used inside `write_list()`.
|
||||
@ -161,7 +161,7 @@ fn collect_beginning_verts(
|
||||
let mut beginning_verts = Vec::with_capacity(arms.len());
|
||||
let mut lo = context.snippet_provider.span_after(span, "{");
|
||||
for arm in arms {
|
||||
let hi = arm.pats[0].span.lo();
|
||||
let hi = arm.pat.span.lo();
|
||||
let missing_span = mk_sp(lo, hi);
|
||||
beginning_verts.push(context.snippet_provider.opt_span_before(missing_span, "|"));
|
||||
lo = arm.span().hi();
|
||||
@ -225,10 +225,7 @@ fn rewrite_match_arm(
|
||||
arm_comma(context.config, body, is_last),
|
||||
));
|
||||
}
|
||||
let missing_span = mk_sp(
|
||||
arm.attrs[arm.attrs.len() - 1].span.hi(),
|
||||
arm.pats[0].span.lo(),
|
||||
);
|
||||
let missing_span = mk_sp(arm.attrs[arm.attrs.len() - 1].span.hi(), arm.pat.span.lo());
|
||||
(missing_span, arm.attrs.rewrite(context, shape)?)
|
||||
} else {
|
||||
(mk_sp(arm.span().lo(), arm.span().lo()), String::new())
|
||||
@ -237,7 +234,7 @@ fn rewrite_match_arm(
|
||||
// Patterns
|
||||
// 5 = ` => {`
|
||||
let pat_shape = shape.sub_width(5)?;
|
||||
let pats_str = rewrite_multiple_patterns(context, &ptr_vec_to_ref_vec(&arm.pats), pat_shape)?;
|
||||
let pats_str = arm.pat.rewrite(context, pat_shape)?;
|
||||
|
||||
// Guard
|
||||
let block_like_pat = trimmed_last_line_width(&pats_str) <= context.config.tab_spaces();
|
||||
@ -259,7 +256,7 @@ fn rewrite_match_arm(
|
||||
false,
|
||||
)?;
|
||||
|
||||
let arrow_span = mk_sp(arm.pats.last().unwrap().span.hi(), arm.body.span().lo());
|
||||
let arrow_span = mk_sp(arm.pat.span.hi(), arm.body.span().lo());
|
||||
rewrite_match_body(
|
||||
context,
|
||||
&arm.body,
|
||||
|
@ -7,7 +7,7 @@ use crate::config::lists::*;
|
||||
use crate::expr::{can_be_overflowed_expr, rewrite_unary_prefix, wrap_struct_field};
|
||||
use crate::lists::{
|
||||
definitive_tactic, itemize_list, shape_for_tactic, struct_lit_formatting, struct_lit_shape,
|
||||
struct_lit_tactic, write_list, ListFormatting, Separator,
|
||||
struct_lit_tactic, write_list, ListFormatting, ListItem, Separator,
|
||||
};
|
||||
use crate::macros::{rewrite_macro, MacroPosition};
|
||||
use crate::overflow;
|
||||
@ -59,30 +59,32 @@ impl Rewrite for Pat {
|
||||
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
|
||||
match self.node {
|
||||
PatKind::Or(ref pats) => {
|
||||
let pat_items = itemize_list(
|
||||
context.snippet_provider,
|
||||
pats.iter(),
|
||||
"",
|
||||
"|",
|
||||
|pat| pat.span().lo(),
|
||||
|pat| pat.span().hi(),
|
||||
|pat| pat.rewrite(context, shape),
|
||||
self.span.lo(),
|
||||
self.span.hi(),
|
||||
false,
|
||||
);
|
||||
let pat_vec: Vec<_> = pat_items.collect();
|
||||
let tactic = definitive_tactic(
|
||||
&pat_vec,
|
||||
ListTactic::HorizontalVertical,
|
||||
Separator::VerticalBar,
|
||||
shape.width,
|
||||
);
|
||||
let pat_strs = pats
|
||||
.iter()
|
||||
.map(|p| p.rewrite(context, shape))
|
||||
.collect::<Option<Vec<_>>>()?;
|
||||
|
||||
let use_mixed_layout = pats
|
||||
.iter()
|
||||
.zip(pat_strs.iter())
|
||||
.all(|(pat, pat_str)| is_short_pattern(pat, pat_str));
|
||||
let items: Vec<_> = pat_strs.into_iter().map(ListItem::from_str).collect();
|
||||
let tactic = if use_mixed_layout {
|
||||
DefinitiveListTactic::Mixed
|
||||
} else {
|
||||
definitive_tactic(
|
||||
&items,
|
||||
ListTactic::HorizontalVertical,
|
||||
Separator::VerticalBar,
|
||||
shape.width,
|
||||
)
|
||||
};
|
||||
let fmt = ListFormatting::new(shape, context.config)
|
||||
.tactic(tactic)
|
||||
.trailing_separator(SeparatorTactic::Never)
|
||||
.separator(" |");
|
||||
write_list(&pat_vec, &fmt)
|
||||
.separator(" |")
|
||||
.separator_place(context.config.binop_separator())
|
||||
.ends_with_newline(false);
|
||||
write_list(&items, &fmt)
|
||||
}
|
||||
PatKind::Box(ref pat) => rewrite_unary_prefix(context, "box ", &**pat, shape),
|
||||
PatKind::Ident(binding_mode, ident, ref sub_pat) => {
|
||||
|
@ -3,8 +3,6 @@ use std::fmt;
|
||||
use std::io;
|
||||
use std::io::Write;
|
||||
|
||||
use diff;
|
||||
|
||||
use crate::config::{Color, Config, Verbosity};
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
|
@ -96,7 +96,7 @@ impl Spanned for ast::Ty {
|
||||
impl Spanned for ast::Arm {
|
||||
fn span(&self) -> Span {
|
||||
let lo = if self.attrs.is_empty() {
|
||||
self.pats[0].span.lo()
|
||||
self.pat.span.lo()
|
||||
} else {
|
||||
self.attrs[0].span.lo()
|
||||
};
|
||||
|
@ -1,7 +1,5 @@
|
||||
use std::borrow::Cow;
|
||||
|
||||
use bytecount;
|
||||
|
||||
use rustc_target::spec::abi;
|
||||
use syntax::ast::{
|
||||
self, Attribute, CrateSugar, MetaItem, MetaItemKind, NestedMetaItem, NodeId, Path, Visibility,
|
||||
|
Loading…
x
Reference in New Issue
Block a user