@@ -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 } ;
@@ -44,9 +44,7 @@ type Res = def::Res<NodeId>;
44
44
45
45
type IdentMap < T > = FxHashMap < Ident , T > ;
46
46
47
- use diagnostics:: {
48
- ElisionFnParameter , LifetimeElisionCandidate , MissingLifetime , MissingLifetimeKind ,
49
- } ;
47
+ use diagnostics:: { ElisionFnParameter , LifetimeElisionCandidate , MissingLifetime } ;
50
48
51
49
#[ derive( Copy , Clone , Debug ) ]
52
50
struct BindingInfo {
@@ -1637,22 +1635,16 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
1637
1635
fn resolve_anonymous_lifetime ( & mut self , lifetime : & Lifetime , elided : bool ) {
1638
1636
debug_assert_eq ! ( lifetime. ident. name, kw:: UnderscoreLifetime ) ;
1639
1637
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 } ;
1650
1642
let elision_candidate = LifetimeElisionCandidate :: Missing ( missing_lifetime) ;
1651
1643
for ( i, rib) in self . lifetime_ribs . iter ( ) . enumerate ( ) . rev ( ) {
1652
1644
debug ! ( ?rib. kind) ;
1653
1645
match rib. kind {
1654
1646
LifetimeRibKind :: AnonymousCreateParameter { binder, .. } => {
1655
- let res = self . create_fresh_lifetime ( lifetime. ident , binder) ;
1647
+ let res = self . create_fresh_lifetime ( lifetime. ident , binder, kind ) ;
1656
1648
self . record_lifetime_res ( lifetime. id , res, elision_candidate) ;
1657
1649
return ;
1658
1650
}
@@ -1744,13 +1736,18 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
1744
1736
}
1745
1737
1746
1738
#[ 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 {
1748
1745
debug_assert_eq ! ( ident. name, kw:: UnderscoreLifetime ) ;
1749
1746
debug ! ( ?ident. span) ;
1750
1747
1751
1748
// Leave the responsibility to create the `LocalDefId` to lowering.
1752
1749
let param = self . r . next_node_id ( ) ;
1753
- let res = LifetimeRes :: Fresh { param, binder } ;
1750
+ let res = LifetimeRes :: Fresh { param, binder, kind } ;
1754
1751
self . record_lifetime_param ( param, res) ;
1755
1752
1756
1753
// 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> {
1844
1841
} ;
1845
1842
let ident = Ident :: new ( kw:: UnderscoreLifetime , elided_lifetime_span) ;
1846
1843
1844
+ let kind = if segment. has_generic_args {
1845
+ MissingLifetimeKind :: Comma
1846
+ } else {
1847
+ MissingLifetimeKind :: Brackets
1848
+ } ;
1847
1849
let missing_lifetime = MissingLifetime {
1848
1850
id : node_ids. start ,
1849
1851
span : elided_lifetime_span,
1850
- kind : if segment. has_generic_args {
1851
- MissingLifetimeKind :: Comma
1852
- } else {
1853
- MissingLifetimeKind :: Brackets
1854
- } ,
1852
+ kind,
1855
1853
count : expected_lifetimes,
1856
1854
} ;
1857
1855
let mut should_lint = true ;
@@ -1897,7 +1895,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
1897
1895
// Group all suggestions into the first record.
1898
1896
let mut candidate = LifetimeElisionCandidate :: Missing ( missing_lifetime) ;
1899
1897
for id in node_ids {
1900
- let res = self . create_fresh_lifetime ( ident, binder) ;
1898
+ let res = self . create_fresh_lifetime ( ident, binder, kind ) ;
1901
1899
self . record_lifetime_res (
1902
1900
id,
1903
1901
res,
0 commit comments