Merge commit 'f712eb5cdc' into clippy-subtree-update
This commit is contained in:
parent
4847c40c8b
commit
6ced8c33c0
248 changed files with 5023 additions and 900 deletions
|
|
@ -53,7 +53,6 @@ book](../lints.md).
|
|||
> - IDE setup
|
||||
> - High level overview on how Clippy works
|
||||
> - Triage procedure
|
||||
> - Bors and Homu
|
||||
|
||||
[ast]: https://rustc-dev-guide.rust-lang.org/syntax-intro.html
|
||||
[hir]: https://rustc-dev-guide.rust-lang.org/hir.html
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ impl<'tcx> LateLintPass<'tcx> for MyStructLint {
|
|||
// Check our expr is calling a method
|
||||
if let hir::ExprKind::MethodCall(path, _, _self_arg, ..) = &expr.kind
|
||||
// Check the name of this method is `some_method`
|
||||
&& path.ident.name == sym!(some_method)
|
||||
&& path.ident.name.as_str() == "some_method"
|
||||
// Optionally, check the type of the self argument.
|
||||
// - See "Checking for a specific type"
|
||||
{
|
||||
|
|
@ -167,7 +167,7 @@ impl<'tcx> LateLintPass<'tcx> for MyTypeImpl {
|
|||
// Check if item is a method/function
|
||||
if let ImplItemKind::Fn(ref signature, _) = impl_item.kind
|
||||
// Check the method is named `some_method`
|
||||
&& impl_item.ident.name == sym!(some_method)
|
||||
&& impl_item.ident.name.as_str() == "some_method"
|
||||
// We can also check it has a parameter `self`
|
||||
&& signature.decl.implicit_self.has_implicit_self()
|
||||
// We can go further and even check if its return type is `String`
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
In some scenarios we might want to check for methods when developing
|
||||
a lint. There are two kinds of questions that we might be curious about:
|
||||
|
||||
- Invocation: Does an expression call a specific method?
|
||||
- Definition: Does an `impl` define a method?
|
||||
- Invocation: Does an expression call a specific method?
|
||||
- Definition: Does an `impl` define a method?
|
||||
|
||||
## Checking if an `expr` is calling a specific method
|
||||
|
||||
|
|
@ -23,7 +23,7 @@ impl<'tcx> LateLintPass<'tcx> for OurFancyMethodLint {
|
|||
// Check our expr is calling a method with pattern matching
|
||||
if let hir::ExprKind::MethodCall(path, _, [self_arg, ..]) = &expr.kind
|
||||
// Check if the name of this method is `our_fancy_method`
|
||||
&& path.ident.name == sym!(our_fancy_method)
|
||||
&& path.ident.name.as_str() == "our_fancy_method"
|
||||
// We can check the type of the self argument whenever necessary.
|
||||
// (It's necessary if we want to check that method is specifically belonging to a specific trait,
|
||||
// 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
|
|||
Lints](defining_lints.md#lint-types), the `methods` lint type is full of pattern
|
||||
matching with `MethodCall` in case the reader wishes to explore more.
|
||||
|
||||
Additionally, we use the [`clippy_utils::sym!`][sym] macro to conveniently
|
||||
convert an input `our_fancy_method` into a `Symbol` and compare that symbol to
|
||||
the [`Ident`]'s name in the [`PathSegment`] in the [`MethodCall`].
|
||||
|
||||
## Checking if a `impl` block implements a method
|
||||
|
||||
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 {
|
|||
// Check if item is a method/function
|
||||
if let ImplItemKind::Fn(ref signature, _) = impl_item.kind
|
||||
// Check the method is named `our_fancy_method`
|
||||
&& impl_item.ident.name == sym!(our_fancy_method)
|
||||
&& impl_item.ident.name.as_str() == "our_fancy_method"
|
||||
// We can also check it has a parameter `self`
|
||||
&& signature.decl.implicit_self.has_implicit_self()
|
||||
// We can go even further and even check if its return type is `String`
|
||||
|
|
@ -85,9 +81,6 @@ impl<'tcx> LateLintPass<'tcx> for MyTypeImpl {
|
|||
|
||||
[`check_impl_item`]: https://doc.rust-lang.org/stable/nightly-rustc/rustc_lint/trait.LateLintPass.html#method.check_impl_item
|
||||
[`ExprKind`]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_hir/hir/enum.ExprKind.html
|
||||
[`Ident`]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_span/symbol/struct.Ident.html
|
||||
[`ImplItem`]: https://doc.rust-lang.org/stable/nightly-rustc/rustc_hir/hir/struct.ImplItem.html
|
||||
[`LateLintPass`]: https://doc.rust-lang.org/stable/nightly-rustc/rustc_lint/trait.LateLintPass.html
|
||||
[`MethodCall`]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_hir/hir/enum.ExprKind.html#variant.MethodCall
|
||||
[`PathSegment`]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_hir/hir/struct.PathSegment.html
|
||||
[sym]: https://doc.rust-lang.org/stable/nightly-rustc/clippy_utils/macro.sym.html
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue