@@ -309,19 +309,12 @@ pub fn suggest_new_region_bound(
309309 let did = item_id. owner_id . to_def_id ( ) ;
310310 let ty = tcx. mk_opaque ( did, ty:: InternalSubsts :: identity_for_item ( tcx, did) ) ;
311311
312- if let Some ( span) = opaque
313- . bounds
314- . iter ( )
315- . filter_map ( |arg| match arg {
316- GenericBound :: Outlives ( Lifetime {
317- res : LifetimeName :: Static ,
318- ident,
319- ..
320- } ) => Some ( ident. span ) ,
321- _ => None ,
322- } )
323- . next ( )
324- {
312+ if let Some ( span) = opaque. bounds . iter ( ) . find_map ( |arg| match arg {
313+ GenericBound :: Outlives ( Lifetime {
314+ res : LifetimeName :: Static , ident, ..
315+ } ) => Some ( ident. span ) ,
316+ _ => None ,
317+ } ) {
325318 if let Some ( explicit_static) = & explicit_static {
326319 err. span_suggestion_verbose (
327320 span,
@@ -338,20 +331,14 @@ pub fn suggest_new_region_bound(
338331 Applicability :: MaybeIncorrect ,
339332 ) ;
340333 }
341- } else if opaque
342- . bounds
343- . iter ( )
344- . filter_map ( |arg| match arg {
345- GenericBound :: Outlives ( Lifetime { ident, .. } )
346- if ident. name . to_string ( ) == lifetime_name =>
347- {
348- Some ( ident. span )
349- }
350- _ => None ,
351- } )
352- . next ( )
353- . is_some ( )
354- {
334+ } else if opaque. bounds . iter ( ) . any ( |arg| match arg {
335+ GenericBound :: Outlives ( Lifetime { ident, .. } )
336+ if ident. name . to_string ( ) == lifetime_name =>
337+ {
338+ true
339+ }
340+ _ => false ,
341+ } ) {
355342 } else {
356343 err. span_suggestion_verbose (
357344 fn_return. span . shrink_to_hi ( ) ,
@@ -428,35 +415,29 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
428415 // obligation comes from the `impl`. Find that `impl` so that we can point
429416 // at it in the suggestion.
430417 let trait_did = trait_did. to_def_id ( ) ;
431- match tcx
432- . hir ( )
433- . trait_impls ( trait_did)
434- . iter ( )
435- . filter_map ( |& impl_did| {
436- match tcx. hir ( ) . get_if_local ( impl_did. to_def_id ( ) ) {
437- Some ( Node :: Item ( Item {
438- kind : ItemKind :: Impl ( hir:: Impl { self_ty, .. } ) ,
439- ..
440- } ) ) if trait_objects. iter ( ) . all ( |did| {
441- // FIXME: we should check `self_ty` against the receiver
442- // type in the `UnifyReceiver` context, but for now, use
443- // this imperfect proxy. This will fail if there are
444- // multiple `impl`s for the same trait like
445- // `impl Foo for Box<dyn Bar>` and `impl Foo for dyn Bar`.
446- // In that case, only the first one will get suggestions.
447- let mut traits = vec ! [ ] ;
448- let mut hir_v = HirTraitObjectVisitor ( & mut traits, * did) ;
449- hir_v. visit_ty ( self_ty) ;
450- !traits. is_empty ( )
451- } ) =>
452- {
453- Some ( self_ty)
454- }
455- _ => None ,
418+ match tcx. hir ( ) . trait_impls ( trait_did) . iter ( ) . find_map ( |& impl_did| {
419+ match tcx. hir ( ) . get_if_local ( impl_did. to_def_id ( ) ) {
420+ Some ( Node :: Item ( Item {
421+ kind : ItemKind :: Impl ( hir:: Impl { self_ty, .. } ) ,
422+ ..
423+ } ) ) if trait_objects. iter ( ) . all ( |did| {
424+ // FIXME: we should check `self_ty` against the receiver
425+ // type in the `UnifyReceiver` context, but for now, use
426+ // this imperfect proxy. This will fail if there are
427+ // multiple `impl`s for the same trait like
428+ // `impl Foo for Box<dyn Bar>` and `impl Foo for dyn Bar`.
429+ // In that case, only the first one will get suggestions.
430+ let mut traits = vec ! [ ] ;
431+ let mut hir_v = HirTraitObjectVisitor ( & mut traits, * did) ;
432+ hir_v. visit_ty ( self_ty) ;
433+ !traits. is_empty ( )
434+ } ) =>
435+ {
436+ Some ( self_ty)
456437 }
457- } )
458- . next ( )
459- {
438+ _ => None ,
439+ }
440+ } ) {
460441 Some ( self_ty) => Some ( ( trait_item. ident , self_ty) ) ,
461442 _ => None ,
462443 }
0 commit comments