Skip to content

Commit 6974f3b

Browse files
Replace emit_span_lint with emit_span_diag_lint in rustc_lint
1 parent 38c4d75 commit 6974f3b

38 files changed

+141
-182
lines changed

compiler/rustc_lint/src/autorefs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitAutorefs {
109109
}
110110
&& method_did.map(|did| find_attr!(cx.tcx, did, RustcNoImplicitAutorefs)).unwrap_or(true)
111111
{
112-
cx.emit_span_diag_lint(
112+
cx.emit_span_lint(
113113
DANGEROUS_IMPLICIT_AUTOREFS,
114114
expr.span.source_callsite(),
115115
ImplicitUnsafeAutorefsDiag {

compiler/rustc_lint/src/builtin.rs

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl EarlyLintPass for WhileTrue {
100100
"{}loop",
101101
label.map_or_else(String::new, |label| format!("{}: ", label.ident,))
102102
);
103-
cx.emit_span_diag_lint(
103+
cx.emit_span_lint(
104104
WHILE_TRUE,
105105
condition_span,
106106
BuiltinWhileTrue { suggestion: condition_span, replace },
@@ -173,7 +173,7 @@ impl<'tcx> LateLintPass<'tcx> for NonShorthandFieldPatterns {
173173
if cx.tcx.find_field_index(ident, variant)
174174
== Some(cx.typeck_results().field_index(fieldpat.hir_id))
175175
{
176-
cx.emit_span_diag_lint(
176+
cx.emit_span_lint(
177177
NON_SHORTHAND_FIELD_PATTERNS,
178178
fieldpat.span,
179179
BuiltinNonShorthandFieldPatterns {
@@ -243,7 +243,7 @@ impl UnsafeCode {
243243
return;
244244
}
245245

246-
cx.emit_span_diag_lint(UNSAFE_CODE, span, decorate);
246+
cx.emit_span_lint(UNSAFE_CODE, span, decorate);
247247
}
248248
}
249249

@@ -424,7 +424,7 @@ impl MissingDoc {
424424
let attrs = cx.tcx.hir_attrs(cx.tcx.local_def_id_to_hir_id(def_id));
425425
let has_doc = attrs.iter().any(has_doc);
426426
if !has_doc {
427-
cx.emit_span_diag_lint(
427+
cx.emit_span_lint(
428428
MISSING_DOCS,
429429
cx.tcx.def_span(def_id),
430430
BuiltinMissingDoc { article, desc },
@@ -625,7 +625,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingCopyImplementations {
625625
)
626626
.is_ok()
627627
{
628-
cx.emit_span_diag_lint(MISSING_COPY_IMPLEMENTATIONS, item.span, BuiltinMissingCopyImpl);
628+
cx.emit_span_lint(MISSING_COPY_IMPLEMENTATIONS, item.span, BuiltinMissingCopyImpl);
629629
}
630630
}
631631
}
@@ -712,7 +712,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDebugImplementations {
712712
.next()
713713
.is_some();
714714
if !has_impl {
715-
cx.emit_span_diag_lint(
715+
cx.emit_span_lint(
716716
MISSING_DEBUG_IMPLEMENTATIONS,
717717
item.span,
718718
BuiltinMissingDebugImpl { tcx: cx.tcx, def_id: debug },
@@ -789,7 +789,7 @@ impl EarlyLintPass for AnonymousParameters {
789789
} else {
790790
("<type>", Applicability::HasPlaceholders)
791791
};
792-
cx.emit_span_diag_lint(
792+
cx.emit_span_lint(
793793
ANONYMOUS_PARAMETERS,
794794
arg.pat.span,
795795
BuiltinAnonymousParams { suggestion: (arg.pat.span, appl), ty_snip },
@@ -834,7 +834,7 @@ fn warn_if_doc(cx: &EarlyContext<'_>, node_span: Span, node_kind: &str, attrs: &
834834
BuiltinUnusedDocCommentSub::BlockHelp
835835
}
836836
};
837-
cx.emit_span_diag_lint(
837+
cx.emit_span_lint(
838838
UNUSED_DOC_COMMENTS,
839839
span,
840840
BuiltinUnusedDocComment { kind: node_kind, label: node_span, sub },
@@ -966,7 +966,7 @@ impl InvalidNoMangleItems {
966966
) {
967967
let generics = cx.tcx.generics_of(def_id);
968968
if generics.requires_monomorphization(cx.tcx) {
969-
cx.emit_span_diag_lint(
969+
cx.emit_span_lint(
970970
NO_MANGLE_GENERIC_ITEMS,
971971
cx.tcx.def_span(def_id),
972972
BuiltinNoMangleGeneric { suggestion: attr_span },
@@ -998,7 +998,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidNoMangleItems {
998998

999999
// Const items do not refer to a particular location in memory, and therefore
10001000
// don't have anything to attach a symbol to
1001-
cx.emit_span_diag_lint(
1001+
cx.emit_span_lint(
10021002
NO_MANGLE_CONST_ITEMS,
10031003
it.span,
10041004
BuiltinConstNoMangle { suggestion },
@@ -1059,7 +1059,7 @@ impl<'tcx> LateLintPass<'tcx> for MutableTransmutes {
10591059
get_transmute_from_to(cx, expr).map(|(ty1, ty2)| (ty1.kind(), ty2.kind()))
10601060
{
10611061
if from_mutbl < to_mutbl {
1062-
cx.emit_span_diag_lint(MUTABLE_TRANSMUTES, expr.span, BuiltinMutablesTransmutes);
1062+
cx.emit_span_lint(MUTABLE_TRANSMUTES, expr.span, BuiltinMutablesTransmutes);
10631063
}
10641064
}
10651065

@@ -1123,7 +1123,7 @@ impl<'tcx> LateLintPass<'tcx> for UnstableFeatures {
11231123
fn check_attributes(&mut self, cx: &LateContext<'_>, attrs: &[hir::Attribute]) {
11241124
if let Some(features) = find_attr!(attrs, Feature(features, _) => features) {
11251125
for feature in features {
1126-
cx.emit_span_diag_lint(UNSTABLE_FEATURES, feature.span, BuiltinUnstableFeatures);
1126+
cx.emit_span_lint(UNSTABLE_FEATURES, feature.span, BuiltinUnstableFeatures);
11271127
}
11281128
}
11291129
}
@@ -1176,7 +1176,7 @@ impl<'tcx> LateLintPass<'tcx> for UngatedAsyncFnTrackCaller {
11761176
// Now, check if the function has the `#[track_caller]` attribute
11771177
&& let Some(attr_span) = find_attr!(cx.tcx, def_id, TrackCaller(span) => *span)
11781178
{
1179-
cx.emit_span_diag_lint(
1179+
cx.emit_span_lint(
11801180
UNGATED_ASYNC_FN_TRACK_CALLER,
11811181
attr_span,
11821182
BuiltinUngatedAsyncFnTrackCaller { label: span, session: &cx.tcx.sess },
@@ -1261,7 +1261,7 @@ impl UnreachablePub {
12611261
applicability = Applicability::MaybeIncorrect;
12621262
}
12631263
let def_span = cx.tcx.def_span(def_id);
1264-
cx.emit_span_diag_lint(
1264+
cx.emit_span_lint(
12651265
UNREACHABLE_PUB,
12661266
def_span,
12671267
BuiltinUnreachablePub {
@@ -1413,7 +1413,7 @@ impl<'tcx> LateLintPass<'tcx> for TypeAliasBounds {
14131413
let enable_feat_help = cx.tcx.sess.is_nightly_build();
14141414

14151415
if let [.., label_sp] = *where_spans {
1416-
cx.emit_span_diag_lint(
1416+
cx.emit_span_lint(
14171417
TYPE_ALIAS_BOUNDS,
14181418
where_spans,
14191419
BuiltinTypeAliasBounds {
@@ -1427,7 +1427,7 @@ impl<'tcx> LateLintPass<'tcx> for TypeAliasBounds {
14271427
);
14281428
}
14291429
if let [.., label_sp] = *inline_spans {
1430-
cx.emit_span_diag_lint(
1430+
cx.emit_span_lint(
14311431
TYPE_ALIAS_BOUNDS,
14321432
inline_spans,
14331433
BuiltinTypeAliasBounds {
@@ -1527,7 +1527,7 @@ impl<'tcx> LateLintPass<'tcx> for TrivialConstraints {
15271527
| ty::ClauseKind::HostEffect(..) => continue,
15281528
};
15291529
if predicate.is_global() {
1530-
cx.emit_span_diag_lint(
1530+
cx.emit_span_lint(
15311531
TRIVIAL_BOUNDS,
15321532
span,
15331533
BuiltinTrivialBounds { predicate_kind_name, predicate },
@@ -1582,7 +1582,7 @@ impl EarlyLintPass for DoubleNegations {
15821582
// Don't lint if this jumps macro expansion boundary (Issue #143980)
15831583
&& expr.span.eq_ctxt(inner.span)
15841584
{
1585-
cx.emit_span_diag_lint(
1585+
cx.emit_span_lint(
15861586
DOUBLE_NEGATIONS,
15871587
expr.span,
15881588
BuiltinDoubleNegations {
@@ -1703,7 +1703,7 @@ impl EarlyLintPass for EllipsisInclusiveRangePatterns {
17031703
replace,
17041704
});
17051705
} else {
1706-
cx.emit_span_diag_lint(
1706+
cx.emit_span_lint(
17071707
ELLIPSIS_INCLUSIVE_RANGE_PATTERNS,
17081708
pat.span,
17091709
BuiltinEllipsisInclusiveRangePatternsLint::Parenthesise {
@@ -1721,7 +1721,7 @@ impl EarlyLintPass for EllipsisInclusiveRangePatterns {
17211721
replace: replace.to_string(),
17221722
});
17231723
} else {
1724-
cx.emit_span_diag_lint(
1724+
cx.emit_span_lint(
17251725
ELLIPSIS_INCLUSIVE_RANGE_PATTERNS,
17261726
join,
17271727
BuiltinEllipsisInclusiveRangePatternsLint::NonParenthesise {
@@ -1903,7 +1903,7 @@ impl KeywordIdents {
19031903
return;
19041904
}
19051905

1906-
cx.emit_span_diag_lint(
1906+
cx.emit_span_lint(
19071907
lint,
19081908
ident.span,
19091909
BuiltinKeywordIdents { kw: ident, next: edition, suggestion: ident.span, prefix },
@@ -2239,7 +2239,7 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
22392239
lint_spans.sort_unstable();
22402240
lint_spans.dedup();
22412241

2242-
cx.emit_span_diag_lint(
2242+
cx.emit_span_lint(
22432243
EXPLICIT_OUTLIVES_REQUIREMENTS,
22442244
lint_spans.clone(),
22452245
BuiltinExplicitOutlives {
@@ -2324,17 +2324,13 @@ impl EarlyLintPass for IncompleteInternalFeatures {
23242324
let help =
23252325
HAS_MIN_FEATURES.contains(&name).then_some(BuiltinIncompleteFeaturesHelp);
23262326

2327-
cx.emit_span_diag_lint(
2327+
cx.emit_span_lint(
23282328
INCOMPLETE_FEATURES,
23292329
span,
23302330
BuiltinIncompleteFeatures { name, note, help },
23312331
);
23322332
} else {
2333-
cx.emit_span_diag_lint(
2334-
INTERNAL_FEATURES,
2335-
span,
2336-
BuiltinInternalFeatures { name },
2337-
);
2333+
cx.emit_span_lint(INTERNAL_FEATURES, span, BuiltinInternalFeatures { name });
23382334
}
23392335
});
23402336
}
@@ -2660,7 +2656,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
26602656
}
26612657
};
26622658
let sub = BuiltinUnpermittedTypeInitSub { err };
2663-
cx.emit_span_diag_lint(
2659+
cx.emit_span_lint(
26642660
INVALID_VALUE,
26652661
expr.span,
26662662
BuiltinUnpermittedTypeInit {
@@ -2766,7 +2762,7 @@ impl<'tcx> LateLintPass<'tcx> for DerefNullPtr {
27662762
{
27672763
// `&raw *NULL` is ok.
27682764
} else {
2769-
cx.emit_span_diag_lint(
2765+
cx.emit_span_lint(
27702766
DEREF_NULLPTR,
27712767
expr.span,
27722768
BuiltinDerefNullptr { label: expr.span },
@@ -3075,14 +3071,14 @@ impl<'tcx> LateLintPass<'tcx> for AsmLabels {
30753071
let span = span.unwrap_or(*template_span);
30763072
match label_kind {
30773073
AsmLabelKind::Named => {
3078-
cx.emit_span_diag_lint(
3074+
cx.emit_span_lint(
30793075
NAMED_ASM_LABELS,
30803076
span,
30813077
InvalidAsmLabel::Named { missing_precise_span },
30823078
);
30833079
}
30843080
AsmLabelKind::FormatArg => {
3085-
cx.emit_span_diag_lint(
3081+
cx.emit_span_lint(
30863082
NAMED_ASM_LABELS,
30873083
span,
30883084
InvalidAsmLabel::FormatArg { missing_precise_span },
@@ -3096,7 +3092,7 @@ impl<'tcx> LateLintPass<'tcx> for AsmLabels {
30963092
Some(InlineAsmArch::X86 | InlineAsmArch::X86_64) | None
30973093
) =>
30983094
{
3099-
cx.emit_span_diag_lint(
3095+
cx.emit_span_lint(
31003096
BINARY_ASM_LABELS,
31013097
span,
31023098
InvalidAsmLabel::Binary { missing_precise_span, span },
@@ -3172,12 +3168,12 @@ impl EarlyLintPass for SpecialModuleName {
31723168
}
31733169

31743170
match ident.name.as_str() {
3175-
"lib" => cx.emit_span_diag_lint(
3171+
"lib" => cx.emit_span_lint(
31763172
SPECIAL_MODULE_NAME,
31773173
item.span,
31783174
BuiltinSpecialModuleNameUsed::Lib,
31793175
),
3180-
"main" => cx.emit_span_diag_lint(
3176+
"main" => cx.emit_span_lint(
31813177
SPECIAL_MODULE_NAME,
31823178
item.span,
31833179
BuiltinSpecialModuleNameUsed::Main,

compiler/rustc_lint/src/context.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -538,19 +538,6 @@ pub trait LintContext {
538538
/// Emit a lint at `span` from a lint struct (some type that implements `LintDiagnostic`,
539539
/// typically generated by `#[derive(LintDiagnostic)]`).
540540
fn emit_span_lint<S: Into<MultiSpan>>(
541-
&self,
542-
lint: &'static Lint,
543-
span: S,
544-
decorator: impl for<'a> LintDiagnostic<'a, ()>,
545-
) {
546-
self.opt_span_lint(lint, Some(span), |lint| {
547-
decorator.decorate_lint(lint);
548-
});
549-
}
550-
551-
/// Emit a lint at `span` from a lint struct (some type that implements `LintDiagnostic`,
552-
/// typically generated by `#[derive(LintDiagnostic)]`).
553-
fn emit_span_diag_lint<S: Into<MultiSpan>>(
554541
&self,
555542
lint: &'static Lint,
556543
span: S,

compiler/rustc_lint/src/deref_into_dyn_supertrait.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl<'tcx> LateLintPass<'tcx> for DerefIntoDynSupertrait {
8989
)
9090
.map(|label| SupertraitAsDerefTargetLabel { label: tcx.def_span(label.def_id) });
9191
let span = tcx.def_span(item.owner_id.def_id);
92-
cx.emit_span_diag_lint(
92+
cx.emit_span_lint(
9393
DEREF_INTO_DYN_SUPERTRAIT,
9494
span,
9595
SupertraitAsDerefTarget {

compiler/rustc_lint/src/drop_forget_useless.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,14 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetUseless {
163163
};
164164
match fn_name {
165165
sym::mem_drop if arg_ty.is_ref() && !drop_is_single_call_in_arm => {
166-
cx.emit_span_diag_lint(
166+
cx.emit_span_lint(
167167
DROPPING_REFERENCES,
168168
expr.span,
169169
DropRefDiag { arg_ty, label: arg.span, sugg: let_underscore_ignore_sugg() },
170170
);
171171
}
172172
sym::mem_forget if arg_ty.is_ref() => {
173-
cx.emit_span_diag_lint(
173+
cx.emit_span_lint(
174174
FORGETTING_REFERENCES,
175175
expr.span,
176176
ForgetRefDiag {
@@ -181,7 +181,7 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetUseless {
181181
);
182182
}
183183
sym::mem_drop if is_copy && !drop_is_single_call_in_arm => {
184-
cx.emit_span_diag_lint(
184+
cx.emit_span_lint(
185185
DROPPING_COPY_TYPES,
186186
expr.span,
187187
DropCopyDiag {
@@ -192,7 +192,7 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetUseless {
192192
);
193193
}
194194
sym::mem_forget if is_copy => {
195-
cx.emit_span_diag_lint(
195+
cx.emit_span_lint(
196196
FORGETTING_COPY_TYPES,
197197
expr.span,
198198
ForgetCopyDiag {
@@ -206,7 +206,7 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetUseless {
206206
if let ty::Adt(adt, _) = arg_ty.kind()
207207
&& adt.is_manually_drop() =>
208208
{
209-
cx.emit_span_diag_lint(
209+
cx.emit_span_lint(
210210
UNDROPPED_MANUALLY_DROPS,
211211
expr.span,
212212
UndroppedManuallyDropsDiag {

compiler/rustc_lint/src/enum_intrinsics_non_enums.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ fn enforce_mem_discriminant(
5353
) {
5454
let ty_param = cx.typeck_results().node_args(func_expr.hir_id).type_at(0);
5555
if is_non_enum(ty_param) {
56-
cx.emit_span_diag_lint(
56+
cx.emit_span_lint(
5757
ENUM_INTRINSICS_NON_ENUMS,
5858
expr_span,
5959
EnumIntrinsicsMemDiscriminate { ty_param, note: args_span },
@@ -64,11 +64,7 @@ fn enforce_mem_discriminant(
6464
fn enforce_mem_variant_count(cx: &LateContext<'_>, func_expr: &hir::Expr<'_>, span: Span) {
6565
let ty_param = cx.typeck_results().node_args(func_expr.hir_id).type_at(0);
6666
if is_non_enum(ty_param) {
67-
cx.emit_span_diag_lint(
68-
ENUM_INTRINSICS_NON_ENUMS,
69-
span,
70-
EnumIntrinsicsMemVariant { ty_param },
71-
);
67+
cx.emit_span_lint(ENUM_INTRINSICS_NON_ENUMS, span, EnumIntrinsicsMemVariant { ty_param });
7268
}
7369
}
7470

compiler/rustc_lint/src/for_loops_over_fallibles.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl<'tcx> LateLintPass<'tcx> for ForLoopsOverFallibles {
9898
end_span: pat.span.between(arg_span),
9999
};
100100

101-
cx.emit_span_diag_lint(
101+
cx.emit_span_lint(
102102
FOR_LOOPS_OVER_FALLIBLES,
103103
arg_span,
104104
ForLoopsOverFalliblesDiag { article, ref_prefix, ty, sub, question_mark, suggestion },

0 commit comments

Comments
 (0)