@@ -22,7 +22,7 @@ use rustc_errors::{
2222use rustc_hir:: def:: Namespace :: { self , * } ;
2323use rustc_hir:: def:: { self , CtorKind , DefKind , LifetimeRes , NonMacroAttrKind , PartialRes , PerNS } ;
2424use rustc_hir:: def_id:: { DefId , LocalDefId , CRATE_DEF_ID , LOCAL_CRATE } ;
25- use rustc_hir:: { PrimTy , TraitCandidate } ;
25+ use rustc_hir:: { MissingLifetimeKind , PrimTy , TraitCandidate } ;
2626use rustc_middle:: middle:: resolve_bound_vars:: Set1 ;
2727use rustc_middle:: { bug, span_bug} ;
2828use rustc_session:: config:: { CrateType , ResolveDocLinks } ;
@@ -44,9 +44,7 @@ type Res = def::Res<NodeId>;
4444
4545type IdentMap < T > = FxHashMap < Ident , T > ;
4646
47- use diagnostics:: {
48- ElisionFnParameter , LifetimeElisionCandidate , MissingLifetime , MissingLifetimeKind ,
49- } ;
47+ use diagnostics:: { ElisionFnParameter , LifetimeElisionCandidate , MissingLifetime } ;
5048
5149#[ derive( Copy , Clone , Debug ) ]
5250struct BindingInfo {
@@ -1637,22 +1635,16 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
16371635 fn resolve_anonymous_lifetime ( & mut self , lifetime : & Lifetime , elided : bool ) {
16381636 debug_assert_eq ! ( lifetime. ident. name, kw:: UnderscoreLifetime ) ;
16391637
1640- let missing_lifetime = MissingLifetime {
1641- id : lifetime. id ,
1642- span : lifetime. ident . span ,
1643- kind : if elided {
1644- MissingLifetimeKind :: Ampersand
1645- } else {
1646- MissingLifetimeKind :: Underscore
1647- } ,
1648- count : 1 ,
1649- } ;
1638+ let kind =
1639+ if elided { MissingLifetimeKind :: Ampersand } else { MissingLifetimeKind :: Underscore } ;
1640+ let missing_lifetime =
1641+ MissingLifetime { id : lifetime. id , span : lifetime. ident . span , kind, count : 1 } ;
16501642 let elision_candidate = LifetimeElisionCandidate :: Missing ( missing_lifetime) ;
16511643 for ( i, rib) in self . lifetime_ribs . iter ( ) . enumerate ( ) . rev ( ) {
16521644 debug ! ( ?rib. kind) ;
16531645 match rib. kind {
16541646 LifetimeRibKind :: AnonymousCreateParameter { binder, .. } => {
1655- let res = self . create_fresh_lifetime ( lifetime. ident , binder) ;
1647+ let res = self . create_fresh_lifetime ( lifetime. ident , binder, kind ) ;
16561648 self . record_lifetime_res ( lifetime. id , res, elision_candidate) ;
16571649 return ;
16581650 }
@@ -1744,13 +1736,18 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
17441736 }
17451737
17461738 #[ instrument( level = "debug" , skip( self ) ) ]
1747- fn create_fresh_lifetime ( & mut self , ident : Ident , binder : NodeId ) -> LifetimeRes {
1739+ fn create_fresh_lifetime (
1740+ & mut self ,
1741+ ident : Ident ,
1742+ binder : NodeId ,
1743+ kind : MissingLifetimeKind ,
1744+ ) -> LifetimeRes {
17481745 debug_assert_eq ! ( ident. name, kw:: UnderscoreLifetime ) ;
17491746 debug ! ( ?ident. span) ;
17501747
17511748 // Leave the responsibility to create the `LocalDefId` to lowering.
17521749 let param = self . r . next_node_id ( ) ;
1753- let res = LifetimeRes :: Fresh { param, binder } ;
1750+ let res = LifetimeRes :: Fresh { param, binder, kind } ;
17541751 self . record_lifetime_param ( param, res) ;
17551752
17561753 // Record the created lifetime parameter so lowering can pick it up and add it to HIR.
@@ -1844,14 +1841,15 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
18441841 } ;
18451842 let ident = Ident :: new ( kw:: UnderscoreLifetime , elided_lifetime_span) ;
18461843
1844+ let kind = if segment. has_generic_args {
1845+ MissingLifetimeKind :: Comma
1846+ } else {
1847+ MissingLifetimeKind :: Brackets
1848+ } ;
18471849 let missing_lifetime = MissingLifetime {
18481850 id : node_ids. start ,
18491851 span : elided_lifetime_span,
1850- kind : if segment. has_generic_args {
1851- MissingLifetimeKind :: Comma
1852- } else {
1853- MissingLifetimeKind :: Brackets
1854- } ,
1852+ kind,
18551853 count : expected_lifetimes,
18561854 } ;
18571855 let mut should_lint = true ;
@@ -1897,7 +1895,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
18971895 // Group all suggestions into the first record.
18981896 let mut candidate = LifetimeElisionCandidate :: Missing ( missing_lifetime) ;
18991897 for id in node_ids {
1900- let res = self . create_fresh_lifetime ( ident, binder) ;
1898+ let res = self . create_fresh_lifetime ( ident, binder, kind ) ;
19011899 self . record_lifetime_res (
19021900 id,
19031901 res,
0 commit comments