1+ use hir:: FnSig ;
12use rustc_ast:: ast:: Attribute ;
23use rustc_errors:: Applicability ;
34use rustc_hir:: def_id:: DefIdSet ;
@@ -23,12 +24,12 @@ use super::{DOUBLE_MUST_USE, MUST_USE_CANDIDATE, MUST_USE_UNIT};
2324pub ( super ) fn check_item < ' tcx > ( cx : & LateContext < ' tcx > , item : & ' tcx hir:: Item < ' _ > ) {
2425 let attrs = cx. tcx . hir ( ) . attrs ( item. hir_id ( ) ) ;
2526 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 {
2728
2829 let is_public = cx. effective_visibilities . is_exported ( item. owner_id . def_id ) ;
2930 let fn_header_span = item. span . with_hi ( sig. decl . output . span ( ) . hi ( ) ) ;
3031 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 ) ;
3233 } else if is_public && !is_proc_macro ( attrs) && !attrs. iter ( ) . any ( |a| a. has_name ( sym:: no_mangle) ) {
3334 check_must_use_candidate (
3435 cx,
@@ -44,13 +45,13 @@ pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>
4445}
4546
4647pub ( 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 {
4849 let is_public = cx. effective_visibilities . is_exported ( item. owner_id . def_id ) ;
4950 let fn_header_span = item. span . with_hi ( sig. decl . output . span ( ) . hi ( ) ) ;
5051 let attrs = cx. tcx . hir ( ) . attrs ( item. hir_id ( ) ) ;
5152 let attr = cx. tcx . get_attr ( item. owner_id , sym:: must_use) ;
5253 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 ) ;
5455 } else if is_public && !is_proc_macro ( attrs) && trait_ref_of_method ( cx, item. owner_id . def_id ) . is_none ( ) {
5556 check_must_use_candidate (
5657 cx,
@@ -66,14 +67,14 @@ pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Imp
6667}
6768
6869pub ( 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 {
7071 let is_public = cx. effective_visibilities . is_exported ( item. owner_id . def_id ) ;
7172 let fn_header_span = item. span . with_hi ( sig. decl . output . span ( ) . hi ( ) ) ;
7273
7374 let attrs = cx. tcx . hir ( ) . attrs ( item. hir_id ( ) ) ;
7475 let attr = cx. tcx . get_attr ( item. owner_id , sym:: must_use) ;
7576 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 ) ;
7778 } else if let hir:: TraitFn :: Provided ( eid) = * eid {
7879 let body = cx. tcx . hir ( ) . body ( eid) ;
7980 if attr. is_none ( ) && is_public && !is_proc_macro ( attrs) {
@@ -98,6 +99,7 @@ fn check_needless_must_use(
9899 item_span : Span ,
99100 fn_header_span : Span ,
100101 attr : & Attribute ,
102+ sig : & FnSig < ' _ >
101103) {
102104 if in_external_macro ( cx. sess ( ) , item_span) {
103105 return ;
@@ -112,7 +114,7 @@ fn check_needless_must_use(
112114 diag. span_suggestion ( attr. span , "remove the attribute" , "" , Applicability :: MachineApplicable ) ;
113115 } ,
114116 ) ;
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 ( ) {
116118 span_lint_and_help (
117119 cx,
118120 DOUBLE_MUST_USE ,
0 commit comments