@@ -37,26 +37,24 @@ impl<'tcx> LateLintPass<'tcx> for OurFancyMethodLint {
37
37
```
38
38
39
39
Take a closer look at the ` ExprKind ` enum variant [ ` MethodCall ` ] for more
40
- information on the pattern matching.
41
- As mentioned in [ Define Lints] ( define_lints.md#lint-types ) ,
42
- the ` methods ` lint type is full of pattern matching with ` Methodcall `
43
- in case the reader wishes to explore more.
40
+ information on the pattern matching. As mentioned in [ Define
41
+ Lints] ( define_lints.md#lint-types ) , the ` methods ` lint type is full of pattern
42
+ matching with ` MethodCall ` in case the reader wishes to explore more.
44
43
45
- Additionally, we use the [ ` clippy_utils::sym! ` ] [ sym ] macro to conveniently convert
46
- an input ` our_fancy_method ` into a ` Symbol ` and compare that symbol to the [ ` ident ` ] [ Ident ] 's name in the [ ` PathSegment ` ]
47
- in the [ ` MethodCall ` ] .
44
+ Additionally, we use the [ ` clippy_utils::sym! ` ] [ sym ] macro to conveniently
45
+ convert an input ` our_fancy_method ` into a ` Symbol ` and compare that symbol to
46
+ the [ ` Ident ` ] 's name in the [ ` PathSegment ` ] in the [ ` MethodCall ` ] .
48
47
49
48
## Checking if a ` impl ` block implements a method
50
49
51
- While sometimes we want to check whether a method is being called or not,
52
- other times we want to know if our ` Ty ` defines a method.
50
+ While sometimes we want to check whether a method is being called or not, other
51
+ times we want to know if our ` Ty ` defines a method.
53
52
54
- To check if our ` impl ` block defines a method ` our_fancy_method ` ,
55
- we will utilize the [ ` check_impl_item ` ] method that is available
56
- in our beloved [ ` LateLintPass ` ] (for more information, refer to the
57
- [ "Lint Passes"] ( lint_passes.md ) chapter in Clippy book).
58
- This method provides us with an [ ` ImplItem ` ] struct, which represents
59
- anything within an ` impl ` block.
53
+ To check if our ` impl ` block defines a method ` our_fancy_method ` , we will
54
+ utilize the [ ` check_impl_item ` ] method that is available in our beloved
55
+ [ ` LateLintPass ` ] (for more information, refer to the [ "Lint
56
+ Passes"] ( lint_passes.md ) chapter in the Clippy book). This method provides us
57
+ with an [ ` ImplItem ` ] struct, which represents anything within an ` impl ` block.
60
58
61
59
Let us take a look at how we might check for the implementation of
62
60
` our_fancy_method ` on a type:
@@ -67,6 +65,7 @@ use clippy_utils::return_ty;
67
65
use rustc_hir :: {ImplItem , ImplItemKind };
68
66
use rustc_lint :: {LateContext , LateLintPass };
69
67
use rustc_span :: symbol :: sym;
68
+
70
69
impl <'tcx > LateLintPass <'tcx > for MyTypeImpl {
71
70
fn check_impl_item (& mut self , cx : & LateContext <'tcx >, impl_item : & 'tcx ImplItem <'_ >) {
72
71
// Check if item is a method/function
@@ -86,7 +85,7 @@ impl<'tcx> LateLintPass<'tcx> for MyTypeImpl {
86
85
87
86
[ `check_impl_item` ] : https://doc.rust-lang.org/stable/nightly-rustc/rustc_lint/trait.LateLintPass.html#method.check_impl_item
88
87
[ `ExprKind` ] : https://doc.rust-lang.org/beta/nightly-rustc/rustc_hir/hir/enum.ExprKind.html
89
- [ Ident ] : https://doc.rust-lang.org/beta/nightly-rustc/rustc_span/symbol/struct.Ident.html
88
+ [ ` Ident` ] : https://doc.rust-lang.org/beta/nightly-rustc/rustc_span/symbol/struct.Ident.html
90
89
[ `ImplItem` ] : https://doc.rust-lang.org/stable/nightly-rustc/rustc_hir/hir/struct.ImplItem.html
91
90
[ `LateLintPass` ] : https://doc.rust-lang.org/stable/nightly-rustc/rustc_lint/trait.LateLintPass.html
92
91
[ `MethodCall` ] : https://doc.rust-lang.org/beta/nightly-rustc/rustc_hir/hir/enum.ExprKind.html#variant.MethodCall
0 commit comments