1
+ use hir:: FnSig ;
1
2
use rustc_ast:: ast:: Attribute ;
2
3
use rustc_errors:: Applicability ;
3
4
use rustc_hir:: def_id:: DefIdSet ;
@@ -23,12 +24,12 @@ use super::{DOUBLE_MUST_USE, MUST_USE_CANDIDATE, MUST_USE_UNIT};
23
24
pub ( super ) fn check_item < ' tcx > ( cx : & LateContext < ' tcx > , item : & ' tcx hir:: Item < ' _ > ) {
24
25
let attrs = cx. tcx . hir ( ) . attrs ( item. hir_id ( ) ) ;
25
26
let attr = cx. tcx . get_attr ( item. owner_id , sym:: must_use) ;
26
- if let hir:: ItemKind :: Fn ( ref sig, _generics, ref body_id) = item. kind && !sig . header . is_async ( ) /* (#10486) */ {
27
+ if let hir:: ItemKind :: Fn ( ref sig, _generics, ref body_id) = item. kind {
27
28
28
29
let is_public = cx. effective_visibilities . is_exported ( item. owner_id . def_id ) ;
29
30
let fn_header_span = item. span . with_hi ( sig. decl . output . span ( ) . hi ( ) ) ;
30
31
if let Some ( attr) = attr {
31
- check_needless_must_use ( cx, sig. decl , item. owner_id , item. span , fn_header_span, attr) ;
32
+ check_needless_must_use ( cx, sig. decl , item. owner_id , item. span , fn_header_span, attr, sig ) ;
32
33
} else if is_public && !is_proc_macro ( attrs) && !attrs. iter ( ) . any ( |a| a. has_name ( sym:: no_mangle) ) {
33
34
check_must_use_candidate (
34
35
cx,
@@ -44,13 +45,13 @@ pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>
44
45
}
45
46
46
47
pub ( super ) fn check_impl_item < ' tcx > ( cx : & LateContext < ' tcx > , item : & ' tcx hir:: ImplItem < ' _ > ) {
47
- if let hir:: ImplItemKind :: Fn ( ref sig, ref body_id) = item. kind && !sig . header . is_async ( ) /* (#10486) */ {
48
+ if let hir:: ImplItemKind :: Fn ( ref sig, ref body_id) = item. kind {
48
49
let is_public = cx. effective_visibilities . is_exported ( item. owner_id . def_id ) ;
49
50
let fn_header_span = item. span . with_hi ( sig. decl . output . span ( ) . hi ( ) ) ;
50
51
let attrs = cx. tcx . hir ( ) . attrs ( item. hir_id ( ) ) ;
51
52
let attr = cx. tcx . get_attr ( item. owner_id , sym:: must_use) ;
52
53
if let Some ( attr) = attr {
53
- check_needless_must_use ( cx, sig. decl , item. owner_id , item. span , fn_header_span, attr) ;
54
+ check_needless_must_use ( cx, sig. decl , item. owner_id , item. span , fn_header_span, attr, sig ) ;
54
55
} else if is_public && !is_proc_macro ( attrs) && trait_ref_of_method ( cx, item. owner_id . def_id ) . is_none ( ) {
55
56
check_must_use_candidate (
56
57
cx,
@@ -66,14 +67,14 @@ pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Imp
66
67
}
67
68
68
69
pub ( super ) fn check_trait_item < ' tcx > ( cx : & LateContext < ' tcx > , item : & ' tcx hir:: TraitItem < ' _ > ) {
69
- if let hir:: TraitItemKind :: Fn ( ref sig, ref eid) = item. kind && !sig . header . is_async ( ) /* (#10486) */ {
70
+ if let hir:: TraitItemKind :: Fn ( ref sig, ref eid) = item. kind {
70
71
let is_public = cx. effective_visibilities . is_exported ( item. owner_id . def_id ) ;
71
72
let fn_header_span = item. span . with_hi ( sig. decl . output . span ( ) . hi ( ) ) ;
72
73
73
74
let attrs = cx. tcx . hir ( ) . attrs ( item. hir_id ( ) ) ;
74
75
let attr = cx. tcx . get_attr ( item. owner_id , sym:: must_use) ;
75
76
if let Some ( attr) = attr {
76
- check_needless_must_use ( cx, sig. decl , item. owner_id , item. span , fn_header_span, attr) ;
77
+ check_needless_must_use ( cx, sig. decl , item. owner_id , item. span , fn_header_span, attr, sig ) ;
77
78
} else if let hir:: TraitFn :: Provided ( eid) = * eid {
78
79
let body = cx. tcx . hir ( ) . body ( eid) ;
79
80
if attr. is_none ( ) && is_public && !is_proc_macro ( attrs) {
@@ -98,6 +99,7 @@ fn check_needless_must_use(
98
99
item_span : Span ,
99
100
fn_header_span : Span ,
100
101
attr : & Attribute ,
102
+ sig : & FnSig < ' _ >
101
103
) {
102
104
if in_external_macro ( cx. sess ( ) , item_span) {
103
105
return ;
@@ -112,7 +114,7 @@ fn check_needless_must_use(
112
114
diag. span_suggestion ( attr. span , "remove the attribute" , "" , Applicability :: MachineApplicable ) ;
113
115
} ,
114
116
) ;
115
- } else if attr. value_str ( ) . is_none ( ) && is_must_use_ty ( cx, return_ty ( cx, item_id) ) {
117
+ } else if attr. value_str ( ) . is_none ( ) && is_must_use_ty ( cx, return_ty ( cx, item_id) ) && !sig . header . is_async ( ) {
116
118
span_lint_and_help (
117
119
cx,
118
120
DOUBLE_MUST_USE ,
0 commit comments