Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flatten and simplify some control flow 🫓 #138590

Merged
merged 1 commit into from
Mar 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions compiler/rustc_borrowck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2479,19 +2479,15 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
let body = self.body;
for local in body.mut_vars_and_args_iter().filter(|local| !self.used_mut.contains(local)) {
let local_decl = &body.local_decls[local];
let lint_root = match &body.source_scopes[local_decl.source_info.scope].local_data {
ClearCrossCrate::Set(data) => data.lint_root,
_ => continue,
let ClearCrossCrate::Set(SourceScopeLocalData { lint_root, .. }) =
body.source_scopes[local_decl.source_info.scope].local_data
else {
continue;
};

// Skip over locals that begin with an underscore or have no name
match self.local_names[local] {
Some(name) => {
if name.as_str().starts_with('_') {
continue;
}
}
None => continue,
if self.local_names[local].is_none_or(|name| name.as_str().starts_with('_')) {
continue;
}

let span = local_decl.source_info.span;
Expand Down
12 changes: 4 additions & 8 deletions compiler/rustc_hir_analysis/src/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,9 @@ pub(super) fn maybe_check_static_with_link_section(tcx: TyCtxt<'_>, id: LocalDef
}

// If `#[link_section]` is missing, then nothing to verify
let attrs = tcx.codegen_fn_attrs(id);
if attrs.link_section.is_none() {
let Some(link_section) = tcx.codegen_fn_attrs(id).link_section else {
return;
}
};

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

if let Ok(alloc) = tcx.eval_static_initializer(id.to_def_id())
&& alloc.inner().provenance().ptrs().len() != 0
&& attrs
.link_section
.map(|link_section| !link_section.as_str().starts_with(".init_array"))
.unwrap()
&& !alloc.inner().provenance().ptrs().is_empty()
&& !link_section.as_str().starts_with(".init_array")
{
let msg = "statics with a custom `#[link_section]` must be a \
simple list of bytes on the wasm target with no \
Expand Down
45 changes: 22 additions & 23 deletions compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1532,30 +1532,29 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if self.may_coerce(blk_ty, *elem_ty)
&& blk.stmts.is_empty()
&& blk.rules == hir::BlockCheckMode::DefaultBlock
&& let source_map = self.tcx.sess.source_map()
&& let Ok(snippet) = source_map.span_to_snippet(blk.span)
&& snippet.starts_with('{')
&& snippet.ends_with('}')
{
let source_map = self.tcx.sess.source_map();
if let Ok(snippet) = source_map.span_to_snippet(blk.span) {
if snippet.starts_with('{') && snippet.ends_with('}') {
diag.multipart_suggestion_verbose(
"to create an array, use square brackets instead of curly braces",
vec![
(
blk.span
.shrink_to_lo()
.with_hi(rustc_span::BytePos(blk.span.lo().0 + 1)),
"[".to_string(),
),
(
blk.span
.shrink_to_hi()
.with_lo(rustc_span::BytePos(blk.span.hi().0 - 1)),
"]".to_string(),
),
],
Applicability::MachineApplicable,
);
}
}
diag.multipart_suggestion_verbose(
"to create an array, use square brackets instead of curly braces",
vec![
(
blk.span
.shrink_to_lo()
.with_hi(rustc_span::BytePos(blk.span.lo().0 + 1)),
"[".to_string(),
),
(
blk.span
.shrink_to_hi()
.with_lo(rustc_span::BytePos(blk.span.hi().0 - 1)),
"]".to_string(),
),
],
Applicability::MachineApplicable,
);
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -843,9 +843,8 @@ fn analyze_attr(attr: &impl AttributeExt, state: &mut AnalyzeAttrState<'_>) -> b
}
}
}
} else if attr.path().starts_with(&[sym::diagnostic]) && attr.path().len() == 2 {
should_encode =
rustc_feature::is_stable_diagnostic_attribute(attr.path()[1], state.features);
} else if let &[sym::diagnostic, seg] = &*attr.path() {
should_encode = rustc_feature::is_stable_diagnostic_attribute(seg, state.features);
} else {
should_encode = true;
}
Expand Down
42 changes: 18 additions & 24 deletions compiler/rustc_middle/src/ty/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,21 +641,19 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for IsSuggestableVisitor<'tcx> {
}
}

Alias(Projection, AliasTy { def_id, .. }) => {
if self.tcx.def_kind(def_id) != DefKind::AssocTy {
return ControlFlow::Break(());
}
Alias(Projection, AliasTy { def_id, .. })
if self.tcx.def_kind(def_id) != DefKind::AssocTy =>
{
return ControlFlow::Break(());
}

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

_ => {}
Expand Down Expand Up @@ -733,17 +731,13 @@ impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for MakeSuggestableFolder<'tcx> {
}
}

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

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

_ => t,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_passes/src/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,7 @@ impl<'tcx> DeadVisitor<'tcx> {
return;
}
dead_codes.sort_by_key(|v| v.level);
for group in dead_codes[..].chunk_by(|a, b| a.level == b.level) {
for group in dead_codes.chunk_by(|a, b| a.level == b.level) {
self.lint_at_single_level(&group, participle, Some(def_id), report_on);
}
}
Expand Down
Loading