@@ -15,15 +15,15 @@ the [`ExprKind`] that we can access from `expr.kind`:
1515``` rust
1616use rustc_hir as hir;
1717use rustc_lint :: {LateContext , LateLintPass };
18- use rustc_span :: sym;
1918use clippy_utils :: res :: {MaybeDef , MaybeTypeckRes };
19+ use clippy_utils :: sym;
2020
2121impl <'tcx > LateLintPass <'tcx > for OurFancyMethodLint {
2222 fn check_expr (& mut self , cx : & LateContext <'tcx >, expr : & 'tcx hir :: Expr <'_ >) {
2323 // Check our expr is calling a method with pattern matching
2424 if let hir :: ExprKind :: MethodCall (path , _ , [self_arg , .. ], _ ) = & expr . kind
2525 // Check if the name of this method is `our_fancy_method`
26- && path . ident. name. as_str () == " our_fancy_method"
26+ && path . ident. name == sym :: our_fancy_method
2727 // We can check the type of the self argument whenever necessary.
2828 // (It's necessary if we want to check that method is specifically belonging to a specific trait,
2929 // for example, a `map` method could belong to user-defined trait instead of to `Iterator`)
@@ -41,6 +41,10 @@ information on the pattern matching. As mentioned in [Define
4141Lints] ( defining_lints.md#lint-types ) , the ` methods ` lint type is full of pattern
4242matching with ` MethodCall ` in case the reader wishes to explore more.
4343
44+ New symbols such as ` our_fancy_method ` need to be added to the ` clippy_utils::sym ` module.
45+ This module extends the list of symbols already provided by the compiler crates
46+ in ` rustc_span::sym ` .
47+
4448## Checking if a ` impl ` block implements a method
4549
4650While sometimes we want to check whether a method is being called or not, other
@@ -56,11 +60,10 @@ Let us take a look at how we might check for the implementation of
5660` our_fancy_method ` on a type:
5761
5862``` rust
63+ use clippy_utils :: {return_ty, sym};
5964use clippy_utils :: res :: MaybeDef ;
60- use clippy_utils :: return_ty;
6165use rustc_hir :: {ImplItem , ImplItemKind };
6266use rustc_lint :: {LateContext , LateLintPass };
63- use rustc_span :: symbol :: sym;
6467
6568impl <'tcx > LateLintPass <'tcx > for MyTypeImpl {
6669 fn check_impl_item (& mut self , cx : & LateContext <'tcx >, impl_item : & 'tcx ImplItem <'_ >) {
0 commit comments