mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 16:54:01 +00:00
Merge branch 'master' of https://github.com/rust-lang-nursery/rustfmt into fix-use-bug
This commit is contained in:
commit
d832525809
@ -336,29 +336,28 @@ fn rewrite_tuple_pat(
|
||||
));
|
||||
pat_vec.insert(pos, dotdot);
|
||||
}
|
||||
|
||||
if pat_vec.is_empty() {
|
||||
return Some(format!("{}()", path_str.unwrap_or_default()));
|
||||
}
|
||||
|
||||
let wildcard_suffix_len = count_wildcard_suffix_len(context, &pat_vec, span, shape);
|
||||
let (pat_vec, span) = if context.config.condense_wildcard_suffixes() && wildcard_suffix_len >= 2
|
||||
{
|
||||
let new_item_count = 1 + pat_vec.len() - wildcard_suffix_len;
|
||||
let sp = pat_vec[new_item_count - 1].span();
|
||||
let snippet = context.snippet(sp);
|
||||
let lo = sp.lo() + BytePos(snippet.find_uncommented("_").unwrap() as u32);
|
||||
pat_vec[new_item_count - 1] = TuplePatField::Dotdot(mk_sp(lo, lo + BytePos(1)));
|
||||
(
|
||||
&pat_vec[..new_item_count],
|
||||
mk_sp(span.lo(), lo + BytePos(1)),
|
||||
)
|
||||
} else {
|
||||
(&pat_vec[..], span)
|
||||
};
|
||||
let (pat_vec, span, condensed) =
|
||||
if context.config.condense_wildcard_suffixes() && wildcard_suffix_len >= 2 {
|
||||
let new_item_count = 1 + pat_vec.len() - wildcard_suffix_len;
|
||||
let sp = pat_vec[new_item_count - 1].span();
|
||||
let snippet = context.snippet(sp);
|
||||
let lo = sp.lo() + BytePos(snippet.find_uncommented("_").unwrap() as u32);
|
||||
pat_vec[new_item_count - 1] = TuplePatField::Dotdot(mk_sp(lo, lo + BytePos(1)));
|
||||
(
|
||||
&pat_vec[..new_item_count],
|
||||
mk_sp(span.lo(), lo + BytePos(1)),
|
||||
true,
|
||||
)
|
||||
} else {
|
||||
(&pat_vec[..], span, false)
|
||||
};
|
||||
|
||||
// add comma if `(x,)`
|
||||
let add_comma = path_str.is_none() && pat_vec.len() == 1 && dotdot_pos.is_none();
|
||||
let add_comma = path_str.is_none() && pat_vec.len() == 1 && dotdot_pos.is_none() && !condensed;
|
||||
let path_str = path_str.unwrap_or_default();
|
||||
let pat_ref_vec = pat_vec.iter().collect::<Vec<_>>();
|
||||
|
||||
|
6
tests/source/issue-2955.rs
Normal file
6
tests/source/issue-2955.rs
Normal file
@ -0,0 +1,6 @@
|
||||
// rustfmt-condense_wildcard_suffixes: true
|
||||
fn main() {
|
||||
match (1, 2, 3) {
|
||||
(_, _, _) => (),
|
||||
}
|
||||
}
|
6
tests/target/issue-2955.rs
Normal file
6
tests/target/issue-2955.rs
Normal file
@ -0,0 +1,6 @@
|
||||
// rustfmt-condense_wildcard_suffixes: true
|
||||
fn main() {
|
||||
match (1, 2, 3) {
|
||||
(..) => (),
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user