@@ -1644,14 +1644,30 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
16441644 continue ;
16451645 }
16461646
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 ,
16491656 PathSource :: Expr ( ..)
16501657 | PathSource :: Pat
16511658 | PathSource :: Struct
1652- | PathSource :: TupleStruct ( ..) => false ,
1659+ | PathSource :: TupleStruct ( ..) => true ,
16531660 } ;
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+ }
16551671 continue ;
16561672 }
16571673
@@ -1666,25 +1682,6 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
16661682 } ;
16671683 let ident = Ident :: new ( kw:: UnderscoreLifetime , elided_lifetime_span) ;
16681684
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-
16881685 let missing_lifetime = MissingLifetime {
16891686 id : node_ids. start ,
16901687 span : elided_lifetime_span,
0 commit comments