Skip to content

Commit 979e297

Browse files
committed
Update book
1 parent a650692 commit 979e297

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

book/src/development/common_tools_writing_lints.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl<'tcx> LateLintPass<'tcx> for MyStructLint {
6868
// Check our expr is calling a method
6969
if let hir::ExprKind::MethodCall(path, _, _self_arg, ..) = &expr.kind
7070
// Check the name of this method is `some_method`
71-
&& path.ident.name == sym!(some_method)
71+
&& path.ident.name.as_str() == "some_method"
7272
// Optionally, check the type of the self argument.
7373
// - See "Checking for a specific type"
7474
{
@@ -167,7 +167,7 @@ impl<'tcx> LateLintPass<'tcx> for MyTypeImpl {
167167
// Check if item is a method/function
168168
if let ImplItemKind::Fn(ref signature, _) = impl_item.kind
169169
// Check the method is named `some_method`
170-
&& impl_item.ident.name == sym!(some_method)
170+
&& impl_item.ident.name.as_str() == "some_method"
171171
// We can also check it has a parameter `self`
172172
&& signature.decl.implicit_self.has_implicit_self()
173173
// We can go further and even check if its return type is `String`

book/src/development/method_checking.md

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
In some scenarios we might want to check for methods when developing
44
a lint. There are two kinds of questions that we might be curious about:
55

6-
- Invocation: Does an expression call a specific method?
7-
- Definition: Does an `impl` define a method?
6+
- Invocation: Does an expression call a specific method?
7+
- Definition: Does an `impl` define a method?
88

99
## Checking if an `expr` is calling a specific method
1010

@@ -23,7 +23,7 @@ impl<'tcx> LateLintPass<'tcx> for OurFancyMethodLint {
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 == sym!(our_fancy_method)
26+
&& path.ident.name.as_str() == "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,10 +41,6 @@ information on the pattern matching. As mentioned in [Define
4141
Lints](defining_lints.md#lint-types), the `methods` lint type is full of pattern
4242
matching with `MethodCall` in case the reader wishes to explore more.
4343

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`].
47-
4844
## Checking if a `impl` block implements a method
4945

5046
While sometimes we want to check whether a method is being called or not, other
@@ -71,7 +67,7 @@ impl<'tcx> LateLintPass<'tcx> for MyTypeImpl {
7167
// Check if item is a method/function
7268
if let ImplItemKind::Fn(ref signature, _) = impl_item.kind
7369
// Check the method is named `our_fancy_method`
74-
&& impl_item.ident.name == sym!(our_fancy_method)
70+
&& impl_item.ident.name.as_str() == "our_fancy_method"
7571
// We can also check it has a parameter `self`
7672
&& signature.decl.implicit_self.has_implicit_self()
7773
// We can go even further and even check if its return type is `String`
@@ -85,9 +81,6 @@ impl<'tcx> LateLintPass<'tcx> for MyTypeImpl {
8581

8682
[`check_impl_item`]: https://doc.rust-lang.org/stable/nightly-rustc/rustc_lint/trait.LateLintPass.html#method.check_impl_item
8783
[`ExprKind`]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_hir/hir/enum.ExprKind.html
88-
[`Ident`]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_span/symbol/struct.Ident.html
8984
[`ImplItem`]: https://doc.rust-lang.org/stable/nightly-rustc/rustc_hir/hir/struct.ImplItem.html
9085
[`LateLintPass`]: https://doc.rust-lang.org/stable/nightly-rustc/rustc_lint/trait.LateLintPass.html
9186
[`MethodCall`]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_hir/hir/enum.ExprKind.html#variant.MethodCall
92-
[`PathSegment`]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_hir/hir/struct.PathSegment.html
93-
[sym]: https://doc.rust-lang.org/stable/nightly-rustc/clippy_utils/macro.sym.html

0 commit comments

Comments
 (0)