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