1
- use rustc:: hir:: * ;
1
+ use rustc:: hir;
2
2
use rustc:: lint:: * ;
3
3
use rustc:: middle:: const_val:: ConstVal ;
4
4
use rustc:: middle:: const_qualif:: ConstQualif ;
@@ -335,13 +335,13 @@ impl LintPass for MethodsPass {
335
335
}
336
336
337
337
impl LateLintPass for MethodsPass {
338
- fn check_expr ( & mut self , cx : & LateContext , expr : & Expr ) {
338
+ fn check_expr ( & mut self , cx : & LateContext , expr : & hir :: Expr ) {
339
339
if in_macro ( cx, expr. span ) {
340
340
return ;
341
341
}
342
342
343
343
match expr. node {
344
- ExprMethodCall ( name, _, ref args) => {
344
+ hir :: ExprMethodCall ( name, _, ref args) => {
345
345
// Chain calls
346
346
if let Some ( arglists) = method_chain_args ( expr, & [ "unwrap" ] ) {
347
347
lint_unwrap ( cx, expr, arglists[ 0 ] ) ;
@@ -384,90 +384,92 @@ impl LateLintPass for MethodsPass {
384
384
_ => ( ) ,
385
385
}
386
386
}
387
- ExprBinary ( op, ref lhs, ref rhs) if op. node == BiEq || op. node == BiNe => {
388
- if !lint_chars_next ( cx, expr, lhs, rhs, op. node == BiEq ) {
389
- lint_chars_next ( cx, expr, rhs, lhs, op. node == BiEq ) ;
387
+ hir :: ExprBinary ( op, ref lhs, ref rhs) if op. node == hir :: BiEq || op. node == hir :: BiNe => {
388
+ if !lint_chars_next ( cx, expr, lhs, rhs, op. node == hir :: BiEq ) {
389
+ lint_chars_next ( cx, expr, rhs, lhs, op. node == hir :: BiEq ) ;
390
390
}
391
391
}
392
392
_ => ( ) ,
393
393
}
394
394
}
395
395
396
- fn check_item ( & mut self , cx : & LateContext , item : & Item ) {
396
+ fn check_item ( & mut self , cx : & LateContext , item : & hir :: Item ) {
397
397
if in_external_macro ( cx, item. span ) {
398
398
return ;
399
399
}
400
400
401
- if let ItemImpl ( _, _, _, None , _, ref items) = item. node {
401
+ if let hir :: ItemImpl ( _, _, _, None , _, ref items) = item. node {
402
402
for implitem in items {
403
403
let name = implitem. name ;
404
- if let ImplItemKind :: Method ( ref sig, _) = implitem. node {
404
+ if_let_chain ! { [
405
+ let hir:: ImplItemKind :: Method ( ref sig, _) = implitem. node,
406
+ let Some ( explicit_self) = sig. decl. inputs. get( 0 ) . and_then( hir:: Arg :: to_self) ,
407
+ ] , {
405
408
// check missing trait implementations
406
409
for & ( method_name, n_args, self_kind, out_type, trait_name) in & TRAIT_METHODS {
407
- if_let_chain ! {
408
- [
409
- name. as_str( ) == method_name,
410
- sig. decl. inputs. len( ) == n_args,
411
- out_type. matches( & sig. decl. output) ,
412
- self_kind. matches( & sig. explicit_self. node, false )
413
- ] , {
414
- span_lint( cx, SHOULD_IMPLEMENT_TRAIT , implitem. span, & format!(
415
- "defining a method called `{}` on this type; consider implementing \
416
- the `{}` trait or choosing a less ambiguous name", name, trait_name) ) ;
417
- }
410
+ if name. as_str( ) == method_name &&
411
+ sig. decl. inputs. len( ) == n_args &&
412
+ out_type. matches( & sig. decl. output) &&
413
+ self_kind. matches( & explicit_self, false ) {
414
+ span_lint( cx, SHOULD_IMPLEMENT_TRAIT , implitem. span, & format!(
415
+ "defining a method called `{}` on this type; consider implementing \
416
+ the `{}` trait or choosing a less ambiguous name", name, trait_name) ) ;
418
417
}
419
418
}
420
419
421
420
// check conventions w.r.t. conversion method names and predicates
422
421
let ty = cx. tcx. lookup_item_type( cx. tcx. map. local_def_id( item. id) ) . ty;
423
422
let is_copy = is_copy( cx, ty, item) ;
424
423
for & ( ref conv, self_kinds) in & CONVENTIONS {
425
- if conv. check ( & name. as_str ( ) ) &&
426
- !self_kinds. iter ( ) . any ( |k| k. matches ( & sig. explicit_self . node , is_copy) ) {
427
- let lint = if item. vis == Visibility :: Public {
424
+ if_let_chain! { [
425
+ conv. check( & name. as_str( ) ) ,
426
+ let Some ( explicit_self) = sig. decl. inputs. get( 0 ) . and_then( hir:: Arg :: to_self) ,
427
+ !self_kinds. iter( ) . any( |k| k. matches( & explicit_self, is_copy) ) ,
428
+ ] , {
429
+ let lint = if item. vis == hir:: Visibility :: Public {
428
430
WRONG_PUB_SELF_CONVENTION
429
431
} else {
430
432
WRONG_SELF_CONVENTION
431
433
} ;
432
434
span_lint( cx,
433
435
lint,
434
- sig . explicit_self . span ,
436
+ explicit_self. span,
435
437
& format!( "methods called `{}` usually take {}; consider choosing a less \
436
438
ambiguous name",
437
439
conv,
438
440
& self_kinds. iter( )
439
441
. map( |k| k. description( ) )
440
442
. collect:: <Vec <_>>( )
441
443
. join( " or " ) ) ) ;
442
- }
444
+ } }
443
445
}
444
446
445
447
let ret_ty = return_ty( cx, implitem. id) ;
446
448
if & name. as_str( ) == & "new" &&
447
449
!ret_ty. map_or( false , |ret_ty| ret_ty. walk( ) . any( |t| same_tys( cx, t, ty, implitem. id) ) ) {
448
450
span_lint( cx,
449
451
NEW_RET_NO_SELF ,
450
- sig . explicit_self . span ,
452
+ explicit_self. span,
451
453
"methods called `new` usually return `Self`" ) ;
452
454
}
453
455
}
454
- }
456
+ } }
455
457
}
456
458
}
457
459
}
458
460
459
461
/// Checks for the `OR_FUN_CALL` lint.
460
- fn lint_or_fun_call ( cx : & LateContext , expr : & Expr , name : & str , args : & [ P < Expr > ] ) {
462
+ fn lint_or_fun_call ( cx : & LateContext , expr : & hir :: Expr , name : & str , args : & [ P < hir :: Expr > ] ) {
461
463
/// Check for `unwrap_or(T::new())` or `unwrap_or(T::default())`.
462
- fn check_unwrap_or_default ( cx : & LateContext , name : & str , fun : & Expr , self_expr : & Expr , arg : & Expr ,
464
+ fn check_unwrap_or_default ( cx : & LateContext , name : & str , fun : & hir :: Expr , self_expr : & hir :: Expr , arg : & hir :: Expr ,
463
465
or_has_args : bool , span : Span )
464
466
-> bool {
465
467
if or_has_args {
466
468
return false ;
467
469
}
468
470
469
471
if name == "unwrap_or" {
470
- if let ExprPath ( _, ref path) = fun. node {
472
+ if let hir :: ExprPath ( _, ref path) = fun. node {
471
473
let path: & str = & path. segments
472
474
. last ( )
473
475
. expect ( "A path must have at least one segment" )
@@ -501,7 +503,7 @@ fn lint_or_fun_call(cx: &LateContext, expr: &Expr, name: &str, args: &[P<Expr>])
501
503
}
502
504
503
505
/// Check for `*or(foo())`.
504
- fn check_general_case ( cx : & LateContext , name : & str , fun : & Expr , self_expr : & Expr , arg : & Expr , or_has_args : bool ,
506
+ fn check_general_case ( cx : & LateContext , name : & str , fun : & hir :: Expr , self_expr : & hir :: Expr , arg : & hir :: Expr , or_has_args : bool ,
505
507
span : Span ) {
506
508
// don't lint for constant values
507
509
// FIXME: can we `expect` here instead of match?
@@ -545,7 +547,7 @@ fn lint_or_fun_call(cx: &LateContext, expr: &Expr, name: &str, args: &[P<Expr>])
545
547
}
546
548
547
549
if args. len ( ) == 2 {
548
- if let ExprCall ( ref fun, ref or_args) = args[ 1 ] . node {
550
+ if let hir :: ExprCall ( ref fun, ref or_args) = args[ 1 ] . node {
549
551
let or_has_args = !or_args. is_empty ( ) ;
550
552
if !check_unwrap_or_default ( cx, name, fun, & args[ 0 ] , & args[ 1 ] , or_has_args, expr. span ) {
551
553
check_general_case ( cx, name, fun, & args[ 0 ] , & args[ 1 ] , or_has_args, expr. span ) ;
@@ -555,7 +557,7 @@ fn lint_or_fun_call(cx: &LateContext, expr: &Expr, name: &str, args: &[P<Expr>])
555
557
}
556
558
557
559
/// Checks for the `CLONE_ON_COPY` lint.
558
- fn lint_clone_on_copy ( cx : & LateContext , expr : & Expr ) {
560
+ fn lint_clone_on_copy ( cx : & LateContext , expr : & hir :: Expr ) {
559
561
let ty = cx. tcx . expr_ty ( expr) ;
560
562
let parent = cx. tcx . map . get_parent ( expr. id ) ;
561
563
let parameter_environment = ty:: ParameterEnvironment :: for_item ( cx. tcx , parent) ;
@@ -566,7 +568,7 @@ fn lint_clone_on_copy(cx: &LateContext, expr: &Expr) {
566
568
}
567
569
568
570
/// Checks for the `CLONE_DOUBLE_REF` lint.
569
- fn lint_clone_double_ref ( cx : & LateContext , expr : & Expr , arg : & Expr , ty : ty:: Ty ) {
571
+ fn lint_clone_double_ref ( cx : & LateContext , expr : & hir :: Expr , arg : & hir :: Expr , ty : ty:: Ty ) {
570
572
if let ty:: TyRef ( _, ty:: TypeAndMut { ty : ref inner, .. } ) = ty. sty {
571
573
if let ty:: TyRef ( ..) = inner. sty {
572
574
let mut db = span_lint ( cx,
@@ -582,7 +584,7 @@ fn lint_clone_double_ref(cx: &LateContext, expr: &Expr, arg: &Expr, ty: ty::Ty)
582
584
}
583
585
}
584
586
585
- fn lint_extend ( cx : & LateContext , expr : & Expr , args : & MethodArgs ) {
587
+ fn lint_extend ( cx : & LateContext , expr : & hir :: Expr , args : & MethodArgs ) {
586
588
let ( obj_ty, _) = walk_ptrs_ty_depth ( cx. tcx . expr_ty ( & args[ 0 ] ) ) ;
587
589
if !match_type ( cx, obj_ty, & paths:: VEC ) {
588
590
return ;
@@ -599,11 +601,11 @@ fn lint_extend(cx: &LateContext, expr: &Expr, args: &MethodArgs) {
599
601
}
600
602
}
601
603
602
- fn lint_cstring_as_ptr ( cx : & LateContext , expr : & Expr , new : & Expr , unwrap : & Expr ) {
604
+ fn lint_cstring_as_ptr ( cx : & LateContext , expr : & hir :: Expr , new : & hir :: Expr , unwrap : & hir :: Expr ) {
603
605
if_let_chain ! { [
604
- let ExprCall ( ref fun, ref args) = new. node,
606
+ let hir :: ExprCall ( ref fun, ref args) = new. node,
605
607
args. len( ) == 1 ,
606
- let ExprPath ( None , ref path) = fun. node,
608
+ let hir :: ExprPath ( None , ref path) = fun. node,
607
609
match_path( path, & paths:: CSTRING_NEW ) ,
608
610
] , {
609
611
span_lint_and_then( cx, TEMPORARY_CSTRING_AS_PTR , expr. span,
@@ -615,7 +617,7 @@ fn lint_cstring_as_ptr(cx: &LateContext, expr: &Expr, new: &Expr, unwrap: &Expr)
615
617
} }
616
618
}
617
619
618
- fn derefs_to_slice ( cx : & LateContext , expr : & Expr , ty : & ty:: Ty ) -> Option < ( Span , & ' static str ) > {
620
+ fn derefs_to_slice ( cx : & LateContext , expr : & hir :: Expr , ty : & ty:: Ty ) -> Option < ( Span , & ' static str ) > {
619
621
fn may_slice ( cx : & LateContext , ty : & ty:: Ty ) -> bool {
620
622
match ty. sty {
621
623
ty:: TySlice ( _) => true ,
@@ -626,7 +628,7 @@ fn derefs_to_slice(cx: &LateContext, expr: &Expr, ty: &ty::Ty) -> Option<(Span,
626
628
_ => false ,
627
629
}
628
630
}
629
- if let ExprMethodCall ( name, _, ref args) = expr. node {
631
+ if let hir :: ExprMethodCall ( name, _, ref args) = expr. node {
630
632
if & name. node . as_str ( ) == & "iter" && may_slice ( cx, & cx. tcx . expr_ty ( & args[ 0 ] ) ) {
631
633
Some ( ( args[ 0 ] . span , "&" ) )
632
634
} else {
@@ -651,7 +653,7 @@ fn derefs_to_slice(cx: &LateContext, expr: &Expr, ty: &ty::Ty) -> Option<(Span,
651
653
#[ allow( ptr_arg) ]
652
654
// Type of MethodArgs is potentially a Vec
653
655
/// lint use of `unwrap()` for `Option`s and `Result`s
654
- fn lint_unwrap ( cx : & LateContext , expr : & Expr , unwrap_args : & MethodArgs ) {
656
+ fn lint_unwrap ( cx : & LateContext , expr : & hir :: Expr , unwrap_args : & MethodArgs ) {
655
657
let ( obj_ty, _) = walk_ptrs_ty_depth ( cx. tcx . expr_ty ( & unwrap_args[ 0 ] ) ) ;
656
658
657
659
let mess = if match_type ( cx, obj_ty, & paths:: OPTION ) {
@@ -677,7 +679,7 @@ fn lint_unwrap(cx: &LateContext, expr: &Expr, unwrap_args: &MethodArgs) {
677
679
#[ allow( ptr_arg) ]
678
680
// Type of MethodArgs is potentially a Vec
679
681
/// lint use of `ok().expect()` for `Result`s
680
- fn lint_ok_expect ( cx : & LateContext , expr : & Expr , ok_args : & MethodArgs ) {
682
+ fn lint_ok_expect ( cx : & LateContext , expr : & hir :: Expr , ok_args : & MethodArgs ) {
681
683
// lint if the caller of `ok()` is a `Result`
682
684
if match_type ( cx, cx. tcx . expr_ty ( & ok_args[ 0 ] ) , & paths:: RESULT ) {
683
685
let result_type = cx. tcx . expr_ty ( & ok_args[ 0 ] ) ;
@@ -695,7 +697,7 @@ fn lint_ok_expect(cx: &LateContext, expr: &Expr, ok_args: &MethodArgs) {
695
697
#[ allow( ptr_arg) ]
696
698
// Type of MethodArgs is potentially a Vec
697
699
/// lint use of `map().unwrap_or()` for `Option`s
698
- fn lint_map_unwrap_or ( cx : & LateContext , expr : & Expr , map_args : & MethodArgs , unwrap_args : & MethodArgs ) {
700
+ fn lint_map_unwrap_or ( cx : & LateContext , expr : & hir :: Expr , map_args : & MethodArgs , unwrap_args : & MethodArgs ) {
699
701
// lint if the caller of `map()` is an `Option`
700
702
if match_type ( cx, cx. tcx . expr_ty ( & map_args[ 0 ] ) , & paths:: OPTION ) {
701
703
// lint message
@@ -726,7 +728,7 @@ fn lint_map_unwrap_or(cx: &LateContext, expr: &Expr, map_args: &MethodArgs, unwr
726
728
#[ allow( ptr_arg) ]
727
729
// Type of MethodArgs is potentially a Vec
728
730
/// lint use of `map().unwrap_or_else()` for `Option`s
729
- fn lint_map_unwrap_or_else ( cx : & LateContext , expr : & Expr , map_args : & MethodArgs , unwrap_args : & MethodArgs ) {
731
+ fn lint_map_unwrap_or_else ( cx : & LateContext , expr : & hir :: Expr , map_args : & MethodArgs , unwrap_args : & MethodArgs ) {
730
732
// lint if the caller of `map()` is an `Option`
731
733
if match_type ( cx, cx. tcx . expr_ty ( & map_args[ 0 ] ) , & paths:: OPTION ) {
732
734
// lint message
@@ -757,7 +759,7 @@ fn lint_map_unwrap_or_else(cx: &LateContext, expr: &Expr, map_args: &MethodArgs,
757
759
#[ allow( ptr_arg) ]
758
760
// Type of MethodArgs is potentially a Vec
759
761
/// lint use of `filter().next() for Iterators`
760
- fn lint_filter_next ( cx : & LateContext , expr : & Expr , filter_args : & MethodArgs ) {
762
+ fn lint_filter_next ( cx : & LateContext , expr : & hir :: Expr , filter_args : & MethodArgs ) {
761
763
// lint if caller of `.filter().next()` is an Iterator
762
764
if match_trait_method ( cx, expr, & paths:: ITERATOR ) {
763
765
let msg = "called `filter(p).next()` on an Iterator. This is more succinctly expressed by calling `.find(p)` \
@@ -780,7 +782,7 @@ fn lint_filter_next(cx: &LateContext, expr: &Expr, filter_args: &MethodArgs) {
780
782
#[ allow( ptr_arg) ]
781
783
// Type of MethodArgs is potentially a Vec
782
784
/// lint searching an Iterator followed by `is_some()`
783
- fn lint_search_is_some ( cx : & LateContext , expr : & Expr , search_method : & str , search_args : & MethodArgs ,
785
+ fn lint_search_is_some ( cx : & LateContext , expr : & hir :: Expr , search_method : & str , search_args : & MethodArgs ,
784
786
is_some_args : & MethodArgs ) {
785
787
// lint if caller of search is an Iterator
786
788
if match_trait_method ( cx, & * is_some_args[ 0 ] , & paths:: ITERATOR ) {
@@ -803,12 +805,12 @@ fn lint_search_is_some(cx: &LateContext, expr: &Expr, search_method: &str, searc
803
805
}
804
806
805
807
/// Checks for the `CHARS_NEXT_CMP` lint.
806
- fn lint_chars_next ( cx : & LateContext , expr : & Expr , chain : & Expr , other : & Expr , eq : bool ) -> bool {
808
+ fn lint_chars_next ( cx : & LateContext , expr : & hir :: Expr , chain : & hir :: Expr , other : & hir :: Expr , eq : bool ) -> bool {
807
809
if_let_chain ! { [
808
810
let Some ( args) = method_chain_args( chain, & [ "chars" , "next" ] ) ,
809
- let ExprCall ( ref fun, ref arg_char) = other. node,
811
+ let hir :: ExprCall ( ref fun, ref arg_char) = other. node,
810
812
arg_char. len( ) == 1 ,
811
- let ExprPath ( None , ref path) = fun. node,
813
+ let hir :: ExprPath ( None , ref path) = fun. node,
812
814
path. segments. len( ) == 1 && path. segments[ 0 ] . identifier. name. as_str( ) == "Some"
813
815
] , {
814
816
let self_ty = walk_ptrs_ty( cx. tcx. expr_ty_adjusted( & args[ 0 ] [ 0 ] ) ) ;
@@ -838,7 +840,7 @@ fn lint_chars_next(cx: &LateContext, expr: &Expr, chain: &Expr, other: &Expr, eq
838
840
}
839
841
840
842
/// lint for length-1 `str`s for methods in `PATTERN_METHODS`
841
- fn lint_single_char_pattern ( cx : & LateContext , expr : & Expr , arg : & Expr ) {
843
+ fn lint_single_char_pattern ( cx : & LateContext , expr : & hir :: Expr , arg : & hir :: Expr ) {
842
844
if let Ok ( ConstVal :: Str ( r) ) = eval_const_expr_partial ( cx. tcx , arg, ExprTypeChecked , None ) {
843
845
if r. len ( ) == 1 {
844
846
let hint = snippet ( cx, expr. span , ".." ) . replace ( & format ! ( "\" {}\" " , r) , & format ! ( "'{}'" , r) ) ;
@@ -954,26 +956,26 @@ enum SelfKind {
954
956
}
955
957
956
958
impl SelfKind {
957
- fn matches ( & self , slf : & ExplicitSelf_ , allow_value_for_ref : bool ) -> bool {
958
- match ( self , slf) {
959
- ( & SelfKind :: Value , & SelfValue ( _) ) |
960
- ( & SelfKind :: Ref , & SelfRegion ( _, Mutability :: MutImmutable , _ ) ) |
961
- ( & SelfKind :: RefMut , & SelfRegion ( _, Mutability :: MutMutable , _ ) ) |
962
- ( & SelfKind :: No , & SelfStatic ) => true ,
963
- ( & SelfKind :: Ref , & SelfValue ( _) ) |
964
- ( & SelfKind :: RefMut , & SelfValue ( _) ) => allow_value_for_ref,
965
- ( _ , & SelfExplicit ( ref ty , _ ) ) => self . matches_explicit_type ( ty , allow_value_for_ref ) ,
959
+ fn matches ( self , slf : & hir :: ExplicitSelf , allow_value_for_ref : bool ) -> bool {
960
+ match ( self , & slf. node ) {
961
+ ( SelfKind :: Value , & hir :: SelfKind :: Value ( _) ) |
962
+ ( SelfKind :: Ref , & hir :: SelfKind :: Region ( _, hir :: Mutability :: MutImmutable ) ) |
963
+ ( SelfKind :: RefMut , & hir :: SelfKind :: Region ( _, hir :: Mutability :: MutMutable ) ) => true ,
964
+ ( SelfKind :: Ref , & hir :: SelfKind :: Value ( _ ) ) |
965
+ ( SelfKind :: RefMut , & hir :: SelfKind :: Value ( _) ) => allow_value_for_ref ,
966
+ ( _ , & hir :: SelfKind :: Explicit ( ref ty , _) ) => self . matches_explicit_type ( ty , allow_value_for_ref) ,
967
+
966
968
_ => false ,
967
969
}
968
970
}
969
971
970
- fn matches_explicit_type ( & self , ty : & Ty , allow_value_for_ref : bool ) -> bool {
972
+ fn matches_explicit_type ( self , ty : & hir :: Ty , allow_value_for_ref : bool ) -> bool {
971
973
match ( self , & ty. node ) {
972
- ( & SelfKind :: Value , & TyPath ( ..) ) |
973
- ( & SelfKind :: Ref , & TyRptr ( _, MutTy { mutbl : Mutability :: MutImmutable , .. } ) ) |
974
- ( & SelfKind :: RefMut , & TyRptr ( _, MutTy { mutbl : Mutability :: MutMutable , .. } ) ) => true ,
975
- ( & SelfKind :: Ref , & TyPath ( ..) ) |
976
- ( & SelfKind :: RefMut , & TyPath ( ..) ) => allow_value_for_ref,
974
+ ( SelfKind :: Value , & hir :: TyPath ( ..) ) |
975
+ ( SelfKind :: Ref , & hir :: TyRptr ( _, hir :: MutTy { mutbl : hir :: Mutability :: MutImmutable , .. } ) ) |
976
+ ( SelfKind :: RefMut , & hir :: TyRptr ( _, hir :: MutTy { mutbl : hir :: Mutability :: MutMutable , .. } ) ) => true ,
977
+ ( SelfKind :: Ref , & hir :: TyPath ( ..) ) |
978
+ ( SelfKind :: RefMut , & hir :: TyPath ( ..) ) => allow_value_for_ref,
977
979
_ => false ,
978
980
}
979
981
}
@@ -1015,14 +1017,14 @@ enum OutType {
1015
1017
}
1016
1018
1017
1019
impl OutType {
1018
- fn matches ( & self , ty : & FunctionRetTy ) -> bool {
1020
+ fn matches ( & self , ty : & hir :: FunctionRetTy ) -> bool {
1019
1021
match ( self , ty) {
1020
- ( & OutType :: Unit , & DefaultReturn ( _) ) => true ,
1021
- ( & OutType :: Unit , & Return ( ref ty) ) if ty. node == TyTup ( vec ! [ ] . into ( ) ) => true ,
1022
- ( & OutType :: Bool , & Return ( ref ty) ) if is_bool ( ty) => true ,
1023
- ( & OutType :: Any , & Return ( ref ty) ) if ty. node != TyTup ( vec ! [ ] . into ( ) ) => true ,
1024
- ( & OutType :: Ref , & Return ( ref ty) ) => {
1025
- if let TyRptr ( _, _) = ty. node {
1022
+ ( & OutType :: Unit , & hir :: DefaultReturn ( _) ) => true ,
1023
+ ( & OutType :: Unit , & hir :: Return ( ref ty) ) if ty. node == hir :: TyTup ( vec ! [ ] . into ( ) ) => true ,
1024
+ ( & OutType :: Bool , & hir :: Return ( ref ty) ) if is_bool ( ty) => true ,
1025
+ ( & OutType :: Any , & hir :: Return ( ref ty) ) if ty. node != hir :: TyTup ( vec ! [ ] . into ( ) ) => true ,
1026
+ ( & OutType :: Ref , & hir :: Return ( ref ty) ) => {
1027
+ if let hir :: TyRptr ( _, _) = ty. node {
1026
1028
true
1027
1029
} else {
1028
1030
false
@@ -1033,16 +1035,16 @@ impl OutType {
1033
1035
}
1034
1036
}
1035
1037
1036
- fn is_bool ( ty : & Ty ) -> bool {
1037
- if let TyPath ( None , ref p) = ty. node {
1038
+ fn is_bool ( ty : & hir :: Ty ) -> bool {
1039
+ if let hir :: TyPath ( None , ref p) = ty. node {
1038
1040
if match_path ( p, & [ "bool" ] ) {
1039
1041
return true ;
1040
1042
}
1041
1043
}
1042
1044
false
1043
1045
}
1044
1046
1045
- fn is_copy < ' a , ' ctx > ( cx : & LateContext < ' a , ' ctx > , ty : ty:: Ty < ' ctx > , item : & Item ) -> bool {
1047
+ fn is_copy < ' a , ' ctx > ( cx : & LateContext < ' a , ' ctx > , ty : ty:: Ty < ' ctx > , item : & hir :: Item ) -> bool {
1046
1048
let env = ty:: ParameterEnvironment :: for_item ( cx. tcx , item. id ) ;
1047
1049
!ty. subst ( cx. tcx , env. free_substs ) . moves_by_default ( cx. tcx . global_tcx ( ) , & env, item. span )
1048
1050
}
0 commit comments