1
Fork 0

Format all the let chains in compiler

This commit is contained in:
Michael Goulet 2023-10-13 08:58:33 +00:00
parent 2763ca50da
commit b2d2184ede
206 changed files with 3120 additions and 2228 deletions

View file

@ -1076,7 +1076,9 @@ impl CheckAttrVisitor<'_> {
) -> bool {
let mut is_valid = true;
if let Some(mi) = attr.meta() && let Some(list) = mi.meta_item_list() {
if let Some(mi) = attr.meta()
&& let Some(list) = mi.meta_item_list()
{
for meta in list {
if let Some(i_meta) = meta.meta_item() {
match i_meta.name_or_empty() {
@ -1133,14 +1135,7 @@ impl CheckAttrVisitor<'_> {
is_valid = false;
}
sym::masked
if !self.check_doc_masked(
attr,
meta,
hir_id,
target,
) =>
{
sym::masked if !self.check_doc_masked(attr, meta, hir_id, target) => {
is_valid = false;
}
@ -1192,13 +1187,11 @@ impl CheckAttrVisitor<'_> {
INVALID_DOC_ATTRIBUTES,
hir_id,
i_meta.span,
errors::DocTestUnknownSpotlight {
path,
span: i_meta.span
}
errors::DocTestUnknownSpotlight { path, span: i_meta.span },
);
} else if i_meta.has_name(sym::include) &&
let Some(value) = i_meta.value_str() {
} else if i_meta.has_name(sym::include)
&& let Some(value) = i_meta.value_str()
{
let applicability = if list.len() == 1 {
Applicability::MachineApplicable
} else {
@ -1213,16 +1206,19 @@ impl CheckAttrVisitor<'_> {
errors::DocTestUnknownInclude {
path,
value: value.to_string(),
inner: match attr.style { AttrStyle::Inner=> "!" , AttrStyle::Outer => "" },
inner: match attr.style {
AttrStyle::Inner => "!",
AttrStyle::Outer => "",
},
sugg: (attr.meta().unwrap().span, applicability),
}
},
);
} else {
self.tcx.emit_spanned_lint(
INVALID_DOC_ATTRIBUTES,
hir_id,
i_meta.span,
errors::DocTestUnknownAny { path }
errors::DocTestUnknownAny { path },
);
}
is_valid = false;
@ -2195,8 +2191,9 @@ impl CheckAttrVisitor<'_> {
attr.span,
errors::MacroExport::Normal,
);
} else if let Some(meta_item_list) = attr.meta_item_list() &&
!meta_item_list.is_empty() {
} else if let Some(meta_item_list) = attr.meta_item_list()
&& !meta_item_list.is_empty()
{
if meta_item_list.len() > 1 {
self.tcx.emit_spanned_lint(
INVALID_MACRO_EXPORT_ARGUMENTS,
@ -2261,9 +2258,9 @@ impl CheckAttrVisitor<'_> {
{
errors::UnusedNote::EmptyList { name: attr.name_or_empty() }
} else if matches!(
attr.name_or_empty(),
sym::allow | sym::warn | sym::deny | sym::forbid | sym::expect
) && let Some(meta) = attr.meta_item_list()
attr.name_or_empty(),
sym::allow | sym::warn | sym::deny | sym::forbid | sym::expect
) && let Some(meta) = attr.meta_item_list()
&& meta.len() == 1
&& let Some(item) = meta[0].meta_item()
&& let MetaItemKind::NameValue(_) = &item.kind

View file

@ -193,15 +193,15 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
if let hir::ExprKind::Assign(lhs, rhs, _) = assign.kind
&& check_for_self_assign_helper(self.typeck_results(), lhs, rhs)
&& !assign.span.from_expansion()
&& !assign.span.from_expansion()
{
let is_field_assign = matches!(lhs.kind, hir::ExprKind::Field(..));
self.tcx.emit_spanned_lint(
lint::builtin::DEAD_CODE,
assign.hir_id,
assign.span,
UselessAssignment { is_field_assign, ty: self.typeck_results().expr_ty(lhs) }
)
let is_field_assign = matches!(lhs.kind, hir::ExprKind::Field(..));
self.tcx.emit_spanned_lint(
lint::builtin::DEAD_CODE,
assign.hir_id,
assign.span,
UselessAssignment { is_field_assign, ty: self.typeck_results().expr_ty(lhs) },
)
}
}
@ -671,7 +671,8 @@ fn check_trait_item(
if matches!(tcx.def_kind(id.owner_id), DefKind::AssocConst | DefKind::AssocFn) {
let trait_item = tcx.hir().trait_item(id);
if matches!(trait_item.kind, Const(_, Some(_)) | Fn(_, hir::TraitFn::Provided(_)))
&& let Some(comes_from_allow) = has_allow_dead_code_or_lang_attr(tcx, trait_item.owner_id.def_id)
&& let Some(comes_from_allow) =
has_allow_dead_code_or_lang_attr(tcx, trait_item.owner_id.def_id)
{
worklist.push((trait_item.owner_id.def_id, comes_from_allow));
}

View file

@ -121,9 +121,13 @@ fn configure_main(tcx: TyCtxt<'_>, visitor: &EntryContext<'_>) -> Option<(DefId,
let def_id = local_def_id.to_def_id();
Some((def_id, EntryFnType::Main { sigpipe: sigpipe(tcx, def_id) }))
} else {
if let Some(main_def) = tcx.resolutions(()).main_def && let Some(def_id) = main_def.opt_fn_def_id() {
if let Some(main_def) = tcx.resolutions(()).main_def
&& let Some(def_id) = main_def.opt_fn_def_id()
{
// non-local main imports are handled below
if let Some(def_id) = def_id.as_local() && matches!(tcx.hir().find_by_def_id(def_id), Some(Node::ForeignItem(_))) {
if let Some(def_id) = def_id.as_local()
&& matches!(tcx.hir().find_by_def_id(def_id), Some(Node::ForeignItem(_)))
{
tcx.sess.emit_err(ExternMain { span: tcx.def_span(def_id) });
return None;
}

View file

@ -1311,7 +1311,9 @@ impl<'a> IntoDiagnostic<'a> for NoMainErr {
diag.span_label(self.sp.shrink_to_hi(), note);
}
if let Some(main_def) = self.main_def_opt && main_def.opt_fn_def_id().is_none(){
if let Some(main_def) = self.main_def_opt
&& main_def.opt_fn_def_id().is_none()
{
// There is something at `crate::main`, but it is not a function definition.
diag.span_label(main_def.span, fluent::passes_non_function_main);
}

View file

@ -56,7 +56,9 @@ impl<'tcx> LibFeatureCollector<'tcx> {
}
}
if let Some(s) = since && s.as_str() == VERSION_PLACEHOLDER {
if let Some(s) = since
&& s.as_str() == VERSION_PLACEHOLDER
{
since = Some(rust_version_symbol());
}

View file

@ -1512,13 +1512,15 @@ impl<'tcx> Liveness<'_, 'tcx> {
Some(body),
|spans, hir_id, ln, var| {
if !self.live_on_entry(ln, var)
&& let Some(name) = self.should_warn(var) {
self.ir.tcx.emit_spanned_lint(
lint::builtin::UNUSED_ASSIGNMENTS,
hir_id,
spans,
errors::UnusedAssignPassed { name },
); }
&& let Some(name) = self.should_warn(var)
{
self.ir.tcx.emit_spanned_lint(
lint::builtin::UNUSED_ASSIGNMENTS,
hir_id,
spans,
errors::UnusedAssignPassed { name },
);
}
},
);
}
@ -1707,13 +1709,14 @@ impl<'tcx> Liveness<'_, 'tcx> {
fn warn_about_dead_assign(&self, spans: Vec<Span>, hir_id: HirId, ln: LiveNode, var: Variable) {
if !self.live_on_exit(ln, var)
&& let Some(name) = self.should_warn(var) {
self.ir.tcx.emit_spanned_lint(
lint::builtin::UNUSED_ASSIGNMENTS,
hir_id,
spans,
errors::UnusedAssign { name },
);
}
&& let Some(name) = self.should_warn(var)
{
self.ir.tcx.emit_spanned_lint(
lint::builtin::UNUSED_ASSIGNMENTS,
hir_id,
spans,
errors::UnusedAssign { name },
);
}
}
}

View file

@ -97,7 +97,9 @@ impl<'tcx> Visitor<'tcx> for ReachableContext<'tcx> {
_ => None,
};
if let Some(res) = res && let Some(def_id) = res.opt_def_id().and_then(|el| el.as_local()) {
if let Some(res) = res
&& let Some(def_id) = res.opt_def_id().and_then(|el| el.as_local())
{
if self.def_id_represents_local_inlined_item(def_id.to_def_id()) {
self.worklist.push(def_id);
} else {

View file

@ -998,14 +998,17 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
all_implications: &FxHashMap<Symbol, Symbol>,
) {
for (feature, since) in defined_features {
if let Some(since) = since && let Some(span) = remaining_lib_features.get(&feature) {
if let Some(since) = since
&& let Some(span) = remaining_lib_features.get(&feature)
{
// Warn if the user has enabled an already-stable lib feature.
if let Some(implies) = all_implications.get(&feature) {
unnecessary_partially_stable_feature_lint(tcx, *span, *feature, *implies, *since);
unnecessary_partially_stable_feature_lint(
tcx, *span, *feature, *implies, *since,
);
} else {
unnecessary_stable_feature_lint(tcx, *span, *feature, *since);
}
}
remaining_lib_features.remove(feature);

View file

@ -26,7 +26,9 @@ pub fn check_crate(tcx: TyCtxt<'_>, items: &mut lang_items::LanguageItems) {
for id in crate_items.foreign_items() {
let attrs = tcx.hir().attrs(id.hir_id());
if let Some((lang_item, _)) = lang_items::extract(attrs) {
if let Some(item) = LangItem::from_name(lang_item) && item.is_weak() {
if let Some(item) = LangItem::from_name(lang_item)
&& item.is_weak()
{
if items.get(item).is_none() {
items.missing.push(item);
}