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

+1-3
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

+14-9
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

+1-3
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

+2-1
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

+7-6
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

+1-2
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

+3-1
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

+4-2
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

+10-11
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

+2-1
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:

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

+11-9
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,14 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
2323
let error = self.error.as_ref()?;
2424
debug!("try_report_impl_not_conforming_to_trait {:?}", error);
2525
if let RegionResolutionError::SubSupConflict(
26-
_, var_origin, sub_origin, _sub, sup_origin, _sup, _,
27-
) = error.clone()
26+
_,
27+
var_origin,
28+
sub_origin,
29+
_sub,
30+
sup_origin,
31+
_sup,
32+
_,
33+
) = error.clone()
2834
&& let (&Subtype(ref sup_trace), &Subtype(ref sub_trace)) = (&sup_origin, &sub_origin)
2935
&& let (
3036
sub_expected_found @ Some((sub_expected, sub_found)),
@@ -33,16 +39,12 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
3339
) = (sub_trace.values.ty(), sup_trace.values.ty(), sub_trace.cause.code())
3440
&& sup_expected_found == sub_expected_found
3541
{
36-
let guar = self.emit_err(
37-
var_origin.span(),
38-
sub_expected,
39-
sub_found,
40-
*trait_item_def_id,
41-
);
42+
let guar =
43+
self.emit_err(var_origin.span(), sub_expected, sub_found, *trait_item_def_id);
4244
return Some(guar);
4345
}
4446
if let RegionResolutionError::ConcreteFailure(origin, _, _)
45-
| RegionResolutionError::GenericBoundFailure(origin, _, _) = error.clone()
47+
| RegionResolutionError::GenericBoundFailure(origin, _, _) = error.clone()
4648
&& let SubregionOrigin::CompareImplTypeObligation {
4749
span,
4850
impl_item_def_id,

compiler/rustc_lint/src/internal.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl LateLintPass<'_> for QueryStability {
7777
if let Some(def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id) =>
7878
{
7979
(segment.ident.span, def_id, cx.typeck_results().node_substs(expr.hir_id))
80-
},
80+
}
8181
_ => {
8282
let &ty::FnDef(def_id, substs) =
8383
cx.typeck_results()

compiler/rustc_lint/src/types.rs

+32-29
Original file line numberDiff line numberDiff line change
@@ -1500,7 +1500,8 @@ impl InvalidAtomicOrdering {
15001500
fn check_atomic_load_store(cx: &LateContext<'_>, expr: &Expr<'_>) {
15011501
use rustc_hir::def::{DefKind, Res};
15021502
use rustc_hir::QPath;
1503-
if let Some((method, args)) = Self::inherent_atomic_method_call(cx, expr, &[sym::load, sym::store])
1503+
if let Some((method, args)) =
1504+
Self::inherent_atomic_method_call(cx, expr, &[sym::load, sym::store])
15041505
&& let Some((ordering_arg, invalid_ordering)) = match method {
15051506
sym::load => Some((&args[1], sym::Release)),
15061507
sym::store => Some((&args[2], sym::Acquire)),
@@ -1536,56 +1537,58 @@ impl InvalidAtomicOrdering {
15361537
{
15371538
cx.struct_span_lint(INVALID_ATOMIC_ORDERING, args[0].span, |diag| {
15381539
diag.build("memory fences cannot have `Relaxed` ordering")
1539-
.help("consider using ordering modes `Acquire`, `Release`, `AcqRel` or `SeqCst`")
1540+
.help(
1541+
"consider using ordering modes `Acquire`, `Release`, `AcqRel` or `SeqCst`",
1542+
)
15401543
.emit();
15411544
});
15421545
}
15431546
}
15441547

15451548
fn check_atomic_compare_exchange(cx: &LateContext<'_>, expr: &Expr<'_>) {
1546-
if let Some((method, args)) = Self::inherent_atomic_method_call(cx, expr, &[sym::fetch_update, sym::compare_exchange, sym::compare_exchange_weak])
1547-
&& let Some((success_order_arg, failure_order_arg)) = match method {
1548-
sym::fetch_update => Some((&args[1], &args[2])),
1549-
sym::compare_exchange | sym::compare_exchange_weak => Some((&args[3], &args[4])),
1550-
_ => None,
1551-
}
1552-
&& let Some(fail_ordering_def_id) = Self::opt_ordering_defid(cx, failure_order_arg)
1549+
if let Some((method, args)) = Self::inherent_atomic_method_call(
1550+
cx,
1551+
expr,
1552+
&[sym::fetch_update, sym::compare_exchange, sym::compare_exchange_weak],
1553+
) && let Some((success_order_arg, failure_order_arg)) = match method {
1554+
sym::fetch_update => Some((&args[1], &args[2])),
1555+
sym::compare_exchange | sym::compare_exchange_weak => Some((&args[3], &args[4])),
1556+
_ => None,
1557+
} && let Some(fail_ordering_def_id) = Self::opt_ordering_defid(cx, failure_order_arg)
15531558
{
15541559
// Helper type holding on to some checking and error reporting data. Has
15551560
// - (success ordering,
15561561
// - list of failure orderings forbidden by the success order,
15571562
// - suggestion message)
15581563
type OrdLintInfo = (Symbol, &'static [Symbol], &'static str);
1559-
const RELAXED: OrdLintInfo = (sym::Relaxed, &[sym::SeqCst, sym::Acquire], "ordering mode `Relaxed`");
1560-
const ACQUIRE: OrdLintInfo = (sym::Acquire, &[sym::SeqCst], "ordering modes `Acquire` or `Relaxed`");
1561-
const SEQ_CST: OrdLintInfo = (sym::SeqCst, &[], "ordering modes `Acquire`, `SeqCst` or `Relaxed`");
1564+
const RELAXED: OrdLintInfo =
1565+
(sym::Relaxed, &[sym::SeqCst, sym::Acquire], "ordering mode `Relaxed`");
1566+
const ACQUIRE: OrdLintInfo =
1567+
(sym::Acquire, &[sym::SeqCst], "ordering modes `Acquire` or `Relaxed`");
1568+
const SEQ_CST: OrdLintInfo =
1569+
(sym::SeqCst, &[], "ordering modes `Acquire`, `SeqCst` or `Relaxed`");
15621570
const RELEASE: OrdLintInfo = (sym::Release, RELAXED.1, RELAXED.2);
15631571
const ACQREL: OrdLintInfo = (sym::AcqRel, ACQUIRE.1, ACQUIRE.2);
15641572
const SEARCH: [OrdLintInfo; 5] = [RELAXED, ACQUIRE, SEQ_CST, RELEASE, ACQREL];
15651573

1566-
let success_lint_info = Self::opt_ordering_defid(cx, success_order_arg)
1567-
.and_then(|success_ord_def_id| -> Option<OrdLintInfo> {
1568-
SEARCH
1569-
.iter()
1570-
.copied()
1571-
.find(|(ordering, ..)| {
1572-
Self::matches_ordering(cx, success_ord_def_id, &[*ordering])
1573-
})
1574-
});
1574+
let success_lint_info = Self::opt_ordering_defid(cx, success_order_arg).and_then(
1575+
|success_ord_def_id| -> Option<OrdLintInfo> {
1576+
SEARCH.iter().copied().find(|(ordering, ..)| {
1577+
Self::matches_ordering(cx, success_ord_def_id, &[*ordering])
1578+
})
1579+
},
1580+
);
15751581
if Self::matches_ordering(cx, fail_ordering_def_id, &[sym::Release, sym::AcqRel]) {
15761582
// If we don't know the success order is, use what we'd suggest
15771583
// if it were maximally permissive.
15781584
let suggested = success_lint_info.unwrap_or(SEQ_CST).2;
15791585
cx.struct_span_lint(INVALID_ATOMIC_ORDERING, failure_order_arg.span, |diag| {
1580-
let msg = format!(
1581-
"{}'s failure ordering may not be `Release` or `AcqRel`",
1582-
method,
1583-
);
1584-
diag.build(&msg)
1585-
.help(&format!("consider using {} instead", suggested))
1586-
.emit();
1586+
let msg =
1587+
format!("{}'s failure ordering may not be `Release` or `AcqRel`", method,);
1588+
diag.build(&msg).help(&format!("consider using {} instead", suggested)).emit();
15871589
});
1588-
} else if let Some((success_ord, bad_ords_given_success, suggested)) = success_lint_info {
1590+
} else if let Some((success_ord, bad_ords_given_success, suggested)) = success_lint_info
1591+
{
15891592
if Self::matches_ordering(cx, fail_ordering_def_id, bad_ords_given_success) {
15901593
cx.struct_span_lint(INVALID_ATOMIC_ORDERING, failure_order_arg.span, |diag| {
15911594
let msg = format!(

compiler/rustc_middle/src/ty/print/pretty.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -910,9 +910,10 @@ pub trait PrettyPrinter<'tcx>:
910910

911911
for (assoc_item_def_id, term) in assoc_items {
912912
// Skip printing `<[generator@] as Generator<_>>::Return` from async blocks
913-
if let Some(ty) = term.skip_binder().ty() &&
914-
let ty::Projection(ty::ProjectionTy { item_def_id, .. }) = ty.kind() &&
915-
Some(*item_def_id) == self.tcx().lang_items().generator_return() {
913+
if let Some(ty) = term.skip_binder().ty()
914+
&& let ty::Projection(ty::ProjectionTy { item_def_id, .. }) = ty.kind()
915+
&& Some(*item_def_id) == self.tcx().lang_items().generator_return()
916+
{
916917
continue;
917918
}
918919

@@ -1202,14 +1203,12 @@ pub trait PrettyPrinter<'tcx>:
12021203
}
12031204
}
12041205
}
1205-
ty::ConstKind::Infer(infer_ct) => {
1206-
match infer_ct {
1207-
ty::InferConst::Var(ct_vid)
1208-
if let Some(name) = self.const_infer_name(ct_vid) =>
1209-
p!(write("{}", name)),
1210-
_ => print_underscore!(),
1206+
ty::ConstKind::Infer(infer_ct) => match infer_ct {
1207+
ty::InferConst::Var(ct_vid) if let Some(name) = self.const_infer_name(ct_vid) => {
1208+
p!(write("{}", name))
12111209
}
1212-
}
1210+
_ => print_underscore!(),
1211+
},
12131212
ty::ConstKind::Param(ParamConst { name, .. }) => p!(write("{}", name)),
12141213
ty::ConstKind::Value(value) => {
12151214
return self.pretty_print_const_value(value, ct.ty(), print_ty);

0 commit comments

Comments
 (0)