Skip to content

Commit b409cb1

Browse files
Replace emit_span_lint with emit_span_diag_lint in rustc_lint
1 parent bca1cb4 commit b409cb1

38 files changed

Lines changed: 141 additions & 182 deletions

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
@@ -99,7 +99,7 @@ impl EarlyLintPass for WhileTrue {
9999
"{}loop",
100100
label.map_or_else(String::new, |label| format!("{}: ", label.ident,))
101101
);
102-
cx.emit_span_diag_lint(
102+
cx.emit_span_lint(
103103
WHILE_TRUE,
104104
condition_span,
105105
BuiltinWhileTrue { suggestion: condition_span, replace },
@@ -172,7 +172,7 @@ impl<'tcx> LateLintPass<'tcx> for NonShorthandFieldPatterns {
172172
if cx.tcx.find_field_index(ident, variant)
173173
== Some(cx.typeck_results().field_index(fieldpat.hir_id))
174174
{
175-
cx.emit_span_diag_lint(
175+
cx.emit_span_lint(
176176
NON_SHORTHAND_FIELD_PATTERNS,
177177
fieldpat.span,
178178
BuiltinNonShorthandFieldPatterns {
@@ -242,7 +242,7 @@ impl UnsafeCode {
242242
return;
243243
}
244244

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

@@ -423,7 +423,7 @@ impl MissingDoc {
423423
let attrs = cx.tcx.hir_attrs(cx.tcx.local_def_id_to_hir_id(def_id));
424424
let has_doc = attrs.iter().any(has_doc);
425425
if !has_doc {
426-
cx.emit_span_diag_lint(
426+
cx.emit_span_lint(
427427
MISSING_DOCS,
428428
cx.tcx.def_span(def_id),
429429
BuiltinMissingDoc { article, desc },
@@ -624,7 +624,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingCopyImplementations {
624624
)
625625
.is_ok()
626626
{
627-
cx.emit_span_diag_lint(MISSING_COPY_IMPLEMENTATIONS, item.span, BuiltinMissingCopyImpl);
627+
cx.emit_span_lint(MISSING_COPY_IMPLEMENTATIONS, item.span, BuiltinMissingCopyImpl);
628628
}
629629
}
630630
}
@@ -711,7 +711,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDebugImplementations {
711711
.next()
712712
.is_some();
713713
if !has_impl {
714-
cx.emit_span_diag_lint(
714+
cx.emit_span_lint(
715715
MISSING_DEBUG_IMPLEMENTATIONS,
716716
item.span,
717717
BuiltinMissingDebugImpl { tcx: cx.tcx, def_id: debug },
@@ -788,7 +788,7 @@ impl EarlyLintPass for AnonymousParameters {
788788
} else {
789789
("<type>", Applicability::HasPlaceholders)
790790
};
791-
cx.emit_span_diag_lint(
791+
cx.emit_span_lint(
792792
ANONYMOUS_PARAMETERS,
793793
arg.pat.span,
794794
BuiltinAnonymousParams { suggestion: (arg.pat.span, appl), ty_snip },
@@ -833,7 +833,7 @@ fn warn_if_doc(cx: &EarlyContext<'_>, node_span: Span, node_kind: &str, attrs: &
833833
BuiltinUnusedDocCommentSub::BlockHelp
834834
}
835835
};
836-
cx.emit_span_diag_lint(
836+
cx.emit_span_lint(
837837
UNUSED_DOC_COMMENTS,
838838
span,
839839
BuiltinUnusedDocComment { kind: node_kind, label: node_span, sub },
@@ -965,7 +965,7 @@ impl InvalidNoMangleItems {
965965
) {
966966
let generics = cx.tcx.generics_of(def_id);
967967
if generics.requires_monomorphization(cx.tcx) {
968-
cx.emit_span_diag_lint(
968+
cx.emit_span_lint(
969969
NO_MANGLE_GENERIC_ITEMS,
970970
cx.tcx.def_span(def_id),
971971
BuiltinNoMangleGeneric { suggestion: attr_span },
@@ -997,7 +997,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidNoMangleItems {
997997

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

@@ -1122,7 +1122,7 @@ impl<'tcx> LateLintPass<'tcx> for UnstableFeatures {
11221122
fn check_attributes(&mut self, cx: &LateContext<'_>, attrs: &[hir::Attribute]) {
11231123
if let Some(features) = find_attr!(attrs, Feature(features, _) => features) {
11241124
for feature in features {
1125-
cx.emit_span_diag_lint(UNSTABLE_FEATURES, feature.span, BuiltinUnstableFeatures);
1125+
cx.emit_span_lint(UNSTABLE_FEATURES, feature.span, BuiltinUnstableFeatures);
11261126
}
11271127
}
11281128
}
@@ -1175,7 +1175,7 @@ impl<'tcx> LateLintPass<'tcx> for UngatedAsyncFnTrackCaller {
11751175
// Now, check if the function has the `#[track_caller]` attribute
11761176
&& let Some(attr_span) = find_attr!(cx.tcx, def_id, TrackCaller(span) => *span)
11771177
{
1178-
cx.emit_span_diag_lint(
1178+
cx.emit_span_lint(
11791179
UNGATED_ASYNC_FN_TRACK_CALLER,
11801180
attr_span,
11811181
BuiltinUngatedAsyncFnTrackCaller { label: span, session: &cx.tcx.sess },
@@ -1260,7 +1260,7 @@ impl UnreachablePub {
12601260
applicability = Applicability::MaybeIncorrect;
12611261
}
12621262
let def_span = cx.tcx.def_span(def_id);
1263-
cx.emit_span_diag_lint(
1263+
cx.emit_span_lint(
12641264
UNREACHABLE_PUB,
12651265
def_span,
12661266
BuiltinUnreachablePub {
@@ -1412,7 +1412,7 @@ impl<'tcx> LateLintPass<'tcx> for TypeAliasBounds {
14121412
let enable_feat_help = cx.tcx.sess.is_nightly_build();
14131413

14141414
if let [.., label_sp] = *where_spans {
1415-
cx.emit_span_diag_lint(
1415+
cx.emit_span_lint(
14161416
TYPE_ALIAS_BOUNDS,
14171417
where_spans,
14181418
BuiltinTypeAliasBounds {
@@ -1426,7 +1426,7 @@ impl<'tcx> LateLintPass<'tcx> for TypeAliasBounds {
14261426
);
14271427
}
14281428
if let [.., label_sp] = *inline_spans {
1429-
cx.emit_span_diag_lint(
1429+
cx.emit_span_lint(
14301430
TYPE_ALIAS_BOUNDS,
14311431
inline_spans,
14321432
BuiltinTypeAliasBounds {
@@ -1526,7 +1526,7 @@ impl<'tcx> LateLintPass<'tcx> for TrivialConstraints {
15261526
| ty::ClauseKind::HostEffect(..) => continue,
15271527
};
15281528
if predicate.is_global() {
1529-
cx.emit_span_diag_lint(
1529+
cx.emit_span_lint(
15301530
TRIVIAL_BOUNDS,
15311531
span,
15321532
BuiltinTrivialBounds { predicate_kind_name, predicate },
@@ -1581,7 +1581,7 @@ impl EarlyLintPass for DoubleNegations {
15811581
// Don't lint if this jumps macro expansion boundary (Issue #143980)
15821582
&& expr.span.eq_ctxt(inner.span)
15831583
{
1584-
cx.emit_span_diag_lint(
1584+
cx.emit_span_lint(
15851585
DOUBLE_NEGATIONS,
15861586
expr.span,
15871587
BuiltinDoubleNegations {
@@ -1702,7 +1702,7 @@ impl EarlyLintPass for EllipsisInclusiveRangePatterns {
17021702
replace,
17031703
});
17041704
} else {
1705-
cx.emit_span_diag_lint(
1705+
cx.emit_span_lint(
17061706
ELLIPSIS_INCLUSIVE_RANGE_PATTERNS,
17071707
pat.span,
17081708
BuiltinEllipsisInclusiveRangePatternsLint::Parenthesise {
@@ -1720,7 +1720,7 @@ impl EarlyLintPass for EllipsisInclusiveRangePatterns {
17201720
replace: replace.to_string(),
17211721
});
17221722
} else {
1723-
cx.emit_span_diag_lint(
1723+
cx.emit_span_lint(
17241724
ELLIPSIS_INCLUSIVE_RANGE_PATTERNS,
17251725
join,
17261726
BuiltinEllipsisInclusiveRangePatternsLint::NonParenthesise {
@@ -1902,7 +1902,7 @@ impl KeywordIdents {
19021902
return;
19031903
}
19041904

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

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

2326-
cx.emit_span_diag_lint(
2326+
cx.emit_span_lint(
23272327
INCOMPLETE_FEATURES,
23282328
span,
23292329
BuiltinIncompleteFeatures { name, note, help },
23302330
);
23312331
} else {
2332-
cx.emit_span_diag_lint(
2333-
INTERNAL_FEATURES,
2334-
span,
2335-
BuiltinInternalFeatures { name },
2336-
);
2332+
cx.emit_span_lint(INTERNAL_FEATURES, span, BuiltinInternalFeatures { name });
23372333
}
23382334
});
23392335
}
@@ -2659,7 +2655,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
26592655
}
26602656
};
26612657
let sub = BuiltinUnpermittedTypeInitSub { err };
2662-
cx.emit_span_diag_lint(
2658+
cx.emit_span_lint(
26632659
INVALID_VALUE,
26642660
expr.span,
26652661
BuiltinUnpermittedTypeInit {
@@ -2765,7 +2761,7 @@ impl<'tcx> LateLintPass<'tcx> for DerefNullPtr {
27652761
{
27662762
// `&raw *NULL` is ok.
27672763
} else {
2768-
cx.emit_span_diag_lint(
2764+
cx.emit_span_lint(
27692765
DEREF_NULLPTR,
27702766
expr.span,
27712767
BuiltinDerefNullptr { label: expr.span },
@@ -3074,14 +3070,14 @@ impl<'tcx> LateLintPass<'tcx> for AsmLabels {
30743070
let span = span.unwrap_or(*template_span);
30753071
match label_kind {
30763072
AsmLabelKind::Named => {
3077-
cx.emit_span_diag_lint(
3073+
cx.emit_span_lint(
30783074
NAMED_ASM_LABELS,
30793075
span,
30803076
InvalidAsmLabel::Named { missing_precise_span },
30813077
);
30823078
}
30833079
AsmLabelKind::FormatArg => {
3084-
cx.emit_span_diag_lint(
3080+
cx.emit_span_lint(
30853081
NAMED_ASM_LABELS,
30863082
span,
30873083
InvalidAsmLabel::FormatArg { missing_precise_span },
@@ -3095,7 +3091,7 @@ impl<'tcx> LateLintPass<'tcx> for AsmLabels {
30953091
Some(InlineAsmArch::X86 | InlineAsmArch::X86_64) | None
30963092
) =>
30973093
{
3098-
cx.emit_span_diag_lint(
3094+
cx.emit_span_lint(
30993095
BINARY_ASM_LABELS,
31003096
span,
31013097
InvalidAsmLabel::Binary { missing_precise_span, span },
@@ -3171,12 +3167,12 @@ impl EarlyLintPass for SpecialModuleName {
31713167
}
31723168

31733169
match ident.name.as_str() {
3174-
"lib" => cx.emit_span_diag_lint(
3170+
"lib" => cx.emit_span_lint(
31753171
SPECIAL_MODULE_NAME,
31763172
item.span,
31773173
BuiltinSpecialModuleNameUsed::Lib,
31783174
),
3179-
"main" => cx.emit_span_diag_lint(
3175+
"main" => cx.emit_span_lint(
31803176
SPECIAL_MODULE_NAME,
31813177
item.span,
31823178
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/disallowed_pass_by_ref.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl<'tcx> LateLintPass<'tcx> for DisallowedPassByRef {
2727
return;
2828
}
2929
if let Some(t) = path_for_pass_by_value(cx, inner_ty) {
30-
cx.emit_span_diag_lint(
30+
cx.emit_span_lint(
3131
DISALLOWED_PASS_BY_REF,
3232
ty.span,
3333
DisallowedPassByRefDiag { ty: t, suggestion: ty.span },

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)