Skip to content

Commit 0578555

Browse files
Format the world (considering let-chains)
1 parent 37b55c8 commit 0578555

File tree

44 files changed

+368
-362
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+368
-362
lines changed

compiler/rustc_ast/src/attr/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -595,9 +595,7 @@ impl NestedMetaItem {
595595
I: Iterator<Item = TokenTree>,
596596
{
597597
match tokens.peek() {
598-
Some(TokenTree::Token(token))
599-
if let Ok(lit) = Lit::from_token(token) =>
600-
{
598+
Some(TokenTree::Token(token)) if let Ok(lit) = Lit::from_token(token) => {
601599
tokens.next();
602600
return Some(NestedMetaItem::Literal(lit));
603601
}

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,8 +1003,10 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
10031003
}
10041004

10051005
fn visit_expr(&mut self, expr: &'a Expr) {
1006-
self.with_let_management(Some(ForbiddenLetReason::GenericForbidden), |this, forbidden_let_reason| {
1007-
match &expr.kind {
1006+
self.with_let_management(
1007+
Some(ForbiddenLetReason::GenericForbidden),
1008+
|this, forbidden_let_reason| {
1009+
match &expr.kind {
10081010
ExprKind::Binary(Spanned { node: BinOpKind::Or, span }, lhs, rhs) => {
10091011
let forbidden_let_reason = Some(ForbiddenLetReason::ForbiddenWithOr(*span));
10101012
this.with_let_management(forbidden_let_reason, |this, _| this.visit_expr(lhs));
@@ -1018,23 +1020,25 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
10181020
}
10191021
ExprKind::Let(..) if let Some(elem) = forbidden_let_reason => {
10201022
this.ban_let_expr(expr, elem);
1021-
},
1023+
}
10221024
ExprKind::Match(scrutinee, arms) => {
10231025
this.visit_expr(scrutinee);
10241026
for arm in arms {
10251027
this.visit_expr(&arm.body);
10261028
this.visit_pat(&arm.pat);
10271029
walk_list!(this, visit_attribute, &arm.attrs);
1028-
if let Some(guard) = &arm.guard && let ExprKind::Let(_, guard_expr, _) = &guard.kind {
1029-
this.with_let_management(None, |this, _| {
1030-
this.visit_expr(guard_expr)
1031-
});
1030+
if let Some(guard) = &arm.guard
1031+
&& let ExprKind::Let(_, guard_expr, _) = &guard.kind
1032+
{
1033+
this.with_let_management(None, |this, _| this.visit_expr(guard_expr));
10321034
return;
10331035
}
10341036
}
10351037
}
10361038
ExprKind::Paren(_) | ExprKind::Binary(Spanned { node: BinOpKind::And, .. }, ..) => {
1037-
this.with_let_management(forbidden_let_reason, |this, _| visit::walk_expr(this, expr));
1039+
this.with_let_management(forbidden_let_reason, |this, _| {
1040+
visit::walk_expr(this, expr)
1041+
});
10381042
return;
10391043
}
10401044
ExprKind::While(cond, then, opt_label) => {
@@ -1045,7 +1049,8 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
10451049
}
10461050
_ => visit::walk_expr(this, expr),
10471051
}
1048-
});
1052+
},
1053+
);
10491054
}
10501055

10511056
fn visit_ty(&mut self, ty: &'a Ty) {

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1840,9 +1840,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
18401840
err.span_label(assigned_span, format!("first assignment to {}", place_description));
18411841
}
18421842
}
1843-
if let Some(decl) = local_decl
1844-
&& let Some(name) = local_name
1845-
&& decl.can_be_made_mutable()
1843+
if let Some(decl) = local_decl && let Some(name) = local_name && decl.can_be_made_mutable()
18461844
{
18471845
err.span_suggestion(
18481846
decl.source_info.span,

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
378378
if self.local_names[local].is_some()
379379
&& let Some((WriteKind::StorageDeadOrDrop, place)) = kind_place
380380
&& let Some(borrowed_local) = place.as_local()
381-
&& self.local_names[borrowed_local].is_some() && local != borrowed_local
381+
&& self.local_names[borrowed_local].is_some()
382+
&& local != borrowed_local
382383
{
383384
should_note_order = true;
384385
}

compiler/rustc_expand/src/config.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,8 @@ impl<'a> StripUnconfigured<'a> {
290290
let trees: Vec<_> = stream
291291
.0
292292
.iter()
293-
.flat_map(|(tree, spacing)| match tree.clone() {
293+
.flat_map(|(tree, spacing)| {
294+
match tree.clone() {
294295
AttrAnnotatedTokenTree::Attributes(mut data) => {
295296
let mut attrs: Vec<_> = std::mem::take(&mut data.attrs).into();
296297
attrs.flat_map_in_place(|attr| self.process_cfg_attr(attr));
@@ -310,15 +311,15 @@ impl<'a> StripUnconfigured<'a> {
310311
Some((AttrAnnotatedTokenTree::Delimited(sp, delim, inner), *spacing))
311312
.into_iter()
312313
}
313-
AttrAnnotatedTokenTree::Token(ref token) if let TokenKind::Interpolated(ref nt) = token.kind => {
314-
panic!(
315-
"Nonterminal should have been flattened at {:?}: {:?}",
316-
token.span, nt
317-
);
314+
AttrAnnotatedTokenTree::Token(ref token)
315+
if let TokenKind::Interpolated(ref nt) = token.kind =>
316+
{
317+
panic!("Nonterminal should have been flattened at {:?}: {:?}", token.span, nt);
318318
}
319319
AttrAnnotatedTokenTree::Token(token) => {
320320
Some((AttrAnnotatedTokenTree::Token(token), *spacing)).into_iter()
321321
}
322+
}
322323
})
323324
.collect();
324325
AttrAnnotatedTokenStream::new(trees)

compiler/rustc_expand/src/mbe/metavar_expr.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,7 @@ fn parse_depth<'sess>(
115115
&& let Ok(n_usize) = usize::try_from(n_u128)
116116
{
117117
Ok(n_usize)
118-
}
119-
else {
118+
} else {
120119
let msg = "only unsuffixes integer literals are supported in meta-variable expressions";
121120
Err(sess.span_diagnostic.struct_span_err(span, msg))
122121
}

compiler/rustc_expand/src/module.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ crate fn mod_dir_path(
8787
inline: Inline,
8888
) -> (PathBuf, DirOwnership) {
8989
match inline {
90-
Inline::Yes if let Some(file_path) = mod_file_path_from_attr(sess, attrs, &module.dir_path) => {
90+
Inline::Yes
91+
if let Some(file_path) = mod_file_path_from_attr(sess, attrs, &module.dir_path) =>
92+
{
9193
// For inline modules file path from `#[path]` is actually the directory path
9294
// for historical reasons, so we don't pop the last segment here.
9395
(file_path, DirOwnership::Owned { relative: None })

compiler/rustc_infer/src/infer/error_reporting/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
607607
err.span_label(span, format!("this expression has type `{}`", ty));
608608
}
609609
if let Some(ty::error::ExpectedFound { found, .. }) = exp_found
610-
&& ty.is_box() && ty.boxed_ty() == found
610+
&& ty.is_box()
611+
&& ty.boxed_ty() == found
611612
&& let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span)
612613
{
613614
err.span_suggestion(
@@ -2047,7 +2048,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
20472048
// specify a character literal (issue #92479)
20482049
(ty::Char, ty::Ref(_, r, _)) if r.is_str() => {
20492050
if let Ok(code) = self.tcx.sess().source_map().span_to_snippet(span)
2050-
&& let Some(code) = code.strip_prefix('"').and_then(|s| s.strip_suffix('"'))
2051+
&& let Some(code) =
2052+
code.strip_prefix('"').and_then(|s| s.strip_suffix('"'))
20512053
&& code.chars().count() == 1
20522054
{
20532055
err.span_suggestion(

compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,13 @@ impl<'a, 'tcx> Visitor<'tcx> for FindHirNodeVisitor<'a, 'tcx> {
124124
}
125125
if let ExprKind::MethodCall(segment, exprs, _) = expr.kind
126126
&& segment.ident.span == self.target_span
127-
&& Some(self.target) == self.infcx.in_progress_typeck_results.and_then(|typeck_results| {
128-
typeck_results
129-
.borrow()
130-
.node_type_opt(exprs.first().unwrap().hir_id)
131-
.map(Into::into)
132-
})
127+
&& Some(self.target)
128+
== self.infcx.in_progress_typeck_results.and_then(|typeck_results| {
129+
typeck_results
130+
.borrow()
131+
.node_type_opt(exprs.first().unwrap().hir_id)
132+
.map(Into::into)
133+
})
133134
{
134135
self.found_exact_method_call = Some(&expr);
135136
return;
@@ -731,17 +732,15 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
731732
// | help: specify type like: `<Impl as Into<u32>>::into(foo_impl)`
732733
// |
733734
// = note: cannot satisfy `Impl: Into<_>`
734-
if !impl_candidates.is_empty() && e.span.contains(span)
735+
if !impl_candidates.is_empty()
736+
&& e.span.contains(span)
735737
&& let Some(expr) = exprs.first()
736738
&& let ExprKind::Path(hir::QPath::Resolved(_, path)) = expr.kind
737739
&& let [path_segment] = path.segments
738740
{
739741
let candidate_len = impl_candidates.len();
740742
let suggestions = impl_candidates.iter().map(|candidate| {
741-
format!(
742-
"{}::{}({})",
743-
candidate, segment.ident, path_segment.ident
744-
)
743+
format!("{}::{}({})", candidate, segment.ident, path_segment.ident)
745744
});
746745
err.span_suggestions(
747746
e.span,

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
237237
ObligationCauseCode::MatchImpl(parent, ..) => parent.code(),
238238
_ => cause.code(),
239239
}
240-
&& let (ObligationCauseCode::ItemObligation(item_def_id), None) = (code, override_error_code)
240+
&& let (ObligationCauseCode::ItemObligation(item_def_id), None) =
241+
(code, override_error_code)
241242
{
242243
// Same case of `impl Foo for dyn Bar { fn qux(&self) {} }` introducing a `'static`
243244
// lifetime as above, but called using a fully-qualified path to the method:

0 commit comments

Comments
 (0)