1
Fork 0

Auto merge of #120017 - nnethercote:lint-api, r=oli-obk

Fix naming in the lint API

Methods for emit lints are named very inconsistently. This PR fixes that up.

r? `@compiler-errors`
This commit is contained in:
bors 2024-01-23 00:06:57 +00:00
commit 0011fac90d
96 changed files with 353 additions and 376 deletions

View file

@ -415,7 +415,7 @@ fn do_mir_borrowck<'tcx>(
let mut_span = tcx.sess.source_map().span_until_non_whitespace(span); let mut_span = tcx.sess.source_map().span_until_non_whitespace(span);
tcx.emit_spanned_lint(UNUSED_MUT, lint_root, span, VarNeedNotMut { span: mut_span }) tcx.emit_node_span_lint(UNUSED_MUT, lint_root, span, VarNeedNotMut { span: mut_span })
} }
let tainted_by_errors = mbcx.emit_errors(); let tainted_by_errors = mbcx.emit_errors();

View file

@ -563,7 +563,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
if codegen_fn_attrs.inline == InlineAttr::Always { if codegen_fn_attrs.inline == InlineAttr::Always {
if let (Some(no_sanitize_span), Some(inline_span)) = (no_sanitize_span, inline_span) { if let (Some(no_sanitize_span), Some(inline_span)) = (no_sanitize_span, inline_span) {
let hir_id = tcx.local_def_id_to_hir_id(did); let hir_id = tcx.local_def_id_to_hir_id(did);
tcx.struct_span_lint_hir( tcx.node_span_lint(
lint::builtin::INLINE_NO_SANITIZE, lint::builtin::INLINE_NO_SANITIZE,
hir_id, hir_id,
no_sanitize_span, no_sanitize_span,

View file

@ -175,7 +175,7 @@ pub(super) fn lint<'tcx, 'mir, L>(
{ {
let (span, frames) = get_span_and_frames(tcx, machine); let (span, frames) = get_span_and_frames(tcx, machine);
tcx.emit_spanned_lint( tcx.emit_node_span_lint(
lint, lint,
// We use the root frame for this so the crate that defines the const defines whether the // We use the root frame for this so the crate that defines the const defines whether the
// lint is emitted. // lint is emitted.

View file

@ -611,7 +611,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
.0 .0
.is_error(); .is_error();
let span = ecx.cur_span(); let span = ecx.cur_span();
ecx.tcx.emit_spanned_lint( ecx.tcx.emit_node_span_lint(
rustc_session::lint::builtin::LONG_RUNNING_CONST_EVAL, rustc_session::lint::builtin::LONG_RUNNING_CONST_EVAL,
hir_id, hir_id,
span, span,

View file

@ -656,7 +656,7 @@ pub(crate) fn prohibit_explicit_late_bound_lifetimes(
} else { } else {
let mut multispan = MultiSpan::from_span(span); let mut multispan = MultiSpan::from_span(span);
multispan.push_span_label(span_late, note); multispan.push_span_label(span_late, note);
tcx.struct_span_lint_hir( tcx.node_span_lint(
LATE_BOUND_LIFETIME_ARGUMENTS, LATE_BOUND_LIFETIME_ARGUMENTS,
args.args[0].hir_id(), args.args[0].hir_id(),
multispan, multispan,

View file

@ -240,24 +240,18 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
diag.stash(self_ty.span, StashKey::TraitMissingMethod); diag.stash(self_ty.span, StashKey::TraitMissingMethod);
} else { } else {
let msg = "trait objects without an explicit `dyn` are deprecated"; let msg = "trait objects without an explicit `dyn` are deprecated";
tcx.struct_span_lint_hir( tcx.node_span_lint(BARE_TRAIT_OBJECTS, self_ty.hir_id, self_ty.span, msg, |lint| {
BARE_TRAIT_OBJECTS, if self_ty.span.can_be_used_for_suggestions()
self_ty.hir_id, && !self.maybe_lint_impl_trait(self_ty, lint)
self_ty.span, {
msg, lint.multipart_suggestion_verbose(
|lint| { "use `dyn`",
if self_ty.span.can_be_used_for_suggestions() sugg,
&& !self.maybe_lint_impl_trait(self_ty, lint) Applicability::MachineApplicable,
{ );
lint.multipart_suggestion_verbose( }
"use `dyn`", self.maybe_lint_blanket_trait_impl(self_ty, lint);
sugg, });
Applicability::MachineApplicable,
);
}
self.maybe_lint_blanket_trait_impl(self_ty, lint);
},
);
} }
} }
} }

View file

@ -1394,7 +1394,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let ty = self.projected_ty_from_poly_trait_ref(span, assoc_ty_did, assoc_segment, bound); let ty = self.projected_ty_from_poly_trait_ref(span, assoc_ty_did, assoc_segment, bound);
if let Some(variant_def_id) = variant_resolution { if let Some(variant_def_id) = variant_resolution {
tcx.struct_span_lint_hir( tcx.node_span_lint(
AMBIGUOUS_ASSOCIATED_ITEMS, AMBIGUOUS_ASSOCIATED_ITEMS,
hir_ref_id, hir_ref_id,
span, span,

View file

@ -220,7 +220,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let def_id = projection_bound.projection_def_id(); let def_id = projection_bound.projection_def_id();
def_ids.remove(&def_id); def_ids.remove(&def_id);
if tcx.generics_require_sized_self(def_id) { if tcx.generics_require_sized_self(def_id) {
tcx.emit_spanned_lint( tcx.emit_node_span_lint(
UNUSED_ASSOCIATED_TYPE_BOUNDS, UNUSED_ASSOCIATED_TYPE_BOUNDS,
hir_id, hir_id,
*span, *span,

View file

@ -46,7 +46,7 @@ pub fn check_abi(tcx: TyCtxt<'_>, hir_id: hir::HirId, span: Span, abi: Abi) {
.emit(); .emit();
} }
None => { None => {
tcx.struct_span_lint_hir( tcx.node_span_lint(
UNSUPPORTED_CALLING_CONVENTIONS, UNSUPPORTED_CALLING_CONVENTIONS,
hir_id, hir_id,
span, span,
@ -183,7 +183,7 @@ fn check_static_inhabited(tcx: TyCtxt<'_>, def_id: LocalDefId) {
} }
}; };
if layout.abi.is_uninhabited() { if layout.abi.is_uninhabited() {
tcx.struct_span_lint_hir( tcx.node_span_lint(
UNINHABITED_STATIC, UNINHABITED_STATIC,
tcx.local_def_id_to_hir_id(def_id), tcx.local_def_id_to_hir_id(def_id),
span, span,
@ -1079,7 +1079,7 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, adt: ty::AdtDef<'tcx>)
// If there are any non-trivial fields, then there can be no non-exhaustive 1-zsts. // If there are any non-trivial fields, then there can be no non-exhaustive 1-zsts.
// Otherwise, it's only an issue if there's >1 non-exhaustive 1-zst. // Otherwise, it's only an issue if there's >1 non-exhaustive 1-zst.
if non_trivial_count > 0 || prev_non_exhaustive_1zst { if non_trivial_count > 0 || prev_non_exhaustive_1zst {
tcx.struct_span_lint_hir( tcx.node_span_lint(
REPR_TRANSPARENT_EXTERNAL_PRIVATE_FIELDS, REPR_TRANSPARENT_EXTERNAL_PRIVATE_FIELDS,
tcx.local_def_id_to_hir_id(adt.did().expect_local()), tcx.local_def_id_to_hir_id(adt.did().expect_local()),
span, span,

View file

@ -283,7 +283,7 @@ fn report_mismatched_rpitit_signature<'tcx>(
}); });
let span = unmatched_bound.unwrap_or(span); let span = unmatched_bound.unwrap_or(span);
tcx.emit_spanned_lint( tcx.emit_node_span_lint(
REFINING_IMPL_TRAIT, REFINING_IMPL_TRAIT,
tcx.local_def_id_to_hir_id(impl_m_def_id.expect_local()), tcx.local_def_id_to_hir_id(impl_m_def_id.expect_local()),
span, span,

View file

@ -88,7 +88,7 @@ fn handle_static_mut_ref(
"shared ", "shared ",
) )
}; };
tcx.emit_spanned_lint( tcx.emit_node_span_lint(
STATIC_MUT_REF, STATIC_MUT_REF,
hir_id, hir_id,
span, span,

View file

@ -270,7 +270,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
if !spans.is_empty() { if !spans.is_empty() {
let (default_modifier, default_result) = let (default_modifier, default_result) =
reg_class.default_modifier(asm_arch).unwrap(); reg_class.default_modifier(asm_arch).unwrap();
self.tcx.struct_span_lint_hir( self.tcx.node_span_lint(
lint::builtin::ASM_SUB_REGISTER, lint::builtin::ASM_SUB_REGISTER,
expr.hir_id, expr.hir_id,
spans, spans,

View file

@ -40,12 +40,6 @@ fn check_unused_traits(tcx: TyCtxt<'_>, (): ()) {
} else { } else {
"unused import".to_owned() "unused import".to_owned()
}; };
tcx.struct_span_lint_hir( tcx.node_span_lint(lint::builtin::UNUSED_IMPORTS, item.hir_id(), path.span, msg, |_| {});
lint::builtin::UNUSED_IMPORTS,
item.hir_id(),
path.span,
msg,
|_| {},
);
} }
} }

View file

@ -495,7 +495,7 @@ fn lint_auto_trait_impl<'tcx>(
return; return;
} }
tcx.struct_span_lint_hir( tcx.node_span_lint(
lint::builtin::SUSPICIOUS_AUTO_TRAIT_IMPLS, lint::builtin::SUSPICIOUS_AUTO_TRAIT_IMPLS,
tcx.local_def_id_to_hir_id(impl_def_id), tcx.local_def_id_to_hir_id(impl_def_id),
tcx.def_span(impl_def_id), tcx.def_span(impl_def_id),

View file

@ -274,7 +274,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
Defaults::FutureCompatDisallowed Defaults::FutureCompatDisallowed
if tcx.features().default_type_parameter_fallback => {} if tcx.features().default_type_parameter_fallback => {}
Defaults::FutureCompatDisallowed => { Defaults::FutureCompatDisallowed => {
tcx.struct_span_lint_hir( tcx.node_span_lint(
lint::builtin::INVALID_TYPE_PARAM_DEFAULT, lint::builtin::INVALID_TYPE_PARAM_DEFAULT,
param.hir_id, param.hir_id,
param.span, param.span,

View file

@ -912,7 +912,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
continue; continue;
} }
self.insert_lifetime(lt, ResolvedArg::StaticLifetime); self.insert_lifetime(lt, ResolvedArg::StaticLifetime);
self.tcx.struct_span_lint_hir( self.tcx.node_span_lint(
lint::builtin::UNUSED_LIFETIMES, lint::builtin::UNUSED_LIFETIMES,
lifetime.hir_id, lifetime.hir_id,
lifetime.ident.span, lifetime.ident.span,

View file

@ -587,7 +587,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
}; };
let expr_ty = fcx.resolve_vars_if_possible(self.expr_ty); let expr_ty = fcx.resolve_vars_if_possible(self.expr_ty);
let cast_ty = fcx.resolve_vars_if_possible(self.cast_ty); let cast_ty = fcx.resolve_vars_if_possible(self.cast_ty);
fcx.tcx.emit_spanned_lint( fcx.tcx.emit_node_span_lint(
lint, lint,
self.expr.hir_id, self.expr.hir_id,
self.span, self.span,
@ -900,7 +900,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
let expr_ty = fcx.resolve_vars_if_possible(self.expr_ty); let expr_ty = fcx.resolve_vars_if_possible(self.expr_ty);
let cast_ty = fcx.resolve_vars_if_possible(self.cast_ty); let cast_ty = fcx.resolve_vars_if_possible(self.cast_ty);
fcx.tcx.emit_spanned_lint( fcx.tcx.emit_node_span_lint(
lint::builtin::CENUM_IMPL_DROP_CAST, lint::builtin::CENUM_IMPL_DROP_CAST,
self.expr.hir_id, self.expr.hir_id,
self.span, self.span,
@ -934,7 +934,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
}; };
let lint = errors::LossyProvenancePtr2Int { expr_ty, cast_ty, sugg }; let lint = errors::LossyProvenancePtr2Int { expr_ty, cast_ty, sugg };
fcx.tcx.emit_spanned_lint( fcx.tcx.emit_node_span_lint(
lint::builtin::LOSSY_PROVENANCE_CASTS, lint::builtin::LOSSY_PROVENANCE_CASTS,
self.expr.hir_id, self.expr.hir_id,
self.span, self.span,
@ -950,7 +950,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
let expr_ty = fcx.resolve_vars_if_possible(self.expr_ty); let expr_ty = fcx.resolve_vars_if_possible(self.expr_ty);
let cast_ty = fcx.resolve_vars_if_possible(self.cast_ty); let cast_ty = fcx.resolve_vars_if_possible(self.cast_ty);
let lint = errors::LossyProvenanceInt2Ptr { expr_ty, cast_ty, sugg }; let lint = errors::LossyProvenanceInt2Ptr { expr_ty, cast_ty, sugg };
fcx.tcx.emit_spanned_lint( fcx.tcx.emit_node_span_lint(
lint::builtin::FUZZY_PROVENANCE_CASTS, lint::builtin::FUZZY_PROVENANCE_CASTS,
self.expr.hir_id, self.expr.hir_id,
self.span, self.span,

View file

@ -62,7 +62,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
debug!("warn_if_unreachable: id={:?} span={:?} kind={}", id, span, kind); debug!("warn_if_unreachable: id={:?} span={:?} kind={}", id, span, kind);
let msg = format!("unreachable {kind}"); let msg = format!("unreachable {kind}");
self.tcx().struct_span_lint_hir( self.tcx().node_span_lint(
lint::builtin::UNREACHABLE_CODE, lint::builtin::UNREACHABLE_CODE,
id, id,
span, span,

View file

@ -77,7 +77,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// Inherent impls only require not relying on autoref and autoderef in order to // Inherent impls only require not relying on autoref and autoderef in order to
// ensure that the trait implementation won't be used // ensure that the trait implementation won't be used
self.tcx.struct_span_lint_hir( self.tcx.node_span_lint(
prelude_or_array_lint, prelude_or_array_lint,
self_expr.hir_id, self_expr.hir_id,
self_expr.span, self_expr.span,
@ -127,7 +127,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} else { } else {
// trait implementations require full disambiguation to not clash with the new prelude // trait implementations require full disambiguation to not clash with the new prelude
// additions (i.e. convert from dot-call to fully-qualified call) // additions (i.e. convert from dot-call to fully-qualified call)
self.tcx.struct_span_lint_hir( self.tcx.node_span_lint(
prelude_or_array_lint, prelude_or_array_lint,
call_expr.hir_id, call_expr.hir_id,
call_expr.span, call_expr.span,
@ -238,7 +238,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return; return;
} }
self.tcx.struct_span_lint_hir( self.tcx.node_span_lint(
RUST_2021_PRELUDE_COLLISIONS, RUST_2021_PRELUDE_COLLISIONS,
expr_id, expr_id,
span, span,

View file

@ -440,7 +440,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if self.tcx.sess.at_least_rust_2018() { if self.tcx.sess.at_least_rust_2018() {
self.dcx().emit_err(MethodCallOnUnknownRawPointee { span }); self.dcx().emit_err(MethodCallOnUnknownRawPointee { span });
} else { } else {
self.tcx.struct_span_lint_hir( self.tcx.node_span_lint(
lint::builtin::TYVAR_BEHIND_RAW_POINTER, lint::builtin::TYVAR_BEHIND_RAW_POINTER,
scope_expr_id, scope_expr_id,
span, span,
@ -1380,7 +1380,7 @@ impl<'tcx> Pick<'tcx> {
return; return;
} }
let def_kind = self.item.kind.as_def_kind(); let def_kind = self.item.kind.as_def_kind();
tcx.struct_span_lint_hir( tcx.node_span_lint(
lint::builtin::UNSTABLE_NAME_COLLISIONS, lint::builtin::UNSTABLE_NAME_COLLISIONS,
scope_expr_id, scope_expr_id,
span, span,

View file

@ -1840,7 +1840,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&unmentioned_fields.iter().map(|(_, i)| i).collect::<Vec<_>>(), &unmentioned_fields.iter().map(|(_, i)| i).collect::<Vec<_>>(),
); );
self.tcx.struct_span_lint_hir(NON_EXHAUSTIVE_OMITTED_PATTERNS, pat.hir_id, pat.span, "some fields are not explicitly listed", |lint| { self.tcx.node_span_lint(NON_EXHAUSTIVE_OMITTED_PATTERNS, pat.hir_id, pat.span, "some fields are not explicitly listed", |lint| {
lint.span_label(pat.span, format!("field{} {} not listed", rustc_errors::pluralize!(unmentioned_fields.len()), joined_patterns)); lint.span_label(pat.span, format!("field{} {} not listed", rustc_errors::pluralize!(unmentioned_fields.len()), joined_patterns));
lint.help( lint.help(
"ensure that all fields are mentioned explicitly by adding the suggested fields", "ensure that all fields are mentioned explicitly by adding the suggested fields",

View file

@ -754,7 +754,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let closure_hir_id = self.tcx.local_def_id_to_hir_id(closure_def_id); let closure_hir_id = self.tcx.local_def_id_to_hir_id(closure_def_id);
let closure_head_span = self.tcx.def_span(closure_def_id); let closure_head_span = self.tcx.def_span(closure_def_id);
self.tcx.struct_span_lint_hir( self.tcx.node_span_lint(
lint::builtin::RUST_2021_INCOMPATIBLE_CLOSURE_CAPTURES, lint::builtin::RUST_2021_INCOMPATIBLE_CLOSURE_CAPTURES,
closure_hir_id, closure_hir_id,
closure_head_span, closure_head_span,

View file

@ -132,7 +132,7 @@ impl<'tcx> LateLintPass<'tcx> for ArrayIntoIter {
} else { } else {
None None
}; };
cx.emit_spanned_lint( cx.emit_span_lint(
ARRAY_INTO_ITER, ARRAY_INTO_ITER,
call.ident.span, call.ident.span,
ArrayIntoIterDiag { target, suggestion: call.ident.span, sub }, ArrayIntoIterDiag { target, suggestion: call.ident.span, sub },

View file

@ -116,7 +116,7 @@ impl<'tcx> LateLintPass<'tcx> for AsyncFnInTrait {
def.owner_id.def_id, def.owner_id.def_id,
" + Send", " + Send",
); );
cx.tcx.emit_spanned_lint( cx.tcx.emit_node_span_lint(
ASYNC_FN_IN_TRAIT, ASYNC_FN_IN_TRAIT,
item.hir_id(), item.hir_id(),
async_span, async_span,

View file

@ -121,7 +121,7 @@ impl EarlyLintPass for WhileTrue {
"{}loop", "{}loop",
label.map_or_else(String::new, |label| format!("{}: ", label.ident,)) label.map_or_else(String::new, |label| format!("{}: ", label.ident,))
); );
cx.emit_spanned_lint( cx.emit_span_lint(
WHILE_TRUE, WHILE_TRUE,
condition_span, condition_span,
BuiltinWhileTrue { suggestion: condition_span, replace }, BuiltinWhileTrue { suggestion: condition_span, replace },
@ -162,7 +162,7 @@ impl BoxPointers {
if let GenericArgKind::Type(leaf_ty) = leaf.unpack() if let GenericArgKind::Type(leaf_ty) = leaf.unpack()
&& leaf_ty.is_box() && leaf_ty.is_box()
{ {
cx.emit_spanned_lint(BOX_POINTERS, span, BuiltinBoxPointers { ty }); cx.emit_span_lint(BOX_POINTERS, span, BuiltinBoxPointers { ty });
} }
} }
} }
@ -265,7 +265,7 @@ impl<'tcx> LateLintPass<'tcx> for NonShorthandFieldPatterns {
if cx.tcx.find_field_index(ident, variant) if cx.tcx.find_field_index(ident, variant)
== Some(cx.typeck_results().field_index(fieldpat.hir_id)) == Some(cx.typeck_results().field_index(fieldpat.hir_id))
{ {
cx.emit_spanned_lint( cx.emit_span_lint(
NON_SHORTHAND_FIELD_PATTERNS, NON_SHORTHAND_FIELD_PATTERNS,
fieldpat.span, fieldpat.span,
BuiltinNonShorthandFieldPatterns { BuiltinNonShorthandFieldPatterns {
@ -334,7 +334,7 @@ impl UnsafeCode {
return; return;
} }
cx.emit_spanned_lint(UNSAFE_CODE, span, decorate); cx.emit_span_lint(UNSAFE_CODE, span, decorate);
} }
} }
@ -509,7 +509,7 @@ impl MissingDoc {
let attrs = cx.tcx.hir().attrs(cx.tcx.local_def_id_to_hir_id(def_id)); let attrs = cx.tcx.hir().attrs(cx.tcx.local_def_id_to_hir_id(def_id));
let has_doc = attrs.iter().any(has_doc); let has_doc = attrs.iter().any(has_doc);
if !has_doc { if !has_doc {
cx.emit_spanned_lint( cx.emit_span_lint(
MISSING_DOCS, MISSING_DOCS,
cx.tcx.def_span(def_id), cx.tcx.def_span(def_id),
BuiltinMissingDoc { article, desc }, BuiltinMissingDoc { article, desc },
@ -710,7 +710,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingCopyImplementations {
) )
.is_ok() .is_ok()
{ {
cx.emit_spanned_lint(MISSING_COPY_IMPLEMENTATIONS, item.span, BuiltinMissingCopyImpl); cx.emit_span_lint(MISSING_COPY_IMPLEMENTATIONS, item.span, BuiltinMissingCopyImpl);
} }
} }
} }
@ -795,7 +795,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDebugImplementations {
.next() .next()
.is_some(); .is_some();
if !has_impl { if !has_impl {
cx.emit_spanned_lint( cx.emit_span_lint(
MISSING_DEBUG_IMPLEMENTATIONS, MISSING_DEBUG_IMPLEMENTATIONS,
item.span, item.span,
BuiltinMissingDebugImpl { tcx: cx.tcx, def_id: debug }, BuiltinMissingDebugImpl { tcx: cx.tcx, def_id: debug },
@ -874,7 +874,7 @@ impl EarlyLintPass for AnonymousParameters {
} else { } else {
("<type>", Applicability::HasPlaceholders) ("<type>", Applicability::HasPlaceholders)
}; };
cx.emit_spanned_lint( cx.emit_span_lint(
ANONYMOUS_PARAMETERS, ANONYMOUS_PARAMETERS,
arg.pat.span, arg.pat.span,
BuiltinAnonymousParams { suggestion: (arg.pat.span, appl), ty_snip }, BuiltinAnonymousParams { suggestion: (arg.pat.span, appl), ty_snip },
@ -921,7 +921,7 @@ impl EarlyLintPass for DeprecatedAttr {
BuiltinDeprecatedAttrLinkSuggestion::Default { suggestion: attr.span } BuiltinDeprecatedAttrLinkSuggestion::Default { suggestion: attr.span }
} }
}; };
cx.emit_spanned_lint( cx.emit_span_lint(
DEPRECATED, DEPRECATED,
attr.span, attr.span,
BuiltinDeprecatedAttrLink { name, reason, link, suggestion }, BuiltinDeprecatedAttrLink { name, reason, link, suggestion },
@ -931,7 +931,7 @@ impl EarlyLintPass for DeprecatedAttr {
} }
} }
if attr.has_name(sym::no_start) || attr.has_name(sym::crate_id) { if attr.has_name(sym::no_start) || attr.has_name(sym::crate_id) {
cx.emit_spanned_lint( cx.emit_span_lint(
DEPRECATED, DEPRECATED,
attr.span, attr.span,
BuiltinDeprecatedAttrUsed { BuiltinDeprecatedAttrUsed {
@ -973,7 +973,7 @@ fn warn_if_doc(cx: &EarlyContext<'_>, node_span: Span, node_kind: &str, attrs: &
BuiltinUnusedDocCommentSub::BlockHelp BuiltinUnusedDocCommentSub::BlockHelp
} }
}; };
cx.emit_spanned_lint( cx.emit_span_lint(
UNUSED_DOC_COMMENTS, UNUSED_DOC_COMMENTS,
span, span,
BuiltinUnusedDocComment { kind: node_kind, label: node_span, sub }, BuiltinUnusedDocComment { kind: node_kind, label: node_span, sub },
@ -1107,7 +1107,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidNoMangleItems {
match param.kind { match param.kind {
GenericParamKind::Lifetime { .. } => {} GenericParamKind::Lifetime { .. } => {}
GenericParamKind::Type { .. } | GenericParamKind::Const { .. } => { GenericParamKind::Type { .. } | GenericParamKind::Const { .. } => {
cx.emit_spanned_lint( cx.emit_span_lint(
NO_MANGLE_GENERIC_ITEMS, NO_MANGLE_GENERIC_ITEMS,
span, span,
BuiltinNoMangleGeneric { suggestion: no_mangle_attr.span }, BuiltinNoMangleGeneric { suggestion: no_mangle_attr.span },
@ -1138,7 +1138,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidNoMangleItems {
// Const items do not refer to a particular location in memory, and therefore // Const items do not refer to a particular location in memory, and therefore
// don't have anything to attach a symbol to // don't have anything to attach a symbol to
cx.emit_spanned_lint( cx.emit_span_lint(
NO_MANGLE_CONST_ITEMS, NO_MANGLE_CONST_ITEMS,
it.span, it.span,
BuiltinConstNoMangle { suggestion }, BuiltinConstNoMangle { suggestion },
@ -1201,7 +1201,7 @@ impl<'tcx> LateLintPass<'tcx> for MutableTransmutes {
get_transmute_from_to(cx, expr).map(|(ty1, ty2)| (ty1.kind(), ty2.kind())) get_transmute_from_to(cx, expr).map(|(ty1, ty2)| (ty1.kind(), ty2.kind()))
{ {
if from_mutbl < to_mutbl { if from_mutbl < to_mutbl {
cx.emit_spanned_lint(MUTABLE_TRANSMUTES, expr.span, BuiltinMutablesTransmutes); cx.emit_span_lint(MUTABLE_TRANSMUTES, expr.span, BuiltinMutablesTransmutes);
} }
} }
@ -1270,7 +1270,7 @@ impl<'tcx> LateLintPass<'tcx> for UnstableFeatures {
&& let Some(items) = attr.meta_item_list() && let Some(items) = attr.meta_item_list()
{ {
for item in items { for item in items {
cx.emit_spanned_lint(UNSTABLE_FEATURES, item.span(), BuiltinUnstableFeatures); cx.emit_span_lint(UNSTABLE_FEATURES, item.span(), BuiltinUnstableFeatures);
} }
} }
} }
@ -1323,7 +1323,7 @@ impl<'tcx> LateLintPass<'tcx> for UngatedAsyncFnTrackCaller {
// Now, check if the function has the `#[track_caller]` attribute // Now, check if the function has the `#[track_caller]` attribute
&& let Some(attr) = cx.tcx.get_attr(def_id, sym::track_caller) && let Some(attr) = cx.tcx.get_attr(def_id, sym::track_caller)
{ {
cx.emit_spanned_lint( cx.emit_span_lint(
UNGATED_ASYNC_FN_TRACK_CALLER, UNGATED_ASYNC_FN_TRACK_CALLER,
attr.span, attr.span,
BuiltinUngatedAsyncFnTrackCaller { label: span, session: &cx.tcx.sess }, BuiltinUngatedAsyncFnTrackCaller { label: span, session: &cx.tcx.sess },
@ -1389,7 +1389,7 @@ impl UnreachablePub {
applicability = Applicability::MaybeIncorrect; applicability = Applicability::MaybeIncorrect;
} }
let def_span = cx.tcx.def_span(def_id); let def_span = cx.tcx.def_span(def_id);
cx.emit_spanned_lint( cx.emit_span_lint(
UNREACHABLE_PUB, UNREACHABLE_PUB,
def_span, def_span,
BuiltinUnreachablePub { BuiltinUnreachablePub {
@ -1518,7 +1518,7 @@ impl<'tcx> LateLintPass<'tcx> for TypeAliasBounds {
suggested_changing_assoc_types = true; suggested_changing_assoc_types = true;
SuggestChangingAssocTypes { ty: hir_ty } SuggestChangingAssocTypes { ty: hir_ty }
}); });
cx.emit_spanned_lint( cx.emit_span_lint(
TYPE_ALIAS_BOUNDS, TYPE_ALIAS_BOUNDS,
where_spans, where_spans,
BuiltinTypeAliasWhereClause { BuiltinTypeAliasWhereClause {
@ -1534,7 +1534,7 @@ impl<'tcx> LateLintPass<'tcx> for TypeAliasBounds {
suggested_changing_assoc_types = true; suggested_changing_assoc_types = true;
SuggestChangingAssocTypes { ty: hir_ty } SuggestChangingAssocTypes { ty: hir_ty }
}); });
cx.emit_spanned_lint( cx.emit_span_lint(
TYPE_ALIAS_BOUNDS, TYPE_ALIAS_BOUNDS,
inline_spans, inline_spans,
BuiltinTypeAliasGenericBounds { suggestion, sub }, BuiltinTypeAliasGenericBounds { suggestion, sub },
@ -1633,7 +1633,7 @@ impl<'tcx> LateLintPass<'tcx> for TrivialConstraints {
| ClauseKind::ConstEvaluatable(..) => continue, | ClauseKind::ConstEvaluatable(..) => continue,
}; };
if predicate.is_global() { if predicate.is_global() {
cx.emit_spanned_lint( cx.emit_span_lint(
TRIVIAL_BOUNDS, TRIVIAL_BOUNDS,
span, span,
BuiltinTrivialBounds { predicate_kind_name, predicate }, BuiltinTrivialBounds { predicate_kind_name, predicate },
@ -1751,7 +1751,7 @@ impl EarlyLintPass for EllipsisInclusiveRangePatterns {
replace, replace,
}); });
} else { } else {
cx.emit_spanned_lint( cx.emit_span_lint(
ELLIPSIS_INCLUSIVE_RANGE_PATTERNS, ELLIPSIS_INCLUSIVE_RANGE_PATTERNS,
pat.span, pat.span,
BuiltinEllipsisInclusiveRangePatternsLint::Parenthesise { BuiltinEllipsisInclusiveRangePatternsLint::Parenthesise {
@ -1769,7 +1769,7 @@ impl EarlyLintPass for EllipsisInclusiveRangePatterns {
replace: replace.to_string(), replace: replace.to_string(),
}); });
} else { } else {
cx.emit_spanned_lint( cx.emit_span_lint(
ELLIPSIS_INCLUSIVE_RANGE_PATTERNS, ELLIPSIS_INCLUSIVE_RANGE_PATTERNS,
join, join,
BuiltinEllipsisInclusiveRangePatternsLint::NonParenthesise { BuiltinEllipsisInclusiveRangePatternsLint::NonParenthesise {
@ -1895,7 +1895,7 @@ impl KeywordIdents {
return; return;
} }
cx.emit_spanned_lint( cx.emit_span_lint(
KEYWORD_IDENTS, KEYWORD_IDENTS,
ident.span, ident.span,
BuiltinKeywordIdents { kw: ident, next: next_edition, suggestion: ident.span }, BuiltinKeywordIdents { kw: ident, next: next_edition, suggestion: ident.span },
@ -2203,7 +2203,7 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
lint_spans.sort_unstable(); lint_spans.sort_unstable();
lint_spans.dedup(); lint_spans.dedup();
cx.emit_spanned_lint( cx.emit_span_lint(
EXPLICIT_OUTLIVES_REQUIREMENTS, EXPLICIT_OUTLIVES_REQUIREMENTS,
lint_spans.clone(), lint_spans.clone(),
BuiltinExplicitOutlives { BuiltinExplicitOutlives {
@ -2290,13 +2290,13 @@ impl EarlyLintPass for IncompleteInternalFeatures {
let help = let help =
HAS_MIN_FEATURES.contains(&name).then_some(BuiltinIncompleteFeaturesHelp); HAS_MIN_FEATURES.contains(&name).then_some(BuiltinIncompleteFeaturesHelp);
cx.emit_spanned_lint( cx.emit_span_lint(
INCOMPLETE_FEATURES, INCOMPLETE_FEATURES,
span, span,
BuiltinIncompleteFeatures { name, note, help }, BuiltinIncompleteFeatures { name, note, help },
); );
} else { } else {
cx.emit_spanned_lint(INTERNAL_FEATURES, span, BuiltinInternalFeatures { name }); cx.emit_span_lint(INTERNAL_FEATURES, span, BuiltinInternalFeatures { name });
} }
}); });
} }
@ -2612,7 +2612,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
InitKind::Uninit => fluent::lint_builtin_unpermitted_type_init_uninit, InitKind::Uninit => fluent::lint_builtin_unpermitted_type_init_uninit,
}; };
let sub = BuiltinUnpermittedTypeInitSub { err }; let sub = BuiltinUnpermittedTypeInitSub { err };
cx.emit_spanned_lint( cx.emit_span_lint(
INVALID_VALUE, INVALID_VALUE,
expr.span, expr.span,
BuiltinUnpermittedTypeInit { BuiltinUnpermittedTypeInit {
@ -2700,7 +2700,7 @@ impl<'tcx> LateLintPass<'tcx> for DerefNullPtr {
if let rustc_hir::ExprKind::Unary(rustc_hir::UnOp::Deref, expr_deref) = expr.kind { if let rustc_hir::ExprKind::Unary(rustc_hir::UnOp::Deref, expr_deref) = expr.kind {
if is_null_ptr(cx, expr_deref) { if is_null_ptr(cx, expr_deref) {
cx.emit_spanned_lint( cx.emit_span_lint(
DEREF_NULLPTR, DEREF_NULLPTR,
expr.span, expr.span,
BuiltinDerefNullptr { label: expr.span }, BuiltinDerefNullptr { label: expr.span },
@ -2849,7 +2849,7 @@ impl<'tcx> LateLintPass<'tcx> for NamedAsmLabels {
let target_spans: MultiSpan = let target_spans: MultiSpan =
if spans.len() > 0 { spans.into() } else { (*template_span).into() }; if spans.len() > 0 { spans.into() } else { (*template_span).into() };
cx.lookup_with_diagnostics( cx.span_lint_with_diagnostics(
NAMED_ASM_LABELS, NAMED_ASM_LABELS,
Some(target_spans), Some(target_spans),
fluent::lint_builtin_asm_labels, fluent::lint_builtin_asm_labels,
@ -2925,12 +2925,12 @@ impl EarlyLintPass for SpecialModuleName {
} }
match item.ident.name.as_str() { match item.ident.name.as_str() {
"lib" => cx.emit_spanned_lint( "lib" => cx.emit_span_lint(
SPECIAL_MODULE_NAME, SPECIAL_MODULE_NAME,
item.span, item.span,
BuiltinSpecialModuleNameUsed::Lib, BuiltinSpecialModuleNameUsed::Lib,
), ),
"main" => cx.emit_spanned_lint( "main" => cx.emit_span_lint(
SPECIAL_MODULE_NAME, SPECIAL_MODULE_NAME,
item.span, item.span,
BuiltinSpecialModuleNameUsed::Main, BuiltinSpecialModuleNameUsed::Main,

View file

@ -530,9 +530,9 @@ pub trait LintContext {
/// Emit a lint at the appropriate level, with an optional associated span and an existing /// Emit a lint at the appropriate level, with an optional associated span and an existing
/// diagnostic. /// diagnostic.
/// ///
/// [`struct_lint_level`]: rustc_middle::lint::struct_lint_level#decorate-signature /// [`lint_level`]: rustc_middle::lint::lint_level#decorate-signature
#[rustc_lint_diagnostics] #[rustc_lint_diagnostics]
fn lookup_with_diagnostics( fn span_lint_with_diagnostics(
&self, &self,
lint: &'static Lint, lint: &'static Lint,
span: Option<impl Into<MultiSpan>>, span: Option<impl Into<MultiSpan>>,
@ -541,7 +541,7 @@ pub trait LintContext {
diagnostic: BuiltinLintDiagnostics, diagnostic: BuiltinLintDiagnostics,
) { ) {
// We first generate a blank diagnostic. // We first generate a blank diagnostic.
self.lookup(lint, span, msg, |db| { self.opt_span_lint(lint, span, msg, |db| {
// Now, set up surrounding context. // Now, set up surrounding context.
diagnostics::builtin(self.sess(), diagnostic, db); diagnostics::builtin(self.sess(), diagnostic, db);
// Rewrap `db`, and pass control to the user. // Rewrap `db`, and pass control to the user.
@ -553,9 +553,9 @@ pub trait LintContext {
// set the span in their `decorate` function (preferably using set_span). // set the span in their `decorate` function (preferably using set_span).
/// Emit a lint at the appropriate level, with an optional associated span. /// Emit a lint at the appropriate level, with an optional associated span.
/// ///
/// [`struct_lint_level`]: rustc_middle::lint::struct_lint_level#decorate-signature /// [`lint_level`]: rustc_middle::lint::lint_level#decorate-signature
#[rustc_lint_diagnostics] #[rustc_lint_diagnostics]
fn lookup<S: Into<MultiSpan>>( fn opt_span_lint<S: Into<MultiSpan>>(
&self, &self,
lint: &'static Lint, lint: &'static Lint,
span: Option<S>, span: Option<S>,
@ -565,42 +565,42 @@ pub trait LintContext {
/// Emit a lint at `span` from a lint struct (some type that implements `DecorateLint`, /// Emit a lint at `span` from a lint struct (some type that implements `DecorateLint`,
/// typically generated by `#[derive(LintDiagnostic)]`). /// typically generated by `#[derive(LintDiagnostic)]`).
fn emit_spanned_lint<S: Into<MultiSpan>>( fn emit_span_lint<S: Into<MultiSpan>>(
&self, &self,
lint: &'static Lint, lint: &'static Lint,
span: S, span: S,
decorator: impl for<'a> DecorateLint<'a, ()>, decorator: impl for<'a> DecorateLint<'a, ()>,
) { ) {
self.lookup(lint, Some(span), decorator.msg(), |diag| { self.opt_span_lint(lint, Some(span), decorator.msg(), |diag| {
decorator.decorate_lint(diag); decorator.decorate_lint(diag);
}); });
} }
/// Emit a lint at the appropriate level, with an associated span. /// Emit a lint at the appropriate level, with an associated span.
/// ///
/// [`struct_lint_level`]: rustc_middle::lint::struct_lint_level#decorate-signature /// [`lint_level`]: rustc_middle::lint::lint_level#decorate-signature
#[rustc_lint_diagnostics] #[rustc_lint_diagnostics]
fn struct_span_lint<S: Into<MultiSpan>>( fn span_lint<S: Into<MultiSpan>>(
&self, &self,
lint: &'static Lint, lint: &'static Lint,
span: S, span: S,
msg: impl Into<DiagnosticMessage>, msg: impl Into<DiagnosticMessage>,
decorate: impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>), decorate: impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>),
) { ) {
self.lookup(lint, Some(span), msg, decorate); self.opt_span_lint(lint, Some(span), msg, decorate);
} }
/// Emit a lint from a lint struct (some type that implements `DecorateLint`, typically /// Emit a lint from a lint struct (some type that implements `DecorateLint`, typically
/// generated by `#[derive(LintDiagnostic)]`). /// generated by `#[derive(LintDiagnostic)]`).
fn emit_lint(&self, lint: &'static Lint, decorator: impl for<'a> DecorateLint<'a, ()>) { fn emit_lint(&self, lint: &'static Lint, decorator: impl for<'a> DecorateLint<'a, ()>) {
self.lookup(lint, None as Option<Span>, decorator.msg(), |diag| { self.opt_span_lint(lint, None as Option<Span>, decorator.msg(), |diag| {
decorator.decorate_lint(diag); decorator.decorate_lint(diag);
}); });
} }
/// Emit a lint at the appropriate level, with no associated span. /// Emit a lint at the appropriate level, with no associated span.
/// ///
/// [`struct_lint_level`]: rustc_middle::lint::struct_lint_level#decorate-signature /// [`lint_level`]: rustc_middle::lint::lint_level#decorate-signature
#[rustc_lint_diagnostics] #[rustc_lint_diagnostics]
fn lint( fn lint(
&self, &self,
@ -608,7 +608,7 @@ pub trait LintContext {
msg: impl Into<DiagnosticMessage>, msg: impl Into<DiagnosticMessage>,
decorate: impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>), decorate: impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>),
) { ) {
self.lookup(lint, None as Option<Span>, msg, decorate); self.opt_span_lint(lint, None as Option<Span>, msg, decorate);
} }
/// This returns the lint level for the given lint at the current location. /// This returns the lint level for the given lint at the current location.
@ -666,7 +666,7 @@ impl<'tcx> LintContext for LateContext<'tcx> {
} }
#[rustc_lint_diagnostics] #[rustc_lint_diagnostics]
fn lookup<S: Into<MultiSpan>>( fn opt_span_lint<S: Into<MultiSpan>>(
&self, &self,
lint: &'static Lint, lint: &'static Lint,
span: Option<S>, span: Option<S>,
@ -676,8 +676,8 @@ impl<'tcx> LintContext for LateContext<'tcx> {
let hir_id = self.last_node_with_lint_attrs; let hir_id = self.last_node_with_lint_attrs;
match span { match span {
Some(s) => self.tcx.struct_span_lint_hir(lint, hir_id, s, msg, decorate), Some(s) => self.tcx.node_span_lint(lint, hir_id, s, msg, decorate),
None => self.tcx.struct_lint_node(lint, hir_id, msg, decorate), None => self.tcx.node_lint(lint, hir_id, msg, decorate),
} }
} }
@ -693,14 +693,14 @@ impl LintContext for EarlyContext<'_> {
} }
#[rustc_lint_diagnostics] #[rustc_lint_diagnostics]
fn lookup<S: Into<MultiSpan>>( fn opt_span_lint<S: Into<MultiSpan>>(
&self, &self,
lint: &'static Lint, lint: &'static Lint,
span: Option<S>, span: Option<S>,
msg: impl Into<DiagnosticMessage>, msg: impl Into<DiagnosticMessage>,
decorate: impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>), decorate: impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>),
) { ) {
self.builder.struct_lint(lint, span.map(|s| s.into()), msg, decorate) self.builder.opt_span_lint(lint, span.map(|s| s.into()), msg, decorate)
} }
fn get_lint_level(&self, lint: &'static Lint) -> Level { fn get_lint_level(&self, lint: &'static Lint) -> Level {

View file

@ -87,7 +87,7 @@ impl<'tcx> LateLintPass<'tcx> for DerefIntoDynSupertrait {
.find_map(|i| (i.ident.name == sym::Target).then_some(i.span)) .find_map(|i| (i.ident.name == sym::Target).then_some(i.span))
.map(|label| SupertraitAsDerefTargetLabel { label }); .map(|label| SupertraitAsDerefTargetLabel { label });
let span = tcx.def_span(item.owner_id.def_id); let span = tcx.def_span(item.owner_id.def_id);
cx.emit_spanned_lint( cx.emit_span_lint(
DEREF_INTO_DYN_SUPERTRAIT, DEREF_INTO_DYN_SUPERTRAIT,
span, span,
SupertraitAsDerefTarget { SupertraitAsDerefTarget {

View file

@ -149,28 +149,28 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetUseless {
let drop_is_single_call_in_arm = is_single_call_in_arm(cx, arg, expr); let drop_is_single_call_in_arm = is_single_call_in_arm(cx, arg, expr);
match fn_name { match fn_name {
sym::mem_drop if arg_ty.is_ref() && !drop_is_single_call_in_arm => { sym::mem_drop if arg_ty.is_ref() && !drop_is_single_call_in_arm => {
cx.emit_spanned_lint( cx.emit_span_lint(
DROPPING_REFERENCES, DROPPING_REFERENCES,
expr.span, expr.span,
DropRefDiag { arg_ty, label: arg.span }, DropRefDiag { arg_ty, label: arg.span },
); );
} }
sym::mem_forget if arg_ty.is_ref() => { sym::mem_forget if arg_ty.is_ref() => {
cx.emit_spanned_lint( cx.emit_span_lint(
FORGETTING_REFERENCES, FORGETTING_REFERENCES,
expr.span, expr.span,
ForgetRefDiag { arg_ty, label: arg.span }, ForgetRefDiag { arg_ty, label: arg.span },
); );
} }
sym::mem_drop if is_copy && !drop_is_single_call_in_arm => { sym::mem_drop if is_copy && !drop_is_single_call_in_arm => {
cx.emit_spanned_lint( cx.emit_span_lint(
DROPPING_COPY_TYPES, DROPPING_COPY_TYPES,
expr.span, expr.span,
DropCopyDiag { arg_ty, label: arg.span }, DropCopyDiag { arg_ty, label: arg.span },
); );
} }
sym::mem_forget if is_copy => { sym::mem_forget if is_copy => {
cx.emit_spanned_lint( cx.emit_span_lint(
FORGETTING_COPY_TYPES, FORGETTING_COPY_TYPES,
expr.span, expr.span,
ForgetCopyDiag { arg_ty, label: arg.span }, ForgetCopyDiag { arg_ty, label: arg.span },
@ -180,7 +180,7 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetUseless {
if let ty::Adt(adt, _) = arg_ty.kind() if let ty::Adt(adt, _) = arg_ty.kind()
&& adt.is_manually_drop() => && adt.is_manually_drop() =>
{ {
cx.emit_spanned_lint( cx.emit_span_lint(
UNDROPPED_MANUALLY_DROPS, UNDROPPED_MANUALLY_DROPS,
expr.span, expr.span,
UndroppedManuallyDropsDiag { UndroppedManuallyDropsDiag {

View file

@ -45,7 +45,13 @@ impl<'a, T: EarlyLintPass> EarlyContextAndPass<'a, T> {
fn inlined_check_id(&mut self, id: ast::NodeId) { fn inlined_check_id(&mut self, id: ast::NodeId) {
for early_lint in self.context.buffered.take(id) { for early_lint in self.context.buffered.take(id) {
let BufferedEarlyLint { span, msg, node_id: _, lint_id, diagnostic } = early_lint; let BufferedEarlyLint { span, msg, node_id: _, lint_id, diagnostic } = early_lint;
self.context.lookup_with_diagnostics(lint_id.lint, Some(span), msg, |_| {}, diagnostic); self.context.span_lint_with_diagnostics(
lint_id.lint,
Some(span),
msg,
|_| {},
diagnostic,
);
} }
} }

View file

@ -53,7 +53,7 @@ fn enforce_mem_discriminant(
) { ) {
let ty_param = cx.typeck_results().node_args(func_expr.hir_id).type_at(0); let ty_param = cx.typeck_results().node_args(func_expr.hir_id).type_at(0);
if is_non_enum(ty_param) { if is_non_enum(ty_param) {
cx.emit_spanned_lint( cx.emit_span_lint(
ENUM_INTRINSICS_NON_ENUMS, ENUM_INTRINSICS_NON_ENUMS,
expr_span, expr_span,
EnumIntrinsicsMemDiscriminate { ty_param, note: args_span }, EnumIntrinsicsMemDiscriminate { ty_param, note: args_span },
@ -64,11 +64,7 @@ fn enforce_mem_discriminant(
fn enforce_mem_variant_count(cx: &LateContext<'_>, func_expr: &hir::Expr<'_>, span: Span) { fn enforce_mem_variant_count(cx: &LateContext<'_>, func_expr: &hir::Expr<'_>, span: Span) {
let ty_param = cx.typeck_results().node_args(func_expr.hir_id).type_at(0); let ty_param = cx.typeck_results().node_args(func_expr.hir_id).type_at(0);
if is_non_enum(ty_param) { if is_non_enum(ty_param) {
cx.emit_spanned_lint( cx.emit_span_lint(ENUM_INTRINSICS_NON_ENUMS, span, EnumIntrinsicsMemVariant { ty_param });
ENUM_INTRINSICS_NON_ENUMS,
span,
EnumIntrinsicsMemVariant { ty_param },
);
} }
} }

View file

@ -29,7 +29,7 @@ fn check_expectations(tcx: TyCtxt<'_>, tool_filter: Option<Symbol>) {
{ {
let rationale = expectation.reason.map(|rationale| ExpectationNote { rationale }); let rationale = expectation.reason.map(|rationale| ExpectationNote { rationale });
let note = expectation.is_unfulfilled_lint_expectations.then_some(()); let note = expectation.is_unfulfilled_lint_expectations.then_some(());
tcx.emit_spanned_lint( tcx.emit_node_span_lint(
UNFULFILLED_LINT_EXPECTATIONS, UNFULFILLED_LINT_EXPECTATIONS,
*hir_id, *hir_id,
expectation.emission_span, expectation.emission_span,

View file

@ -81,7 +81,7 @@ impl<'tcx> LateLintPass<'tcx> for ForLoopsOverFallibles {
end_span: pat.span.between(arg.span), end_span: pat.span.between(arg.span),
}; };
cx.emit_spanned_lint( cx.emit_span_lint(
FOR_LOOPS_OVER_FALLIBLES, FOR_LOOPS_OVER_FALLIBLES,
arg.span, arg.span,
ForLoopsOverFalliblesDiag { article, ty, sub, question_mark, suggestion }, ForLoopsOverFalliblesDiag { article, ty, sub, question_mark, suggestion },

View file

@ -161,7 +161,7 @@ impl ClashingExternDeclarations {
sub, sub,
} }
}; };
tcx.emit_spanned_lint( tcx.emit_node_span_lint(
CLASHING_EXTERN_DECLARATIONS, CLASHING_EXTERN_DECLARATIONS,
this_fi.hir_id(), this_fi.hir_id(),
mismatch_label, mismatch_label,

View file

@ -74,7 +74,7 @@ impl HiddenUnicodeCodepoints {
HiddenUnicodeCodepointsDiagSub::NoEscape { spans } HiddenUnicodeCodepointsDiagSub::NoEscape { spans }
}; };
cx.emit_spanned_lint( cx.emit_span_lint(
TEXT_DIRECTION_CODEPOINT_IN_LITERAL, TEXT_DIRECTION_CODEPOINT_IN_LITERAL,
span, span,
HiddenUnicodeCodepointsDiag { label, count, span_label: span, labels, sub }, HiddenUnicodeCodepointsDiag { label, count, span_label: span, labels, sub },

View file

@ -43,7 +43,7 @@ impl LateLintPass<'_> for DefaultHashTypes {
Some(sym::HashSet) => "FxHashSet", Some(sym::HashSet) => "FxHashSet",
_ => return, _ => return,
}; };
cx.emit_spanned_lint( cx.emit_span_lint(
DEFAULT_HASH_TYPES, DEFAULT_HASH_TYPES,
path.span, path.span,
DefaultHashTypesDiag { preferred, used: cx.tcx.item_name(def_id) }, DefaultHashTypesDiag { preferred, used: cx.tcx.item_name(def_id) },
@ -91,7 +91,7 @@ impl LateLintPass<'_> for QueryStability {
if let Ok(Some(instance)) = ty::Instance::resolve(cx.tcx, cx.param_env, def_id, args) { if let Ok(Some(instance)) = ty::Instance::resolve(cx.tcx, cx.param_env, def_id, args) {
let def_id = instance.def_id(); let def_id = instance.def_id();
if cx.tcx.has_attr(def_id, sym::rustc_lint_query_instability) { if cx.tcx.has_attr(def_id, sym::rustc_lint_query_instability) {
cx.emit_spanned_lint( cx.emit_span_lint(
POTENTIAL_QUERY_INSTABILITY, POTENTIAL_QUERY_INSTABILITY,
span, span,
QueryInstability { query: cx.tcx.item_name(def_id) }, QueryInstability { query: cx.tcx.item_name(def_id) },
@ -136,7 +136,7 @@ impl<'tcx> LateLintPass<'tcx> for TyTyKind {
{ {
let span = let span =
path.span.with_hi(segment.args.map_or(segment.ident.span, |a| a.span_ext).hi()); path.span.with_hi(segment.args.map_or(segment.ident.span, |a| a.span_ext).hi());
cx.emit_spanned_lint(USAGE_OF_TY_TYKIND, path.span, TykindKind { suggestion: span }); cx.emit_span_lint(USAGE_OF_TY_TYKIND, path.span, TykindKind { suggestion: span });
} }
} }
@ -186,19 +186,19 @@ impl<'tcx> LateLintPass<'tcx> for TyTyKind {
match span { match span {
Some(span) => { Some(span) => {
cx.emit_spanned_lint( cx.emit_span_lint(
USAGE_OF_TY_TYKIND, USAGE_OF_TY_TYKIND,
path.span, path.span,
TykindKind { suggestion: span }, TykindKind { suggestion: span },
); );
} }
None => cx.emit_spanned_lint(USAGE_OF_TY_TYKIND, path.span, TykindDiag), None => cx.emit_span_lint(USAGE_OF_TY_TYKIND, path.span, TykindDiag),
} }
} else if !ty.span.from_expansion() } else if !ty.span.from_expansion()
&& path.segments.len() > 1 && path.segments.len() > 1
&& let Some(ty) = is_ty_or_ty_ctxt(cx, path) && let Some(ty) = is_ty_or_ty_ctxt(cx, path)
{ {
cx.emit_spanned_lint( cx.emit_span_lint(
USAGE_OF_QUALIFIED_TY, USAGE_OF_QUALIFIED_TY,
path.span, path.span,
TyQualified { ty, suggestion: path.span }, TyQualified { ty, suggestion: path.span },
@ -285,7 +285,7 @@ impl EarlyLintPass for LintPassImpl {
&& call_site.ctxt().outer_expn_data().kind && call_site.ctxt().outer_expn_data().kind
!= ExpnKind::Macro(MacroKind::Bang, sym::declare_lint_pass) != ExpnKind::Macro(MacroKind::Bang, sym::declare_lint_pass)
{ {
cx.emit_spanned_lint( cx.emit_span_lint(
LINT_PASS_IMPL_WITHOUT_MACRO, LINT_PASS_IMPL_WITHOUT_MACRO,
lint_pass.path.span, lint_pass.path.span,
LintPassByHand, LintPassByHand,
@ -327,7 +327,7 @@ impl<'tcx> LateLintPass<'tcx> for ExistingDocKeyword {
if is_doc_keyword(keyword) { if is_doc_keyword(keyword) {
return; return;
} }
cx.emit_spanned_lint( cx.emit_span_lint(
EXISTING_DOC_KEYWORD, EXISTING_DOC_KEYWORD,
attr.span, attr.span,
NonExistentDocKeyword { keyword }, NonExistentDocKeyword { keyword },
@ -405,7 +405,7 @@ impl LateLintPass<'_> for Diagnostics {
} }
debug!(?found_impl); debug!(?found_impl);
if !found_parent_with_attr && !found_impl { if !found_parent_with_attr && !found_impl {
cx.emit_spanned_lint(DIAGNOSTIC_OUTSIDE_OF_IMPL, span, DiagOutOfImpl); cx.emit_span_lint(DIAGNOSTIC_OUTSIDE_OF_IMPL, span, DiagOutOfImpl);
} }
let mut found_diagnostic_message = false; let mut found_diagnostic_message = false;
@ -421,7 +421,7 @@ impl LateLintPass<'_> for Diagnostics {
} }
debug!(?found_diagnostic_message); debug!(?found_diagnostic_message);
if !found_parent_with_attr && !found_diagnostic_message { if !found_parent_with_attr && !found_diagnostic_message {
cx.emit_spanned_lint(UNTRANSLATABLE_DIAGNOSTIC, span, UntranslatableDiag); cx.emit_span_lint(UNTRANSLATABLE_DIAGNOSTIC, span, UntranslatableDiag);
} }
} }
} }
@ -490,7 +490,7 @@ impl EarlyLintPass for Diagnostics {
}) { }) {
return; return;
} }
cx.emit_spanned_lint( cx.emit_span_lint(
UNTRANSLATABLE_DIAGNOSTIC_TRIVIAL, UNTRANSLATABLE_DIAGNOSTIC_TRIVIAL,
stmt.span, stmt.span,
UntranslatableDiagnosticTrivial, UntranslatableDiagnosticTrivial,
@ -528,7 +528,7 @@ impl LateLintPass<'_> for BadOptAccess {
&& let Some(lit) = item.lit() && let Some(lit) = item.lit()
&& let ast::LitKind::Str(val, _) = lit.kind && let ast::LitKind::Str(val, _) = lit.kind
{ {
cx.emit_spanned_lint( cx.emit_span_lint(
BAD_OPT_ACCESS, BAD_OPT_ACCESS,
expr.span, expr.span,
BadOptAccessDiag { msg: val.as_str() }, BadOptAccessDiag { msg: val.as_str() },
@ -553,7 +553,7 @@ impl<'tcx> LateLintPass<'tcx> for SpanUseEqCtxt {
expr.kind expr.kind
{ {
if is_span_ctxt_call(cx, lhs) && is_span_ctxt_call(cx, rhs) { if is_span_ctxt_call(cx, lhs) && is_span_ctxt_call(cx, rhs) {
cx.emit_spanned_lint(SPAN_USE_EQ_CTXT, expr.span, SpanUseEqCtxtDiag); cx.emit_span_lint(SPAN_USE_EQ_CTXT, expr.span, SpanUseEqCtxtDiag);
} }
} }
} }

View file

@ -78,7 +78,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidFromUtf8 {
let valid_up_to = utf8_error.valid_up_to(); let valid_up_to = utf8_error.valid_up_to();
let is_unchecked_variant = diag_item.as_str().contains("unchecked"); let is_unchecked_variant = diag_item.as_str().contains("unchecked");
cx.emit_spanned_lint( cx.emit_span_lint(
if is_unchecked_variant { if is_unchecked_variant {
INVALID_FROM_UTF8_UNCHECKED INVALID_FROM_UTF8_UNCHECKED
} else { } else {

View file

@ -160,14 +160,10 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
pat.span, pat.span,
"this lock is not assigned to a binding and is immediately dropped".to_string(), "this lock is not assigned to a binding and is immediately dropped".to_string(),
); );
cx.emit_spanned_lint(LET_UNDERSCORE_LOCK, span, NonBindingLet::SyncLock { sub }); cx.emit_span_lint(LET_UNDERSCORE_LOCK, span, NonBindingLet::SyncLock { sub });
// Only emit let_underscore_drop for top-level `_` patterns. // Only emit let_underscore_drop for top-level `_` patterns.
} else if can_use_init.is_some() { } else if can_use_init.is_some() {
cx.emit_spanned_lint( cx.emit_span_lint(LET_UNDERSCORE_DROP, local.span, NonBindingLet::DropType { sub });
LET_UNDERSCORE_DROP,
local.span,
NonBindingLet::DropType { sub },
);
} }
}); });
} }

View file

@ -24,7 +24,7 @@ use rustc_hir::HirId;
use rustc_index::IndexVec; use rustc_index::IndexVec;
use rustc_middle::hir::nested_filter; use rustc_middle::hir::nested_filter;
use rustc_middle::lint::{ use rustc_middle::lint::{
reveal_actual_level, struct_lint_level, LevelAndSource, LintExpectation, LintLevelSource, lint_level, reveal_actual_level, LevelAndSource, LintExpectation, LintLevelSource,
ShallowLintLevelMap, ShallowLintLevelMap,
}; };
use rustc_middle::query::Providers; use rustc_middle::query::Providers;
@ -682,7 +682,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
sub, sub,
}); });
} else { } else {
self.emit_spanned_lint( self.emit_span_lint(
FORBIDDEN_LINT_GROUPS, FORBIDDEN_LINT_GROUPS,
src.span().into(), src.span().into(),
OverruledAttributeLint { OverruledAttributeLint {
@ -925,7 +925,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
} }
Err((Some(ids), ref new_lint_name)) => { Err((Some(ids), ref new_lint_name)) => {
let lint = builtin::RENAMED_AND_REMOVED_LINTS; let lint = builtin::RENAMED_AND_REMOVED_LINTS;
self.emit_spanned_lint( self.emit_span_lint(
lint, lint,
sp.into(), sp.into(),
DeprecatedLintName { DeprecatedLintName {
@ -976,13 +976,13 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
RenamedLintSuggestion::WithSpan { suggestion: sp, replace }; RenamedLintSuggestion::WithSpan { suggestion: sp, replace };
let name = tool_ident.map(|tool| format!("{tool}::{name}")).unwrap_or(name); let name = tool_ident.map(|tool| format!("{tool}::{name}")).unwrap_or(name);
let lint = RenamedLint { name: name.as_str(), suggestion }; let lint = RenamedLint { name: name.as_str(), suggestion };
self.emit_spanned_lint(RENAMED_AND_REMOVED_LINTS, sp.into(), lint); self.emit_span_lint(RENAMED_AND_REMOVED_LINTS, sp.into(), lint);
} }
CheckLintNameResult::Removed(ref reason) => { CheckLintNameResult::Removed(ref reason) => {
let name = tool_ident.map(|tool| format!("{tool}::{name}")).unwrap_or(name); let name = tool_ident.map(|tool| format!("{tool}::{name}")).unwrap_or(name);
let lint = RemovedLint { name: name.as_str(), reason }; let lint = RemovedLint { name: name.as_str(), reason };
self.emit_spanned_lint(RENAMED_AND_REMOVED_LINTS, sp.into(), lint); self.emit_span_lint(RENAMED_AND_REMOVED_LINTS, sp.into(), lint);
} }
CheckLintNameResult::NoLint(suggestion) => { CheckLintNameResult::NoLint(suggestion) => {
@ -995,7 +995,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
UnknownLintSuggestion::WithSpan { suggestion: sp, replace, from_rustc } UnknownLintSuggestion::WithSpan { suggestion: sp, replace, from_rustc }
}); });
let lint = UnknownLint { name, suggestion }; let lint = UnknownLint { name, suggestion };
self.emit_spanned_lint(UNKNOWN_LINTS, sp.into(), lint); self.emit_span_lint(UNKNOWN_LINTS, sp.into(), lint);
} }
} }
// If this lint was renamed, apply the new lint instead of ignoring the attribute. // If this lint was renamed, apply the new lint instead of ignoring the attribute.
@ -1041,7 +1041,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
continue; continue;
}; };
self.emit_spanned_lint( self.emit_span_lint(
UNUSED_ATTRIBUTES, UNUSED_ATTRIBUTES,
lint_attr_span.into(), lint_attr_span.into(),
IgnoredUnlessCrateSpecified { level: level.as_str(), name: lint_attr_name }, IgnoredUnlessCrateSpecified { level: level.as_str(), name: lint_attr_name },
@ -1062,7 +1062,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
if self.lint_added_lints { if self.lint_added_lints {
let lint = builtin::UNKNOWN_LINTS; let lint = builtin::UNKNOWN_LINTS;
let (level, src) = self.lint_level(builtin::UNKNOWN_LINTS); let (level, src) = self.lint_level(builtin::UNKNOWN_LINTS);
struct_lint_level( lint_level(
self.sess, self.sess,
lint, lint,
level, level,
@ -1096,10 +1096,10 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
/// Used to emit a lint-related diagnostic based on the current state of /// Used to emit a lint-related diagnostic based on the current state of
/// this lint context. /// this lint context.
/// ///
/// [`struct_lint_level`]: rustc_middle::lint::struct_lint_level#decorate-signature /// [`lint_level`]: rustc_middle::lint::lint_level#decorate-signature
#[rustc_lint_diagnostics] #[rustc_lint_diagnostics]
#[track_caller] #[track_caller]
pub(crate) fn struct_lint( pub(crate) fn opt_span_lint(
&self, &self,
lint: &'static Lint, lint: &'static Lint,
span: Option<MultiSpan>, span: Option<MultiSpan>,
@ -1107,18 +1107,18 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
decorate: impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>), decorate: impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>),
) { ) {
let (level, src) = self.lint_level(lint); let (level, src) = self.lint_level(lint);
struct_lint_level(self.sess, lint, level, src, span, msg, decorate) lint_level(self.sess, lint, level, src, span, msg, decorate)
} }
#[track_caller] #[track_caller]
pub fn emit_spanned_lint( pub fn emit_span_lint(
&self, &self,
lint: &'static Lint, lint: &'static Lint,
span: MultiSpan, span: MultiSpan,
decorate: impl for<'a> DecorateLint<'a, ()>, decorate: impl for<'a> DecorateLint<'a, ()>,
) { ) {
let (level, src) = self.lint_level(lint); let (level, src) = self.lint_level(lint);
struct_lint_level(self.sess, lint, level, src, Some(span), decorate.msg(), |lint| { lint_level(self.sess, lint, level, src, Some(span), decorate.msg(), |lint| {
decorate.decorate_lint(lint); decorate.decorate_lint(lint);
}); });
} }
@ -1126,7 +1126,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
#[track_caller] #[track_caller]
pub fn emit_lint(&self, lint: &'static Lint, decorate: impl for<'a> DecorateLint<'a, ()>) { pub fn emit_lint(&self, lint: &'static Lint, decorate: impl for<'a> DecorateLint<'a, ()>) {
let (level, src) = self.lint_level(lint); let (level, src) = self.lint_level(lint);
struct_lint_level(self.sess, lint, level, src, None, decorate.msg(), |lint| { lint_level(self.sess, lint, level, src, None, decorate.msg(), |lint| {
decorate.decorate_lint(lint); decorate.decorate_lint(lint);
}); });
} }

View file

@ -61,7 +61,7 @@ impl<'tcx> LateLintPass<'tcx> for MapUnitFn {
let fn_ty = cx.tcx.fn_sig(id).skip_binder(); let fn_ty = cx.tcx.fn_sig(id).skip_binder();
let ret_ty = fn_ty.output().skip_binder(); let ret_ty = fn_ty.output().skip_binder();
if is_unit_type(ret_ty) { if is_unit_type(ret_ty) {
cx.emit_spanned_lint( cx.emit_span_lint(
MAP_UNIT_FN, MAP_UNIT_FN,
span, span,
MappingToUnit { MappingToUnit {
@ -80,7 +80,7 @@ impl<'tcx> LateLintPass<'tcx> for MapUnitFn {
let cl_ty = subs.as_closure().sig(); let cl_ty = subs.as_closure().sig();
let ret_ty = cl_ty.output().skip_binder(); let ret_ty = cl_ty.output().skip_binder();
if is_unit_type(ret_ty) { if is_unit_type(ret_ty) {
cx.emit_spanned_lint( cx.emit_span_lint(
MAP_UNIT_FN, MAP_UNIT_FN,
span, span,
MappingToUnit { MappingToUnit {

View file

@ -57,7 +57,7 @@ fn lint_cstring_as_ptr(
if cx.tcx.is_diagnostic_item(sym::Result, def.did()) { if cx.tcx.is_diagnostic_item(sym::Result, def.did()) {
if let ty::Adt(adt, _) = args.type_at(0).kind() { if let ty::Adt(adt, _) = args.type_at(0).kind() {
if cx.tcx.is_diagnostic_item(sym::cstring_type, adt.did()) { if cx.tcx.is_diagnostic_item(sym::cstring_type, adt.did()) {
cx.emit_spanned_lint( cx.emit_span_lint(
TEMPORARY_CSTRING_AS_PTR, TEMPORARY_CSTRING_AS_PTR,
as_ptr_span, as_ptr_span,
CStringPtr { as_ptr: as_ptr_span, unwrap: unwrap.span }, CStringPtr { as_ptr: as_ptr_span, unwrap: unwrap.span },

View file

@ -49,7 +49,7 @@ impl<'tcx> LateLintPass<'tcx> for MultipleSupertraitUpcastable {
.into_iter() .into_iter()
.filter_map(|(pred, _)| pred.as_trait_clause()); .filter_map(|(pred, _)| pred.as_trait_clause());
if direct_super_traits_iter.count() > 1 { if direct_super_traits_iter.count() > 1 {
cx.emit_spanned_lint( cx.emit_span_lint(
MULTIPLE_SUPERTRAIT_UPCASTABLE, MULTIPLE_SUPERTRAIT_UPCASTABLE,
cx.tcx.def_span(def_id), cx.tcx.def_span(def_id),
crate::lints::MultipleSupertraitUpcastable { ident: item.ident }, crate::lints::MultipleSupertraitUpcastable { ident: item.ident },

View file

@ -186,11 +186,11 @@ impl EarlyLintPass for NonAsciiIdents {
continue; continue;
} }
has_non_ascii_idents = true; has_non_ascii_idents = true;
cx.emit_spanned_lint(NON_ASCII_IDENTS, sp, IdentifierNonAsciiChar); cx.emit_span_lint(NON_ASCII_IDENTS, sp, IdentifierNonAsciiChar);
if check_uncommon_codepoints if check_uncommon_codepoints
&& !symbol_str.chars().all(GeneralSecurityProfile::identifier_allowed) && !symbol_str.chars().all(GeneralSecurityProfile::identifier_allowed)
{ {
cx.emit_spanned_lint(UNCOMMON_CODEPOINTS, sp, IdentifierUncommonCodepoints); cx.emit_span_lint(UNCOMMON_CODEPOINTS, sp, IdentifierUncommonCodepoints);
} }
} }
@ -218,7 +218,7 @@ impl EarlyLintPass for NonAsciiIdents {
.entry(skeleton_sym) .entry(skeleton_sym)
.and_modify(|(existing_symbol, existing_span, existing_is_ascii)| { .and_modify(|(existing_symbol, existing_span, existing_is_ascii)| {
if !*existing_is_ascii || !is_ascii { if !*existing_is_ascii || !is_ascii {
cx.emit_spanned_lint( cx.emit_span_lint(
CONFUSABLE_IDENTS, CONFUSABLE_IDENTS,
sp, sp,
ConfusableIdentifierPair { ConfusableIdentifierPair {
@ -339,7 +339,7 @@ impl EarlyLintPass for NonAsciiIdents {
let char_info = format!("'{}' (U+{:04X})", ch, ch as u32); let char_info = format!("'{}' (U+{:04X})", ch, ch as u32);
includes += &char_info; includes += &char_info;
} }
cx.emit_spanned_lint( cx.emit_span_lint(
MIXED_SCRIPT_CONFUSABLES, MIXED_SCRIPT_CONFUSABLES,
sp, sp,
MixedScriptConfusables { set: script_set.to_string(), includes }, MixedScriptConfusables { set: script_set.to_string(), includes },

View file

@ -121,7 +121,7 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc
} }
#[allow(rustc::diagnostic_outside_of_impl)] #[allow(rustc::diagnostic_outside_of_impl)]
cx.struct_span_lint(NON_FMT_PANICS, arg_span, fluent::lint_non_fmt_panic, |lint| { cx.span_lint(NON_FMT_PANICS, arg_span, fluent::lint_non_fmt_panic, |lint| {
lint.arg("name", symbol); lint.arg("name", symbol);
lint.note(fluent::lint_note); lint.note(fluent::lint_note);
lint.note(fluent::lint_more_info_note); lint.note(fluent::lint_more_info_note);
@ -251,7 +251,7 @@ fn check_panic_str<'tcx>(
.map(|span| fmt_span.from_inner(InnerSpan::new(span.start, span.end))) .map(|span| fmt_span.from_inner(InnerSpan::new(span.start, span.end)))
.collect(), .collect(),
}; };
cx.emit_spanned_lint( cx.emit_span_lint(
NON_FMT_PANICS, NON_FMT_PANICS,
arg_spans, arg_spans,
NonFmtPanicUnused { NonFmtPanicUnused {
@ -268,7 +268,7 @@ fn check_panic_str<'tcx>(
.collect() .collect()
}); });
let count = brace_spans.as_ref().map(|v| v.len()).unwrap_or(/* any number >1 */ 2); let count = brace_spans.as_ref().map(|v| v.len()).unwrap_or(/* any number >1 */ 2);
cx.emit_spanned_lint( cx.emit_span_lint(
NON_FMT_PANICS, NON_FMT_PANICS,
brace_spans.unwrap_or_else(|| vec![span]), brace_spans.unwrap_or_else(|| vec![span]),
NonFmtPanicBraces { NonFmtPanicBraces {

View file

@ -150,7 +150,7 @@ impl NonCamelCaseTypes {
} else { } else {
NonCamelCaseTypeSub::Label { span: ident.span } NonCamelCaseTypeSub::Label { span: ident.span }
}; };
cx.emit_spanned_lint( cx.emit_span_lint(
NON_CAMEL_CASE_TYPES, NON_CAMEL_CASE_TYPES,
ident.span, ident.span,
NonCamelCaseType { sort, name, sub }, NonCamelCaseType { sort, name, sub },
@ -320,7 +320,7 @@ impl NonSnakeCase {
} else { } else {
NonSnakeCaseDiagSub::Label { span } NonSnakeCaseDiagSub::Label { span }
}; };
cx.emit_spanned_lint(NON_SNAKE_CASE, span, NonSnakeCaseDiag { sort, name, sc, sub }); cx.emit_span_lint(NON_SNAKE_CASE, span, NonSnakeCaseDiag { sort, name, sc, sub });
} }
} }
} }
@ -481,7 +481,7 @@ impl NonUpperCaseGlobals {
} else { } else {
NonUpperCaseGlobalSub::Label { span: ident.span } NonUpperCaseGlobalSub::Label { span: ident.span }
}; };
cx.emit_spanned_lint( cx.emit_span_lint(
NON_UPPER_CASE_GLOBALS, NON_UPPER_CASE_GLOBALS,
ident.span, ident.span,
NonUpperCaseGlobal { sort, name, sub }, NonUpperCaseGlobal { sort, name, sub },

View file

@ -121,7 +121,7 @@ impl<'tcx> LateLintPass<'tcx> for NoopMethodCall {
let orig_ty = expr_ty.peel_refs(); let orig_ty = expr_ty.peel_refs();
if receiver_ty == expr_ty { if receiver_ty == expr_ty {
cx.emit_spanned_lint( cx.emit_span_lint(
NOOP_METHOD_CALL, NOOP_METHOD_CALL,
span, span,
NoopMethodCallDiag { method: call.ident.name, orig_ty, trait_, label: span }, NoopMethodCallDiag { method: call.ident.name, orig_ty, trait_, label: span },
@ -131,12 +131,12 @@ impl<'tcx> LateLintPass<'tcx> for NoopMethodCall {
// If `type_of(x) == T` and `x.borrow()` is used to get `&T`, // If `type_of(x) == T` and `x.borrow()` is used to get `&T`,
// then that should be allowed // then that should be allowed
sym::noop_method_borrow => return, sym::noop_method_borrow => return,
sym::noop_method_clone => cx.emit_spanned_lint( sym::noop_method_clone => cx.emit_span_lint(
SUSPICIOUS_DOUBLE_REF_OP, SUSPICIOUS_DOUBLE_REF_OP,
span, span,
SuspiciousDoubleRefCloneDiag { ty: expr_ty }, SuspiciousDoubleRefCloneDiag { ty: expr_ty },
), ),
sym::noop_method_deref => cx.emit_spanned_lint( sym::noop_method_deref => cx.emit_span_lint(
SUSPICIOUS_DOUBLE_REF_OP, SUSPICIOUS_DOUBLE_REF_OP,
span, span,
SuspiciousDoubleRefDerefDiag { ty: expr_ty }, SuspiciousDoubleRefDerefDiag { ty: expr_ty },

View file

@ -145,7 +145,7 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound {
}), }),
_ => None, _ => None,
}; };
cx.emit_spanned_lint( cx.emit_span_lint(
OPAQUE_HIDDEN_INFERRED_BOUND, OPAQUE_HIDDEN_INFERRED_BOUND,
pred_span, pred_span,
OpaqueHiddenInferredBoundLint { OpaqueHiddenInferredBoundLint {

View file

@ -29,7 +29,7 @@ impl<'tcx> LateLintPass<'tcx> for PassByValue {
} }
} }
if let Some(t) = path_for_pass_by_value(cx, inner_ty) { if let Some(t) = path_for_pass_by_value(cx, inner_ty) {
cx.emit_spanned_lint( cx.emit_span_lint(
PASS_BY_VALUE, PASS_BY_VALUE,
ty.span, ty.span,
PassByValueDiag { ty: t, suggestion: ty.span }, PassByValueDiag { ty: t, suggestion: ty.span },

View file

@ -97,7 +97,7 @@ impl<'tcx> LateLintPass<'tcx> for PtrNullChecks {
) )
&& let Some(diag) = incorrect_check(cx, arg) => && let Some(diag) = incorrect_check(cx, arg) =>
{ {
cx.emit_spanned_lint(USELESS_PTR_NULL_CHECKS, expr.span, diag) cx.emit_span_lint(USELESS_PTR_NULL_CHECKS, expr.span, diag)
} }
// Catching: // Catching:
@ -110,7 +110,7 @@ impl<'tcx> LateLintPass<'tcx> for PtrNullChecks {
) )
&& let Some(diag) = incorrect_check(cx, receiver) => && let Some(diag) = incorrect_check(cx, receiver) =>
{ {
cx.emit_spanned_lint(USELESS_PTR_NULL_CHECKS, expr.span, diag) cx.emit_span_lint(USELESS_PTR_NULL_CHECKS, expr.span, diag)
} }
ExprKind::Binary(op, left, right) if matches!(op.node, BinOpKind::Eq) => { ExprKind::Binary(op, left, right) if matches!(op.node, BinOpKind::Eq) => {
@ -134,7 +134,7 @@ impl<'tcx> LateLintPass<'tcx> for PtrNullChecks {
&& let LitKind::Int(v, _) = spanned.node && let LitKind::Int(v, _) = spanned.node
&& v == 0 => && v == 0 =>
{ {
cx.emit_spanned_lint(USELESS_PTR_NULL_CHECKS, expr.span, diag) cx.emit_span_lint(USELESS_PTR_NULL_CHECKS, expr.span, diag)
} }
// Catching: // Catching:
@ -145,7 +145,7 @@ impl<'tcx> LateLintPass<'tcx> for PtrNullChecks {
&& let Some(diag_item) = cx.tcx.get_diagnostic_name(def_id) && let Some(diag_item) = cx.tcx.get_diagnostic_name(def_id)
&& (diag_item == sym::ptr_null || diag_item == sym::ptr_null_mut) => && (diag_item == sym::ptr_null || diag_item == sym::ptr_null_mut) =>
{ {
cx.emit_spanned_lint(USELESS_PTR_NULL_CHECKS, expr.span, diag) cx.emit_span_lint(USELESS_PTR_NULL_CHECKS, expr.span, diag)
} }
_ => {} _ => {}

View file

@ -47,7 +47,7 @@ fn maybe_lint_redundant_semis(cx: &EarlyContext<'_>, seq: &mut Option<(Span, boo
return; return;
} }
cx.emit_spanned_lint( cx.emit_span_lint(
REDUNDANT_SEMICOLONS, REDUNDANT_SEMICOLONS,
span, span,
RedundantSemicolonsDiag { multiple, suggestion: span }, RedundantSemicolonsDiag { multiple, suggestion: span },

View file

@ -47,7 +47,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidReferenceCasting {
let orig_cast = if init.span != e.span { Some(init.span) } else { None }; let orig_cast = if init.span != e.span { Some(init.span) } else { None };
let ty_has_interior_mutability = ty_has_interior_mutability.then_some(()); let ty_has_interior_mutability = ty_has_interior_mutability.then_some(());
cx.emit_spanned_lint( cx.emit_span_lint(
INVALID_REFERENCE_CASTING, INVALID_REFERENCE_CASTING,
expr.span, expr.span,
if pat == PatternKind::Assign { if pat == PatternKind::Assign {

View file

@ -101,7 +101,7 @@ impl<'tcx> LateLintPass<'tcx> for DropTraitConstraints {
continue; continue;
} }
let Some(def_id) = cx.tcx.get_diagnostic_item(sym::needs_drop) else { return }; let Some(def_id) = cx.tcx.get_diagnostic_item(sym::needs_drop) else { return };
cx.emit_spanned_lint( cx.emit_span_lint(
DROP_BOUNDS, DROP_BOUNDS,
span, span,
DropTraitConstraintsDiag { predicate, tcx: cx.tcx, def_id }, DropTraitConstraintsDiag { predicate, tcx: cx.tcx, def_id },
@ -116,7 +116,7 @@ impl<'tcx> LateLintPass<'tcx> for DropTraitConstraints {
let def_id = bound.trait_ref.trait_def_id(); let def_id = bound.trait_ref.trait_def_id();
if cx.tcx.lang_items().drop_trait() == def_id { if cx.tcx.lang_items().drop_trait() == def_id {
let Some(def_id) = cx.tcx.get_diagnostic_item(sym::needs_drop) else { return }; let Some(def_id) = cx.tcx.get_diagnostic_item(sym::needs_drop) else { return };
cx.emit_spanned_lint(DYN_DROP, bound.span, DropGlue { tcx: cx.tcx, def_id }); cx.emit_span_lint(DYN_DROP, bound.span, DropGlue { tcx: cx.tcx, def_id });
} }
} }
} }

View file

@ -254,7 +254,7 @@ fn lint_overflowing_range_endpoint<'tcx>(
} }
}; };
cx.emit_spanned_lint( cx.emit_span_lint(
OVERFLOWING_LITERALS, OVERFLOWING_LITERALS,
struct_expr.span, struct_expr.span,
RangeEndpointOutOfRange { ty, sub: sub_sugg }, RangeEndpointOutOfRange { ty, sub: sub_sugg },
@ -371,7 +371,7 @@ fn report_bin_hex_error(
}) })
.flatten(); .flatten();
cx.emit_spanned_lint( cx.emit_span_lint(
OVERFLOWING_LITERALS, OVERFLOWING_LITERALS,
expr.span, expr.span,
OverflowingBinHex { OverflowingBinHex {
@ -473,7 +473,7 @@ fn lint_int_literal<'tcx>(
let help = get_type_suggestion(cx.typeck_results().node_type(e.hir_id), v, negative) let help = get_type_suggestion(cx.typeck_results().node_type(e.hir_id), v, negative)
.map(|suggestion_ty| OverflowingIntHelp { suggestion_ty }); .map(|suggestion_ty| OverflowingIntHelp { suggestion_ty });
cx.emit_spanned_lint( cx.emit_span_lint(
OVERFLOWING_LITERALS, OVERFLOWING_LITERALS,
span, span,
OverflowingInt { ty: t.name_str(), lit, min, max, help }, OverflowingInt { ty: t.name_str(), lit, min, max, help },
@ -501,7 +501,7 @@ fn lint_uint_literal<'tcx>(
match par_e.kind { match par_e.kind {
hir::ExprKind::Cast(..) => { hir::ExprKind::Cast(..) => {
if let ty::Char = cx.typeck_results().expr_ty(par_e).kind() { if let ty::Char = cx.typeck_results().expr_ty(par_e).kind() {
cx.emit_spanned_lint( cx.emit_span_lint(
OVERFLOWING_LITERALS, OVERFLOWING_LITERALS,
par_e.span, par_e.span,
OnlyCastu8ToChar { span: par_e.span, literal: lit_val }, OnlyCastu8ToChar { span: par_e.span, literal: lit_val },
@ -528,7 +528,7 @@ fn lint_uint_literal<'tcx>(
); );
return; return;
} }
cx.emit_spanned_lint( cx.emit_span_lint(
OVERFLOWING_LITERALS, OVERFLOWING_LITERALS,
e.span, e.span,
OverflowingUInt { OverflowingUInt {
@ -570,7 +570,7 @@ fn lint_literal<'tcx>(
_ => bug!(), _ => bug!(),
}; };
if is_infinite == Ok(true) { if is_infinite == Ok(true) {
cx.emit_spanned_lint( cx.emit_span_lint(
OVERFLOWING_LITERALS, OVERFLOWING_LITERALS,
e.span, e.span,
OverflowingLiteral { OverflowingLiteral {
@ -654,7 +654,7 @@ fn lint_nan<'tcx>(
_ => return, _ => return,
}; };
cx.emit_spanned_lint(INVALID_NAN_COMPARISONS, e.span, lint); cx.emit_span_lint(INVALID_NAN_COMPARISONS, e.span, lint);
} }
fn lint_wide_pointer<'tcx>( fn lint_wide_pointer<'tcx>(
@ -700,7 +700,7 @@ fn lint_wide_pointer<'tcx>(
let (Some(l_span), Some(r_span)) = let (Some(l_span), Some(r_span)) =
(l.span.find_ancestor_inside(e.span), r.span.find_ancestor_inside(e.span)) (l.span.find_ancestor_inside(e.span), r.span.find_ancestor_inside(e.span))
else { else {
return cx.emit_spanned_lint( return cx.emit_span_lint(
AMBIGUOUS_WIDE_POINTER_COMPARISONS, AMBIGUOUS_WIDE_POINTER_COMPARISONS,
e.span, e.span,
AmbiguousWidePointerComparisons::Spanless, AmbiguousWidePointerComparisons::Spanless,
@ -718,7 +718,7 @@ fn lint_wide_pointer<'tcx>(
let deref_left = &*"*".repeat(l_ty_refs); let deref_left = &*"*".repeat(l_ty_refs);
let deref_right = &*"*".repeat(r_ty_refs); let deref_right = &*"*".repeat(r_ty_refs);
cx.emit_spanned_lint( cx.emit_span_lint(
AMBIGUOUS_WIDE_POINTER_COMPARISONS, AMBIGUOUS_WIDE_POINTER_COMPARISONS,
e.span, e.span,
AmbiguousWidePointerComparisons::Spanful { AmbiguousWidePointerComparisons::Spanful {
@ -770,7 +770,7 @@ impl<'tcx> LateLintPass<'tcx> for TypeLimits {
hir::ExprKind::Binary(binop, ref l, ref r) => { hir::ExprKind::Binary(binop, ref l, ref r) => {
if is_comparison(binop) { if is_comparison(binop) {
if !check_limits(cx, binop, l, r) { if !check_limits(cx, binop, l, r) {
cx.emit_spanned_lint(UNUSED_COMPARISONS, e.span, UnusedComparisons); cx.emit_span_lint(UNUSED_COMPARISONS, e.span, UnusedComparisons);
} else { } else {
lint_nan(cx, e, binop, l, r); lint_nan(cx, e, binop, l, r);
lint_wide_pointer(cx, e, binop.node, l, r); lint_wide_pointer(cx, e, binop.node, l, r);
@ -1464,7 +1464,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
} else { } else {
None None
}; };
self.cx.emit_spanned_lint( self.cx.emit_span_lint(
lint, lint,
sp, sp,
ImproperCTypes { ty, desc, label: sp, help, note, span_note }, ImproperCTypes { ty, desc, label: sp, help, note, span_note },
@ -1792,7 +1792,7 @@ impl<'tcx> LateLintPass<'tcx> for VariantSizeDifferences {
// We only warn if the largest variant is at least thrice as large as // We only warn if the largest variant is at least thrice as large as
// the second-largest. // the second-largest.
if largest > slargest * 3 && slargest > 0 { if largest > slargest * 3 && slargest > 0 {
cx.emit_spanned_lint( cx.emit_span_lint(
VARIANT_SIZE_DIFFERENCES, VARIANT_SIZE_DIFFERENCES,
enum_definition.variants[largest_index].span, enum_definition.variants[largest_index].span,
VariantSizeDifferencesDiag { largest }, VariantSizeDifferencesDiag { largest },
@ -1913,17 +1913,9 @@ impl InvalidAtomicOrdering {
&& (ordering == invalid_ordering || ordering == sym::AcqRel) && (ordering == invalid_ordering || ordering == sym::AcqRel)
{ {
if method == sym::load { if method == sym::load {
cx.emit_spanned_lint( cx.emit_span_lint(INVALID_ATOMIC_ORDERING, ordering_arg.span, AtomicOrderingLoad);
INVALID_ATOMIC_ORDERING,
ordering_arg.span,
AtomicOrderingLoad,
);
} else { } else {
cx.emit_spanned_lint( cx.emit_span_lint(INVALID_ATOMIC_ORDERING, ordering_arg.span, AtomicOrderingStore);
INVALID_ATOMIC_ORDERING,
ordering_arg.span,
AtomicOrderingStore,
);
}; };
} }
} }
@ -1935,7 +1927,7 @@ impl InvalidAtomicOrdering {
&& matches!(cx.tcx.get_diagnostic_name(def_id), Some(sym::fence | sym::compiler_fence)) && matches!(cx.tcx.get_diagnostic_name(def_id), Some(sym::fence | sym::compiler_fence))
&& Self::match_ordering(cx, &args[0]) == Some(sym::Relaxed) && Self::match_ordering(cx, &args[0]) == Some(sym::Relaxed)
{ {
cx.emit_spanned_lint(INVALID_ATOMIC_ORDERING, args[0].span, AtomicOrderingFence); cx.emit_span_lint(INVALID_ATOMIC_ORDERING, args[0].span, AtomicOrderingFence);
} }
} }
@ -1957,7 +1949,7 @@ impl InvalidAtomicOrdering {
let Some(fail_ordering) = Self::match_ordering(cx, fail_order_arg) else { return }; let Some(fail_ordering) = Self::match_ordering(cx, fail_order_arg) else { return };
if matches!(fail_ordering, sym::Release | sym::AcqRel) { if matches!(fail_ordering, sym::Release | sym::AcqRel) {
cx.emit_spanned_lint( cx.emit_span_lint(
INVALID_ATOMIC_ORDERING, INVALID_ATOMIC_ORDERING,
fail_order_arg.span, fail_order_arg.span,
InvalidAtomicOrderingDiag { method, fail_order_arg_span: fail_order_arg.span }, InvalidAtomicOrderingDiag { method, fail_order_arg_span: fail_order_arg.span },

View file

@ -62,7 +62,7 @@ impl<'tcx> LateLintPass<'tcx> for UnitBindings {
&& !matches!(init.kind, hir::ExprKind::Tup([])) && !matches!(init.kind, hir::ExprKind::Tup([]))
&& !matches!(local.pat.kind, hir::PatKind::Tuple([], ..)) && !matches!(local.pat.kind, hir::PatKind::Tuple([], ..))
{ {
cx.emit_spanned_lint( cx.emit_span_lint(
UNIT_BINDINGS, UNIT_BINDINGS,
local.span, local.span,
UnitBindingsDiag { label: local.pat.span }, UnitBindingsDiag { label: local.pat.span },

View file

@ -182,7 +182,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
let mut op_warned = false; let mut op_warned = false;
if let Some(must_use_op) = must_use_op { if let Some(must_use_op) = must_use_op {
cx.emit_spanned_lint( cx.emit_span_lint(
UNUSED_MUST_USE, UNUSED_MUST_USE,
expr.span, expr.span,
UnusedOp { UnusedOp {
@ -202,7 +202,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
} }
if !(type_lint_emitted_or_suppressed || fn_warned || op_warned) { if !(type_lint_emitted_or_suppressed || fn_warned || op_warned) {
cx.emit_spanned_lint(UNUSED_RESULTS, s.span, UnusedResult { ty }); cx.emit_span_lint(UNUSED_RESULTS, s.span, UnusedResult { ty });
} }
fn check_fn_must_use( fn check_fn_must_use(
@ -494,21 +494,21 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
); );
} }
MustUsePath::Closure(span) => { MustUsePath::Closure(span) => {
cx.emit_spanned_lint( cx.emit_span_lint(
UNUSED_MUST_USE, UNUSED_MUST_USE,
*span, *span,
UnusedClosure { count: plural_len, pre: descr_pre, post: descr_post }, UnusedClosure { count: plural_len, pre: descr_pre, post: descr_post },
); );
} }
MustUsePath::Coroutine(span) => { MustUsePath::Coroutine(span) => {
cx.emit_spanned_lint( cx.emit_span_lint(
UNUSED_MUST_USE, UNUSED_MUST_USE,
*span, *span,
UnusedCoroutine { count: plural_len, pre: descr_pre, post: descr_post }, UnusedCoroutine { count: plural_len, pre: descr_pre, post: descr_post },
); );
} }
MustUsePath::Def(span, def_id, reason) => { MustUsePath::Def(span, def_id, reason) => {
cx.emit_spanned_lint( cx.emit_span_lint(
UNUSED_MUST_USE, UNUSED_MUST_USE,
*span, *span,
UnusedDef { UnusedDef {
@ -568,9 +568,9 @@ impl<'tcx> LateLintPass<'tcx> for PathStatements {
} else { } else {
PathStatementDropSub::Help { span: s.span } PathStatementDropSub::Help { span: s.span }
}; };
cx.emit_spanned_lint(PATH_STATEMENTS, s.span, PathStatementDrop { sub }) cx.emit_span_lint(PATH_STATEMENTS, s.span, PathStatementDrop { sub })
} else { } else {
cx.emit_spanned_lint(PATH_STATEMENTS, s.span, PathStatementNoEffect); cx.emit_span_lint(PATH_STATEMENTS, s.span, PathStatementNoEffect);
} }
} }
} }
@ -824,7 +824,7 @@ trait UnusedDelimLint {
end_replace: hi_replace, end_replace: hi_replace,
} }
}); });
cx.emit_spanned_lint( cx.emit_span_lint(
self.lint(), self.lint(),
primary_span, primary_span,
UnusedDelim { delim: Self::DELIM_STR, item: msg, suggestion }, UnusedDelim { delim: Self::DELIM_STR, item: msg, suggestion },
@ -1507,7 +1507,7 @@ impl UnusedImportBraces {
ast::UseTreeKind::Nested(_) => return, ast::UseTreeKind::Nested(_) => return,
}; };
cx.emit_spanned_lint( cx.emit_span_lint(
UNUSED_IMPORT_BRACES, UNUSED_IMPORT_BRACES,
item.span, item.span,
UnusedImportBracesDiag { node: node_name }, UnusedImportBracesDiag { node: node_name },
@ -1564,10 +1564,10 @@ impl<'tcx> LateLintPass<'tcx> for UnusedAllocation {
if let adjustment::Adjust::Borrow(adjustment::AutoBorrow::Ref(_, m)) = adj.kind { if let adjustment::Adjust::Borrow(adjustment::AutoBorrow::Ref(_, m)) = adj.kind {
match m { match m {
adjustment::AutoBorrowMutability::Not => { adjustment::AutoBorrowMutability::Not => {
cx.emit_spanned_lint(UNUSED_ALLOCATION, e.span, UnusedAllocationDiag); cx.emit_span_lint(UNUSED_ALLOCATION, e.span, UnusedAllocationDiag);
} }
adjustment::AutoBorrowMutability::Mut { .. } => { adjustment::AutoBorrowMutability::Mut { .. } => {
cx.emit_spanned_lint(UNUSED_ALLOCATION, e.span, UnusedAllocationMutDiag); cx.emit_span_lint(UNUSED_ALLOCATION, e.span, UnusedAllocationMutDiag);
} }
}; };
} }

View file

@ -90,7 +90,7 @@ pub fn session_diagnostic_derive(s: Structure<'_>) -> TokenStream {
/// Then, later, to emit the error: /// Then, later, to emit the error:
/// ///
/// ```ignore (rust) /// ```ignore (rust)
/// cx.struct_span_lint(INVALID_ATOMIC_ORDERING, fail_order_arg_span, AtomicOrderingInvalidLint { /// cx.span_lint(INVALID_ATOMIC_ORDERING, fail_order_arg_span, AtomicOrderingInvalidLint {
/// method, /// method,
/// success_ordering, /// success_ordering,
/// fail_ordering, /// fail_ordering,

View file

@ -247,18 +247,18 @@ pub fn explain_lint_level_source(
/// ///
/// If you are looking to implement a lint, look for higher level functions, /// If you are looking to implement a lint, look for higher level functions,
/// for example: /// for example:
/// - [`TyCtxt::emit_spanned_lint`] /// - [`TyCtxt::emit_node_span_lint`]
/// - [`TyCtxt::struct_span_lint_hir`] /// - [`TyCtxt::node_span_lint`]
/// - [`TyCtxt::emit_lint`] /// - [`TyCtxt::emit_node_lint`]
/// - [`TyCtxt::struct_lint_node`] /// - [`TyCtxt::node_lint`]
/// - `LintContext::lookup` /// - `LintContext::opt_span_lint`
/// ///
/// ## `decorate` /// ## `decorate`
/// ///
/// It is not intended to call `emit`/`cancel` on the `DiagnosticBuilder` passed /// It is not intended to call `emit`/`cancel` on the `DiagnosticBuilder` passed
/// in the `decorate` callback. /// in the `decorate` callback.
#[track_caller] #[track_caller]
pub fn struct_lint_level( pub fn lint_level(
sess: &Session, sess: &Session,
lint: &'static Lint, lint: &'static Lint,
level: Level, level: Level,
@ -270,7 +270,7 @@ pub fn struct_lint_level(
// Avoid codegen bloat from monomorphization by immediately doing dyn dispatch of `decorate` to // Avoid codegen bloat from monomorphization by immediately doing dyn dispatch of `decorate` to
// the "real" work. // the "real" work.
#[track_caller] #[track_caller]
fn struct_lint_level_impl( fn lint_level_impl(
sess: &Session, sess: &Session,
lint: &'static Lint, lint: &'static Lint,
level: Level, level: Level,
@ -399,7 +399,7 @@ pub fn struct_lint_level(
explain_lint_level_source(lint, level, src, &mut *err); explain_lint_level_source(lint, level, src, &mut *err);
err.emit() err.emit()
} }
struct_lint_level_impl(sess, lint, level, src, span, msg, Box::new(decorate)) lint_level_impl(sess, lint, level, src, span, msg, Box::new(decorate))
} }
/// Returns whether `span` originates in a foreign crate's external macro. /// Returns whether `span` originates in a foreign crate's external macro.

View file

@ -217,7 +217,7 @@ fn late_report_deprecation(
return; return;
} }
let method_span = method_span.unwrap_or(span); let method_span = method_span.unwrap_or(span);
tcx.struct_span_lint_hir(lint, hir_id, method_span, message, |diag| { tcx.node_span_lint(lint, hir_id, method_span, message, |diag| {
if let hir::Node::Expr(_) = tcx.hir_node(hir_id) { if let hir::Node::Expr(_) = tcx.hir_node(hir_id) {
let kind = tcx.def_descr(def_id); let kind = tcx.def_descr(def_id);
deprecation_suggestion(diag, kind, suggestion, method_span); deprecation_suggestion(diag, kind, suggestion, method_span);
@ -585,7 +585,7 @@ impl<'tcx> TyCtxt<'tcx> {
unmarked: impl FnOnce(Span, DefId), unmarked: impl FnOnce(Span, DefId),
) -> bool { ) -> bool {
let soft_handler = |lint, span, msg: String| { let soft_handler = |lint, span, msg: String| {
self.struct_span_lint_hir(lint, id.unwrap_or(hir::CRATE_HIR_ID), span, msg, |_| {}) self.node_span_lint(lint, id.unwrap_or(hir::CRATE_HIR_ID), span, msg, |_| {})
}; };
let eval_result = let eval_result =
self.eval_stability_allow_unstable(def_id, id, span, method_span, allow_unstable); self.eval_stability_allow_unstable(def_id, id, span, method_span, allow_unstable);

View file

@ -108,7 +108,7 @@ impl<'tcx> TyCtxt<'tcx> {
let mir_body = self.mir_for_ctfe(instance.def_id()); let mir_body = self.mir_for_ctfe(instance.def_id());
if mir_body.is_polymorphic { if mir_body.is_polymorphic {
let Some(local_def_id) = ct.def.as_local() else { return }; let Some(local_def_id) = ct.def.as_local() else { return };
self.struct_span_lint_hir( self.node_span_lint(
lint::builtin::CONST_EVALUATABLE_UNCHECKED, lint::builtin::CONST_EVALUATABLE_UNCHECKED,
self.local_def_id_to_hir_id(local_def_id), self.local_def_id_to_hir_id(local_def_id),
self.def_span(ct.def), self.def_span(ct.def),

View file

@ -7,7 +7,7 @@ pub mod tls;
use crate::arena::Arena; use crate::arena::Arena;
use crate::dep_graph::{DepGraph, DepKindStruct}; use crate::dep_graph::{DepGraph, DepKindStruct};
use crate::infer::canonical::{CanonicalParamEnvCache, CanonicalVarInfo, CanonicalVarInfos}; use crate::infer::canonical::{CanonicalParamEnvCache, CanonicalVarInfo, CanonicalVarInfos};
use crate::lint::struct_lint_level; use crate::lint::lint_level;
use crate::metadata::ModChild; use crate::metadata::ModChild;
use crate::middle::codegen_fn_attrs::CodegenFnAttrs; use crate::middle::codegen_fn_attrs::CodegenFnAttrs;
use crate::middle::resolve_bound_vars; use crate::middle::resolve_bound_vars;
@ -2077,7 +2077,7 @@ impl<'tcx> TyCtxt<'tcx> {
/// Emit a lint at `span` from a lint struct (some type that implements `DecorateLint`, /// Emit a lint at `span` from a lint struct (some type that implements `DecorateLint`,
/// typically generated by `#[derive(LintDiagnostic)]`). /// typically generated by `#[derive(LintDiagnostic)]`).
#[track_caller] #[track_caller]
pub fn emit_spanned_lint( pub fn emit_node_span_lint(
self, self,
lint: &'static Lint, lint: &'static Lint,
hir_id: HirId, hir_id: HirId,
@ -2086,17 +2086,17 @@ impl<'tcx> TyCtxt<'tcx> {
) { ) {
let msg = decorator.msg(); let msg = decorator.msg();
let (level, src) = self.lint_level_at_node(lint, hir_id); let (level, src) = self.lint_level_at_node(lint, hir_id);
struct_lint_level(self.sess, lint, level, src, Some(span.into()), msg, |diag| { lint_level(self.sess, lint, level, src, Some(span.into()), msg, |diag| {
decorator.decorate_lint(diag); decorator.decorate_lint(diag);
}) })
} }
/// Emit a lint at the appropriate level for a hir node, with an associated span. /// Emit a lint at the appropriate level for a hir node, with an associated span.
/// ///
/// [`struct_lint_level`]: rustc_middle::lint::struct_lint_level#decorate-signature /// [`lint_level`]: rustc_middle::lint::lint_level#decorate-signature
#[rustc_lint_diagnostics] #[rustc_lint_diagnostics]
#[track_caller] #[track_caller]
pub fn struct_span_lint_hir( pub fn node_span_lint(
self, self,
lint: &'static Lint, lint: &'static Lint,
hir_id: HirId, hir_id: HirId,
@ -2105,29 +2105,29 @@ impl<'tcx> TyCtxt<'tcx> {
decorate: impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>), decorate: impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>),
) { ) {
let (level, src) = self.lint_level_at_node(lint, hir_id); let (level, src) = self.lint_level_at_node(lint, hir_id);
struct_lint_level(self.sess, lint, level, src, Some(span.into()), msg, decorate); lint_level(self.sess, lint, level, src, Some(span.into()), msg, decorate);
} }
/// Emit a lint from a lint struct (some type that implements `DecorateLint`, typically /// Emit a lint from a lint struct (some type that implements `DecorateLint`, typically
/// generated by `#[derive(LintDiagnostic)]`). /// generated by `#[derive(LintDiagnostic)]`).
#[track_caller] #[track_caller]
pub fn emit_lint( pub fn emit_node_lint(
self, self,
lint: &'static Lint, lint: &'static Lint,
id: HirId, id: HirId,
decorator: impl for<'a> DecorateLint<'a, ()>, decorator: impl for<'a> DecorateLint<'a, ()>,
) { ) {
self.struct_lint_node(lint, id, decorator.msg(), |diag| { self.node_lint(lint, id, decorator.msg(), |diag| {
decorator.decorate_lint(diag); decorator.decorate_lint(diag);
}) })
} }
/// Emit a lint at the appropriate level for a hir node. /// Emit a lint at the appropriate level for a hir node.
/// ///
/// [`struct_lint_level`]: rustc_middle::lint::struct_lint_level#decorate-signature /// [`lint_level`]: rustc_middle::lint::lint_level#decorate-signature
#[rustc_lint_diagnostics] #[rustc_lint_diagnostics]
#[track_caller] #[track_caller]
pub fn struct_lint_node( pub fn node_lint(
self, self,
lint: &'static Lint, lint: &'static Lint,
id: HirId, id: HirId,
@ -2135,7 +2135,7 @@ impl<'tcx> TyCtxt<'tcx> {
decorate: impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>), decorate: impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>),
) { ) {
let (level, src) = self.lint_level_at_node(lint, id); let (level, src) = self.lint_level_at_node(lint, id);
struct_lint_level(self.sess, lint, level, src, None, msg, decorate); lint_level(self.sess, lint, level, src, None, msg, decorate);
} }
pub fn in_scope_traits(self, id: HirId) -> Option<&'tcx [TraitCandidate]> { pub fn in_scope_traits(self, id: HirId) -> Option<&'tcx [TraitCandidate]> {

View file

@ -599,7 +599,7 @@ impl UnsafeOpKind {
// FIXME: ideally we would want to trim the def paths, but this is not // FIXME: ideally we would want to trim the def paths, but this is not
// feasible with the current lint emission API (see issue #106126). // feasible with the current lint emission API (see issue #106126).
match self { match self {
CallToUnsafeFunction(Some(did)) => tcx.emit_spanned_lint( CallToUnsafeFunction(Some(did)) => tcx.emit_node_span_lint(
UNSAFE_OP_IN_UNSAFE_FN, UNSAFE_OP_IN_UNSAFE_FN,
hir_id, hir_id,
span, span,
@ -609,7 +609,7 @@ impl UnsafeOpKind {
unsafe_not_inherited_note, unsafe_not_inherited_note,
}, },
), ),
CallToUnsafeFunction(None) => tcx.emit_spanned_lint( CallToUnsafeFunction(None) => tcx.emit_node_span_lint(
UNSAFE_OP_IN_UNSAFE_FN, UNSAFE_OP_IN_UNSAFE_FN,
hir_id, hir_id,
span, span,
@ -618,7 +618,7 @@ impl UnsafeOpKind {
unsafe_not_inherited_note, unsafe_not_inherited_note,
}, },
), ),
UseOfInlineAssembly => tcx.emit_spanned_lint( UseOfInlineAssembly => tcx.emit_node_span_lint(
UNSAFE_OP_IN_UNSAFE_FN, UNSAFE_OP_IN_UNSAFE_FN,
hir_id, hir_id,
span, span,
@ -627,7 +627,7 @@ impl UnsafeOpKind {
unsafe_not_inherited_note, unsafe_not_inherited_note,
}, },
), ),
InitializingTypeWith => tcx.emit_spanned_lint( InitializingTypeWith => tcx.emit_node_span_lint(
UNSAFE_OP_IN_UNSAFE_FN, UNSAFE_OP_IN_UNSAFE_FN,
hir_id, hir_id,
span, span,
@ -636,7 +636,7 @@ impl UnsafeOpKind {
unsafe_not_inherited_note, unsafe_not_inherited_note,
}, },
), ),
UseOfMutableStatic => tcx.emit_spanned_lint( UseOfMutableStatic => tcx.emit_node_span_lint(
UNSAFE_OP_IN_UNSAFE_FN, UNSAFE_OP_IN_UNSAFE_FN,
hir_id, hir_id,
span, span,
@ -645,7 +645,7 @@ impl UnsafeOpKind {
unsafe_not_inherited_note, unsafe_not_inherited_note,
}, },
), ),
UseOfExternStatic => tcx.emit_spanned_lint( UseOfExternStatic => tcx.emit_node_span_lint(
UNSAFE_OP_IN_UNSAFE_FN, UNSAFE_OP_IN_UNSAFE_FN,
hir_id, hir_id,
span, span,
@ -654,7 +654,7 @@ impl UnsafeOpKind {
unsafe_not_inherited_note, unsafe_not_inherited_note,
}, },
), ),
DerefOfRawPointer => tcx.emit_spanned_lint( DerefOfRawPointer => tcx.emit_node_span_lint(
UNSAFE_OP_IN_UNSAFE_FN, UNSAFE_OP_IN_UNSAFE_FN,
hir_id, hir_id,
span, span,
@ -663,7 +663,7 @@ impl UnsafeOpKind {
unsafe_not_inherited_note, unsafe_not_inherited_note,
}, },
), ),
AccessToUnionField => tcx.emit_spanned_lint( AccessToUnionField => tcx.emit_node_span_lint(
UNSAFE_OP_IN_UNSAFE_FN, UNSAFE_OP_IN_UNSAFE_FN,
hir_id, hir_id,
span, span,
@ -672,7 +672,7 @@ impl UnsafeOpKind {
unsafe_not_inherited_note, unsafe_not_inherited_note,
}, },
), ),
MutationOfLayoutConstrainedField => tcx.emit_spanned_lint( MutationOfLayoutConstrainedField => tcx.emit_node_span_lint(
UNSAFE_OP_IN_UNSAFE_FN, UNSAFE_OP_IN_UNSAFE_FN,
hir_id, hir_id,
span, span,
@ -681,7 +681,7 @@ impl UnsafeOpKind {
unsafe_not_inherited_note, unsafe_not_inherited_note,
}, },
), ),
BorrowOfLayoutConstrainedField => tcx.emit_spanned_lint( BorrowOfLayoutConstrainedField => tcx.emit_node_span_lint(
UNSAFE_OP_IN_UNSAFE_FN, UNSAFE_OP_IN_UNSAFE_FN,
hir_id, hir_id,
span, span,
@ -690,7 +690,7 @@ impl UnsafeOpKind {
unsafe_not_inherited_note, unsafe_not_inherited_note,
}, },
), ),
CallToFunctionWith { function, missing, build_enabled } => tcx.emit_spanned_lint( CallToFunctionWith { function, missing, build_enabled } => tcx.emit_node_span_lint(
UNSAFE_OP_IN_UNSAFE_FN, UNSAFE_OP_IN_UNSAFE_FN,
hir_id, hir_id,
span, span,
@ -941,7 +941,7 @@ pub fn check_unsafety(tcx: TyCtxt<'_>, def: LocalDefId) {
warnings.sort_by_key(|w| w.block_span); warnings.sort_by_key(|w| w.block_span);
for UnusedUnsafeWarning { hir_id, block_span, enclosing_unsafe } in warnings { for UnusedUnsafeWarning { hir_id, block_span, enclosing_unsafe } in warnings {
let block_span = tcx.sess.source_map().guess_head_span(block_span); let block_span = tcx.sess.source_map().guess_head_span(block_span);
tcx.emit_spanned_lint( tcx.emit_node_span_lint(
UNUSED_UNSAFE, UNUSED_UNSAFE,
hir_id, hir_id,
block_span, block_span,

View file

@ -53,7 +53,7 @@ fn check_recursion<'tcx>(
let sp = tcx.def_span(def_id); let sp = tcx.def_span(def_id);
let hir_id = tcx.local_def_id_to_hir_id(def_id); let hir_id = tcx.local_def_id_to_hir_id(def_id);
tcx.emit_spanned_lint( tcx.emit_node_span_lint(
UNCONDITIONAL_RECURSION, UNCONDITIONAL_RECURSION,
hir_id, hir_id,
sp, sp,

View file

@ -539,7 +539,7 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> {
let span_end = prefix.last().unwrap().unwrap().0; let span_end = prefix.last().unwrap().unwrap().0;
let span = span_start.to(span_end); let span = span_start.to(span_end);
let count = prefix.len(); let count = prefix.len();
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
IRREFUTABLE_LET_PATTERNS, IRREFUTABLE_LET_PATTERNS,
self.lint_level, self.lint_level,
span, span,
@ -558,7 +558,7 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> {
let span_end = suffix.last().unwrap().unwrap().0; let span_end = suffix.last().unwrap().unwrap().0;
let span = span_start.to(span_end); let span = span_start.to(span_end);
let count = suffix.len(); let count = suffix.len();
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
IRREFUTABLE_LET_PATTERNS, IRREFUTABLE_LET_PATTERNS,
self.lint_level, self.lint_level,
span, span,
@ -814,7 +814,7 @@ fn check_for_bindings_named_same_as_variants(
{ {
let variant_count = edef.variants().len(); let variant_count = edef.variants().len();
let ty_path = with_no_trimmed_paths!(cx.tcx.def_path_str(edef.did())); let ty_path = with_no_trimmed_paths!(cx.tcx.def_path_str(edef.did()));
cx.tcx.emit_spanned_lint( cx.tcx.emit_node_span_lint(
BINDINGS_WITH_VARIANT_NAME, BINDINGS_WITH_VARIANT_NAME,
cx.lint_level, cx.lint_level,
pat.span, pat.span,
@ -856,7 +856,7 @@ fn report_irrefutable_let_patterns(
) { ) {
macro_rules! emit_diag { macro_rules! emit_diag {
($lint:tt) => {{ ($lint:tt) => {{
tcx.emit_spanned_lint(IRREFUTABLE_LET_PATTERNS, id, span, $lint { count }); tcx.emit_node_span_lint(IRREFUTABLE_LET_PATTERNS, id, span, $lint { count });
}}; }};
} }
@ -876,7 +876,7 @@ fn report_unreachable_pattern<'p, 'tcx>(
span: Span, span: Span,
catchall: Option<Span>, catchall: Option<Span>,
) { ) {
cx.tcx.emit_spanned_lint( cx.tcx.emit_node_span_lint(
UNREACHABLE_PATTERNS, UNREACHABLE_PATTERNS,
hir_id, hir_id,
span, span,

View file

@ -214,7 +214,7 @@ impl<'tcx> ConstToPat<'tcx> {
if let Some(mir_structural_match_violation) = mir_structural_match_violation { if let Some(mir_structural_match_violation) = mir_structural_match_violation {
match non_sm_ty.kind() { match non_sm_ty.kind() {
ty::Adt(..) if mir_structural_match_violation => { ty::Adt(..) if mir_structural_match_violation => {
self.tcx().emit_spanned_lint( self.tcx().emit_node_span_lint(
lint::builtin::INDIRECT_STRUCTURAL_MATCH, lint::builtin::INDIRECT_STRUCTURAL_MATCH,
self.id, self.id,
self.span, self.span,
@ -233,7 +233,7 @@ impl<'tcx> ConstToPat<'tcx> {
} else if !have_valtree && !self.saw_const_match_lint.get() { } else if !have_valtree && !self.saw_const_match_lint.get() {
// The only way valtree construction can fail without the structural match // The only way valtree construction can fail without the structural match
// checker finding a violation is if there is a pointer somewhere. // checker finding a violation is if there is a pointer somewhere.
self.tcx().emit_spanned_lint( self.tcx().emit_node_span_lint(
lint::builtin::POINTER_STRUCTURAL_MATCH, lint::builtin::POINTER_STRUCTURAL_MATCH,
self.id, self.id,
self.span, self.span,
@ -244,7 +244,7 @@ impl<'tcx> ConstToPat<'tcx> {
// Always check for `PartialEq`, even if we emitted other lints. (But not if there were // Always check for `PartialEq`, even if we emitted other lints. (But not if there were
// any errors.) This ensures it shows up in cargo's future-compat reports as well. // any errors.) This ensures it shows up in cargo's future-compat reports as well.
if !self.type_has_partial_eq_impl(cv.ty()) { if !self.type_has_partial_eq_impl(cv.ty()) {
self.tcx().emit_spanned_lint( self.tcx().emit_node_span_lint(
lint::builtin::CONST_PATTERNS_WITHOUT_PARTIAL_EQ, lint::builtin::CONST_PATTERNS_WITHOUT_PARTIAL_EQ,
self.id, self.id,
self.span, self.span,
@ -319,7 +319,7 @@ impl<'tcx> ConstToPat<'tcx> {
let kind = match ty.kind() { let kind = match ty.kind() {
ty::Float(_) => { ty::Float(_) => {
self.saw_const_match_lint.set(true); self.saw_const_match_lint.set(true);
tcx.emit_spanned_lint( tcx.emit_node_span_lint(
lint::builtin::ILLEGAL_FLOATING_POINT_LITERAL_PATTERN, lint::builtin::ILLEGAL_FLOATING_POINT_LITERAL_PATTERN,
id, id,
span, span,
@ -339,7 +339,7 @@ impl<'tcx> ConstToPat<'tcx> {
ty::Adt(..) if !self.type_marked_structural(ty) && self.behind_reference.get() => { ty::Adt(..) if !self.type_marked_structural(ty) && self.behind_reference.get() => {
if self.saw_const_match_error.get().is_none() && !self.saw_const_match_lint.get() { if self.saw_const_match_error.get().is_none() && !self.saw_const_match_lint.get() {
self.saw_const_match_lint.set(true); self.saw_const_match_lint.set(true);
tcx.emit_spanned_lint( tcx.emit_node_span_lint(
lint::builtin::INDIRECT_STRUCTURAL_MATCH, lint::builtin::INDIRECT_STRUCTURAL_MATCH,
id, id,
span, span,
@ -435,7 +435,7 @@ impl<'tcx> ConstToPat<'tcx> {
&& !self.saw_const_match_lint.get() && !self.saw_const_match_lint.get()
{ {
self.saw_const_match_lint.set(true); self.saw_const_match_lint.set(true);
tcx.emit_spanned_lint( tcx.emit_node_span_lint(
lint::builtin::INDIRECT_STRUCTURAL_MATCH, lint::builtin::INDIRECT_STRUCTURAL_MATCH,
self.id, self.id,
span, span,
@ -516,7 +516,7 @@ impl<'tcx> ConstToPat<'tcx> {
&& let Some(non_sm_ty) = traits::search_for_structural_match_violation(span, tcx, ty) && let Some(non_sm_ty) = traits::search_for_structural_match_violation(span, tcx, ty)
{ {
self.saw_const_match_lint.set(true); self.saw_const_match_lint.set(true);
tcx.emit_spanned_lint( tcx.emit_node_span_lint(
lint::builtin::NONTRIVIAL_STRUCTURAL_MATCH, lint::builtin::NONTRIVIAL_STRUCTURAL_MATCH,
id, id,
span, span,

View file

@ -100,7 +100,7 @@ impl<'tcx> Visitor<'tcx> for ConstMutationChecker<'_, 'tcx> {
&& let Some((lint_root, span, item)) = && let Some((lint_root, span, item)) =
self.should_lint_const_item_usage(lhs, def_id, loc) self.should_lint_const_item_usage(lhs, def_id, loc)
{ {
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
CONST_ITEM_MUTATION, CONST_ITEM_MUTATION,
lint_root, lint_root,
span, span,
@ -145,7 +145,7 @@ impl<'tcx> Visitor<'tcx> for ConstMutationChecker<'_, 'tcx> {
if let Some((lint_root, span, item)) = if let Some((lint_root, span, item)) =
self.should_lint_const_item_usage(place, def_id, lint_loc) self.should_lint_const_item_usage(place, def_id, lint_loc)
{ {
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
CONST_ITEM_MUTATION, CONST_ITEM_MUTATION,
lint_root, lint_root,
span, span,

View file

@ -527,7 +527,7 @@ fn report_unused_unsafe(tcx: TyCtxt<'_>, kind: UnusedUnsafe, id: HirId) {
} else { } else {
None None
}; };
tcx.emit_spanned_lint(UNUSED_UNSAFE, id, span, errors::UnusedUnsafe { span, nested_parent }); tcx.emit_node_span_lint(UNUSED_UNSAFE, id, span, errors::UnusedUnsafe { span, nested_parent });
} }
pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: LocalDefId) { pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: LocalDefId) {
@ -577,7 +577,7 @@ pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: LocalDefId) {
}); });
} }
UnsafetyViolationKind::UnsafeFn => { UnsafetyViolationKind::UnsafeFn => {
tcx.emit_spanned_lint( tcx.emit_node_span_lint(
UNSAFE_OP_IN_UNSAFE_FN, UNSAFE_OP_IN_UNSAFE_FN,
lint_root, lint_root,
source_info.span, source_info.span,

View file

@ -278,7 +278,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
fn report_assert_as_lint(&self, source_info: &SourceInfo, lint: AssertLint<impl Debug>) { fn report_assert_as_lint(&self, source_info: &SourceInfo, lint: AssertLint<impl Debug>) {
if let Some(lint_root) = self.lint_root(*source_info) { if let Some(lint_root) = self.lint_root(*source_info) {
self.tcx.emit_spanned_lint(lint.lint(), lint_root, source_info.span, lint); self.tcx.emit_node_span_lint(lint.lint(), lint_root, source_info.span, lint);
} }
} }

View file

@ -2071,7 +2071,7 @@ fn check_must_not_suspend_def(
span: data.source_span, span: data.source_span,
reason: s.as_str().to_string(), reason: s.as_str().to_string(),
}); });
tcx.emit_spanned_lint( tcx.emit_node_span_lint(
rustc_session::lint::builtin::MUST_NOT_SUSPEND, rustc_session::lint::builtin::MUST_NOT_SUSPEND,
hir_id, hir_id,
data.source_span, data.source_span,

View file

@ -112,7 +112,7 @@ fn has_ffi_unwind_calls(tcx: TyCtxt<'_>, local_def_id: LocalDefId) -> bool {
let span = terminator.source_info.span; let span = terminator.source_info.span;
let foreign = fn_def_id.is_some(); let foreign = fn_def_id.is_some();
tcx.emit_spanned_lint( tcx.emit_node_span_lint(
FFI_UNWIND_CALLS, FFI_UNWIND_CALLS,
lint_root, lint_root,
span, span,

View file

@ -185,7 +185,7 @@ impl<'tcx> FunctionItemRefChecker<'_, 'tcx> {
ret, ret,
); );
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
FUNCTION_ITEM_REFERENCES, FUNCTION_ITEM_REFERENCES,
lint_root, lint_root,
span, span,

View file

@ -714,7 +714,7 @@ impl<'a, 'tcx> MirUsedCollector<'a, 'tcx> {
// but correct span? This would make the lint at least accept crate-level lint attributes. // but correct span? This would make the lint at least accept crate-level lint attributes.
return; return;
}; };
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
LARGE_ASSIGNMENTS, LARGE_ASSIGNMENTS,
lint_root, lint_root,
span, span,

View file

@ -246,13 +246,13 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
attr.ident().and_then(|ident| BUILTIN_ATTRIBUTE_MAP.get(&ident.name)) attr.ident().and_then(|ident| BUILTIN_ATTRIBUTE_MAP.get(&ident.name))
{ {
match attr.style { match attr.style {
ast::AttrStyle::Outer => self.tcx.emit_spanned_lint( ast::AttrStyle::Outer => self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES, UNUSED_ATTRIBUTES,
hir_id, hir_id,
attr.span, attr.span,
errors::OuterCrateLevelAttr, errors::OuterCrateLevelAttr,
), ),
ast::AttrStyle::Inner => self.tcx.emit_spanned_lint( ast::AttrStyle::Inner => self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES, UNUSED_ATTRIBUTES,
hir_id, hir_id,
attr.span, attr.span,
@ -274,7 +274,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
} }
fn inline_attr_str_error_with_macro_def(&self, hir_id: HirId, attr: &Attribute, sym: &str) { fn inline_attr_str_error_with_macro_def(&self, hir_id: HirId, attr: &Attribute, sym: &str) {
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES, UNUSED_ATTRIBUTES,
hir_id, hir_id,
attr.span, attr.span,
@ -283,7 +283,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
} }
fn inline_attr_str_error_without_macro_def(&self, hir_id: HirId, attr: &Attribute, sym: &str) { fn inline_attr_str_error_without_macro_def(&self, hir_id: HirId, attr: &Attribute, sym: &str) {
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES, UNUSED_ATTRIBUTES,
hir_id, hir_id,
attr.span, attr.span,
@ -304,7 +304,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
/// Checks if `#[diagnostic::on_unimplemented]` is applied to a trait definition /// Checks if `#[diagnostic::on_unimplemented]` is applied to a trait definition
fn check_diagnostic_on_unimplemented(&self, attr_span: Span, hir_id: HirId, target: Target) { fn check_diagnostic_on_unimplemented(&self, attr_span: Span, hir_id: HirId, target: Target) {
if !matches!(target, Target::Trait) { if !matches!(target, Target::Trait) {
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES, UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,
hir_id, hir_id,
attr_span, attr_span,
@ -320,7 +320,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
| Target::Closure | Target::Closure
| Target::Method(MethodKind::Trait { body: true } | MethodKind::Inherent) => true, | Target::Method(MethodKind::Trait { body: true } | MethodKind::Inherent) => true,
Target::Method(MethodKind::Trait { body: false }) | Target::ForeignFn => { Target::Method(MethodKind::Trait { body: false }) | Target::ForeignFn => {
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES, UNUSED_ATTRIBUTES,
hir_id, hir_id,
attr.span, attr.span,
@ -333,7 +333,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
// accidentally, to be compatible with crates depending on them, we can't throw an // accidentally, to be compatible with crates depending on them, we can't throw an
// error here. // error here.
Target::AssocConst => { Target::AssocConst => {
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES, UNUSED_ATTRIBUTES,
hir_id, hir_id,
attr.span, attr.span,
@ -366,7 +366,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
// function prototypes can't be covered // function prototypes can't be covered
Target::Method(MethodKind::Trait { body: false }) | Target::ForeignFn => { Target::Method(MethodKind::Trait { body: false }) | Target::ForeignFn => {
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES, UNUSED_ATTRIBUTES,
hir_id, hir_id,
attr.span, attr.span,
@ -376,7 +376,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
} }
Target::Mod | Target::ForeignMod | Target::Impl | Target::Trait => { Target::Mod | Target::ForeignMod | Target::Impl | Target::Trait => {
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES, UNUSED_ATTRIBUTES,
hir_id, hir_id,
attr.span, attr.span,
@ -386,7 +386,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
} }
Target::Expression | Target::Statement | Target::Arm => { Target::Expression | Target::Statement | Target::Arm => {
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES, UNUSED_ATTRIBUTES,
hir_id, hir_id,
attr.span, attr.span,
@ -413,7 +413,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
allowed_target: Target, allowed_target: Target,
) { ) {
if target != allowed_target { if target != allowed_target {
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES, UNUSED_ATTRIBUTES,
hir_id, hir_id,
attr.span, attr.span,
@ -630,7 +630,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
// FIXME: #[target_feature] was previously erroneously allowed on statements and some // FIXME: #[target_feature] was previously erroneously allowed on statements and some
// crates used this, so only emit a warning. // crates used this, so only emit a warning.
Target::Statement => { Target::Statement => {
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES, UNUSED_ATTRIBUTES,
hir_id, hir_id,
attr.span, attr.span,
@ -769,7 +769,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
return false; return false;
} }
if let Err(entry) = aliases.try_insert(doc_alias_str.to_owned(), span) { if let Err(entry) = aliases.try_insert(doc_alias_str.to_owned(), span) {
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES, UNUSED_ATTRIBUTES,
hir_id, hir_id,
span, span,
@ -914,7 +914,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
} }
} }
_ => { _ => {
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
INVALID_DOC_ATTRIBUTES, INVALID_DOC_ATTRIBUTES,
hir_id, hir_id,
meta.span(), meta.span(),
@ -937,7 +937,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
target: Target, target: Target,
) -> bool { ) -> bool {
if target != Target::ExternCrate { if target != Target::ExternCrate {
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
INVALID_DOC_ATTRIBUTES, INVALID_DOC_ATTRIBUTES,
hir_id, hir_id,
meta.span(), meta.span(),
@ -951,7 +951,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
} }
if self.tcx.extern_mod_stmt_cnum(hir_id.owner).is_none() { if self.tcx.extern_mod_stmt_cnum(hir_id.owner).is_none() {
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
INVALID_DOC_ATTRIBUTES, INVALID_DOC_ATTRIBUTES,
hir_id, hir_id,
meta.span(), meta.span(),
@ -996,7 +996,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
.then_some(errors::AttrCrateLevelOnlySugg { .then_some(errors::AttrCrateLevelOnlySugg {
attr: attr.span.with_lo(bang_span).with_hi(bang_span), attr: attr.span.with_lo(bang_span).with_hi(bang_span),
}); });
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
INVALID_DOC_ATTRIBUTES, INVALID_DOC_ATTRIBUTES,
hir_id, hir_id,
meta.span(), meta.span(),
@ -1016,7 +1016,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
match (i_meta.name_or_empty(), i_meta.meta_item()) { match (i_meta.name_or_empty(), i_meta.meta_item()) {
(sym::attr | sym::no_crate_inject, _) => {} (sym::attr | sym::no_crate_inject, _) => {}
(_, Some(m)) => { (_, Some(m)) => {
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
INVALID_DOC_ATTRIBUTES, INVALID_DOC_ATTRIBUTES,
hir_id, hir_id,
i_meta.span(), i_meta.span(),
@ -1027,7 +1027,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
is_valid = false; is_valid = false;
} }
(_, None) => { (_, None) => {
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
INVALID_DOC_ATTRIBUTES, INVALID_DOC_ATTRIBUTES,
hir_id, hir_id,
i_meta.span(), i_meta.span(),
@ -1038,7 +1038,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
} }
} }
} else { } else {
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
INVALID_DOC_ATTRIBUTES, INVALID_DOC_ATTRIBUTES,
hir_id, hir_id,
meta.span(), meta.span(),
@ -1055,7 +1055,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
if meta.meta_item_list().is_some() { if meta.meta_item_list().is_some() {
true true
} else { } else {
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
INVALID_DOC_ATTRIBUTES, INVALID_DOC_ATTRIBUTES,
hir_id, hir_id,
meta.span(), meta.span(),
@ -1188,7 +1188,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
_ => { _ => {
let path = rustc_ast_pretty::pprust::path_to_string(&i_meta.path); let path = rustc_ast_pretty::pprust::path_to_string(&i_meta.path);
if i_meta.has_name(sym::spotlight) { if i_meta.has_name(sym::spotlight) {
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
INVALID_DOC_ATTRIBUTES, INVALID_DOC_ATTRIBUTES,
hir_id, hir_id,
i_meta.span, i_meta.span,
@ -1204,7 +1204,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
}; };
// If there are multiple attributes, the suggestion would suggest // If there are multiple attributes, the suggestion would suggest
// deleting all of them, which is incorrect. // deleting all of them, which is incorrect.
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
INVALID_DOC_ATTRIBUTES, INVALID_DOC_ATTRIBUTES,
hir_id, hir_id,
i_meta.span, i_meta.span,
@ -1219,7 +1219,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
}, },
); );
} else { } else {
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
INVALID_DOC_ATTRIBUTES, INVALID_DOC_ATTRIBUTES,
hir_id, hir_id,
i_meta.span, i_meta.span,
@ -1230,7 +1230,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
} }
} }
} else { } else {
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
INVALID_DOC_ATTRIBUTES, INVALID_DOC_ATTRIBUTES,
hir_id, hir_id,
meta.span(), meta.span(),
@ -1343,7 +1343,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
_ => "a", _ => "a",
}; };
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES, UNUSED_ATTRIBUTES,
hir_id, hir_id,
attr.span, attr.span,
@ -1380,7 +1380,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
_ => { _ => {
// FIXME: #[cold] was previously allowed on non-functions and some crates used // FIXME: #[cold] was previously allowed on non-functions and some crates used
// this, so only emit a warning. // this, so only emit a warning.
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES, UNUSED_ATTRIBUTES,
hir_id, hir_id,
attr.span, attr.span,
@ -1400,7 +1400,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
return; return;
} }
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES, UNUSED_ATTRIBUTES,
hir_id, hir_id,
attr.span, attr.span,
@ -1424,14 +1424,14 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
// used this, so only emit a warning. // used this, so only emit a warning.
let attr_span = matches!(target, Target::ForeignMod).then_some(attr.span); let attr_span = matches!(target, Target::ForeignMod).then_some(attr.span);
if let Some(s) = attr.value_str() { if let Some(s) = attr.value_str() {
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES, UNUSED_ATTRIBUTES,
hir_id, hir_id,
attr.span, attr.span,
errors::LinkName { span, attr_span, value: s.as_str() }, errors::LinkName { span, attr_span, value: s.as_str() },
); );
} else { } else {
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES, UNUSED_ATTRIBUTES,
hir_id, hir_id,
attr.span, attr.span,
@ -1710,7 +1710,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
_ => { _ => {
// FIXME: #[link_section] was previously allowed on non-functions/statics and some // FIXME: #[link_section] was previously allowed on non-functions/statics and some
// crates used this, so only emit a warning. // crates used this, so only emit a warning.
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES, UNUSED_ATTRIBUTES,
hir_id, hir_id,
attr.span, attr.span,
@ -1741,7 +1741,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
Target::ForeignStatic => "static", Target::ForeignStatic => "static",
_ => unreachable!(), _ => unreachable!(),
}; };
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES, UNUSED_ATTRIBUTES,
hir_id, hir_id,
attr.span, attr.span,
@ -1751,7 +1751,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
_ => { _ => {
// FIXME: #[no_mangle] was previously allowed on non-functions/statics and some // FIXME: #[no_mangle] was previously allowed on non-functions/statics and some
// crates used this, so only emit a warning. // crates used this, so only emit a warning.
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES, UNUSED_ATTRIBUTES,
hir_id, hir_id,
attr.span, attr.span,
@ -1929,7 +1929,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
return false; return false;
})) }))
{ {
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
CONFLICTING_REPR_HINTS, CONFLICTING_REPR_HINTS,
hir_id, hir_id,
hint_spans.collect::<Vec<Span>>(), hint_spans.collect::<Vec<Span>>(),
@ -2171,7 +2171,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
fn check_deprecated(&self, hir_id: HirId, attr: &Attribute, _span: Span, target: Target) { fn check_deprecated(&self, hir_id: HirId, attr: &Attribute, _span: Span, target: Target) {
match target { match target {
Target::Closure | Target::Expression | Target::Statement | Target::Arm => { Target::Closure | Target::Expression | Target::Statement | Target::Arm => {
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES, UNUSED_ATTRIBUTES,
hir_id, hir_id,
attr.span, attr.span,
@ -2187,7 +2187,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
match target { match target {
Target::ExternCrate | Target::Mod => {} Target::ExternCrate | Target::Mod => {}
_ => { _ => {
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES, UNUSED_ATTRIBUTES,
hir_id, hir_id,
attr.span, attr.span,
@ -2199,7 +2199,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
fn check_macro_export(&self, hir_id: HirId, attr: &Attribute, target: Target) { fn check_macro_export(&self, hir_id: HirId, attr: &Attribute, target: Target) {
if target != Target::MacroDef { if target != Target::MacroDef {
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES, UNUSED_ATTRIBUTES,
hir_id, hir_id,
attr.span, attr.span,
@ -2209,7 +2209,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
&& !meta_item_list.is_empty() && !meta_item_list.is_empty()
{ {
if meta_item_list.len() > 1 { if meta_item_list.len() > 1 {
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
INVALID_MACRO_EXPORT_ARGUMENTS, INVALID_MACRO_EXPORT_ARGUMENTS,
hir_id, hir_id,
attr.span, attr.span,
@ -2217,7 +2217,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
); );
} else { } else {
if meta_item_list[0].name_or_empty() != sym::local_inner_macros { if meta_item_list[0].name_or_empty() != sym::local_inner_macros {
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
INVALID_MACRO_EXPORT_ARGUMENTS, INVALID_MACRO_EXPORT_ARGUMENTS,
hir_id, hir_id,
meta_item_list[0].span(), meta_item_list[0].span(),
@ -2234,7 +2234,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
let is_decl_macro = !macro_definition.macro_rules; let is_decl_macro = !macro_definition.macro_rules;
if is_decl_macro { if is_decl_macro {
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES, UNUSED_ATTRIBUTES,
hir_id, hir_id,
attr.span, attr.span,
@ -2276,7 +2276,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
return; return;
}; };
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES, UNUSED_ATTRIBUTES,
hir_id, hir_id,
attr.span, attr.span,
@ -2609,7 +2609,7 @@ fn check_duplicates(
} else { } else {
(attr.span, *entry.get()) (attr.span, *entry.get())
}; };
tcx.emit_spanned_lint( tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES, UNUSED_ATTRIBUTES,
hir_id, hir_id,
this, this,

View file

@ -199,7 +199,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
&& !assign.span.from_expansion() && !assign.span.from_expansion()
{ {
let is_field_assign = matches!(lhs.kind, hir::ExprKind::Field(..)); let is_field_assign = matches!(lhs.kind, hir::ExprKind::Field(..));
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
lint::builtin::DEAD_CODE, lint::builtin::DEAD_CODE,
assign.hir_id, assign.hir_id,
assign.span, assign.span,
@ -899,7 +899,7 @@ impl<'tcx> DeadVisitor<'tcx> {
}; };
let hir_id = tcx.local_def_id_to_hir_id(first_item.def_id); let hir_id = tcx.local_def_id_to_hir_id(first_item.def_id);
self.tcx.emit_spanned_lint(DEAD_CODE, hir_id, MultiSpan::from_spans(spans), diag); self.tcx.emit_node_span_lint(DEAD_CODE, hir_id, MultiSpan::from_spans(spans), diag);
} }
fn warn_multiple( fn warn_multiple(

View file

@ -1285,7 +1285,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
// that we do not emit the same warning twice if the uninhabited type // that we do not emit the same warning twice if the uninhabited type
// is indeed `!`. // is indeed `!`.
self.ir.tcx.emit_spanned_lint( self.ir.tcx.emit_node_span_lint(
lint::builtin::UNREACHABLE_CODE, lint::builtin::UNREACHABLE_CODE,
expr_id, expr_id,
expr_span, expr_span,
@ -1446,7 +1446,7 @@ impl<'tcx> Liveness<'_, 'tcx> {
if self.used_on_entry(entry_ln, var) { if self.used_on_entry(entry_ln, var) {
if !self.live_on_entry(entry_ln, var) { if !self.live_on_entry(entry_ln, var) {
if let Some(name) = self.should_warn(var) { if let Some(name) = self.should_warn(var) {
self.ir.tcx.emit_spanned_lint( self.ir.tcx.emit_node_span_lint(
lint::builtin::UNUSED_ASSIGNMENTS, lint::builtin::UNUSED_ASSIGNMENTS,
var_hir_id, var_hir_id,
vec![span], vec![span],
@ -1456,7 +1456,7 @@ impl<'tcx> Liveness<'_, 'tcx> {
} }
} else { } else {
if let Some(name) = self.should_warn(var) { if let Some(name) = self.should_warn(var) {
self.ir.tcx.emit_spanned_lint( self.ir.tcx.emit_node_span_lint(
lint::builtin::UNUSED_VARIABLES, lint::builtin::UNUSED_VARIABLES,
var_hir_id, var_hir_id,
vec![span], vec![span],
@ -1478,7 +1478,7 @@ impl<'tcx> Liveness<'_, 'tcx> {
if !self.live_on_entry(ln, var) if !self.live_on_entry(ln, var)
&& let Some(name) = self.should_warn(var) && let Some(name) = self.should_warn(var)
{ {
self.ir.tcx.emit_spanned_lint( self.ir.tcx.emit_node_span_lint(
lint::builtin::UNUSED_ASSIGNMENTS, lint::builtin::UNUSED_ASSIGNMENTS,
hir_id, hir_id,
spans, spans,
@ -1552,7 +1552,7 @@ impl<'tcx> Liveness<'_, 'tcx> {
if ln == self.exit_ln { false } else { self.assigned_on_exit(ln, var) }; if ln == self.exit_ln { false } else { self.assigned_on_exit(ln, var) };
if is_assigned { if is_assigned {
self.ir.tcx.emit_spanned_lint( self.ir.tcx.emit_node_span_lint(
lint::builtin::UNUSED_VARIABLES, lint::builtin::UNUSED_VARIABLES,
first_hir_id, first_hir_id,
hir_ids_and_spans hir_ids_and_spans
@ -1574,7 +1574,7 @@ impl<'tcx> Liveness<'_, 'tcx> {
span.with_hi(BytePos(span.hi().0 + 1)) span.with_hi(BytePos(span.hi().0 + 1))
}) })
.collect(); .collect();
self.ir.tcx.emit_spanned_lint( self.ir.tcx.emit_node_span_lint(
lint::builtin::UNUSED_VARIABLES, lint::builtin::UNUSED_VARIABLES,
first_hir_id, first_hir_id,
hir_ids_and_spans.iter().map(|(_, pat_span, _)| *pat_span).collect::<Vec<_>>(), hir_ids_and_spans.iter().map(|(_, pat_span, _)| *pat_span).collect::<Vec<_>>(),
@ -1599,7 +1599,7 @@ impl<'tcx> Liveness<'_, 'tcx> {
let non_shorthands = let non_shorthands =
non_shorthands.into_iter().map(|(_, pat_span, _)| pat_span).collect(); non_shorthands.into_iter().map(|(_, pat_span, _)| pat_span).collect();
self.ir.tcx.emit_spanned_lint( self.ir.tcx.emit_node_span_lint(
lint::builtin::UNUSED_VARIABLES, lint::builtin::UNUSED_VARIABLES,
first_hir_id, first_hir_id,
hir_ids_and_spans hir_ids_and_spans
@ -1638,7 +1638,7 @@ impl<'tcx> Liveness<'_, 'tcx> {
} }
}; };
self.ir.tcx.emit_spanned_lint( self.ir.tcx.emit_node_span_lint(
lint::builtin::UNUSED_VARIABLES, lint::builtin::UNUSED_VARIABLES,
first_hir_id, first_hir_id,
hir_ids_and_spans hir_ids_and_spans
@ -1690,7 +1690,7 @@ impl<'tcx> Liveness<'_, 'tcx> {
if !self.live_on_exit(ln, var) if !self.live_on_exit(ln, var)
&& let Some(name) = self.should_warn(var) && let Some(name) = self.should_warn(var)
{ {
self.ir.tcx.emit_spanned_lint( self.ir.tcx.emit_node_span_lint(
lint::builtin::UNUSED_ASSIGNMENTS, lint::builtin::UNUSED_ASSIGNMENTS,
hir_id, hir_id,
spans, spans,

View file

@ -70,7 +70,7 @@ fn check_abi(tcx: TyCtxt<'_>, def_id: LocalDefId, abi: Abi) {
if abi == Abi::Rust { if abi == Abi::Rust {
let hir_id = tcx.local_def_id_to_hir_id(def_id); let hir_id = tcx.local_def_id_to_hir_id(def_id);
let span = tcx.def_span(def_id); let span = tcx.def_span(def_id);
tcx.emit_spanned_lint( tcx.emit_node_span_lint(
UNDEFINED_NAKED_FUNCTION_ABI, UNDEFINED_NAKED_FUNCTION_ABI,
hir_id, hir_id,
span, span,

View file

@ -122,7 +122,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
if matches!(kind, AnnotationKind::Prohibited | AnnotationKind::DeprecationProhibited) { if matches!(kind, AnnotationKind::Prohibited | AnnotationKind::DeprecationProhibited) {
let hir_id = self.tcx.local_def_id_to_hir_id(def_id); let hir_id = self.tcx.local_def_id_to_hir_id(def_id);
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
USELESS_DEPRECATED, USELESS_DEPRECATED,
hir_id, hir_id,
*span, *span,
@ -739,7 +739,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> {
// do not lint when the trait isn't resolved, since resolution error should // do not lint when the trait isn't resolved, since resolution error should
// be fixed first // be fixed first
if t.path.res != Res::Err && c.fully_stable { if t.path.res != Res::Err && c.fully_stable {
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
INEFFECTIVE_UNSTABLE_TRAIT_IMPL, INEFFECTIVE_UNSTABLE_TRAIT_IMPL,
item.hir_id(), item.hir_id(),
span, span,
@ -1073,7 +1073,7 @@ fn unnecessary_partially_stable_feature_lint(
implies: Symbol, implies: Symbol,
since: Symbol, since: Symbol,
) { ) {
tcx.emit_spanned_lint( tcx.emit_node_span_lint(
lint::builtin::STABLE_FEATURES, lint::builtin::STABLE_FEATURES,
hir::CRATE_HIR_ID, hir::CRATE_HIR_ID,
span, span,
@ -1096,7 +1096,7 @@ fn unnecessary_stable_feature_lint(
if since.as_str() == VERSION_PLACEHOLDER { if since.as_str() == VERSION_PLACEHOLDER {
since = sym::env_CFG_RELEASE; since = sym::env_CFG_RELEASE;
} }
tcx.emit_spanned_lint( tcx.emit_node_span_lint(
lint::builtin::STABLE_FEATURES, lint::builtin::STABLE_FEATURES,
hir::CRATE_HIR_ID, hir::CRATE_HIR_ID,
span, span,

View file

@ -158,7 +158,7 @@ pub(crate) fn lint_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
// is not exhaustive enough. // is not exhaustive enough.
// //
// NB: The partner lint for structs lives in `compiler/rustc_hir_analysis/src/check/pat.rs`. // NB: The partner lint for structs lives in `compiler/rustc_hir_analysis/src/check/pat.rs`.
rcx.tcx.emit_spanned_lint( rcx.tcx.emit_node_span_lint(
NON_EXHAUSTIVE_OMITTED_PATTERNS, NON_EXHAUSTIVE_OMITTED_PATTERNS,
rcx.match_lint_level, rcx.match_lint_level,
rcx.scrut_span, rcx.scrut_span,

View file

@ -1001,7 +1001,7 @@ impl<'p, 'tcx> TypeCx for RustcMatchCheckCtxt<'p, 'tcx> {
.map(|span| errors::Overlap { range: overlap_as_pat.clone(), span }) .map(|span| errors::Overlap { range: overlap_as_pat.clone(), span })
.collect(); .collect();
let pat_span = pat.data().unwrap().span; let pat_span = pat.data().unwrap().span;
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
lint::builtin::OVERLAPPING_RANGE_ENDPOINTS, lint::builtin::OVERLAPPING_RANGE_ENDPOINTS,
self.match_lint_level, self.match_lint_level,
pat_span, pat_span,

View file

@ -1399,7 +1399,7 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
fn check_def_id(&mut self, def_id: DefId, kind: &str, descr: &dyn fmt::Display) -> bool { fn check_def_id(&mut self, def_id: DefId, kind: &str, descr: &dyn fmt::Display) -> bool {
if self.leaks_private_dep(def_id) { if self.leaks_private_dep(def_id) {
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
lint::builtin::EXPORTED_PRIVATE_DEPENDENCIES, lint::builtin::EXPORTED_PRIVATE_DEPENDENCIES,
self.tcx.local_def_id_to_hir_id(self.item_def_id), self.tcx.local_def_id_to_hir_id(self.item_def_id),
self.tcx.def_span(self.item_def_id.to_def_id()), self.tcx.def_span(self.item_def_id.to_def_id()),
@ -1456,7 +1456,7 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
} else { } else {
lint::builtin::PRIVATE_BOUNDS lint::builtin::PRIVATE_BOUNDS
}; };
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
lint, lint,
self.tcx.local_def_id_to_hir_id(self.item_def_id), self.tcx.local_def_id_to_hir_id(self.item_def_id),
span, span,
@ -1543,7 +1543,7 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'tcx, '_> {
if reachable_at_vis.is_public() && reexported_at_vis != reachable_at_vis { if reachable_at_vis.is_public() && reexported_at_vis != reachable_at_vis {
let hir_id = self.tcx.local_def_id_to_hir_id(def_id); let hir_id = self.tcx.local_def_id_to_hir_id(def_id);
let span = self.tcx.def_span(def_id.to_def_id()); let span = self.tcx.def_span(def_id.to_def_id());
self.tcx.emit_spanned_lint( self.tcx.emit_node_span_lint(
lint::builtin::UNNAMEABLE_TYPES, lint::builtin::UNNAMEABLE_TYPES,
hir_id, hir_id,
span, span,

View file

@ -144,7 +144,7 @@ pub fn feature_warn_issue(
let mut err = sess.parse_sess.dcx.struct_span_warn(span, explain); let mut err = sess.parse_sess.dcx.struct_span_warn(span, explain);
add_feature_diagnostics_for_issue(&mut err, sess, feature, issue, false); add_feature_diagnostics_for_issue(&mut err, sess, feature, issue, false);
// Decorate this as a future-incompatibility lint as in rustc_middle::lint::struct_lint_level // Decorate this as a future-incompatibility lint as in rustc_middle::lint::lint_level
let lint = UNSTABLE_SYNTAX_PRE_EXPANSION; let lint = UNSTABLE_SYNTAX_PRE_EXPANSION;
let future_incompatible = lint.future_incompatible.as_ref().unwrap(); let future_incompatible = lint.future_incompatible.as_ref().unwrap();
err.is_lint(lint.name_lower(), /* has_future_breakage */ false); err.is_lint(lint.name_lower(), /* has_future_breakage */ false);

View file

@ -359,7 +359,7 @@ impl IgnoredDiagnosticOption {
option_name: &'static str, option_name: &'static str,
) { ) {
if let (Some(new_item), Some(old_item)) = (new, old) { if let (Some(new_item), Some(old_item)) = (new, old) {
tcx.emit_spanned_lint( tcx.emit_node_span_lint(
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES, UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,
tcx.local_def_id_to_hir_id(item_def_id.expect_local()), tcx.local_def_id_to_hir_id(item_def_id.expect_local()),
new_item, new_item,
@ -491,7 +491,7 @@ impl<'tcx> OnUnimplementedDirective {
} }
if is_diagnostic_namespace_variant { if is_diagnostic_namespace_variant {
tcx.emit_spanned_lint( tcx.emit_node_span_lint(
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES, UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,
tcx.local_def_id_to_hir_id(item_def_id.expect_local()), tcx.local_def_id_to_hir_id(item_def_id.expect_local()),
vec![item.span()], vec![item.span()],
@ -629,7 +629,7 @@ impl<'tcx> OnUnimplementedDirective {
AttrArgs::Eq(span, AttrArgsEq::Hir(expr)) => span.to(expr.span), AttrArgs::Eq(span, AttrArgsEq::Hir(expr)) => span.to(expr.span),
}; };
tcx.emit_spanned_lint( tcx.emit_node_span_lint(
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES, UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,
tcx.local_def_id_to_hir_id(item_def_id.expect_local()), tcx.local_def_id_to_hir_id(item_def_id.expect_local()),
report_span, report_span,
@ -640,14 +640,14 @@ impl<'tcx> OnUnimplementedDirective {
} else if is_diagnostic_namespace_variant { } else if is_diagnostic_namespace_variant {
match &attr.kind { match &attr.kind {
AttrKind::Normal(p) if !matches!(p.item.args, AttrArgs::Empty) => { AttrKind::Normal(p) if !matches!(p.item.args, AttrArgs::Empty) => {
tcx.emit_spanned_lint( tcx.emit_node_span_lint(
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES, UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,
tcx.local_def_id_to_hir_id(item_def_id.expect_local()), tcx.local_def_id_to_hir_id(item_def_id.expect_local()),
attr.span, attr.span,
MalformedOnUnimplementedAttrLint::new(attr.span), MalformedOnUnimplementedAttrLint::new(attr.span),
); );
} }
_ => tcx.emit_spanned_lint( _ => tcx.emit_node_span_lint(
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES, UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,
tcx.local_def_id_to_hir_id(item_def_id.expect_local()), tcx.local_def_id_to_hir_id(item_def_id.expect_local()),
attr.span, attr.span,
@ -776,7 +776,7 @@ impl<'tcx> OnUnimplementedFormatString {
s if generics.params.iter().any(|param| param.name == s) => (), s if generics.params.iter().any(|param| param.name == s) => (),
s => { s => {
if self.is_diagnostic_namespace_variant { if self.is_diagnostic_namespace_variant {
tcx.emit_spanned_lint( tcx.emit_node_span_lint(
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES, UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,
tcx.local_def_id_to_hir_id(item_def_id.expect_local()), tcx.local_def_id_to_hir_id(item_def_id.expect_local()),
self.span, self.span,

View file

@ -161,7 +161,7 @@ fn lint_object_unsafe_trait(
) { ) {
// Using `CRATE_NODE_ID` is wrong, but it's hard to get a more precise id. // Using `CRATE_NODE_ID` is wrong, but it's hard to get a more precise id.
// It's also hard to get a use site span, so we use the method definition span. // It's also hard to get a use site span, so we use the method definition span.
tcx.struct_span_lint_hir( tcx.node_span_lint(
WHERE_CLAUSES_OBJECT_SAFETY, WHERE_CLAUSES_OBJECT_SAFETY,
hir::CRATE_HIR_ID, hir::CRATE_HIR_ID,
span, span,

View file

@ -387,7 +387,7 @@ fn report_conflicting_impls<'tcx>(
let impl_span = tcx.def_span(impl_def_id); let impl_span = tcx.def_span(impl_def_id);
// Work to be done after we've built the DiagnosticBuilder. We have to define it // Work to be done after we've built the DiagnosticBuilder. We have to define it
// now because the struct_lint methods don't return back the DiagnosticBuilder // now because the lint emit methods don't return back the DiagnosticBuilder
// that's passed in. // that's passed in.
fn decorate<'tcx>( fn decorate<'tcx>(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
@ -462,7 +462,7 @@ fn report_conflicting_impls<'tcx>(
FutureCompatOverlapErrorKind::Issue33140 => ORDER_DEPENDENT_TRAIT_OBJECTS, FutureCompatOverlapErrorKind::Issue33140 => ORDER_DEPENDENT_TRAIT_OBJECTS,
FutureCompatOverlapErrorKind::LeakCheck => COHERENCE_LEAK_CHECK, FutureCompatOverlapErrorKind::LeakCheck => COHERENCE_LEAK_CHECK,
}; };
tcx.struct_span_lint_hir( tcx.node_span_lint(
lint, lint,
tcx.local_def_id_to_hir_id(impl_def_id), tcx.local_def_id_to_hir_id(impl_def_id),
impl_span, impl_span,

View file

@ -377,7 +377,7 @@ pub(crate) fn run_global_ctxt(
{}/rustdoc/how-to-write-documentation.html", {}/rustdoc/how-to-write-documentation.html",
crate::DOC_RUST_LANG_ORG_CHANNEL crate::DOC_RUST_LANG_ORG_CHANNEL
); );
tcx.struct_lint_node( tcx.node_lint(
crate::lint::MISSING_CRATE_LEVEL_DOCS, crate::lint::MISSING_CRATE_LEVEL_DOCS,
DocContext::as_local_hir_id(tcx, krate.module.item_id).unwrap(), DocContext::as_local_hir_id(tcx, krate.module.item_id).unwrap(),
"no documentation found for this crate's top-level module", "no documentation found for this crate's top-level module",

View file

@ -827,7 +827,7 @@ impl<'tcx> ExtraInfo<'tcx> {
fn error_invalid_codeblock_attr(&self, msg: impl Into<DiagnosticMessage>) { fn error_invalid_codeblock_attr(&self, msg: impl Into<DiagnosticMessage>) {
if let Some(def_id) = self.def_id.as_local() { if let Some(def_id) = self.def_id.as_local() {
self.tcx.struct_span_lint_hir( self.tcx.node_span_lint(
crate::lint::INVALID_CODEBLOCK_ATTRIBUTES, crate::lint::INVALID_CODEBLOCK_ATTRIBUTES,
self.tcx.local_def_id_to_hir_id(def_id), self.tcx.local_def_id_to_hir_id(def_id),
self.sp, self.sp,
@ -843,7 +843,7 @@ impl<'tcx> ExtraInfo<'tcx> {
f: impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>), f: impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>),
) { ) {
if let Some(def_id) = self.def_id.as_local() { if let Some(def_id) = self.def_id.as_local() {
self.tcx.struct_span_lint_hir( self.tcx.node_span_lint(
crate::lint::INVALID_CODEBLOCK_ATTRIBUTES, crate::lint::INVALID_CODEBLOCK_ATTRIBUTES,
self.tcx.local_def_id_to_hir_id(def_id), self.tcx.local_def_id_to_hir_id(def_id),
self.sp, self.sp,

View file

@ -126,7 +126,7 @@ pub(crate) fn look_for_tests<'tcx>(cx: &DocContext<'tcx>, dox: &str, item: &Item
if should_have_doc_example(cx, item) { if should_have_doc_example(cx, item) {
debug!("reporting error for {item:?} (hir_id={hir_id:?})"); debug!("reporting error for {item:?} (hir_id={hir_id:?})");
let sp = item.attr_span(cx.tcx); let sp = item.attr_span(cx.tcx);
cx.tcx.struct_span_lint_hir( cx.tcx.node_span_lint(
crate::lint::MISSING_DOC_CODE_EXAMPLES, crate::lint::MISSING_DOC_CODE_EXAMPLES,
hir_id, hir_id,
sp, sp,
@ -137,7 +137,7 @@ pub(crate) fn look_for_tests<'tcx>(cx: &DocContext<'tcx>, dox: &str, item: &Item
} else if tests.found_tests > 0 } else if tests.found_tests > 0
&& !cx.cache.effective_visibilities.is_exported(cx.tcx, item.item_id.expect_def_id()) && !cx.cache.effective_visibilities.is_exported(cx.tcx, item.item_id.expect_def_id())
{ {
cx.tcx.struct_span_lint_hir( cx.tcx.node_span_lint(
crate::lint::PRIVATE_DOC_TESTS, crate::lint::PRIVATE_DOC_TESTS,
hir_id, hir_id,
item.attr_span(cx.tcx), item.attr_span(cx.tcx),

View file

@ -1704,7 +1704,7 @@ fn report_diagnostic(
let sp = item.attr_span(tcx); let sp = item.attr_span(tcx);
tcx.struct_span_lint_hir(lint, hir_id, sp, msg, |lint| { tcx.node_span_lint(lint, hir_id, sp, msg, |lint| {
let (span, link_range) = match link_range { let (span, link_range) = match link_range {
MarkdownLinkRange::Destination(md_range) => { MarkdownLinkRange::Destination(md_range) => {
let mut md_range = md_range.clone(); let mut md_range = md_range.clone();

View file

@ -24,7 +24,7 @@ pub(super) fn visit_item(cx: &DocContext<'_>, item: &Item) {
let sp = let sp =
source_span_for_markdown_range(cx.tcx, &dox, &range, &item.attrs.doc_strings) source_span_for_markdown_range(cx.tcx, &dox, &range, &item.attrs.doc_strings)
.unwrap_or_else(|| item.attr_span(cx.tcx)); .unwrap_or_else(|| item.attr_span(cx.tcx));
cx.tcx.struct_span_lint_hir(crate::lint::BARE_URLS, hir_id, sp, msg, |lint| { cx.tcx.node_span_lint(crate::lint::BARE_URLS, hir_id, sp, msg, |lint| {
lint.note("bare URLs are not automatically turned into clickable links") lint.note("bare URLs are not automatically turned into clickable links")
.span_suggestion( .span_suggestion(
sp, sp,

View file

@ -99,7 +99,7 @@ fn check_rust_syntax(
// All points of divergence have been handled earlier so this can be // All points of divergence have been handled earlier so this can be
// done the same way whether the span is precise or not. // done the same way whether the span is precise or not.
let hir_id = cx.tcx.local_def_id_to_hir_id(local_id); let hir_id = cx.tcx.local_def_id_to_hir_id(local_id);
cx.tcx.struct_span_lint_hir(crate::lint::INVALID_RUST_CODEBLOCKS, hir_id, sp, msg, |lint| { cx.tcx.node_span_lint(crate::lint::INVALID_RUST_CODEBLOCKS, hir_id, sp, msg, |lint| {
let explanation = if is_ignore { let explanation = if is_ignore {
"`ignore` code blocks require valid Rust code for syntax highlighting; \ "`ignore` code blocks require valid Rust code for syntax highlighting; \
mark blocks that do not contain Rust code as text" mark blocks that do not contain Rust code as text"

View file

@ -25,7 +25,7 @@ pub(crate) fn visit_item(cx: &DocContext<'_>, item: &Item) {
Some(sp) => sp, Some(sp) => sp,
None => item.attr_span(tcx), None => item.attr_span(tcx),
}; };
tcx.struct_span_lint_hir(crate::lint::INVALID_HTML_TAGS, hir_id, sp, msg, |lint| { tcx.node_span_lint(crate::lint::INVALID_HTML_TAGS, hir_id, sp, msg, |lint| {
use rustc_lint_defs::Applicability; use rustc_lint_defs::Applicability;
// If a tag looks like `<this>`, it might actually be a generic. // If a tag looks like `<this>`, it might actually be a generic.
// We don't try to detect stuff `<like, this>` because that's not valid HTML, // We don't try to detect stuff `<like, this>` because that's not valid HTML,

View file

@ -176,7 +176,7 @@ fn check_inline_or_reference_unknown_redundancy(
&item.attrs.doc_strings, &item.attrs.doc_strings,
)?; )?;
cx.tcx.struct_span_lint_hir(crate::lint::REDUNDANT_EXPLICIT_LINKS, hir_id, explicit_span, "redundant explicit link target", |lint| { cx.tcx.node_span_lint(crate::lint::REDUNDANT_EXPLICIT_LINKS, hir_id, explicit_span, "redundant explicit link target", |lint| {
lint.span_label(explicit_span, "explicit target is redundant") lint.span_label(explicit_span, "explicit target is redundant")
.span_label(display_span, "because label contains path that resolves to same destination") .span_label(display_span, "because label contains path that resolves to same destination")
.note("when a link's destination is not specified,\nthe label is used to resolve intra-doc links") .note("when a link's destination is not specified,\nthe label is used to resolve intra-doc links")
@ -226,7 +226,7 @@ fn check_reference_redundancy(
&item.attrs.doc_strings, &item.attrs.doc_strings,
)?; )?;
cx.tcx.struct_span_lint_hir(crate::lint::REDUNDANT_EXPLICIT_LINKS, hir_id, explicit_span, "redundant explicit link target", |lint| { cx.tcx.node_span_lint(crate::lint::REDUNDANT_EXPLICIT_LINKS, hir_id, explicit_span, "redundant explicit link target", |lint| {
lint.span_label(explicit_span, "explicit target is redundant") lint.span_label(explicit_span, "explicit target is redundant")
.span_label(display_span, "because label contains path that resolves to same destination") .span_label(display_span, "because label contains path that resolves to same destination")
.span_note(def_span, "referenced explicit link target defined here") .span_note(def_span, "referenced explicit link target defined here")

View file

@ -56,7 +56,7 @@ pub(crate) fn visit_item(cx: &DocContext<'_>, item: &Item) {
) )
.unwrap_or_else(|| item.attr_span(tcx)); .unwrap_or_else(|| item.attr_span(tcx));
tcx.struct_span_lint_hir(crate::lint::UNESCAPED_BACKTICKS, hir_id, span, "unescaped backtick", |lint| { tcx.node_span_lint(crate::lint::UNESCAPED_BACKTICKS, hir_id, span, "unescaped backtick", |lint| {
let mut help_emitted = false; let mut help_emitted = false;
match element.prev_code_guess { match element.prev_code_guess {

View file

@ -2,6 +2,6 @@ avoid-breaking-exported-api = false
# use the various `span_lint_*` methods instead, which also add a link to the docs # use the various `span_lint_*` methods instead, which also add a link to the docs
disallowed-methods = [ disallowed-methods = [
"rustc_lint::context::LintContext::struct_span_lint", "rustc_lint::context::LintContext::span_lint",
"rustc_middle::ty::context::TyCtxt::struct_span_lint_hir" "rustc_middle::ty::context::TyCtxt::node_span_lint"
] ]

View file

@ -41,7 +41,6 @@ impl CompilerLintFunctions {
pub fn new() -> Self { pub fn new() -> Self {
let mut map = FxHashMap::default(); let mut map = FxHashMap::default();
map.insert("span_lint", "utils::span_lint"); map.insert("span_lint", "utils::span_lint");
map.insert("struct_span_lint", "utils::span_lint");
map.insert("lint", "utils::span_lint"); map.insert("lint", "utils::span_lint");
map.insert("span_lint_note", "utils::span_lint_and_note"); map.insert("span_lint_note", "utils::span_lint_and_note");
map.insert("span_lint_help", "utils::span_lint_and_help"); map.insert("span_lint_help", "utils::span_lint_and_help");

View file

@ -47,7 +47,7 @@ fn docs_link(diag: &mut Diagnostic, lint: &'static Lint) {
/// ``` /// ```
pub fn span_lint<T: LintContext>(cx: &T, lint: &'static Lint, sp: impl Into<MultiSpan>, msg: &str) { pub fn span_lint<T: LintContext>(cx: &T, lint: &'static Lint, sp: impl Into<MultiSpan>, msg: &str) {
#[expect(clippy::disallowed_methods)] #[expect(clippy::disallowed_methods)]
cx.struct_span_lint(lint, sp, msg.to_string(), |diag| { cx.span_lint(lint, sp, msg.to_string(), |diag| {
docs_link(diag, lint); docs_link(diag, lint);
}); });
} }
@ -81,7 +81,7 @@ pub fn span_lint_and_help<T: LintContext>(
help: &str, help: &str,
) { ) {
#[expect(clippy::disallowed_methods)] #[expect(clippy::disallowed_methods)]
cx.struct_span_lint(lint, span, msg.to_string(), |diag| { cx.span_lint(lint, span, msg.to_string(), |diag| {
let help = help.to_string(); let help = help.to_string();
if let Some(help_span) = help_span { if let Some(help_span) = help_span {
diag.span_help(help_span, help.to_string()); diag.span_help(help_span, help.to_string());
@ -124,7 +124,7 @@ pub fn span_lint_and_note<T: LintContext>(
note: &str, note: &str,
) { ) {
#[expect(clippy::disallowed_methods)] #[expect(clippy::disallowed_methods)]
cx.struct_span_lint(lint, span, msg.to_string(), |diag| { cx.span_lint(lint, span, msg.to_string(), |diag| {
let note = note.to_string(); let note = note.to_string();
if let Some(note_span) = note_span { if let Some(note_span) = note_span {
diag.span_note(note_span, note); diag.span_note(note_span, note);
@ -146,7 +146,7 @@ where
F: FnOnce(&mut Diagnostic), F: FnOnce(&mut Diagnostic),
{ {
#[expect(clippy::disallowed_methods)] #[expect(clippy::disallowed_methods)]
cx.struct_span_lint(lint, sp, msg.to_string(), |diag| { cx.span_lint(lint, sp, msg.to_string(), |diag| {
f(diag); f(diag);
docs_link(diag, lint); docs_link(diag, lint);
}); });
@ -154,7 +154,7 @@ where
pub fn span_lint_hir(cx: &LateContext<'_>, lint: &'static Lint, hir_id: HirId, sp: Span, msg: &str) { pub fn span_lint_hir(cx: &LateContext<'_>, lint: &'static Lint, hir_id: HirId, sp: Span, msg: &str) {
#[expect(clippy::disallowed_methods)] #[expect(clippy::disallowed_methods)]
cx.tcx.struct_span_lint_hir(lint, hir_id, sp, msg.to_string(), |diag| { cx.tcx.node_span_lint(lint, hir_id, sp, msg.to_string(), |diag| {
docs_link(diag, lint); docs_link(diag, lint);
}); });
} }
@ -168,7 +168,7 @@ pub fn span_lint_hir_and_then(
f: impl FnOnce(&mut Diagnostic), f: impl FnOnce(&mut Diagnostic),
) { ) {
#[expect(clippy::disallowed_methods)] #[expect(clippy::disallowed_methods)]
cx.tcx.struct_span_lint_hir(lint, hir_id, sp, msg.to_string(), |diag| { cx.tcx.node_span_lint(lint, hir_id, sp, msg.to_string(), |diag| {
f(diag); f(diag);
docs_link(diag, lint); docs_link(diag, lint);
}); });

View file

@ -11,7 +11,7 @@ use rustc_lint::{Lint, LintContext};
use rustc_middle::ty::TyCtxt; use rustc_middle::ty::TyCtxt;
pub fn a(cx: impl LintContext, lint: &'static Lint, span: impl Into<MultiSpan>, msg: impl Into<DiagnosticMessage>) { pub fn a(cx: impl LintContext, lint: &'static Lint, span: impl Into<MultiSpan>, msg: impl Into<DiagnosticMessage>) {
cx.struct_span_lint(lint, span, msg, |_| {}); cx.span_lint(lint, span, msg, |_| {});
} }
pub fn b( pub fn b(
@ -21,7 +21,7 @@ pub fn b(
span: impl Into<MultiSpan>, span: impl Into<MultiSpan>,
msg: impl Into<DiagnosticMessage>, msg: impl Into<DiagnosticMessage>,
) { ) {
tcx.struct_span_lint_hir(lint, hir_id, span, msg, |_| {}); tcx.node_span_lint(lint, hir_id, span, msg, |_| {});
} }
fn main() {} fn main() {}

View file

@ -1,16 +1,16 @@
error: use of a disallowed method `rustc_lint::context::LintContext::struct_span_lint` error: use of a disallowed method `rustc_lint::context::LintContext::span_lint`
--> $DIR/disallow_struct_span_lint.rs:14:5 --> $DIR/disallow_struct_span_lint.rs:14:5
| |
LL | cx.struct_span_lint(lint, span, msg, |_| {}); LL | cx.span_lint(lint, span, msg, |_| {});
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
= note: `-D clippy::disallowed-methods` implied by `-D warnings` = note: `-D clippy::disallowed-methods` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::disallowed_methods)]` = help: to override `-D warnings` add `#[allow(clippy::disallowed_methods)]`
error: use of a disallowed method `rustc_middle::ty::context::TyCtxt::struct_span_lint_hir` error: use of a disallowed method `rustc_middle::ty::context::TyCtxt::node_span_lint`
--> $DIR/disallow_struct_span_lint.rs:24:5 --> $DIR/disallow_struct_span_lint.rs:24:5
| |
LL | tcx.struct_span_lint_hir(lint, hir_id, span, msg, |_| {}); LL | tcx.node_span_lint(lint, hir_id, span, msg, |_| {});
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 2 previous errors error: aborting due to 2 previous errors