1
1
use crate :: utils:: {
2
- attrs:: is_proc_macro, iter_input_pats, match_def_path, qpath_res, return_ty, snippet, snippet_opt,
3
- span_help_and_lint, span_lint, span_lint_and_then, trait_ref_of_method, type_is_unsafe_function,
2
+ attrs:: is_proc_macro, is_must_use_ty, iter_input_pats, match_def_path, must_use_attr, qpath_res, return_ty,
3
+ snippet, snippet_opt, span_help_and_lint, span_lint, span_lint_and_then, trait_ref_of_method,
4
+ type_is_unsafe_function,
4
5
} ;
5
6
use matches:: matches;
6
7
use rustc:: hir:: { self , def:: Res , def_id:: DefId , intravisit} ;
@@ -466,15 +467,6 @@ fn check_must_use_candidate<'a, 'tcx>(
466
467
} ) ;
467
468
}
468
469
469
- fn must_use_attr ( attrs : & [ Attribute ] ) -> Option < & Attribute > {
470
- attrs. iter ( ) . find ( |attr| {
471
- attr. ident ( ) . map_or ( false , |ident| {
472
- let ident: & str = & ident. as_str ( ) ;
473
- "must_use" == ident
474
- } )
475
- } )
476
- }
477
-
478
470
fn returns_unit ( decl : & hir:: FnDecl ) -> bool {
479
471
match decl. output {
480
472
hir:: FunctionRetTy :: DefaultReturn ( _) => true ,
@@ -486,41 +478,6 @@ fn returns_unit(decl: &hir::FnDecl) -> bool {
486
478
}
487
479
}
488
480
489
- fn is_must_use_ty < ' a , ' tcx > ( cx : & LateContext < ' a , ' tcx > , ty : Ty < ' tcx > ) -> bool {
490
- use ty:: TyKind :: * ;
491
- match ty. kind {
492
- Adt ( ref adt, _) => must_use_attr ( & cx. tcx . get_attrs ( adt. did ) ) . is_some ( ) ,
493
- Foreign ( ref did) => must_use_attr ( & cx. tcx . get_attrs ( * did) ) . is_some ( ) ,
494
- Slice ( ref ty) | Array ( ref ty, _) | RawPtr ( ty:: TypeAndMut { ref ty, .. } ) | Ref ( _, ref ty, _) => {
495
- // for the Array case we don't need to care for the len == 0 case
496
- // because we don't want to lint functions returning empty arrays
497
- is_must_use_ty ( cx, * ty)
498
- } ,
499
- Tuple ( ref substs) => substs. types ( ) . any ( |ty| is_must_use_ty ( cx, ty) ) ,
500
- Opaque ( ref def_id, _) => {
501
- for ( predicate, _) in cx. tcx . predicates_of ( * def_id) . predicates {
502
- if let ty:: Predicate :: Trait ( ref poly_trait_predicate) = predicate {
503
- if must_use_attr ( & cx. tcx . get_attrs ( poly_trait_predicate. skip_binder ( ) . trait_ref . def_id ) ) . is_some ( ) {
504
- return true ;
505
- }
506
- }
507
- }
508
- false
509
- } ,
510
- Dynamic ( binder, _) => {
511
- for predicate in binder. skip_binder ( ) . iter ( ) {
512
- if let ty:: ExistentialPredicate :: Trait ( ref trait_ref) = predicate {
513
- if must_use_attr ( & cx. tcx . get_attrs ( trait_ref. def_id ) ) . is_some ( ) {
514
- return true ;
515
- }
516
- }
517
- }
518
- false
519
- } ,
520
- _ => false ,
521
- }
522
- }
523
-
524
481
fn has_mutable_arg ( cx : & LateContext < ' _ , ' _ > , body : & hir:: Body < ' _ > ) -> bool {
525
482
let mut tys = FxHashSet :: default ( ) ;
526
483
body. params . iter ( ) . any ( |param| is_mutable_pat ( cx, & param. pat , & mut tys) )
0 commit comments