@@ -151,7 +151,6 @@ pub fn is_ty_must_use<'tcx>(
151151 cx : & LateContext < ' tcx > ,
152152 ty : Ty < ' tcx > ,
153153 expr : & hir:: Expr < ' _ > ,
154- span : Span ,
155154 simplify_uninhabited : bool ,
156155) -> IsTyMustUse {
157156 if ty. is_unit ( ) {
@@ -165,12 +164,12 @@ pub fn is_ty_must_use<'tcx>(
165164 match * ty. kind ( ) {
166165 _ if is_uninhabited ( ty) => IsTyMustUse :: Trivial ,
167166 ty:: Adt ( ..) if let Some ( boxed) = ty. boxed_ty ( ) => {
168- is_ty_must_use ( cx, boxed, expr, span , simplify_uninhabited)
167+ is_ty_must_use ( cx, boxed, expr, simplify_uninhabited)
169168 . map ( |inner| MustUsePath :: Boxed ( Box :: new ( inner) ) )
170169 }
171170 ty:: Adt ( def, args) if cx. tcx . is_lang_item ( def. did ( ) , LangItem :: Pin ) => {
172171 let pinned_ty = args. type_at ( 0 ) ;
173- is_ty_must_use ( cx, pinned_ty, expr, span , simplify_uninhabited)
172+ is_ty_must_use ( cx, pinned_ty, expr, simplify_uninhabited)
174173 . map ( |inner| MustUsePath :: Pinned ( Box :: new ( inner) ) )
175174 }
176175 // Consider `Result<T, Uninhabited>` (e.g. `Result<(), !>`) equivalent to `T`.
@@ -180,7 +179,7 @@ pub fn is_ty_must_use<'tcx>(
180179 && is_uninhabited ( args. type_at ( 1 ) ) =>
181180 {
182181 let ok_ty = args. type_at ( 0 ) ;
183- is_ty_must_use ( cx, ok_ty, expr, span , simplify_uninhabited)
182+ is_ty_must_use ( cx, ok_ty, expr, simplify_uninhabited)
184183 . map ( |path| MustUsePath :: Result ( Box :: new ( path) ) )
185184 }
186185 // Consider `ControlFlow<Uninhabited, T>` (e.g. `ControlFlow<!, ()>`) equivalent to `T`.
@@ -190,7 +189,7 @@ pub fn is_ty_must_use<'tcx>(
190189 && is_uninhabited ( args. type_at ( 0 ) ) =>
191190 {
192191 let continue_ty = args. type_at ( 1 ) ;
193- is_ty_must_use ( cx, continue_ty, expr, span , simplify_uninhabited)
192+ is_ty_must_use ( cx, continue_ty, expr, simplify_uninhabited)
194193 . map ( |path| MustUsePath :: ControlFlow ( Box :: new ( path) ) )
195194 }
196195 // Suppress warnings on `Result<(), Uninhabited>` (e.g. `Result<(), !>`).
@@ -210,7 +209,7 @@ pub fn is_ty_must_use<'tcx>(
210209 IsTyMustUse :: Trivial
211210 }
212211 ty:: Adt ( def, _) => {
213- is_def_must_use ( cx, def. did ( ) , span) . map_or ( IsTyMustUse :: No , IsTyMustUse :: Yes )
212+ is_def_must_use ( cx, def. did ( ) , expr . span ) . map_or ( IsTyMustUse :: No , IsTyMustUse :: Yes )
214213 }
215214 ty:: Alias ( ty:: Opaque | ty:: Projection , ty:: AliasTy { def_id : def, .. } ) => {
216215 elaborate ( cx. tcx , cx. tcx . explicit_item_self_bounds ( def) . iter_identity_copied ( ) )
@@ -223,7 +222,7 @@ pub fn is_ty_must_use<'tcx>(
223222 {
224223 let def_id = poly_trait_predicate. trait_ref . def_id ;
225224
226- is_def_must_use ( cx, def_id, span)
225+ is_def_must_use ( cx, def_id, expr . span )
227226 } else {
228227 None
229228 }
@@ -236,7 +235,7 @@ pub fn is_ty_must_use<'tcx>(
236235 . find_map ( |predicate| {
237236 if let ty:: ExistentialPredicate :: Trait ( ref trait_ref) = predicate. skip_binder ( ) {
238237 let def_id = trait_ref. def_id ;
239- is_def_must_use ( cx, def_id, span)
238+ is_def_must_use ( cx, def_id, expr . span )
240239 . map ( |inner| MustUsePath :: TraitObject ( Box :: new ( inner) ) )
241240 } else {
242241 None
@@ -260,9 +259,7 @@ pub fn is_ty_must_use<'tcx>(
260259 . zip ( elem_exprs)
261260 . enumerate ( )
262261 . filter_map ( |( i, ( ty, expr) ) | {
263- is_ty_must_use ( cx, ty, expr, expr. span , simplify_uninhabited)
264- . yes ( )
265- . map ( |path| ( i, path) )
262+ is_ty_must_use ( cx, ty, expr, simplify_uninhabited) . yes ( ) . map ( |path| ( i, path) )
266263 } )
267264 . collect :: < Vec < _ > > ( ) ;
268265
@@ -276,21 +273,23 @@ pub fn is_ty_must_use<'tcx>(
276273 // If the array is empty we don't lint, to avoid false positives
277274 Some ( 0 ) | None => IsTyMustUse :: No ,
278275 // If the array is definitely non-empty, we can do `#[must_use]` checking.
279- Some ( len) => is_ty_must_use ( cx, ty, expr, span , simplify_uninhabited)
276+ Some ( len) => is_ty_must_use ( cx, ty, expr, simplify_uninhabited)
280277 . map ( |inner| MustUsePath :: Array ( Box :: new ( inner) , len) ) ,
281278 } ,
282- ty:: Closure ( ..) | ty:: CoroutineClosure ( ..) => IsTyMustUse :: Yes ( MustUsePath :: Closure ( span) ) ,
279+ ty:: Closure ( ..) | ty:: CoroutineClosure ( ..) => {
280+ IsTyMustUse :: Yes ( MustUsePath :: Closure ( expr. span ) )
281+ }
283282 ty:: Coroutine ( def_id, ..) => {
284283 // async fn should be treated as "implementor of `Future`"
285284 if cx. tcx . coroutine_is_async ( def_id)
286285 && let Some ( def_id) = cx. tcx . lang_items ( ) . future_trait ( )
287286 {
288287 IsTyMustUse :: Yes ( MustUsePath :: Opaque ( Box :: new (
289- is_def_must_use ( cx, def_id, span)
288+ is_def_must_use ( cx, def_id, expr . span )
290289 . expect ( "future trait is marked as `#[must_use]`" ) ,
291290 ) ) )
292291 } else {
293- IsTyMustUse :: Yes ( MustUsePath :: Coroutine ( span) )
292+ IsTyMustUse :: Yes ( MustUsePath :: Coroutine ( expr . span ) )
294293 }
295294 }
296295 _ => IsTyMustUse :: No ,
@@ -339,7 +338,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
339338
340339 let ty = cx. typeck_results ( ) . expr_ty ( expr) ;
341340
342- let must_use_result = is_ty_must_use ( cx, ty, expr, expr . span , false ) ;
341+ let must_use_result = is_ty_must_use ( cx, ty, expr, false ) ;
343342 let type_lint_emitted_or_trivial = match must_use_result {
344343 IsTyMustUse :: Yes ( path) => {
345344 emit_must_use_untranslated ( cx, & path, "" , "" , 1 , false , expr_is_from_block) ;
0 commit comments