@@ -22,7 +22,7 @@ use rustc_errors::{
22
22
use rustc_hir:: def:: Namespace :: { self , * } ;
23
23
use rustc_hir:: def:: { self , CtorKind , DefKind , LifetimeRes , NonMacroAttrKind , PartialRes , PerNS } ;
24
24
use rustc_hir:: def_id:: { DefId , LocalDefId , CRATE_DEF_ID , LOCAL_CRATE } ;
25
- use rustc_hir:: { PrimTy , TraitCandidate } ;
25
+ use rustc_hir:: { MissingLifetimeKind , PrimTy , TraitCandidate } ;
26
26
use rustc_middle:: middle:: resolve_bound_vars:: Set1 ;
27
27
use rustc_middle:: { bug, span_bug} ;
28
28
use rustc_session:: config:: { CrateType , ResolveDocLinks } ;
@@ -43,9 +43,7 @@ type Res = def::Res<NodeId>;
43
43
44
44
type IdentMap < T > = FxHashMap < Ident , T > ;
45
45
46
- use diagnostics:: {
47
- ElisionFnParameter , LifetimeElisionCandidate , MissingLifetime , MissingLifetimeKind ,
48
- } ;
46
+ use diagnostics:: { ElisionFnParameter , LifetimeElisionCandidate , MissingLifetime } ;
49
47
50
48
#[ derive( Copy , Clone , Debug ) ]
51
49
struct BindingInfo {
@@ -1630,22 +1628,16 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
1630
1628
fn resolve_anonymous_lifetime ( & mut self , lifetime : & Lifetime , elided : bool ) {
1631
1629
debug_assert_eq ! ( lifetime. ident. name, kw:: UnderscoreLifetime ) ;
1632
1630
1633
- let missing_lifetime = MissingLifetime {
1634
- id : lifetime. id ,
1635
- span : lifetime. ident . span ,
1636
- kind : if elided {
1637
- MissingLifetimeKind :: Ampersand
1638
- } else {
1639
- MissingLifetimeKind :: Underscore
1640
- } ,
1641
- count : 1 ,
1642
- } ;
1631
+ let kind =
1632
+ if elided { MissingLifetimeKind :: Ampersand } else { MissingLifetimeKind :: Underscore } ;
1633
+ let missing_lifetime =
1634
+ MissingLifetime { id : lifetime. id , span : lifetime. ident . span , kind, count : 1 } ;
1643
1635
let elision_candidate = LifetimeElisionCandidate :: Missing ( missing_lifetime) ;
1644
1636
for ( i, rib) in self . lifetime_ribs . iter ( ) . enumerate ( ) . rev ( ) {
1645
1637
debug ! ( ?rib. kind) ;
1646
1638
match rib. kind {
1647
1639
LifetimeRibKind :: AnonymousCreateParameter { binder, .. } => {
1648
- let res = self . create_fresh_lifetime ( lifetime. ident , binder) ;
1640
+ let res = self . create_fresh_lifetime ( lifetime. ident , binder, kind ) ;
1649
1641
self . record_lifetime_res ( lifetime. id , res, elision_candidate) ;
1650
1642
return ;
1651
1643
}
@@ -1737,13 +1729,18 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
1737
1729
}
1738
1730
1739
1731
#[ instrument( level = "debug" , skip( self ) ) ]
1740
- fn create_fresh_lifetime ( & mut self , ident : Ident , binder : NodeId ) -> LifetimeRes {
1732
+ fn create_fresh_lifetime (
1733
+ & mut self ,
1734
+ ident : Ident ,
1735
+ binder : NodeId ,
1736
+ kind : MissingLifetimeKind ,
1737
+ ) -> LifetimeRes {
1741
1738
debug_assert_eq ! ( ident. name, kw:: UnderscoreLifetime ) ;
1742
1739
debug ! ( ?ident. span) ;
1743
1740
1744
1741
// Leave the responsibility to create the `LocalDefId` to lowering.
1745
1742
let param = self . r . next_node_id ( ) ;
1746
- let res = LifetimeRes :: Fresh { param, binder } ;
1743
+ let res = LifetimeRes :: Fresh { param, binder, kind } ;
1747
1744
self . record_lifetime_param ( param, res) ;
1748
1745
1749
1746
// Record the created lifetime parameter so lowering can pick it up and add it to HIR.
@@ -1837,14 +1834,15 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
1837
1834
} ;
1838
1835
let ident = Ident :: new ( kw:: UnderscoreLifetime , elided_lifetime_span) ;
1839
1836
1837
+ let kind = if segment. has_generic_args {
1838
+ MissingLifetimeKind :: Comma
1839
+ } else {
1840
+ MissingLifetimeKind :: Brackets
1841
+ } ;
1840
1842
let missing_lifetime = MissingLifetime {
1841
1843
id : node_ids. start ,
1842
1844
span : elided_lifetime_span,
1843
- kind : if segment. has_generic_args {
1844
- MissingLifetimeKind :: Comma
1845
- } else {
1846
- MissingLifetimeKind :: Brackets
1847
- } ,
1845
+ kind,
1848
1846
count : expected_lifetimes,
1849
1847
} ;
1850
1848
let mut should_lint = true ;
@@ -1890,7 +1888,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
1890
1888
// Group all suggestions into the first record.
1891
1889
let mut candidate = LifetimeElisionCandidate :: Missing ( missing_lifetime) ;
1892
1890
for id in node_ids {
1893
- let res = self . create_fresh_lifetime ( ident, binder) ;
1891
+ let res = self . create_fresh_lifetime ( ident, binder, kind ) ;
1894
1892
self . record_lifetime_res (
1895
1893
id,
1896
1894
res,
0 commit comments