Make MissingDebugImplementation a module lint.
This commit is contained in:
parent
6c7054e962
commit
53e5fd6a61
4 changed files with 27 additions and 35 deletions
|
@ -39,7 +39,7 @@ use crate::{
|
||||||
BuiltinUnstableFeatures, BuiltinUnusedDocComment, BuiltinUnusedDocCommentSub,
|
BuiltinUnstableFeatures, BuiltinUnusedDocComment, BuiltinUnusedDocCommentSub,
|
||||||
BuiltinWhileTrue, SuggestChangingAssocTypes,
|
BuiltinWhileTrue, SuggestChangingAssocTypes,
|
||||||
},
|
},
|
||||||
EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext,
|
EarlyContext, EarlyLintPass, LateContext, LateLintPass, Level, LintContext,
|
||||||
};
|
};
|
||||||
use hir::IsAsync;
|
use hir::IsAsync;
|
||||||
use rustc_ast::attr;
|
use rustc_ast::attr;
|
||||||
|
@ -51,7 +51,7 @@ use rustc_errors::{Applicability, DecorateLint, MultiSpan};
|
||||||
use rustc_feature::{deprecated_attributes, AttributeGate, BuiltinAttribute, GateIssue, Stability};
|
use rustc_feature::{deprecated_attributes, AttributeGate, BuiltinAttribute, GateIssue, Stability};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::{DefKind, Res};
|
use rustc_hir::def::{DefKind, Res};
|
||||||
use rustc_hir::def_id::{DefId, LocalDefId, LocalDefIdSet, CRATE_DEF_ID};
|
use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_ID};
|
||||||
use rustc_hir::intravisit::FnKind as HirFnKind;
|
use rustc_hir::intravisit::FnKind as HirFnKind;
|
||||||
use rustc_hir::{Body, FnDecl, GenericParamKind, Node, PatKind, PredicateOrigin};
|
use rustc_hir::{Body, FnDecl, GenericParamKind, Node, PatKind, PredicateOrigin};
|
||||||
use rustc_middle::lint::in_external_macro;
|
use rustc_middle::lint::in_external_macro;
|
||||||
|
@ -774,9 +774,7 @@ declare_lint! {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct MissingDebugImplementations {
|
pub(crate) struct MissingDebugImplementations;
|
||||||
impling_types: Option<LocalDefIdSet>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl_lint_pass!(MissingDebugImplementations => [MISSING_DEBUG_IMPLEMENTATIONS]);
|
impl_lint_pass!(MissingDebugImplementations => [MISSING_DEBUG_IMPLEMENTATIONS]);
|
||||||
|
|
||||||
|
@ -793,21 +791,18 @@ impl<'tcx> LateLintPass<'tcx> for MissingDebugImplementations {
|
||||||
|
|
||||||
let Some(debug) = cx.tcx.get_diagnostic_item(sym::Debug) else { return };
|
let Some(debug) = cx.tcx.get_diagnostic_item(sym::Debug) else { return };
|
||||||
|
|
||||||
if self.impling_types.is_none() {
|
// Avoid listing trait impls if the trait is allowed.
|
||||||
let mut impls = LocalDefIdSet::default();
|
let (level, _) = cx.tcx.lint_level_at_node(MISSING_DEBUG_IMPLEMENTATIONS, item.hir_id());
|
||||||
cx.tcx.for_each_impl(debug, |d| {
|
if level == Level::Allow {
|
||||||
if let Some(ty_def) = cx.tcx.type_of(d).instantiate_identity().ty_adt_def() {
|
return;
|
||||||
if let Some(def_id) = ty_def.did().as_local() {
|
|
||||||
impls.insert(def_id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
self.impling_types = Some(impls);
|
|
||||||
debug!("{:?}", self.impling_types);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !self.impling_types.as_ref().unwrap().contains(&item.owner_id.def_id) {
|
let has_impl = cx
|
||||||
|
.tcx
|
||||||
|
.non_blanket_impls_for_ty(debug, cx.tcx.type_of(item.owner_id).instantiate_identity())
|
||||||
|
.next()
|
||||||
|
.is_some();
|
||||||
|
if !has_impl {
|
||||||
cx.emit_spanned_lint(
|
cx.emit_spanned_lint(
|
||||||
MISSING_DEBUG_IMPLEMENTATIONS,
|
MISSING_DEBUG_IMPLEMENTATIONS,
|
||||||
item.span,
|
item.span,
|
||||||
|
|
|
@ -193,10 +193,6 @@ late_lint_methods!(
|
||||||
[
|
[
|
||||||
// Tracks attributes of parents
|
// Tracks attributes of parents
|
||||||
MissingDoc: MissingDoc::new(),
|
MissingDoc: MissingDoc::new(),
|
||||||
// Builds a global list of all impls of `Debug`.
|
|
||||||
// FIXME: Turn the computation of types which implement Debug into a query
|
|
||||||
// and change this to a module lint pass
|
|
||||||
MissingDebugImplementations: MissingDebugImplementations::default(),
|
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
@ -253,6 +249,7 @@ late_lint_methods!(
|
||||||
OpaqueHiddenInferredBound: OpaqueHiddenInferredBound,
|
OpaqueHiddenInferredBound: OpaqueHiddenInferredBound,
|
||||||
MultipleSupertraitUpcastable: MultipleSupertraitUpcastable,
|
MultipleSupertraitUpcastable: MultipleSupertraitUpcastable,
|
||||||
MapUnitFn: MapUnitFn,
|
MapUnitFn: MapUnitFn,
|
||||||
|
MissingDebugImplementations: MissingDebugImplementations,
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,15 +1,3 @@
|
||||||
error: type does not implement `Debug`; consider adding `#[derive(Debug)]` or a manual implementation
|
|
||||||
--> $DIR/issue-111359.rs:7:5
|
|
||||||
|
|
|
||||||
LL | pub struct BarPub;
|
|
||||||
| ^^^^^^^^^^^^^^^^^^
|
|
||||||
|
|
|
||||||
note: the lint level is defined here
|
|
||||||
--> $DIR/issue-111359.rs:1:8
|
|
||||||
|
|
|
||||||
LL | #[deny(missing_debug_implementations)]
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
|
|
||||||
error: type could implement `Copy`; consider adding `impl Copy`
|
error: type could implement `Copy`; consider adding `impl Copy`
|
||||||
--> $DIR/issue-111359.rs:7:5
|
--> $DIR/issue-111359.rs:7:5
|
||||||
|
|
|
|
||||||
|
@ -22,5 +10,17 @@ note: the lint level is defined here
|
||||||
LL | #[deny(missing_copy_implementations)]
|
LL | #[deny(missing_copy_implementations)]
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: type does not implement `Debug`; consider adding `#[derive(Debug)]` or a manual implementation
|
||||||
|
--> $DIR/issue-111359.rs:7:5
|
||||||
|
|
|
||||||
|
LL | pub struct BarPub;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
note: the lint level is defined here
|
||||||
|
--> $DIR/issue-111359.rs:1:8
|
||||||
|
|
|
||||||
|
LL | #[deny(missing_debug_implementations)]
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
|
|
@ -35,4 +35,4 @@ struct PrivateStruct;
|
||||||
enum PrivateEnum {}
|
enum PrivateEnum {}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct GenericType<T>(T);
|
pub struct GenericType<T>(T);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue