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);
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();

View File

@ -563,7 +563,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
if codegen_fn_attrs.inline == InlineAttr::Always {
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);
tcx.struct_span_lint_hir(
tcx.node_span_lint(
lint::builtin::INLINE_NO_SANITIZE,
hir_id,
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);
tcx.emit_spanned_lint(
tcx.emit_node_span_lint(
lint,
// We use the root frame for this so the crate that defines the const defines whether the
// lint is emitted.

View File

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

View File

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

View File

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

View File

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

View File

@ -46,7 +46,7 @@ pub fn check_abi(tcx: TyCtxt<'_>, hir_id: hir::HirId, span: Span, abi: Abi) {
.emit();
}
None => {
tcx.struct_span_lint_hir(
tcx.node_span_lint(
UNSUPPORTED_CALLING_CONVENTIONS,
hir_id,
span,
@ -183,7 +183,7 @@ fn check_static_inhabited(tcx: TyCtxt<'_>, def_id: LocalDefId) {
}
};
if layout.abi.is_uninhabited() {
tcx.struct_span_lint_hir(
tcx.node_span_lint(
UNINHABITED_STATIC,
tcx.local_def_id_to_hir_id(def_id),
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.
// Otherwise, it's only an issue if there's >1 non-exhaustive 1-zst.
if non_trivial_count > 0 || prev_non_exhaustive_1zst {
tcx.struct_span_lint_hir(
tcx.node_span_lint(
REPR_TRANSPARENT_EXTERNAL_PRIVATE_FIELDS,
tcx.local_def_id_to_hir_id(adt.did().expect_local()),
span,

View File

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

View File

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

View File

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

View File

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

View File

@ -495,7 +495,7 @@ fn lint_auto_trait_impl<'tcx>(
return;
}
tcx.struct_span_lint_hir(
tcx.node_span_lint(
lint::builtin::SUSPICIOUS_AUTO_TRAIT_IMPLS,
tcx.local_def_id_to_hir_id(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
if tcx.features().default_type_parameter_fallback => {}
Defaults::FutureCompatDisallowed => {
tcx.struct_span_lint_hir(
tcx.node_span_lint(
lint::builtin::INVALID_TYPE_PARAM_DEFAULT,
param.hir_id,
param.span,

View File

@ -912,7 +912,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
continue;
}
self.insert_lifetime(lt, ResolvedArg::StaticLifetime);
self.tcx.struct_span_lint_hir(
self.tcx.node_span_lint(
lint::builtin::UNUSED_LIFETIMES,
lifetime.hir_id,
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 cast_ty = fcx.resolve_vars_if_possible(self.cast_ty);
fcx.tcx.emit_spanned_lint(
fcx.tcx.emit_node_span_lint(
lint,
self.expr.hir_id,
self.span,
@ -900,7 +900,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
let expr_ty = fcx.resolve_vars_if_possible(self.expr_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,
self.expr.hir_id,
self.span,
@ -934,7 +934,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
};
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,
self.expr.hir_id,
self.span,
@ -950,7 +950,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
let expr_ty = fcx.resolve_vars_if_possible(self.expr_ty);
let cast_ty = fcx.resolve_vars_if_possible(self.cast_ty);
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,
self.expr.hir_id,
self.span,

View File

@ -62,7 +62,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
debug!("warn_if_unreachable: id={:?} span={:?} kind={}", id, span, kind);
let msg = format!("unreachable {kind}");
self.tcx().struct_span_lint_hir(
self.tcx().node_span_lint(
lint::builtin::UNREACHABLE_CODE,
id,
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
// ensure that the trait implementation won't be used
self.tcx.struct_span_lint_hir(
self.tcx.node_span_lint(
prelude_or_array_lint,
self_expr.hir_id,
self_expr.span,
@ -127,7 +127,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} else {
// trait implementations require full disambiguation to not clash with the new prelude
// 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,
call_expr.hir_id,
call_expr.span,
@ -238,7 +238,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return;
}
self.tcx.struct_span_lint_hir(
self.tcx.node_span_lint(
RUST_2021_PRELUDE_COLLISIONS,
expr_id,
span,

View File

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

View File

@ -1840,7 +1840,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&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.help(
"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_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,
closure_hir_id,
closure_head_span,

View File

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

View File

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

View File

@ -121,7 +121,7 @@ impl EarlyLintPass for WhileTrue {
"{}loop",
label.map_or_else(String::new, |label| format!("{}: ", label.ident,))
);
cx.emit_spanned_lint(
cx.emit_span_lint(
WHILE_TRUE,
condition_span,
BuiltinWhileTrue { suggestion: condition_span, replace },
@ -162,7 +162,7 @@ impl BoxPointers {
if let GenericArgKind::Type(leaf_ty) = leaf.unpack()
&& 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)
== Some(cx.typeck_results().field_index(fieldpat.hir_id))
{
cx.emit_spanned_lint(
cx.emit_span_lint(
NON_SHORTHAND_FIELD_PATTERNS,
fieldpat.span,
BuiltinNonShorthandFieldPatterns {
@ -334,7 +334,7 @@ impl UnsafeCode {
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 has_doc = attrs.iter().any(has_doc);
if !has_doc {
cx.emit_spanned_lint(
cx.emit_span_lint(
MISSING_DOCS,
cx.tcx.def_span(def_id),
BuiltinMissingDoc { article, desc },
@ -710,7 +710,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingCopyImplementations {
)
.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()
.is_some();
if !has_impl {
cx.emit_spanned_lint(
cx.emit_span_lint(
MISSING_DEBUG_IMPLEMENTATIONS,
item.span,
BuiltinMissingDebugImpl { tcx: cx.tcx, def_id: debug },
@ -874,7 +874,7 @@ impl EarlyLintPass for AnonymousParameters {
} else {
("<type>", Applicability::HasPlaceholders)
};
cx.emit_spanned_lint(
cx.emit_span_lint(
ANONYMOUS_PARAMETERS,
arg.pat.span,
BuiltinAnonymousParams { suggestion: (arg.pat.span, appl), ty_snip },
@ -921,7 +921,7 @@ impl EarlyLintPass for DeprecatedAttr {
BuiltinDeprecatedAttrLinkSuggestion::Default { suggestion: attr.span }
}
};
cx.emit_spanned_lint(
cx.emit_span_lint(
DEPRECATED,
attr.span,
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) {
cx.emit_spanned_lint(
cx.emit_span_lint(
DEPRECATED,
attr.span,
BuiltinDeprecatedAttrUsed {
@ -973,7 +973,7 @@ fn warn_if_doc(cx: &EarlyContext<'_>, node_span: Span, node_kind: &str, attrs: &
BuiltinUnusedDocCommentSub::BlockHelp
}
};
cx.emit_spanned_lint(
cx.emit_span_lint(
UNUSED_DOC_COMMENTS,
span,
BuiltinUnusedDocComment { kind: node_kind, label: node_span, sub },
@ -1107,7 +1107,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidNoMangleItems {
match param.kind {
GenericParamKind::Lifetime { .. } => {}
GenericParamKind::Type { .. } | GenericParamKind::Const { .. } => {
cx.emit_spanned_lint(
cx.emit_span_lint(
NO_MANGLE_GENERIC_ITEMS,
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
// don't have anything to attach a symbol to
cx.emit_spanned_lint(
cx.emit_span_lint(
NO_MANGLE_CONST_ITEMS,
it.span,
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()))
{
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()
{
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
&& 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,
attr.span,
BuiltinUngatedAsyncFnTrackCaller { label: span, session: &cx.tcx.sess },
@ -1389,7 +1389,7 @@ impl UnreachablePub {
applicability = Applicability::MaybeIncorrect;
}
let def_span = cx.tcx.def_span(def_id);
cx.emit_spanned_lint(
cx.emit_span_lint(
UNREACHABLE_PUB,
def_span,
BuiltinUnreachablePub {
@ -1518,7 +1518,7 @@ impl<'tcx> LateLintPass<'tcx> for TypeAliasBounds {
suggested_changing_assoc_types = true;
SuggestChangingAssocTypes { ty: hir_ty }
});
cx.emit_spanned_lint(
cx.emit_span_lint(
TYPE_ALIAS_BOUNDS,
where_spans,
BuiltinTypeAliasWhereClause {
@ -1534,7 +1534,7 @@ impl<'tcx> LateLintPass<'tcx> for TypeAliasBounds {
suggested_changing_assoc_types = true;
SuggestChangingAssocTypes { ty: hir_ty }
});
cx.emit_spanned_lint(
cx.emit_span_lint(
TYPE_ALIAS_BOUNDS,
inline_spans,
BuiltinTypeAliasGenericBounds { suggestion, sub },
@ -1633,7 +1633,7 @@ impl<'tcx> LateLintPass<'tcx> for TrivialConstraints {
| ClauseKind::ConstEvaluatable(..) => continue,
};
if predicate.is_global() {
cx.emit_spanned_lint(
cx.emit_span_lint(
TRIVIAL_BOUNDS,
span,
BuiltinTrivialBounds { predicate_kind_name, predicate },
@ -1751,7 +1751,7 @@ impl EarlyLintPass for EllipsisInclusiveRangePatterns {
replace,
});
} else {
cx.emit_spanned_lint(
cx.emit_span_lint(
ELLIPSIS_INCLUSIVE_RANGE_PATTERNS,
pat.span,
BuiltinEllipsisInclusiveRangePatternsLint::Parenthesise {
@ -1769,7 +1769,7 @@ impl EarlyLintPass for EllipsisInclusiveRangePatterns {
replace: replace.to_string(),
});
} else {
cx.emit_spanned_lint(
cx.emit_span_lint(
ELLIPSIS_INCLUSIVE_RANGE_PATTERNS,
join,
BuiltinEllipsisInclusiveRangePatternsLint::NonParenthesise {
@ -1895,7 +1895,7 @@ impl KeywordIdents {
return;
}
cx.emit_spanned_lint(
cx.emit_span_lint(
KEYWORD_IDENTS,
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.dedup();
cx.emit_spanned_lint(
cx.emit_span_lint(
EXPLICIT_OUTLIVES_REQUIREMENTS,
lint_spans.clone(),
BuiltinExplicitOutlives {
@ -2290,13 +2290,13 @@ impl EarlyLintPass for IncompleteInternalFeatures {
let help =
HAS_MIN_FEATURES.contains(&name).then_some(BuiltinIncompleteFeaturesHelp);
cx.emit_spanned_lint(
cx.emit_span_lint(
INCOMPLETE_FEATURES,
span,
BuiltinIncompleteFeatures { name, note, help },
);
} 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,
};
let sub = BuiltinUnpermittedTypeInitSub { err };
cx.emit_spanned_lint(
cx.emit_span_lint(
INVALID_VALUE,
expr.span,
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 is_null_ptr(cx, expr_deref) {
cx.emit_spanned_lint(
cx.emit_span_lint(
DEREF_NULLPTR,
expr.span,
BuiltinDerefNullptr { label: expr.span },
@ -2849,7 +2849,7 @@ impl<'tcx> LateLintPass<'tcx> for NamedAsmLabels {
let target_spans: MultiSpan =
if spans.len() > 0 { spans.into() } else { (*template_span).into() };
cx.lookup_with_diagnostics(
cx.span_lint_with_diagnostics(
NAMED_ASM_LABELS,
Some(target_spans),
fluent::lint_builtin_asm_labels,
@ -2925,12 +2925,12 @@ impl EarlyLintPass for SpecialModuleName {
}
match item.ident.name.as_str() {
"lib" => cx.emit_spanned_lint(
"lib" => cx.emit_span_lint(
SPECIAL_MODULE_NAME,
item.span,
BuiltinSpecialModuleNameUsed::Lib,
),
"main" => cx.emit_spanned_lint(
"main" => cx.emit_span_lint(
SPECIAL_MODULE_NAME,
item.span,
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
/// diagnostic.
///
/// [`struct_lint_level`]: rustc_middle::lint::struct_lint_level#decorate-signature
/// [`lint_level`]: rustc_middle::lint::lint_level#decorate-signature
#[rustc_lint_diagnostics]
fn lookup_with_diagnostics(
fn span_lint_with_diagnostics(
&self,
lint: &'static Lint,
span: Option<impl Into<MultiSpan>>,
@ -541,7 +541,7 @@ pub trait LintContext {
diagnostic: BuiltinLintDiagnostics,
) {
// 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.
diagnostics::builtin(self.sess(), diagnostic, db);
// 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).
/// 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]
fn lookup<S: Into<MultiSpan>>(
fn opt_span_lint<S: Into<MultiSpan>>(
&self,
lint: &'static Lint,
span: Option<S>,
@ -565,42 +565,42 @@ pub trait LintContext {
/// Emit a lint at `span` from a lint struct (some type that implements `DecorateLint`,
/// typically generated by `#[derive(LintDiagnostic)]`).
fn emit_spanned_lint<S: Into<MultiSpan>>(
fn emit_span_lint<S: Into<MultiSpan>>(
&self,
lint: &'static Lint,
span: S,
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);
});
}
/// 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]
fn struct_span_lint<S: Into<MultiSpan>>(
fn span_lint<S: Into<MultiSpan>>(
&self,
lint: &'static Lint,
span: S,
msg: impl Into<DiagnosticMessage>,
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
/// generated by `#[derive(LintDiagnostic)]`).
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);
});
}
/// 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]
fn lint(
&self,
@ -608,7 +608,7 @@ pub trait LintContext {
msg: impl Into<DiagnosticMessage>,
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.
@ -666,7 +666,7 @@ impl<'tcx> LintContext for LateContext<'tcx> {
}
#[rustc_lint_diagnostics]
fn lookup<S: Into<MultiSpan>>(
fn opt_span_lint<S: Into<MultiSpan>>(
&self,
lint: &'static Lint,
span: Option<S>,
@ -676,8 +676,8 @@ impl<'tcx> LintContext for LateContext<'tcx> {
let hir_id = self.last_node_with_lint_attrs;
match span {
Some(s) => self.tcx.struct_span_lint_hir(lint, hir_id, s, msg, decorate),
None => self.tcx.struct_lint_node(lint, hir_id, msg, decorate),
Some(s) => self.tcx.node_span_lint(lint, hir_id, s, msg, decorate),
None => self.tcx.node_lint(lint, hir_id, msg, decorate),
}
}
@ -693,14 +693,14 @@ impl LintContext for EarlyContext<'_> {
}
#[rustc_lint_diagnostics]
fn lookup<S: Into<MultiSpan>>(
fn opt_span_lint<S: Into<MultiSpan>>(
&self,
lint: &'static Lint,
span: Option<S>,
msg: impl Into<DiagnosticMessage>,
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 {

View File

@ -87,7 +87,7 @@ impl<'tcx> LateLintPass<'tcx> for DerefIntoDynSupertrait {
.find_map(|i| (i.ident.name == sym::Target).then_some(i.span))
.map(|label| SupertraitAsDerefTargetLabel { label });
let span = tcx.def_span(item.owner_id.def_id);
cx.emit_spanned_lint(
cx.emit_span_lint(
DEREF_INTO_DYN_SUPERTRAIT,
span,
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);
match fn_name {
sym::mem_drop if arg_ty.is_ref() && !drop_is_single_call_in_arm => {
cx.emit_spanned_lint(
cx.emit_span_lint(
DROPPING_REFERENCES,
expr.span,
DropRefDiag { arg_ty, label: arg.span },
);
}
sym::mem_forget if arg_ty.is_ref() => {
cx.emit_spanned_lint(
cx.emit_span_lint(
FORGETTING_REFERENCES,
expr.span,
ForgetRefDiag { arg_ty, label: arg.span },
);
}
sym::mem_drop if is_copy && !drop_is_single_call_in_arm => {
cx.emit_spanned_lint(
cx.emit_span_lint(
DROPPING_COPY_TYPES,
expr.span,
DropCopyDiag { arg_ty, label: arg.span },
);
}
sym::mem_forget if is_copy => {
cx.emit_spanned_lint(
cx.emit_span_lint(
FORGETTING_COPY_TYPES,
expr.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()
&& adt.is_manually_drop() =>
{
cx.emit_spanned_lint(
cx.emit_span_lint(
UNDROPPED_MANUALLY_DROPS,
expr.span,
UndroppedManuallyDropsDiag {

View File

@ -45,7 +45,13 @@ impl<'a, T: EarlyLintPass> EarlyContextAndPass<'a, T> {
fn inlined_check_id(&mut self, id: ast::NodeId) {
for early_lint in self.context.buffered.take(id) {
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);
if is_non_enum(ty_param) {
cx.emit_spanned_lint(
cx.emit_span_lint(
ENUM_INTRINSICS_NON_ENUMS,
expr_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) {
let ty_param = cx.typeck_results().node_args(func_expr.hir_id).type_at(0);
if is_non_enum(ty_param) {
cx.emit_spanned_lint(
ENUM_INTRINSICS_NON_ENUMS,
span,
EnumIntrinsicsMemVariant { ty_param },
);
cx.emit_span_lint(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 note = expectation.is_unfulfilled_lint_expectations.then_some(());
tcx.emit_spanned_lint(
tcx.emit_node_span_lint(
UNFULFILLED_LINT_EXPECTATIONS,
*hir_id,
expectation.emission_span,

View File

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

View File

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

View File

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

View File

@ -43,7 +43,7 @@ impl LateLintPass<'_> for DefaultHashTypes {
Some(sym::HashSet) => "FxHashSet",
_ => return,
};
cx.emit_spanned_lint(
cx.emit_span_lint(
DEFAULT_HASH_TYPES,
path.span,
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) {
let def_id = instance.def_id();
if cx.tcx.has_attr(def_id, sym::rustc_lint_query_instability) {
cx.emit_spanned_lint(
cx.emit_span_lint(
POTENTIAL_QUERY_INSTABILITY,
span,
QueryInstability { query: cx.tcx.item_name(def_id) },
@ -136,7 +136,7 @@ impl<'tcx> LateLintPass<'tcx> for TyTyKind {
{
let span =
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 {
Some(span) => {
cx.emit_spanned_lint(
cx.emit_span_lint(
USAGE_OF_TY_TYKIND,
path.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()
&& path.segments.len() > 1
&& let Some(ty) = is_ty_or_ty_ctxt(cx, path)
{
cx.emit_spanned_lint(
cx.emit_span_lint(
USAGE_OF_QUALIFIED_TY,
path.span,
TyQualified { ty, suggestion: path.span },
@ -285,7 +285,7 @@ impl EarlyLintPass for LintPassImpl {
&& call_site.ctxt().outer_expn_data().kind
!= ExpnKind::Macro(MacroKind::Bang, sym::declare_lint_pass)
{
cx.emit_spanned_lint(
cx.emit_span_lint(
LINT_PASS_IMPL_WITHOUT_MACRO,
lint_pass.path.span,
LintPassByHand,
@ -327,7 +327,7 @@ impl<'tcx> LateLintPass<'tcx> for ExistingDocKeyword {
if is_doc_keyword(keyword) {
return;
}
cx.emit_spanned_lint(
cx.emit_span_lint(
EXISTING_DOC_KEYWORD,
attr.span,
NonExistentDocKeyword { keyword },
@ -405,7 +405,7 @@ impl LateLintPass<'_> for Diagnostics {
}
debug!(?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;
@ -421,7 +421,7 @@ impl LateLintPass<'_> for Diagnostics {
}
debug!(?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;
}
cx.emit_spanned_lint(
cx.emit_span_lint(
UNTRANSLATABLE_DIAGNOSTIC_TRIVIAL,
stmt.span,
UntranslatableDiagnosticTrivial,
@ -528,7 +528,7 @@ impl LateLintPass<'_> for BadOptAccess {
&& let Some(lit) = item.lit()
&& let ast::LitKind::Str(val, _) = lit.kind
{
cx.emit_spanned_lint(
cx.emit_span_lint(
BAD_OPT_ACCESS,
expr.span,
BadOptAccessDiag { msg: val.as_str() },
@ -553,7 +553,7 @@ impl<'tcx> LateLintPass<'tcx> for SpanUseEqCtxt {
expr.kind
{
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 is_unchecked_variant = diag_item.as_str().contains("unchecked");
cx.emit_spanned_lint(
cx.emit_span_lint(
if is_unchecked_variant {
INVALID_FROM_UTF8_UNCHECKED
} else {

View File

@ -160,14 +160,10 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
pat.span,
"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.
} else if can_use_init.is_some() {
cx.emit_spanned_lint(
LET_UNDERSCORE_DROP,
local.span,
NonBindingLet::DropType { sub },
);
cx.emit_span_lint(LET_UNDERSCORE_DROP, local.span, NonBindingLet::DropType { sub });
}
});
}

View File

@ -24,7 +24,7 @@ use rustc_hir::HirId;
use rustc_index::IndexVec;
use rustc_middle::hir::nested_filter;
use rustc_middle::lint::{
reveal_actual_level, struct_lint_level, LevelAndSource, LintExpectation, LintLevelSource,
lint_level, reveal_actual_level, LevelAndSource, LintExpectation, LintLevelSource,
ShallowLintLevelMap,
};
use rustc_middle::query::Providers;
@ -682,7 +682,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
sub,
});
} else {
self.emit_spanned_lint(
self.emit_span_lint(
FORBIDDEN_LINT_GROUPS,
src.span().into(),
OverruledAttributeLint {
@ -925,7 +925,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
}
Err((Some(ids), ref new_lint_name)) => {
let lint = builtin::RENAMED_AND_REMOVED_LINTS;
self.emit_spanned_lint(
self.emit_span_lint(
lint,
sp.into(),
DeprecatedLintName {
@ -976,13 +976,13 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
RenamedLintSuggestion::WithSpan { suggestion: sp, replace };
let name = tool_ident.map(|tool| format!("{tool}::{name}")).unwrap_or(name);
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) => {
let name = tool_ident.map(|tool| format!("{tool}::{name}")).unwrap_or(name);
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) => {
@ -995,7 +995,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
UnknownLintSuggestion::WithSpan { suggestion: sp, replace, from_rustc }
});
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.
@ -1041,7 +1041,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
continue;
};
self.emit_spanned_lint(
self.emit_span_lint(
UNUSED_ATTRIBUTES,
lint_attr_span.into(),
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 {
let lint = builtin::UNKNOWN_LINTS;
let (level, src) = self.lint_level(builtin::UNKNOWN_LINTS);
struct_lint_level(
lint_level(
self.sess,
lint,
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
/// 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]
#[track_caller]
pub(crate) fn struct_lint(
pub(crate) fn opt_span_lint(
&self,
lint: &'static Lint,
span: Option<MultiSpan>,
@ -1107,18 +1107,18 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
decorate: impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>),
) {
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]
pub fn emit_spanned_lint(
pub fn emit_span_lint(
&self,
lint: &'static Lint,
span: MultiSpan,
decorate: impl for<'a> DecorateLint<'a, ()>,
) {
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);
});
}
@ -1126,7 +1126,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
#[track_caller]
pub fn emit_lint(&self, lint: &'static Lint, decorate: impl for<'a> DecorateLint<'a, ()>) {
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);
});
}

View File

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

View File

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

View File

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

View File

@ -186,11 +186,11 @@ impl EarlyLintPass for NonAsciiIdents {
continue;
}
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
&& !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)
.and_modify(|(existing_symbol, existing_span, existing_is_ascii)| {
if !*existing_is_ascii || !is_ascii {
cx.emit_spanned_lint(
cx.emit_span_lint(
CONFUSABLE_IDENTS,
sp,
ConfusableIdentifierPair {
@ -339,7 +339,7 @@ impl EarlyLintPass for NonAsciiIdents {
let char_info = format!("'{}' (U+{:04X})", ch, ch as u32);
includes += &char_info;
}
cx.emit_spanned_lint(
cx.emit_span_lint(
MIXED_SCRIPT_CONFUSABLES,
sp,
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)]
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.note(fluent::lint_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)))
.collect(),
};
cx.emit_spanned_lint(
cx.emit_span_lint(
NON_FMT_PANICS,
arg_spans,
NonFmtPanicUnused {
@ -268,7 +268,7 @@ fn check_panic_str<'tcx>(
.collect()
});
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,
brace_spans.unwrap_or_else(|| vec![span]),
NonFmtPanicBraces {

View File

@ -150,7 +150,7 @@ impl NonCamelCaseTypes {
} else {
NonCamelCaseTypeSub::Label { span: ident.span }
};
cx.emit_spanned_lint(
cx.emit_span_lint(
NON_CAMEL_CASE_TYPES,
ident.span,
NonCamelCaseType { sort, name, sub },
@ -320,7 +320,7 @@ impl NonSnakeCase {
} else {
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 {
NonUpperCaseGlobalSub::Label { span: ident.span }
};
cx.emit_spanned_lint(
cx.emit_span_lint(
NON_UPPER_CASE_GLOBALS,
ident.span,
NonUpperCaseGlobal { sort, name, sub },

View File

@ -121,7 +121,7 @@ impl<'tcx> LateLintPass<'tcx> for NoopMethodCall {
let orig_ty = expr_ty.peel_refs();
if receiver_ty == expr_ty {
cx.emit_spanned_lint(
cx.emit_span_lint(
NOOP_METHOD_CALL,
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`,
// then that should be allowed
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,
span,
SuspiciousDoubleRefCloneDiag { ty: expr_ty },
),
sym::noop_method_deref => cx.emit_spanned_lint(
sym::noop_method_deref => cx.emit_span_lint(
SUSPICIOUS_DOUBLE_REF_OP,
span,
SuspiciousDoubleRefDerefDiag { ty: expr_ty },

View File

@ -145,7 +145,7 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound {
}),
_ => None,
};
cx.emit_spanned_lint(
cx.emit_span_lint(
OPAQUE_HIDDEN_INFERRED_BOUND,
pred_span,
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) {
cx.emit_spanned_lint(
cx.emit_span_lint(
PASS_BY_VALUE,
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) =>
{
cx.emit_spanned_lint(USELESS_PTR_NULL_CHECKS, expr.span, diag)
cx.emit_span_lint(USELESS_PTR_NULL_CHECKS, expr.span, diag)
}
// Catching:
@ -110,7 +110,7 @@ impl<'tcx> LateLintPass<'tcx> for PtrNullChecks {
)
&& 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) => {
@ -134,7 +134,7 @@ impl<'tcx> LateLintPass<'tcx> for PtrNullChecks {
&& let LitKind::Int(v, _) = spanned.node
&& 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:
@ -145,7 +145,7 @@ impl<'tcx> LateLintPass<'tcx> for PtrNullChecks {
&& let Some(diag_item) = cx.tcx.get_diagnostic_name(def_id)
&& (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;
}
cx.emit_spanned_lint(
cx.emit_span_lint(
REDUNDANT_SEMICOLONS,
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 ty_has_interior_mutability = ty_has_interior_mutability.then_some(());
cx.emit_spanned_lint(
cx.emit_span_lint(
INVALID_REFERENCE_CASTING,
expr.span,
if pat == PatternKind::Assign {

View File

@ -101,7 +101,7 @@ impl<'tcx> LateLintPass<'tcx> for DropTraitConstraints {
continue;
}
let Some(def_id) = cx.tcx.get_diagnostic_item(sym::needs_drop) else { return };
cx.emit_spanned_lint(
cx.emit_span_lint(
DROP_BOUNDS,
span,
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();
if cx.tcx.lang_items().drop_trait() == def_id {
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,
struct_expr.span,
RangeEndpointOutOfRange { ty, sub: sub_sugg },
@ -371,7 +371,7 @@ fn report_bin_hex_error(
})
.flatten();
cx.emit_spanned_lint(
cx.emit_span_lint(
OVERFLOWING_LITERALS,
expr.span,
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)
.map(|suggestion_ty| OverflowingIntHelp { suggestion_ty });
cx.emit_spanned_lint(
cx.emit_span_lint(
OVERFLOWING_LITERALS,
span,
OverflowingInt { ty: t.name_str(), lit, min, max, help },
@ -501,7 +501,7 @@ fn lint_uint_literal<'tcx>(
match par_e.kind {
hir::ExprKind::Cast(..) => {
if let ty::Char = cx.typeck_results().expr_ty(par_e).kind() {
cx.emit_spanned_lint(
cx.emit_span_lint(
OVERFLOWING_LITERALS,
par_e.span,
OnlyCastu8ToChar { span: par_e.span, literal: lit_val },
@ -528,7 +528,7 @@ fn lint_uint_literal<'tcx>(
);
return;
}
cx.emit_spanned_lint(
cx.emit_span_lint(
OVERFLOWING_LITERALS,
e.span,
OverflowingUInt {
@ -570,7 +570,7 @@ fn lint_literal<'tcx>(
_ => bug!(),
};
if is_infinite == Ok(true) {
cx.emit_spanned_lint(
cx.emit_span_lint(
OVERFLOWING_LITERALS,
e.span,
OverflowingLiteral {
@ -654,7 +654,7 @@ fn lint_nan<'tcx>(
_ => 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>(
@ -700,7 +700,7 @@ fn lint_wide_pointer<'tcx>(
let (Some(l_span), Some(r_span)) =
(l.span.find_ancestor_inside(e.span), r.span.find_ancestor_inside(e.span))
else {
return cx.emit_spanned_lint(
return cx.emit_span_lint(
AMBIGUOUS_WIDE_POINTER_COMPARISONS,
e.span,
AmbiguousWidePointerComparisons::Spanless,
@ -718,7 +718,7 @@ fn lint_wide_pointer<'tcx>(
let deref_left = &*"*".repeat(l_ty_refs);
let deref_right = &*"*".repeat(r_ty_refs);
cx.emit_spanned_lint(
cx.emit_span_lint(
AMBIGUOUS_WIDE_POINTER_COMPARISONS,
e.span,
AmbiguousWidePointerComparisons::Spanful {
@ -770,7 +770,7 @@ impl<'tcx> LateLintPass<'tcx> for TypeLimits {
hir::ExprKind::Binary(binop, ref l, ref r) => {
if is_comparison(binop) {
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 {
lint_nan(cx, e, binop, l, r);
lint_wide_pointer(cx, e, binop.node, l, r);
@ -1464,7 +1464,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
} else {
None
};
self.cx.emit_spanned_lint(
self.cx.emit_span_lint(
lint,
sp,
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
// the second-largest.
if largest > slargest * 3 && slargest > 0 {
cx.emit_spanned_lint(
cx.emit_span_lint(
VARIANT_SIZE_DIFFERENCES,
enum_definition.variants[largest_index].span,
VariantSizeDifferencesDiag { largest },
@ -1913,17 +1913,9 @@ impl InvalidAtomicOrdering {
&& (ordering == invalid_ordering || ordering == sym::AcqRel)
{
if method == sym::load {
cx.emit_spanned_lint(
INVALID_ATOMIC_ORDERING,
ordering_arg.span,
AtomicOrderingLoad,
);
cx.emit_span_lint(INVALID_ATOMIC_ORDERING, ordering_arg.span, AtomicOrderingLoad);
} else {
cx.emit_spanned_lint(
INVALID_ATOMIC_ORDERING,
ordering_arg.span,
AtomicOrderingStore,
);
cx.emit_span_lint(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))
&& 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 };
if matches!(fail_ordering, sym::Release | sym::AcqRel) {
cx.emit_spanned_lint(
cx.emit_span_lint(
INVALID_ATOMIC_ORDERING,
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!(local.pat.kind, hir::PatKind::Tuple([], ..))
{
cx.emit_spanned_lint(
cx.emit_span_lint(
UNIT_BINDINGS,
local.span,
UnitBindingsDiag { label: local.pat.span },

View File

@ -182,7 +182,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
let mut op_warned = false;
if let Some(must_use_op) = must_use_op {
cx.emit_spanned_lint(
cx.emit_span_lint(
UNUSED_MUST_USE,
expr.span,
UnusedOp {
@ -202,7 +202,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
}
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(
@ -494,21 +494,21 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
);
}
MustUsePath::Closure(span) => {
cx.emit_spanned_lint(
cx.emit_span_lint(
UNUSED_MUST_USE,
*span,
UnusedClosure { count: plural_len, pre: descr_pre, post: descr_post },
);
}
MustUsePath::Coroutine(span) => {
cx.emit_spanned_lint(
cx.emit_span_lint(
UNUSED_MUST_USE,
*span,
UnusedCoroutine { count: plural_len, pre: descr_pre, post: descr_post },
);
}
MustUsePath::Def(span, def_id, reason) => {
cx.emit_spanned_lint(
cx.emit_span_lint(
UNUSED_MUST_USE,
*span,
UnusedDef {
@ -568,9 +568,9 @@ impl<'tcx> LateLintPass<'tcx> for PathStatements {
} else {
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 {
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,
}
});
cx.emit_spanned_lint(
cx.emit_span_lint(
self.lint(),
primary_span,
UnusedDelim { delim: Self::DELIM_STR, item: msg, suggestion },
@ -1507,7 +1507,7 @@ impl UnusedImportBraces {
ast::UseTreeKind::Nested(_) => return,
};
cx.emit_spanned_lint(
cx.emit_span_lint(
UNUSED_IMPORT_BRACES,
item.span,
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 {
match m {
adjustment::AutoBorrowMutability::Not => {
cx.emit_spanned_lint(UNUSED_ALLOCATION, e.span, UnusedAllocationDiag);
cx.emit_span_lint(UNUSED_ALLOCATION, e.span, UnusedAllocationDiag);
}
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:
///
/// ```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,
/// success_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,
/// for example:
/// - [`TyCtxt::emit_spanned_lint`]
/// - [`TyCtxt::struct_span_lint_hir`]
/// - [`TyCtxt::emit_lint`]
/// - [`TyCtxt::struct_lint_node`]
/// - `LintContext::lookup`
/// - [`TyCtxt::emit_node_span_lint`]
/// - [`TyCtxt::node_span_lint`]
/// - [`TyCtxt::emit_node_lint`]
/// - [`TyCtxt::node_lint`]
/// - `LintContext::opt_span_lint`
///
/// ## `decorate`
///
/// It is not intended to call `emit`/`cancel` on the `DiagnosticBuilder` passed
/// in the `decorate` callback.
#[track_caller]
pub fn struct_lint_level(
pub fn lint_level(
sess: &Session,
lint: &'static Lint,
level: Level,
@ -270,7 +270,7 @@ pub fn struct_lint_level(
// Avoid codegen bloat from monomorphization by immediately doing dyn dispatch of `decorate` to
// the "real" work.
#[track_caller]
fn struct_lint_level_impl(
fn lint_level_impl(
sess: &Session,
lint: &'static Lint,
level: Level,
@ -399,7 +399,7 @@ pub fn struct_lint_level(
explain_lint_level_source(lint, level, src, &mut *err);
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.

View File

@ -217,7 +217,7 @@ fn late_report_deprecation(
return;
}
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) {
let kind = tcx.def_descr(def_id);
deprecation_suggestion(diag, kind, suggestion, method_span);
@ -585,7 +585,7 @@ impl<'tcx> TyCtxt<'tcx> {
unmarked: impl FnOnce(Span, DefId),
) -> bool {
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 =
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());
if mir_body.is_polymorphic {
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,
self.local_def_id_to_hir_id(local_def_id),
self.def_span(ct.def),

View File

@ -7,7 +7,7 @@ pub mod tls;
use crate::arena::Arena;
use crate::dep_graph::{DepGraph, DepKindStruct};
use crate::infer::canonical::{CanonicalParamEnvCache, CanonicalVarInfo, CanonicalVarInfos};
use crate::lint::struct_lint_level;
use crate::lint::lint_level;
use crate::metadata::ModChild;
use crate::middle::codegen_fn_attrs::CodegenFnAttrs;
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`,
/// typically generated by `#[derive(LintDiagnostic)]`).
#[track_caller]
pub fn emit_spanned_lint(
pub fn emit_node_span_lint(
self,
lint: &'static Lint,
hir_id: HirId,
@ -2086,17 +2086,17 @@ impl<'tcx> TyCtxt<'tcx> {
) {
let msg = decorator.msg();
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);
})
}
/// 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]
#[track_caller]
pub fn struct_span_lint_hir(
pub fn node_span_lint(
self,
lint: &'static Lint,
hir_id: HirId,
@ -2105,29 +2105,29 @@ impl<'tcx> TyCtxt<'tcx> {
decorate: impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>),
) {
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
/// generated by `#[derive(LintDiagnostic)]`).
#[track_caller]
pub fn emit_lint(
pub fn emit_node_lint(
self,
lint: &'static Lint,
id: HirId,
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);
})
}
/// 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]
#[track_caller]
pub fn struct_lint_node(
pub fn node_lint(
self,
lint: &'static Lint,
id: HirId,
@ -2135,7 +2135,7 @@ impl<'tcx> TyCtxt<'tcx> {
decorate: impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>),
) {
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]> {

View File

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

View File

@ -53,7 +53,7 @@ fn check_recursion<'tcx>(
let sp = tcx.def_span(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,
hir_id,
sp,

View File

@ -539,7 +539,7 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> {
let span_end = prefix.last().unwrap().unwrap().0;
let span = span_start.to(span_end);
let count = prefix.len();
self.tcx.emit_spanned_lint(
self.tcx.emit_node_span_lint(
IRREFUTABLE_LET_PATTERNS,
self.lint_level,
span,
@ -558,7 +558,7 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> {
let span_end = suffix.last().unwrap().unwrap().0;
let span = span_start.to(span_end);
let count = suffix.len();
self.tcx.emit_spanned_lint(
self.tcx.emit_node_span_lint(
IRREFUTABLE_LET_PATTERNS,
self.lint_level,
span,
@ -814,7 +814,7 @@ fn check_for_bindings_named_same_as_variants(
{
let variant_count = edef.variants().len();
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,
cx.lint_level,
pat.span,
@ -856,7 +856,7 @@ fn report_irrefutable_let_patterns(
) {
macro_rules! emit_diag {
($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,
catchall: Option<Span>,
) {
cx.tcx.emit_spanned_lint(
cx.tcx.emit_node_span_lint(
UNREACHABLE_PATTERNS,
hir_id,
span,

View File

@ -214,7 +214,7 @@ impl<'tcx> ConstToPat<'tcx> {
if let Some(mir_structural_match_violation) = mir_structural_match_violation {
match non_sm_ty.kind() {
ty::Adt(..) if mir_structural_match_violation => {
self.tcx().emit_spanned_lint(
self.tcx().emit_node_span_lint(
lint::builtin::INDIRECT_STRUCTURAL_MATCH,
self.id,
self.span,
@ -233,7 +233,7 @@ impl<'tcx> ConstToPat<'tcx> {
} else if !have_valtree && !self.saw_const_match_lint.get() {
// The only way valtree construction can fail without the structural match
// 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,
self.id,
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
// any errors.) This ensures it shows up in cargo's future-compat reports as well.
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,
self.id,
self.span,
@ -319,7 +319,7 @@ impl<'tcx> ConstToPat<'tcx> {
let kind = match ty.kind() {
ty::Float(_) => {
self.saw_const_match_lint.set(true);
tcx.emit_spanned_lint(
tcx.emit_node_span_lint(
lint::builtin::ILLEGAL_FLOATING_POINT_LITERAL_PATTERN,
id,
span,
@ -339,7 +339,7 @@ impl<'tcx> ConstToPat<'tcx> {
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() {
self.saw_const_match_lint.set(true);
tcx.emit_spanned_lint(
tcx.emit_node_span_lint(
lint::builtin::INDIRECT_STRUCTURAL_MATCH,
id,
span,
@ -435,7 +435,7 @@ impl<'tcx> ConstToPat<'tcx> {
&& !self.saw_const_match_lint.get()
{
self.saw_const_match_lint.set(true);
tcx.emit_spanned_lint(
tcx.emit_node_span_lint(
lint::builtin::INDIRECT_STRUCTURAL_MATCH,
self.id,
span,
@ -516,7 +516,7 @@ impl<'tcx> ConstToPat<'tcx> {
&& let Some(non_sm_ty) = traits::search_for_structural_match_violation(span, tcx, ty)
{
self.saw_const_match_lint.set(true);
tcx.emit_spanned_lint(
tcx.emit_node_span_lint(
lint::builtin::NONTRIVIAL_STRUCTURAL_MATCH,
id,
span,

View File

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

View File

@ -527,7 +527,7 @@ fn report_unused_unsafe(tcx: TyCtxt<'_>, kind: UnusedUnsafe, id: HirId) {
} else {
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) {
@ -577,7 +577,7 @@ pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: LocalDefId) {
});
}
UnsafetyViolationKind::UnsafeFn => {
tcx.emit_spanned_lint(
tcx.emit_node_span_lint(
UNSAFE_OP_IN_UNSAFE_FN,
lint_root,
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>) {
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,
reason: s.as_str().to_string(),
});
tcx.emit_spanned_lint(
tcx.emit_node_span_lint(
rustc_session::lint::builtin::MUST_NOT_SUSPEND,
hir_id,
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 foreign = fn_def_id.is_some();
tcx.emit_spanned_lint(
tcx.emit_node_span_lint(
FFI_UNWIND_CALLS,
lint_root,
span,

View File

@ -185,7 +185,7 @@ impl<'tcx> FunctionItemRefChecker<'_, 'tcx> {
ret,
);
self.tcx.emit_spanned_lint(
self.tcx.emit_node_span_lint(
FUNCTION_ITEM_REFERENCES,
lint_root,
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.
return;
};
self.tcx.emit_spanned_lint(
self.tcx.emit_node_span_lint(
LARGE_ASSIGNMENTS,
lint_root,
span,

View File

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

View File

@ -199,7 +199,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
&& !assign.span.from_expansion()
{
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,
assign.hir_id,
assign.span,
@ -899,7 +899,7 @@ impl<'tcx> DeadVisitor<'tcx> {
};
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(

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
// is indeed `!`.
self.ir.tcx.emit_spanned_lint(
self.ir.tcx.emit_node_span_lint(
lint::builtin::UNREACHABLE_CODE,
expr_id,
expr_span,
@ -1446,7 +1446,7 @@ impl<'tcx> Liveness<'_, 'tcx> {
if self.used_on_entry(entry_ln, var) {
if !self.live_on_entry(entry_ln, 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,
var_hir_id,
vec![span],
@ -1456,7 +1456,7 @@ impl<'tcx> Liveness<'_, 'tcx> {
}
} else {
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,
var_hir_id,
vec![span],
@ -1478,7 +1478,7 @@ impl<'tcx> Liveness<'_, 'tcx> {
if !self.live_on_entry(ln, 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,
hir_id,
spans,
@ -1552,7 +1552,7 @@ impl<'tcx> Liveness<'_, 'tcx> {
if ln == self.exit_ln { false } else { self.assigned_on_exit(ln, var) };
if is_assigned {
self.ir.tcx.emit_spanned_lint(
self.ir.tcx.emit_node_span_lint(
lint::builtin::UNUSED_VARIABLES,
first_hir_id,
hir_ids_and_spans
@ -1574,7 +1574,7 @@ impl<'tcx> Liveness<'_, 'tcx> {
span.with_hi(BytePos(span.hi().0 + 1))
})
.collect();
self.ir.tcx.emit_spanned_lint(
self.ir.tcx.emit_node_span_lint(
lint::builtin::UNUSED_VARIABLES,
first_hir_id,
hir_ids_and_spans.iter().map(|(_, pat_span, _)| *pat_span).collect::<Vec<_>>(),
@ -1599,7 +1599,7 @@ impl<'tcx> Liveness<'_, 'tcx> {
let non_shorthands =
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,
first_hir_id,
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,
first_hir_id,
hir_ids_and_spans
@ -1690,7 +1690,7 @@ impl<'tcx> Liveness<'_, 'tcx> {
if !self.live_on_exit(ln, 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,
hir_id,
spans,

View File

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

View File

@ -122,7 +122,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
if matches!(kind, AnnotationKind::Prohibited | AnnotationKind::DeprecationProhibited) {
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,
hir_id,
*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
// be fixed first
if t.path.res != Res::Err && c.fully_stable {
self.tcx.emit_spanned_lint(
self.tcx.emit_node_span_lint(
INEFFECTIVE_UNSTABLE_TRAIT_IMPL,
item.hir_id(),
span,
@ -1073,7 +1073,7 @@ fn unnecessary_partially_stable_feature_lint(
implies: Symbol,
since: Symbol,
) {
tcx.emit_spanned_lint(
tcx.emit_node_span_lint(
lint::builtin::STABLE_FEATURES,
hir::CRATE_HIR_ID,
span,
@ -1096,7 +1096,7 @@ fn unnecessary_stable_feature_lint(
if since.as_str() == VERSION_PLACEHOLDER {
since = sym::env_CFG_RELEASE;
}
tcx.emit_spanned_lint(
tcx.emit_node_span_lint(
lint::builtin::STABLE_FEATURES,
hir::CRATE_HIR_ID,
span,

View File

@ -158,7 +158,7 @@ pub(crate) fn lint_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
// is not exhaustive enough.
//
// 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,
rcx.match_lint_level,
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 })
.collect();
let pat_span = pat.data().unwrap().span;
self.tcx.emit_spanned_lint(
self.tcx.emit_node_span_lint(
lint::builtin::OVERLAPPING_RANGE_ENDPOINTS,
self.match_lint_level,
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 {
if self.leaks_private_dep(def_id) {
self.tcx.emit_spanned_lint(
self.tcx.emit_node_span_lint(
lint::builtin::EXPORTED_PRIVATE_DEPENDENCIES,
self.tcx.local_def_id_to_hir_id(self.item_def_id),
self.tcx.def_span(self.item_def_id.to_def_id()),
@ -1456,7 +1456,7 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
} else {
lint::builtin::PRIVATE_BOUNDS
};
self.tcx.emit_spanned_lint(
self.tcx.emit_node_span_lint(
lint,
self.tcx.local_def_id_to_hir_id(self.item_def_id),
span,
@ -1543,7 +1543,7 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'tcx, '_> {
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 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,
hir_id,
span,

View File

@ -144,7 +144,7 @@ pub fn feature_warn_issue(
let mut err = sess.parse_sess.dcx.struct_span_warn(span, explain);
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 future_incompatible = lint.future_incompatible.as_ref().unwrap();
err.is_lint(lint.name_lower(), /* has_future_breakage */ false);

View File

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

View File

@ -387,7 +387,7 @@ fn report_conflicting_impls<'tcx>(
let impl_span = tcx.def_span(impl_def_id);
// 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.
fn decorate<'tcx>(
tcx: TyCtxt<'tcx>,
@ -462,7 +462,7 @@ fn report_conflicting_impls<'tcx>(
FutureCompatOverlapErrorKind::Issue33140 => ORDER_DEPENDENT_TRAIT_OBJECTS,
FutureCompatOverlapErrorKind::LeakCheck => COHERENCE_LEAK_CHECK,
};
tcx.struct_span_lint_hir(
tcx.node_span_lint(
lint,
tcx.local_def_id_to_hir_id(impl_def_id),
impl_span,

View File

@ -377,7 +377,7 @@ pub(crate) fn run_global_ctxt(
{}/rustdoc/how-to-write-documentation.html",
crate::DOC_RUST_LANG_ORG_CHANNEL
);
tcx.struct_lint_node(
tcx.node_lint(
crate::lint::MISSING_CRATE_LEVEL_DOCS,
DocContext::as_local_hir_id(tcx, krate.module.item_id).unwrap(),
"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>) {
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,
self.tcx.local_def_id_to_hir_id(def_id),
self.sp,
@ -843,7 +843,7 @@ impl<'tcx> ExtraInfo<'tcx> {
f: impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>),
) {
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,
self.tcx.local_def_id_to_hir_id(def_id),
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) {
debug!("reporting error for {item:?} (hir_id={hir_id:?})");
let sp = item.attr_span(cx.tcx);
cx.tcx.struct_span_lint_hir(
cx.tcx.node_span_lint(
crate::lint::MISSING_DOC_CODE_EXAMPLES,
hir_id,
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
&& !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,
hir_id,
item.attr_span(cx.tcx),

View File

@ -1704,7 +1704,7 @@ fn report_diagnostic(
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 {
MarkdownLinkRange::Destination(md_range) => {
let mut md_range = md_range.clone();

View File

@ -24,7 +24,7 @@ pub(super) fn visit_item(cx: &DocContext<'_>, item: &Item) {
let sp =
source_span_for_markdown_range(cx.tcx, &dox, &range, &item.attrs.doc_strings)
.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")
.span_suggestion(
sp,

View File

@ -99,7 +99,7 @@ fn check_rust_syntax(
// All points of divergence have been handled earlier so this can be
// done the same way whether the span is precise or not.
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 {
"`ignore` code blocks require valid Rust code for syntax highlighting; \
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,
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;
// 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,

View File

@ -176,7 +176,7 @@ fn check_inline_or_reference_unknown_redundancy(
&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")
.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")
@ -226,7 +226,7 @@ fn check_reference_redundancy(
&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")
.span_label(display_span, "because label contains path that resolves to same destination")
.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));
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;
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
disallowed-methods = [
"rustc_lint::context::LintContext::struct_span_lint",
"rustc_middle::ty::context::TyCtxt::struct_span_lint_hir"
"rustc_lint::context::LintContext::span_lint",
"rustc_middle::ty::context::TyCtxt::node_span_lint"
]

View File

@ -41,7 +41,6 @@ impl CompilerLintFunctions {
pub fn new() -> Self {
let mut map = FxHashMap::default();
map.insert("span_lint", "utils::span_lint");
map.insert("struct_span_lint", "utils::span_lint");
map.insert("lint", "utils::span_lint");
map.insert("span_lint_note", "utils::span_lint_and_note");
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) {
#[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);
});
}
@ -81,7 +81,7 @@ pub fn span_lint_and_help<T: LintContext>(
help: &str,
) {
#[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();
if let Some(help_span) = help_span {
diag.span_help(help_span, help.to_string());
@ -124,7 +124,7 @@ pub fn span_lint_and_note<T: LintContext>(
note: &str,
) {
#[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();
if let Some(note_span) = note_span {
diag.span_note(note_span, note);
@ -146,7 +146,7 @@ where
F: FnOnce(&mut Diagnostic),
{
#[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);
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) {
#[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);
});
}
@ -168,7 +168,7 @@ pub fn span_lint_hir_and_then(
f: impl FnOnce(&mut Diagnostic),
) {
#[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);
docs_link(diag, lint);
});

View File

@ -11,7 +11,7 @@ use rustc_lint::{Lint, LintContext};
use rustc_middle::ty::TyCtxt;
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(
@ -21,7 +21,7 @@ pub fn b(
span: impl Into<MultiSpan>,
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() {}

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
|
LL | cx.struct_span_lint(lint, span, msg, |_| {});
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | cx.span_lint(lint, span, msg, |_| {});
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::disallowed-methods` implied by `-D warnings`
= 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
|
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