Skip to content

Commit c961665

Browse files
committed
Tweak common tool docs on type implement trait check
Common tool documentation uses `match_trait_method` which is deprecated. Additionally, adds information on why `is_trait_method` is not the preferred way.
1 parent 1fc1aee commit c961665

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

doc/common_tools_writing_lints.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,15 @@ impl LateLintPass<'_> for MyStructLint {
7878
There are two ways to do this, depending if the target trait is part of lang items.
7979

8080
```rust
81-
use clippy_utils::{implements_trait, match_trait_method, paths};
81+
use clippy_utils::{implements_trait, is_trait_method};
82+
use rustc_span::symbol::sym;
8283

8384
impl LateLintPass<'_> for MyStructLint {
8485
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
8586
// 1. Using expression and Clippy's convenient method
86-
// we use `match_trait_method` function from Clippy's toolbox
87-
if match_trait_method(cx, expr, &paths::INTO) {
88-
// `expr` implements `Into` trait
87+
// we use `is_trait_method` function from Clippy's toolbox
88+
if is_trait_method(cx, expr, sym::Iterator) {
89+
// method call in `expr` belongs to `Iterator` trait
8990
}
9091

9192
// 2. Using type context `TyCtxt`
@@ -101,9 +102,7 @@ impl LateLintPass<'_> for MyStructLint {
101102
}
102103
```
103104

104-
> Prefer using lang items, if the target trait is available there.
105-
106-
A list of defined paths for Clippy can be found in [paths.rs][paths]
105+
> Prefer using lang items, if the target trait is available there. `is_trait_method` checks for method call and can introduce unwanted behaviours.
107106
108107
We access lang items through the type context `tcx`. `tcx` is of type [`TyCtxt`][TyCtxt] and is defined in the `rustc_middle` crate.
109108

0 commit comments

Comments
 (0)