@@ -10,7 +10,7 @@ use syntax::codemap::{Span, BytePos};
1010use crate :: utils:: { get_arg_name, get_trait_def_id, implements_trait, in_external_macro, in_macro, is_copy, is_expn_of, is_self,
1111 is_self_ty, iter_input_pats, last_path_segment, match_def_path, match_path, match_qpath, match_trait_method,
1212 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 } ;
1414use crate :: utils:: paths;
1515use crate :: utils:: sugg;
1616use crate :: consts:: { constant, Constant } ;
@@ -820,8 +820,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
820820 for & ( method_name, n_args, self_kind, out_type, trait_name) in & TRAIT_METHODS {
821821 if name == method_name &&
822822 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) {
825825 span_lint( cx, SHOULD_IMPLEMENT_TRAIT , implitem. span, & format!(
826826 "defining a method called `{}` on this type; consider implementing \
827827 the `{}` trait or choosing a less ambiguous name", name, trait_name) ) ;
@@ -838,9 +838,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
838838 if conv. check( & name. as_str( ) ) ;
839839 if !self_kinds
840840 . 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) ) ;
842842 then {
843- let lint = if item. vis. node == hir :: VisibilityKind :: Public {
843+ let lint = if item. vis. node. is_pub ( ) {
844844 WRONG_PUB_SELF_CONVENTION
845845 } else {
846846 WRONG_SELF_CONVENTION
@@ -2030,6 +2030,7 @@ enum SelfKind {
20302030impl SelfKind {
20312031 fn matches (
20322032 self ,
2033+ cx : & LateContext ,
20332034 ty : & hir:: Ty ,
20342035 arg : & hir:: Arg ,
20352036 self_ty : & hir:: Ty ,
@@ -2047,7 +2048,7 @@ impl SelfKind {
20472048 // `Self`, `&mut Self`,
20482049 // and `Box<Self>`, including the equivalent types with `Foo`.
20492050
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) ;
20512052 if is_self ( arg) {
20522053 match self {
20532054 SelfKind :: Value => is_actually_self ( ty) ,
@@ -2173,12 +2174,13 @@ enum OutType {
21732174}
21742175
21752176impl 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 ( ) ) ) ;
21772179 match ( self , ty) {
21782180 ( 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 ,
21802182 ( 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 ,
21822184 ( OutType :: Ref , & hir:: Return ( ref ty) ) => matches ! ( ty. node, hir:: TyRptr ( _, _) ) ,
21832185 _ => false ,
21842186 }
0 commit comments