@@ -145,22 +145,38 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
145145 }
146146
147147 let t = cx. tables . expr_ty ( & expr) ;
148- let warned = match t. sty {
149- ty:: TyTuple ( ref tys, _) if tys. is_empty ( ) => return ,
150- ty:: TyNever => return ,
151- ty:: TyBool => return ,
152- ty:: TyAdt ( def, _) => check_must_use ( cx, def. did , s. span ) ,
148+ let ty_warned = match t. sty {
149+ ty:: TyAdt ( def, _) => check_must_use ( cx, def. did , s. span , "" ) ,
153150 _ => false ,
154151 } ;
155- if !warned {
152+
153+ let mut fn_warned = false ;
154+ let maybe_def = match expr. node {
155+ hir:: ExprCall ( ref callee, _) => {
156+ match callee. node {
157+ hir:: ExprPath ( ref qpath) => Some ( cx. tables . qpath_def ( qpath, callee. id ) ) ,
158+ _ => None
159+ }
160+ } ,
161+ hir:: ExprMethodCall ( ..) => {
162+ cx. tables . type_dependent_defs . get ( & expr. id ) . cloned ( )
163+ } ,
164+ _ => { None }
165+ } ;
166+ if let Some ( def) = maybe_def {
167+ let def_id = def. def_id ( ) ;
168+ fn_warned = check_must_use ( cx, def_id, s. span , "return value of " ) ;
169+ }
170+
171+ if !( ty_warned || fn_warned) {
156172 cx. span_lint ( UNUSED_RESULTS , s. span , "unused result" ) ;
157173 }
158174
159- fn check_must_use ( cx : & LateContext , def_id : DefId , sp : Span ) -> bool {
175+ fn check_must_use ( cx : & LateContext , def_id : DefId , sp : Span , describe_path : & str ) -> bool {
160176 for attr in cx. tcx . get_attrs ( def_id) . iter ( ) {
161177 if attr. check_name ( "must_use" ) {
162- let mut msg = format ! ( "unused `{}` which must be used" ,
163- cx. tcx. item_path_str( def_id) ) ;
178+ let mut msg = format ! ( "unused {} `{}` which must be used" ,
179+ describe_path , cx. tcx. item_path_str( def_id) ) ;
164180 // check for #[must_use="..."]
165181 if let Some ( s) = attr. value_str ( ) {
166182 msg. push_str ( ": " ) ;
0 commit comments