Do not show spans from external crates in missing_trait_methods
Pointing to the missing method definition in external crates will use paths which depend on the system, and even on the Rust compiler version used when the iterator is defined in the standard library. When the trait being implemented and whose method is missing is external, point only to the trait implementation. The user will be able to figure out, or even navigate using their IDE, to the proper definition. As a side-effect, this will remove a large lintcheck churn at every Rustup for this lint.
This commit is contained in:
parent
669fbcb478
commit
47b987eccb
3 changed files with 25 additions and 2 deletions
|
|
@ -1,6 +1,7 @@
|
|||
use clippy_utils::diagnostics::span_lint_and_then;
|
||||
use clippy_utils::is_lint_allowed;
|
||||
use clippy_utils::macros::span_is_local;
|
||||
use clippy_utils::source::snippet_opt;
|
||||
use rustc_hir::def_id::DefIdSet;
|
||||
use rustc_hir::{Impl, Item, ItemKind};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
|
|
@ -84,7 +85,14 @@ impl<'tcx> LateLintPass<'tcx> for MissingTraitMethods {
|
|||
cx.tcx.def_span(item.owner_id),
|
||||
format!("missing trait method provided by default: `{}`", assoc.name()),
|
||||
|diag| {
|
||||
diag.span_help(cx.tcx.def_span(assoc.def_id), "implement the method");
|
||||
if assoc.def_id.is_local() {
|
||||
diag.span_help(cx.tcx.def_span(assoc.def_id), "implement the method");
|
||||
} else if let Some(snippet) = snippet_opt(cx, of_trait.trait_ref.path.span) {
|
||||
diag.help(format!(
|
||||
"implement the missing `{}` method of the `{snippet}` trait",
|
||||
assoc.name(),
|
||||
));
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,3 +62,10 @@ impl MissingMultiple for Partial {}
|
|||
//~| missing_trait_methods
|
||||
|
||||
fn main() {}
|
||||
|
||||
//~v missing_trait_methods
|
||||
impl PartialEq<Partial> for Partial {
|
||||
fn eq(&self, other: &Partial) -> bool {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,5 +60,13 @@ help: implement the method
|
|||
LL | fn three() {}
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
error: missing trait method provided by default: `ne`
|
||||
--> tests/ui/missing_trait_methods.rs:67:1
|
||||
|
|
||||
LL | impl PartialEq<Partial> for Partial {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: implement the missing `ne` method of the `PartialEq<Partial>` trait
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue