@@ -10,7 +10,7 @@ use syntax::codemap::{Span, BytePos};
10
10
use crate :: utils:: { get_arg_name, get_trait_def_id, implements_trait, in_external_macro, in_macro, is_copy, is_expn_of, is_self,
11
11
is_self_ty, iter_input_pats, last_path_segment, match_def_path, match_path, match_qpath, match_trait_method,
12
12
match_type, method_chain_args, match_var, return_ty, remove_blocks, same_tys, single_segment_path, snippet,
13
- span_lint, span_lint_and_sugg, span_lint_and_then, span_note_and_lint, walk_ptrs_ty, walk_ptrs_ty_depth} ;
13
+ span_lint, span_lint_and_sugg, span_lint_and_then, span_note_and_lint, walk_ptrs_ty, walk_ptrs_ty_depth, SpanlessEq } ;
14
14
use crate :: utils:: paths;
15
15
use crate :: utils:: sugg;
16
16
use crate :: consts:: { constant, Constant } ;
@@ -820,8 +820,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
820
820
for & ( method_name, n_args, self_kind, out_type, trait_name) in & TRAIT_METHODS {
821
821
if name == method_name &&
822
822
sig. decl. inputs. len( ) == n_args &&
823
- out_type. matches( & sig. decl. output) &&
824
- self_kind. matches( first_arg_ty, first_arg, self_ty, false , & implitem. generics) {
823
+ out_type. matches( cx , & sig. decl. output) &&
824
+ self_kind. matches( cx , first_arg_ty, first_arg, self_ty, false , & implitem. generics) {
825
825
span_lint( cx, SHOULD_IMPLEMENT_TRAIT , implitem. span, & format!(
826
826
"defining a method called `{}` on this type; consider implementing \
827
827
the `{}` trait or choosing a less ambiguous name", name, trait_name) ) ;
@@ -838,9 +838,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
838
838
if conv. check( & name. as_str( ) ) ;
839
839
if !self_kinds
840
840
. iter( )
841
- . any( |k| k. matches( first_arg_ty, first_arg, self_ty, is_copy, & implitem. generics) ) ;
841
+ . any( |k| k. matches( cx , first_arg_ty, first_arg, self_ty, is_copy, & implitem. generics) ) ;
842
842
then {
843
- let lint = if item. vis. node == hir :: VisibilityKind :: Public {
843
+ let lint = if item. vis. node. is_pub ( ) {
844
844
WRONG_PUB_SELF_CONVENTION
845
845
} else {
846
846
WRONG_SELF_CONVENTION
@@ -2030,6 +2030,7 @@ enum SelfKind {
2030
2030
impl SelfKind {
2031
2031
fn matches (
2032
2032
self ,
2033
+ cx : & LateContext ,
2033
2034
ty : & hir:: Ty ,
2034
2035
arg : & hir:: Arg ,
2035
2036
self_ty : & hir:: Ty ,
@@ -2047,7 +2048,7 @@ impl SelfKind {
2047
2048
// `Self`, `&mut Self`,
2048
2049
// and `Box<Self>`, including the equivalent types with `Foo`.
2049
2050
2050
- let is_actually_self = |ty| is_self_ty ( ty) || ty == self_ty;
2051
+ let is_actually_self = |ty| is_self_ty ( ty) || SpanlessEq :: new ( cx ) . eq_ty ( ty , self_ty) ;
2051
2052
if is_self ( arg) {
2052
2053
match self {
2053
2054
SelfKind :: Value => is_actually_self ( ty) ,
@@ -2173,12 +2174,13 @@ enum OutType {
2173
2174
}
2174
2175
2175
2176
impl OutType {
2176
- fn matches ( self , ty : & hir:: FunctionRetTy ) -> bool {
2177
+ fn matches ( self , cx : & LateContext , ty : & hir:: FunctionRetTy ) -> bool {
2178
+ let is_unit = |ty : & hir:: Ty | SpanlessEq :: new ( cx) . eq_ty_kind ( & ty. node , & hir:: TyTup ( vec ! [ ] . into ( ) ) ) ;
2177
2179
match ( self , ty) {
2178
2180
( OutType :: Unit , & hir:: DefaultReturn ( _) ) => true ,
2179
- ( OutType :: Unit , & hir:: Return ( ref ty) ) if ty . node == hir :: TyTup ( vec ! [ ] . into ( ) ) => true ,
2181
+ ( OutType :: Unit , & hir:: Return ( ref ty) ) if is_unit ( ty ) => true ,
2180
2182
( OutType :: Bool , & hir:: Return ( ref ty) ) if is_bool ( ty) => true ,
2181
- ( OutType :: Any , & hir:: Return ( ref ty) ) if ty . node != hir :: TyTup ( vec ! [ ] . into ( ) ) => true ,
2183
+ ( OutType :: Any , & hir:: Return ( ref ty) ) if ! is_unit ( ty ) => true ,
2182
2184
( OutType :: Ref , & hir:: Return ( ref ty) ) => matches ! ( ty. node, hir:: TyRptr ( _, _) ) ,
2183
2185
_ => false ,
2184
2186
}
0 commit comments