Skip to content

Commit

Permalink
feat: v2 support for nested tuples w/o spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
calebcartwright committed Oct 30, 2020
1 parent bc755f3 commit 63f172d
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/chains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ use rustc_ast::{ast, ptr};
use rustc_span::{symbol, BytePos, Span};

use crate::comment::{rewrite_comment, CharClasses, FullCodeCharKind, RichChar};
use crate::config::IndentStyle;
use crate::config::{IndentStyle, Version};
use crate::expr::rewrite_call;
use crate::lists::extract_pre_comment;
use crate::macros::convert_try_mac;
Expand Down Expand Up @@ -200,7 +200,11 @@ impl Rewrite for ChainItem {
ChainItemKind::StructField(ident) => format!(".{}", rewrite_ident(context, ident)),
ChainItemKind::TupleField(ident, nested) => format!(
"{}.{}",
if nested { " " } else { "" },
if nested && context.config.version() == Version::One {
" "
} else {
""
},
rewrite_ident(context, ident)
),
ChainItemKind::Await => ".await".to_owned(),
Expand Down
11 changes: 11 additions & 0 deletions tests/source/tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,14 @@ fn issue1725() {
bench_antialiased_lines!(bench_draw_antialiased_line_segment_diagonal, (10, 10), (450, 450));
bench_antialiased_lines!(bench_draw_antialiased_line_segment_shallow, (10, 10), (450, 80));
}

fn issue_4355() {
let _ = ((1,),).0.0;
}

// https://github.com/rust-lang/rustfmt/issues/4410
impl Drop for LockGuard {
fn drop(&mut self) {
LockMap::unlock(&self.0.0, &self.0.1);
}
}
5 changes: 5 additions & 0 deletions tests/source/tuple_v2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// rustfmt-version: Two

fn issue_4355() {
let _ = ((1,),).0 .0;
}
11 changes: 11 additions & 0 deletions tests/target/tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,14 @@ fn issue1725() {
(450, 80)
);
}

fn issue_4355() {
let _ = ((1,),).0 .0;
}

// https://github.com/rust-lang/rustfmt/issues/4410
impl Drop for LockGuard {
fn drop(&mut self) {
LockMap::unlock(&self.0 .0, &self.0 .1);
}
}
5 changes: 5 additions & 0 deletions tests/target/tuple_v2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// rustfmt-version: Two

fn issue_4355() {
let _ = ((1,),).0.0;
}

0 comments on commit 63f172d

Please sign in to comment.