Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6648575

Browse files
authoredMar 17, 2025
Unrolled build for rust-lang#138590
Rollup merge of rust-lang#138590 - yotamofek:pr/flatten-ifs, r=fmease Flatten and simplify some control flow 🫓
2 parents 9bad8ac + 51e8309 commit 6648575

File tree

6 files changed

+53
-69
lines changed

6 files changed

+53
-69
lines changed
 

‎compiler/rustc_borrowck/src/lib.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -2479,19 +2479,15 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
24792479
let body = self.body;
24802480
for local in body.mut_vars_and_args_iter().filter(|local| !self.used_mut.contains(local)) {
24812481
let local_decl = &body.local_decls[local];
2482-
let lint_root = match &body.source_scopes[local_decl.source_info.scope].local_data {
2483-
ClearCrossCrate::Set(data) => data.lint_root,
2484-
_ => continue,
2482+
let ClearCrossCrate::Set(SourceScopeLocalData { lint_root, .. }) =
2483+
body.source_scopes[local_decl.source_info.scope].local_data
2484+
else {
2485+
continue;
24852486
};
24862487

24872488
// Skip over locals that begin with an underscore or have no name
2488-
match self.local_names[local] {
2489-
Some(name) => {
2490-
if name.as_str().starts_with('_') {
2491-
continue;
2492-
}
2493-
}
2494-
None => continue,
2489+
if self.local_names[local].is_none_or(|name| name.as_str().starts_with('_')) {
2490+
continue;
24952491
}
24962492

24972493
let span = local_decl.source_info.span;

‎compiler/rustc_hir_analysis/src/check/mod.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,9 @@ pub(super) fn maybe_check_static_with_link_section(tcx: TyCtxt<'_>, id: LocalDef
153153
}
154154

155155
// If `#[link_section]` is missing, then nothing to verify
156-
let attrs = tcx.codegen_fn_attrs(id);
157-
if attrs.link_section.is_none() {
156+
let Some(link_section) = tcx.codegen_fn_attrs(id).link_section else {
158157
return;
159-
}
158+
};
160159

161160
// For the wasm32 target statics with `#[link_section]` other than `.init_array`
162161
// are placed into custom sections of the final output file, but this isn't like
@@ -182,11 +181,8 @@ pub(super) fn maybe_check_static_with_link_section(tcx: TyCtxt<'_>, id: LocalDef
182181
// continue to work, but would no longer be necessary.
183182

184183
if let Ok(alloc) = tcx.eval_static_initializer(id.to_def_id())
185-
&& alloc.inner().provenance().ptrs().len() != 0
186-
&& attrs
187-
.link_section
188-
.map(|link_section| !link_section.as_str().starts_with(".init_array"))
189-
.unwrap()
184+
&& !alloc.inner().provenance().ptrs().is_empty()
185+
&& !link_section.as_str().starts_with(".init_array")
190186
{
191187
let msg = "statics with a custom `#[link_section]` must be a \
192188
simple list of bytes on the wasm target with no \

‎compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

+22-23
Original file line numberDiff line numberDiff line change
@@ -1532,30 +1532,29 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15321532
if self.may_coerce(blk_ty, *elem_ty)
15331533
&& blk.stmts.is_empty()
15341534
&& blk.rules == hir::BlockCheckMode::DefaultBlock
1535+
&& let source_map = self.tcx.sess.source_map()
1536+
&& let Ok(snippet) = source_map.span_to_snippet(blk.span)
1537+
&& snippet.starts_with('{')
1538+
&& snippet.ends_with('}')
15351539
{
1536-
let source_map = self.tcx.sess.source_map();
1537-
if let Ok(snippet) = source_map.span_to_snippet(blk.span) {
1538-
if snippet.starts_with('{') && snippet.ends_with('}') {
1539-
diag.multipart_suggestion_verbose(
1540-
"to create an array, use square brackets instead of curly braces",
1541-
vec![
1542-
(
1543-
blk.span
1544-
.shrink_to_lo()
1545-
.with_hi(rustc_span::BytePos(blk.span.lo().0 + 1)),
1546-
"[".to_string(),
1547-
),
1548-
(
1549-
blk.span
1550-
.shrink_to_hi()
1551-
.with_lo(rustc_span::BytePos(blk.span.hi().0 - 1)),
1552-
"]".to_string(),
1553-
),
1554-
],
1555-
Applicability::MachineApplicable,
1556-
);
1557-
}
1558-
}
1540+
diag.multipart_suggestion_verbose(
1541+
"to create an array, use square brackets instead of curly braces",
1542+
vec![
1543+
(
1544+
blk.span
1545+
.shrink_to_lo()
1546+
.with_hi(rustc_span::BytePos(blk.span.lo().0 + 1)),
1547+
"[".to_string(),
1548+
),
1549+
(
1550+
blk.span
1551+
.shrink_to_hi()
1552+
.with_lo(rustc_span::BytePos(blk.span.hi().0 - 1)),
1553+
"]".to_string(),
1554+
),
1555+
],
1556+
Applicability::MachineApplicable,
1557+
);
15591558
}
15601559
}
15611560
}

‎compiler/rustc_metadata/src/rmeta/encoder.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -843,9 +843,8 @@ fn analyze_attr(attr: &impl AttributeExt, state: &mut AnalyzeAttrState<'_>) -> b
843843
}
844844
}
845845
}
846-
} else if attr.path().starts_with(&[sym::diagnostic]) && attr.path().len() == 2 {
847-
should_encode =
848-
rustc_feature::is_stable_diagnostic_attribute(attr.path()[1], state.features);
846+
} else if let &[sym::diagnostic, seg] = &*attr.path() {
847+
should_encode = rustc_feature::is_stable_diagnostic_attribute(seg, state.features);
849848
} else {
850849
should_encode = true;
851850
}

