@@ -1644,14 +1644,30 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
1644
1644
continue ;
1645
1645
}
1646
1646
1647
- let missing = match source {
1648
- PathSource :: Trait ( ..) | PathSource :: TraitItem ( ..) | PathSource :: Type => true ,
1647
+ let node_ids = self . r . next_node_ids ( expected_lifetimes) ;
1648
+ self . record_lifetime_res (
1649
+ segment_id,
1650
+ LifetimeRes :: ElidedAnchor { start : node_ids. start , end : node_ids. end } ,
1651
+ LifetimeElisionCandidate :: Ignore ,
1652
+ ) ;
1653
+
1654
+ let inferred = match source {
1655
+ PathSource :: Trait ( ..) | PathSource :: TraitItem ( ..) | PathSource :: Type => false ,
1649
1656
PathSource :: Expr ( ..)
1650
1657
| PathSource :: Pat
1651
1658
| PathSource :: Struct
1652
- | PathSource :: TupleStruct ( ..) => false ,
1659
+ | PathSource :: TupleStruct ( ..) => true ,
1653
1660
} ;
1654
- if !missing && !segment. has_generic_args {
1661
+ if inferred {
1662
+ // Do not create a parameter for patterns and expressions: type checking can infer
1663
+ // the appropriate lifetime for us.
1664
+ for id in node_ids {
1665
+ self . record_lifetime_res (
1666
+ id,
1667
+ LifetimeRes :: Infer ,
1668
+ LifetimeElisionCandidate :: Named ,
1669
+ ) ;
1670
+ }
1655
1671
continue ;
1656
1672
}
1657
1673
@@ -1666,25 +1682,6 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
1666
1682
} ;
1667
1683
let ident = Ident :: new ( kw:: UnderscoreLifetime , elided_lifetime_span) ;
1668
1684
1669
- let node_ids = self . r . next_node_ids ( expected_lifetimes) ;
1670
- self . record_lifetime_res (
1671
- segment_id,
1672
- LifetimeRes :: ElidedAnchor { start : node_ids. start , end : node_ids. end } ,
1673
- LifetimeElisionCandidate :: Ignore ,
1674
- ) ;
1675
-
1676
- if !missing {
1677
- // Do not create a parameter for patterns and expressions.
1678
- for id in node_ids {
1679
- self . record_lifetime_res (
1680
- id,
1681
- LifetimeRes :: Infer ,
1682
- LifetimeElisionCandidate :: Named ,
1683
- ) ;
1684
- }
1685
- continue ;
1686
- }
1687
-
1688
1685
let missing_lifetime = MissingLifetime {
1689
1686
id : node_ids. start ,
1690
1687
span : elided_lifetime_span,
0 commit comments