diff options
Diffstat (limited to 'compiler/rustc_lint/src/builtin.rs')
| -rw-r--r-- | compiler/rustc_lint/src/builtin.rs | 213 |
1 files changed, 123 insertions, 90 deletions
diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index e2bafbed6e1..5e6b854ff52 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -102,10 +102,11 @@ impl EarlyLintPass for WhileTrue { "{}loop", label.map_or_else(String::new, |label| format!("{}: ", label.ident,)) ); - cx.emit_span_lint(WHILE_TRUE, condition_span, BuiltinWhileTrue { - suggestion: condition_span, - replace, - }); + cx.emit_span_lint( + WHILE_TRUE, + condition_span, + BuiltinWhileTrue { suggestion: condition_span, replace }, + ); } } } @@ -421,10 +422,11 @@ impl MissingDoc { let attrs = cx.tcx.hir().attrs(cx.tcx.local_def_id_to_hir_id(def_id)); let has_doc = attrs.iter().any(has_doc); if !has_doc { - cx.emit_span_lint(MISSING_DOCS, cx.tcx.def_span(def_id), BuiltinMissingDoc { - article, - desc, - }); + cx.emit_span_lint( + MISSING_DOCS, + cx.tcx.def_span(def_id), + BuiltinMissingDoc { article, desc }, + ); } } } @@ -706,10 +708,11 @@ impl<'tcx> LateLintPass<'tcx> for MissingDebugImplementations { .next() .is_some(); if !has_impl { - cx.emit_span_lint(MISSING_DEBUG_IMPLEMENTATIONS, item.span, BuiltinMissingDebugImpl { - tcx: cx.tcx, - def_id: debug, - }); + cx.emit_span_lint( + MISSING_DEBUG_IMPLEMENTATIONS, + item.span, + BuiltinMissingDebugImpl { tcx: cx.tcx, def_id: debug }, + ); } } } @@ -831,12 +834,11 @@ impl EarlyLintPass for DeprecatedAttr { BuiltinDeprecatedAttrLinkSuggestion::Default { suggestion: attr.span } } }; - cx.emit_span_lint(DEPRECATED, attr.span, BuiltinDeprecatedAttrLink { - name, - reason, - link, - suggestion, - }); + cx.emit_span_lint( + DEPRECATED, + attr.span, + BuiltinDeprecatedAttrLink { name, reason, link, suggestion }, + ); } return; } @@ -874,11 +876,11 @@ fn warn_if_doc(cx: &EarlyContext<'_>, node_span: Span, node_kind: &str, attrs: & BuiltinUnusedDocCommentSub::BlockHelp } }; - cx.emit_span_lint(UNUSED_DOC_COMMENTS, span, BuiltinUnusedDocComment { - kind: node_kind, - label: node_span, - sub, - }); + cx.emit_span_lint( + UNUSED_DOC_COMMENTS, + span, + BuiltinUnusedDocComment { kind: node_kind, label: node_span, sub }, + ); } } } @@ -1008,9 +1010,11 @@ impl<'tcx> LateLintPass<'tcx> for InvalidNoMangleItems { match param.kind { GenericParamKind::Lifetime { .. } => {} GenericParamKind::Type { .. } | GenericParamKind::Const { .. } => { - cx.emit_span_lint(NO_MANGLE_GENERIC_ITEMS, span, BuiltinNoMangleGeneric { - suggestion: no_mangle_attr.span, - }); + cx.emit_span_lint( + NO_MANGLE_GENERIC_ITEMS, + span, + BuiltinNoMangleGeneric { suggestion: no_mangle_attr.span }, + ); break; } } @@ -1037,9 +1041,11 @@ impl<'tcx> LateLintPass<'tcx> for InvalidNoMangleItems { // Const items do not refer to a particular location in memory, and therefore // don't have anything to attach a symbol to - cx.emit_span_lint(NO_MANGLE_CONST_ITEMS, it.span, BuiltinConstNoMangle { - suggestion, - }); + cx.emit_span_lint( + NO_MANGLE_CONST_ITEMS, + it.span, + BuiltinConstNoMangle { suggestion }, + ); } } hir::ItemKind::Impl(hir::Impl { generics, items, .. }) => { @@ -1305,12 +1311,16 @@ impl UnreachablePub { applicability = Applicability::MaybeIncorrect; } let def_span = cx.tcx.def_span(def_id); - cx.emit_span_lint(UNREACHABLE_PUB, def_span, BuiltinUnreachablePub { - what, - new_vis, - suggestion: (vis_span, applicability), - help: exportable, - }); + cx.emit_span_lint( + UNREACHABLE_PUB, + def_span, + BuiltinUnreachablePub { + what, + new_vis, + suggestion: (vis_span, applicability), + help: exportable, + }, + ); } } } @@ -1454,24 +1464,32 @@ impl<'tcx> LateLintPass<'tcx> for TypeAliasBounds { let enable_feat_help = cx.tcx.sess.is_nightly_build(); if let [.., label_sp] = *where_spans { - cx.emit_span_lint(TYPE_ALIAS_BOUNDS, where_spans, BuiltinTypeAliasBounds { - in_where_clause: true, - label: label_sp, - enable_feat_help, - suggestions: vec![(generics.where_clause_span, String::new())], - preds: generics.predicates, - ty: ty.take(), - }); + cx.emit_span_lint( + TYPE_ALIAS_BOUNDS, + where_spans, + BuiltinTypeAliasBounds { + in_where_clause: true, + label: label_sp, + enable_feat_help, + suggestions: vec![(generics.where_clause_span, String::new())], + preds: generics.predicates, + ty: ty.take(), + }, + ); } if let [.., label_sp] = *inline_spans { - cx.emit_span_lint(TYPE_ALIAS_BOUNDS, inline_spans, BuiltinTypeAliasBounds { - in_where_clause: false, - label: label_sp, - enable_feat_help, - suggestions: inline_sugg, - preds: generics.predicates, - ty, - }); + cx.emit_span_lint( + TYPE_ALIAS_BOUNDS, + inline_spans, + BuiltinTypeAliasBounds { + in_where_clause: false, + label: label_sp, + enable_feat_help, + suggestions: inline_sugg, + preds: generics.predicates, + ty, + }, + ); } } } @@ -1559,10 +1577,11 @@ impl<'tcx> LateLintPass<'tcx> for TrivialConstraints { | ty::ClauseKind::HostEffect(..) => continue, }; if predicate.is_global() { - cx.emit_span_lint(TRIVIAL_BOUNDS, span, BuiltinTrivialBounds { - predicate_kind_name, - predicate, - }); + cx.emit_span_lint( + TRIVIAL_BOUNDS, + span, + BuiltinTrivialBounds { predicate_kind_name, predicate }, + ); } } } @@ -1611,12 +1630,16 @@ impl EarlyLintPass for DoubleNegations { && let ExprKind::Unary(UnOp::Neg, ref inner2) = inner.kind && !matches!(inner2.kind, ExprKind::Unary(UnOp::Neg, _)) { - cx.emit_span_lint(DOUBLE_NEGATIONS, expr.span, BuiltinDoubleNegations { - add_parens: BuiltinDoubleNegationsAddParens { - start_span: inner.span.shrink_to_lo(), - end_span: inner.span.shrink_to_hi(), + cx.emit_span_lint( + DOUBLE_NEGATIONS, + expr.span, + BuiltinDoubleNegations { + add_parens: BuiltinDoubleNegationsAddParens { + start_span: inner.span.shrink_to_lo(), + end_span: inner.span.shrink_to_hi(), + }, }, - }); + ); } } } @@ -1931,12 +1954,11 @@ impl KeywordIdents { return; } - cx.emit_span_lint(lint, ident.span, BuiltinKeywordIdents { - kw: ident, - next: edition, - suggestion: ident.span, - prefix, - }); + cx.emit_span_lint( + lint, + ident.span, + BuiltinKeywordIdents { kw: ident, next: edition, suggestion: ident.span, prefix }, + ); } } @@ -2357,11 +2379,11 @@ impl EarlyLintPass for IncompleteInternalFeatures { let help = HAS_MIN_FEATURES.contains(&name).then_some(BuiltinIncompleteFeaturesHelp); - cx.emit_span_lint(INCOMPLETE_FEATURES, span, BuiltinIncompleteFeatures { - name, - note, - help, - }); + cx.emit_span_lint( + INCOMPLETE_FEATURES, + span, + BuiltinIncompleteFeatures { name, note, help }, + ); } else { cx.emit_span_lint(INTERNAL_FEATURES, span, BuiltinInternalFeatures { name }); } @@ -2684,13 +2706,17 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue { InitKind::Uninit => fluent::lint_builtin_unpermitted_type_init_uninit, }; let sub = BuiltinUnpermittedTypeInitSub { err }; - cx.emit_span_lint(INVALID_VALUE, expr.span, BuiltinUnpermittedTypeInit { - msg, - ty: conjured_ty, - label: expr.span, - sub, - tcx: cx.tcx, - }); + cx.emit_span_lint( + INVALID_VALUE, + expr.span, + BuiltinUnpermittedTypeInit { + msg, + ty: conjured_ty, + label: expr.span, + sub, + tcx: cx.tcx, + }, + ); } } } @@ -2776,9 +2802,11 @@ impl<'tcx> LateLintPass<'tcx> for DerefNullPtr { { // `&raw *NULL` is ok. } else { - cx.emit_span_lint(DEREF_NULLPTR, expr.span, BuiltinDerefNullptr { - label: expr.span, - }); + cx.emit_span_lint( + DEREF_NULLPTR, + expr.span, + BuiltinDerefNullptr { label: expr.span }, + ); } } } @@ -2995,14 +3023,18 @@ impl<'tcx> LateLintPass<'tcx> for AsmLabels { let span = span.unwrap_or(*template_span); match label_kind { AsmLabelKind::Named => { - cx.emit_span_lint(NAMED_ASM_LABELS, span, InvalidAsmLabel::Named { - missing_precise_span, - }); + cx.emit_span_lint( + NAMED_ASM_LABELS, + span, + InvalidAsmLabel::Named { missing_precise_span }, + ); } AsmLabelKind::FormatArg => { - cx.emit_span_lint(NAMED_ASM_LABELS, span, InvalidAsmLabel::FormatArg { - missing_precise_span, - }); + cx.emit_span_lint( + NAMED_ASM_LABELS, + span, + InvalidAsmLabel::FormatArg { missing_precise_span }, + ); } // the binary asm issue only occurs when using intel syntax on x86 targets AsmLabelKind::Binary @@ -3012,10 +3044,11 @@ impl<'tcx> LateLintPass<'tcx> for AsmLabels { Some(InlineAsmArch::X86 | InlineAsmArch::X86_64) | None ) => { - cx.emit_span_lint(BINARY_ASM_LABELS, span, InvalidAsmLabel::Binary { - missing_precise_span, + cx.emit_span_lint( + BINARY_ASM_LABELS, span, - }) + InvalidAsmLabel::Binary { missing_precise_span, span }, + ) } // No lint on anything other than x86 AsmLabelKind::Binary => (), |
