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