@@ -364,14 +364,52 @@ impl AstConv<'tcx> for ItemCtxt<'tcx> {
364364 ) ;
365365
366366 match self . node ( ) {
367- hir:: Node :: Field ( _)
368- | hir:: Node :: Variant ( _)
369- | hir:: Node :: Ctor ( _)
370- | hir:: Node :: Item ( hir:: Item { kind : hir:: ItemKind :: Struct ( ..) , .. } )
371- | hir:: Node :: Item ( hir:: Item { kind : hir:: ItemKind :: Enum ( ..) , .. } )
372- | hir:: Node :: Item ( hir:: Item { kind : hir:: ItemKind :: Union ( ..) , .. } ) => {
373- // The suggestion is only valid if this is not an ADT.
367+ hir:: Node :: Field ( _) | hir:: Node :: Ctor ( _) | hir:: Node :: Variant ( _) => {
368+ let item =
369+ self . tcx . hir ( ) . expect_item ( self . tcx . hir ( ) . get_parent_item ( self . hir_id ( ) ) ) ;
370+ match & item. kind {
371+ hir:: ItemKind :: Enum ( _, generics)
372+ | hir:: ItemKind :: Struct ( _, generics)
373+ | hir:: ItemKind :: Union ( _, generics) => {
374+ // FIXME: look for an appropriate lt name if `'a` is already used
375+ let ( lt_sp, sugg) = match & generics. params [ ..] {
376+ [ ] => ( generics. span , "<'a>" . to_string ( ) ) ,
377+ [ bound, ..] => ( bound. span . shrink_to_lo ( ) , "'a, " . to_string ( ) ) ,
378+ } ;
379+ let suggestions = vec ! [
380+ ( lt_sp, sugg) ,
381+ (
382+ span,
383+ format!(
384+ "{}::{}" ,
385+ // Replace the existing lifetimes with a new named lifetime.
386+ self . tcx
387+ . replace_late_bound_regions( & poly_trait_ref, |_| {
388+ self . tcx. mk_region( ty:: ReEarlyBound (
389+ ty:: EarlyBoundRegion {
390+ def_id: item_def_id,
391+ index: 0 ,
392+ name: Symbol :: intern( "'a" ) ,
393+ } ,
394+ ) )
395+ } )
396+ . 0 ,
397+ item_segment. ident
398+ ) ,
399+ ) ,
400+ ] ;
401+ err. multipart_suggestion (
402+ "use a fully qualified path with explicit lifetimes" ,
403+ suggestions,
404+ Applicability :: MaybeIncorrect ,
405+ ) ;
406+ }
407+ _ => { }
408+ }
374409 }
410+ hir:: Node :: Item ( hir:: Item { kind : hir:: ItemKind :: Struct ( ..) , .. } )
411+ | hir:: Node :: Item ( hir:: Item { kind : hir:: ItemKind :: Enum ( ..) , .. } )
412+ | hir:: Node :: Item ( hir:: Item { kind : hir:: ItemKind :: Union ( ..) , .. } ) => { }
375413 hir:: Node :: Item ( _)
376414 | hir:: Node :: ForeignItem ( _)
377415 | hir:: Node :: TraitItem ( _)
0 commit comments