|
1 | 1 | use clippy_utils::diagnostics::span_lint_and_help;
|
2 | 2 | use clippy_utils::ty::{implements_trait, is_type_lang_item};
|
3 | 3 | use clippy_utils::{return_ty, trait_ref_of_method};
|
4 |
| -use if_chain::if_chain; |
5 |
| -use rustc_hir::{GenericParamKind, ImplItem, ImplItemKind, LangItem}; |
| 4 | +use rustc_hir::{GenericParamKind, ImplItem, ImplItemKind, LangItem, Unsafety}; |
6 | 5 | use rustc_lint::{LateContext, LateLintPass};
|
7 | 6 | use rustc_session::{declare_lint_pass, declare_tool_lint};
|
8 | 7 | use rustc_span::sym;
|
| 8 | +use rustc_target::spec::abi::Abi; |
9 | 9 |
|
10 | 10 | declare_clippy_lint! {
|
11 | 11 | /// ### What it does
|
@@ -95,24 +95,23 @@ impl<'tcx> LateLintPass<'tcx> for InherentToString {
|
95 | 95 | return;
|
96 | 96 | }
|
97 | 97 |
|
98 |
| - if_chain! { |
99 |
| - // Check if item is a method, called to_string and has a parameter 'self' |
100 |
| - if let ImplItemKind::Fn(ref signature, _) = impl_item.kind; |
101 |
| - if impl_item.ident.name == sym::to_string; |
102 |
| - let decl = &signature.decl; |
103 |
| - if decl.implicit_self.has_implicit_self(); |
104 |
| - if decl.inputs.len() == 1; |
105 |
| - if impl_item.generics.params.iter().all(|p| matches!(p.kind, GenericParamKind::Lifetime { .. })); |
106 |
| - |
| 98 | + // Check if item is a method called `to_string` and has a parameter 'self' |
| 99 | + if let ImplItemKind::Fn(ref signature, _) = impl_item.kind |
| 100 | + // #11201 |
| 101 | + && let header = signature.header |
| 102 | + && header.unsafety == Unsafety::Normal |
| 103 | + && header.abi == Abi::Rust |
| 104 | + && impl_item.ident.name == sym::to_string |
| 105 | + && let decl = signature.decl |
| 106 | + && decl.implicit_self.has_implicit_self() |
| 107 | + && decl.inputs.len() == 1 |
| 108 | + && impl_item.generics.params.iter().all(|p| matches!(p.kind, GenericParamKind::Lifetime { .. })) |
107 | 109 | // Check if return type is String
|
108 |
| - if is_type_lang_item(cx, return_ty(cx, impl_item.owner_id), LangItem::String); |
109 |
| - |
| 110 | + && is_type_lang_item(cx, return_ty(cx, impl_item.owner_id), LangItem::String) |
110 | 111 | // Filters instances of to_string which are required by a trait
|
111 |
| - if trait_ref_of_method(cx, impl_item.owner_id.def_id).is_none(); |
112 |
| - |
113 |
| - then { |
114 |
| - show_lint(cx, impl_item); |
115 |
| - } |
| 112 | + && trait_ref_of_method(cx, impl_item.owner_id.def_id).is_none() |
| 113 | + { |
| 114 | + show_lint(cx, impl_item); |
116 | 115 | }
|
117 | 116 | }
|
118 | 117 | }
|
|
0 commit comments