Add an internal lint that warns when accessing untracked data
This commit is contained in:
parent
6199b69c53
commit
040239465a
11 changed files with 82 additions and 35 deletions
|
@ -17,8 +17,8 @@ use tracing::debug;
|
|||
|
||||
use crate::lints::{
|
||||
BadOptAccessDiag, DefaultHashTypesDiag, DiagOutOfImpl, LintPassByHand, NonExistentDocKeyword,
|
||||
NonGlobImportTypeIrInherent, QueryInstability, SpanUseEqCtxtDiag, TyQualified, TykindDiag,
|
||||
TykindKind, TypeIrInherentUsage, UntranslatableDiag,
|
||||
NonGlobImportTypeIrInherent, QueryInstability, QueryUntracked, SpanUseEqCtxtDiag, TyQualified,
|
||||
TykindDiag, TykindKind, TypeIrInherentUsage, UntranslatableDiag,
|
||||
};
|
||||
use crate::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext};
|
||||
|
||||
|
@ -88,7 +88,18 @@ declare_tool_lint! {
|
|||
report_in_external_macro: true
|
||||
}
|
||||
|
||||
declare_lint_pass!(QueryStability => [POTENTIAL_QUERY_INSTABILITY]);
|
||||
declare_tool_lint! {
|
||||
/// The `untracked_query_information` lint detects use of methods which leak information not
|
||||
/// tracked by the query system, such as whether a `Steal<T>` value has already been stolen. In
|
||||
/// order not to break incremental compilation, such methods must be used very carefully or not
|
||||
/// at all.
|
||||
pub rustc::UNTRACKED_QUERY_INFORMATION,
|
||||
Allow,
|
||||
"require explicit opt-in when accessing information not tracked by the query system",
|
||||
report_in_external_macro: true
|
||||
}
|
||||
|
||||
declare_lint_pass!(QueryStability => [POTENTIAL_QUERY_INSTABILITY, UNTRACKED_QUERY_INFORMATION]);
|
||||
|
||||
impl LateLintPass<'_> for QueryStability {
|
||||
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
|
||||
|
@ -102,6 +113,13 @@ impl LateLintPass<'_> for QueryStability {
|
|||
QueryInstability { query: cx.tcx.item_name(def_id) },
|
||||
);
|
||||
}
|
||||
if cx.tcx.has_attr(def_id, sym::rustc_lint_untracked_query_information) {
|
||||
cx.emit_span_lint(
|
||||
UNTRACKED_QUERY_INFORMATION,
|
||||
span,
|
||||
QueryUntracked { method: cx.tcx.item_name(def_id) },
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -609,6 +609,7 @@ fn register_internals(store: &mut LintStore) {
|
|||
vec![
|
||||
LintId::of(DEFAULT_HASH_TYPES),
|
||||
LintId::of(POTENTIAL_QUERY_INSTABILITY),
|
||||
LintId::of(UNTRACKED_QUERY_INFORMATION),
|
||||
LintId::of(USAGE_OF_TY_TYKIND),
|
||||
LintId::of(PASS_BY_VALUE),
|
||||
LintId::of(LINT_PASS_IMPL_WITHOUT_MACRO),
|
||||
|
|
|
@ -894,6 +894,13 @@ pub(crate) struct QueryInstability {
|
|||
pub query: Symbol,
|
||||
}
|
||||
|
||||
#[derive(LintDiagnostic)]
|
||||
#[diag(lint_query_untracked)]
|
||||
#[note]
|
||||
pub(crate) struct QueryUntracked {
|
||||
pub method: Symbol,
|
||||
}
|
||||
|
||||
#[derive(LintDiagnostic)]
|
||||
#[diag(lint_span_use_eq_ctxt)]
|
||||
pub(crate) struct SpanUseEqCtxtDiag;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue