1
Fork 0

Flatten and simplify some control flow

This commit is contained in:
Yotam Ofek 2025-03-16 22:23:48 +00:00
parent 227690a258
commit 51e8309f50
6 changed files with 53 additions and 69 deletions

View file

@ -2479,20 +2479,16 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
let body = self.body; let body = self.body;
for local in body.mut_vars_and_args_iter().filter(|local| !self.used_mut.contains(local)) { for local in body.mut_vars_and_args_iter().filter(|local| !self.used_mut.contains(local)) {
let local_decl = &body.local_decls[local]; let local_decl = &body.local_decls[local];
let lint_root = match &body.source_scopes[local_decl.source_info.scope].local_data { let ClearCrossCrate::Set(SourceScopeLocalData { lint_root, .. }) =
ClearCrossCrate::Set(data) => data.lint_root, body.source_scopes[local_decl.source_info.scope].local_data
_ => continue, else {
continue;
}; };
// Skip over locals that begin with an underscore or have no name // Skip over locals that begin with an underscore or have no name
match self.local_names[local] { if self.local_names[local].is_none_or(|name| name.as_str().starts_with('_')) {
Some(name) => {
if name.as_str().starts_with('_') {
continue; continue;
} }
}
None => continue,
}
let span = local_decl.source_info.span; let span = local_decl.source_info.span;
if span.desugaring_kind().is_some() { if span.desugaring_kind().is_some() {

View file

@ -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 // If `#[link_section]` is missing, then nothing to verify
let attrs = tcx.codegen_fn_attrs(id); let Some(link_section) = tcx.codegen_fn_attrs(id).link_section else {
if attrs.link_section.is_none() {
return; return;
} };
// For the wasm32 target statics with `#[link_section]` other than `.init_array` // 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 // 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
// continue to work, but would no longer be necessary. // continue to work, but would no longer be necessary.
if let Ok(alloc) = tcx.eval_static_initializer(id.to_def_id()) if let Ok(alloc) = tcx.eval_static_initializer(id.to_def_id())
&& alloc.inner().provenance().ptrs().len() != 0 && !alloc.inner().provenance().ptrs().is_empty()
&& attrs && !link_section.as_str().starts_with(".init_array")
.link_section
.map(|link_section| !link_section.as_str().starts_with(".init_array"))
.unwrap()
{ {
let msg = "statics with a custom `#[link_section]` must be a \ let msg = "statics with a custom `#[link_section]` must be a \
simple list of bytes on the wasm target with no \ simple list of bytes on the wasm target with no \

View file

@ -1532,10 +1532,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if self.may_coerce(blk_ty, *elem_ty) if self.may_coerce(blk_ty, *elem_ty)
&& blk.stmts.is_empty() && blk.stmts.is_empty()
&& blk.rules == hir::BlockCheckMode::DefaultBlock && 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( diag.multipart_suggestion_verbose(
"to create an array, use square brackets instead of curly braces", "to create an array, use square brackets instead of curly braces",
vec![ vec![
@ -1557,8 +1558,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
} }
} }
}
}
#[instrument(skip(self, err))] #[instrument(skip(self, err))]
pub(crate) fn suggest_floating_point_literal( pub(crate) fn suggest_floating_point_literal(

View file

@ -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 { } else if let &[sym::diagnostic, seg] = &*attr.path() {
should_encode = should_encode = rustc_feature::is_stable_diagnostic_attribute(seg, state.features);
rustc_feature::is_stable_diagnostic_attribute(attr.path()[1], state.features);
} else { } else {
should_encode = true; should_encode = true;
} }

View file

@ -641,22 +641,20 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for IsSuggestableVisitor<'tcx> {
} }
} }
Alias(Projection, AliasTy { def_id, .. }) => { Alias(Projection, AliasTy { def_id, .. })
if self.tcx.def_kind(def_id) != DefKind::AssocTy { if self.tcx.def_kind(def_id) != DefKind::AssocTy =>
{
return ControlFlow::Break(()); return ControlFlow::Break(());
} }
}
Param(param) => {
// FIXME: It would be nice to make this not use string manipulation, // 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 // 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 // sufficient info to determine if it is synthetic, and we don't
// always have a convenient way of getting `ty::Generics` at the call // always have a convenient way of getting `ty::Generics` at the call
// sites we invoke `IsSuggestable::is_suggestable`. // sites we invoke `IsSuggestable::is_suggestable`.
if param.name.as_str().starts_with("impl ") { Param(param) if param.name.as_str().starts_with("impl ") => {
return ControlFlow::Break(()); return ControlFlow::Break(());
} }
}
_ => {} _ => {}
} }
@ -733,19 +731,15 @@ impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for MakeSuggestableFolder<'tcx> {
} }
} }
Param(param) => {
// FIXME: It would be nice to make this not use string manipulation, // 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 // 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 // sufficient info to determine if it is synthetic, and we don't
// always have a convenient way of getting `ty::Generics` at the call // always have a convenient way of getting `ty::Generics` at the call
// sites we invoke `IsSuggestable::is_suggestable`. // sites we invoke `IsSuggestable::is_suggestable`.
if param.name.as_str().starts_with("impl ") { Param(param) if param.name.as_str().starts_with("impl ") => {
return Err(()); return Err(());
} }
t
}
_ => t, _ => t,
}; };

View file

@ -1132,7 +1132,7 @@ impl<'tcx> DeadVisitor<'tcx> {
return; return;
} }
dead_codes.sort_by_key(|v| v.level); 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); self.lint_at_single_level(&group, participle, Some(def_id), report_on);
} }
} }