‎compiler/rustc_middle/src/ty/diagnostics.rs

+18-24
Original file line numberDiff line numberDiff line change
@@ -641,21 +641,19 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for IsSuggestableVisitor<'tcx> {
641641
}
642642
}
643643

644-
Alias(Projection, AliasTy { def_id, .. }) => {
645-
if self.tcx.def_kind(def_id) != DefKind::AssocTy {
646-
return ControlFlow::Break(());
647-
}
644+
Alias(Projection, AliasTy { def_id, .. })
645+
if self.tcx.def_kind(def_id) != DefKind::AssocTy =>
646+
{
647+
return ControlFlow::Break(());
648648
}
649649

650-
Param(param) => {
651-
// FIXME: It would be nice to make this not use string manipulation,
652-
// but it's pretty hard to do this, since `ty::ParamTy` is missing
653-
// sufficient info to determine if it is synthetic, and we don't
654-
// always have a convenient way of getting `ty::Generics` at the call
655-
// sites we invoke `IsSuggestable::is_suggestable`.
656-
if param.name.as_str().starts_with("impl ") {
657-
return ControlFlow::Break(());
658-
}
650+
// FIXME: It would be nice to make this not use string manipulation,
651+
// but it's pretty hard to do this, since `ty::ParamTy` is missing
652+
// sufficient info to determine if it is synthetic, and we don't
653+
// always have a convenient way of getting `ty::Generics` at the call
654+
// sites we invoke `IsSuggestable::is_suggestable`.
655+
Param(param) if param.name.as_str().starts_with("impl ") => {
656+
return ControlFlow::Break(());
659657
}
660658

661659
_ => {}
@@ -733,17 +731,13 @@ impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for MakeSuggestableFolder<'tcx> {
733731
}
734732
}
735733

736-
Param(param) => {
737-
// FIXME: It would be nice to make this not use string manipulation,
738-
// but it's pretty hard to do this, since `ty::ParamTy` is missing
739-
// sufficient info to determine if it is synthetic, and we don't
740-
// always have a convenient way of getting `ty::Generics` at the call
741-
// sites we invoke `IsSuggestable::is_suggestable`.
742-
if param.name.as_str().starts_with("impl ") {
743-
return Err(());
744-
}
745-
746-
t
734+
// FIXME: It would be nice to make this not use string manipulation,
735+
// but it's pretty hard to do this, since `ty::ParamTy` is missing
736+
// sufficient info to determine if it is synthetic, and we don't
737+
// always have a convenient way of getting `ty::Generics` at the call
738+
// sites we invoke `IsSuggestable::is_suggestable`.
739+
Param(param) if param.name.as_str().starts_with("impl ") => {
740+
return Err(());
747741
}
748742

749743
_ => t,

‎compiler/rustc_passes/src/dead.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,7 @@ impl<'tcx> DeadVisitor<'tcx> {
11321132
return;
11331133
}
11341134
dead_codes.sort_by_key(|v| v.level);
1135-
for group in dead_codes[..].chunk_by(|a, b| a.level == b.level) {
1135+
for group in dead_codes.chunk_by(|a, b| a.level == b.level) {
11361136
self.lint_at_single_level(&group, participle, Some(def_id), report_on);
11371137
}
11381138
}

0 commit comments

Comments
 (0)
Failed to load comments.