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:
commit
0011fac90d
96 changed files with 353 additions and 376 deletions
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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]> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue