Skip to content

Commit d6bcfce

Browse files
nrcmarcusklaas
authored andcommitted
Don't put a newline before ? when it is the second sub-expression in a chain (#1012)
Fixes #1003
1 parent 775de8a commit d6bcfce

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

src/chains.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,9 @@ pub fn rewrite_chain(expr: &ast::Expr,
179179
format!("\n{}", indent.to_string(context.config))
180180
};
181181

182-
let first_connector = if extend {
182+
let first_connector = if extend || subexpr_list.len() == 0 {
183+
""
184+
} else if let ast::ExprKind::Try(_) = subexpr_list[0].node {
183185
""
184186
} else {
185187
&*connector

tests/source/chains.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,12 @@ fn try_shorthand() {
124124
let y = a.very .loooooooooooooooooooooooooooooooooooooong() .chain()
125125
.inside() .weeeeeeeeeeeeeee()? .test() .0
126126
.x;
127+
128+
parameterized(f,
129+
substs,
130+
def_id,
131+
Ns::Value,
132+
&[],
133+
|tcx| tcx.lookup_item_type(def_id).generics)?;
134+
fooooooooooooooooooooooooooo()?.bar()?.baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz()?;
127135
}

tests/target/chains.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,14 @@ fn try_shorthand() {
151151
.test()
152152
.0
153153
.x;
154+
155+
parameterized(f,
156+
substs,
157+
def_id,
158+
Ns::Value,
159+
&[],
160+
|tcx| tcx.lookup_item_type(def_id).generics)?;
161+
fooooooooooooooooooooooooooo()?
162+
.bar()?
163+
.baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz()?;
154164
}

0 commit comments

Comments
 (0)