@@ -28,7 +28,7 @@ use rustc_session::lint::{self, BuiltinLintDiag};
2828use rustc_session:: parse:: feature_err;
2929use rustc_span:: source_map:: { respan, Spanned } ;
3030use rustc_span:: symbol:: { kw, sym, Ident , Symbol } ;
31- use rustc_span:: { BytePos , Span , SyntaxContext } ;
31+ use rustc_span:: { BytePos , ErrorGuaranteed , Span , SyntaxContext } ;
3232use smallvec:: { smallvec, SmallVec } ;
3333use tracing:: { debug, instrument, trace} ;
3434
@@ -1621,19 +1621,19 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
16211621 match rib. kind {
16221622 LifetimeRibKind :: Item => break ,
16231623 LifetimeRibKind :: ConstParamTy => {
1624- self . emit_non_static_lt_in_const_param_ty_error ( lifetime) ;
1624+ let guar = self . emit_non_static_lt_in_const_param_ty_error ( lifetime) ;
16251625 self . record_lifetime_res (
16261626 lifetime. id ,
1627- LifetimeRes :: Error ,
1627+ LifetimeRes :: Error ( guar ) ,
16281628 LifetimeElisionCandidate :: Ignore ,
16291629 ) ;
16301630 return ;
16311631 }
16321632 LifetimeRibKind :: ConcreteAnonConst ( cause) => {
1633- self . emit_forbidden_non_static_lifetime_error ( cause, lifetime) ;
1633+ let guar = self . emit_forbidden_non_static_lifetime_error ( cause, lifetime) ;
16341634 self . record_lifetime_res (
16351635 lifetime. id ,
1636- LifetimeRes :: Error ,
1636+ LifetimeRes :: Error ( guar ) ,
16371637 LifetimeElisionCandidate :: Ignore ,
16381638 ) ;
16391639 return ;
@@ -1656,8 +1656,12 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
16561656 }
16571657 }
16581658
1659- self . emit_undeclared_lifetime_error ( lifetime, outer_res) ;
1660- self . record_lifetime_res ( lifetime. id , LifetimeRes :: Error , LifetimeElisionCandidate :: Named ) ;
1659+ let guar = self . emit_undeclared_lifetime_error ( lifetime, outer_res) ;
1660+ self . record_lifetime_res (
1661+ lifetime. id ,
1662+ LifetimeRes :: Error ( guar) ,
1663+ LifetimeElisionCandidate :: Named ,
1664+ ) ;
16611665 }
16621666
16631667 #[ instrument( level = "debug" , skip( self ) ) ]
@@ -1689,7 +1693,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
16891693 ) ;
16901694 }
16911695 LifetimeRibKind :: AnonymousReportError => {
1692- if elided {
1696+ let guar = if elided {
16931697 let mut suggestion = None ;
16941698 for rib in self . lifetime_ribs [ i..] . iter ( ) . rev ( ) {
16951699 if let LifetimeRibKind :: Generics {
@@ -1723,24 +1727,28 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
17231727 self . r . dcx ( ) . emit_err ( errors:: LendingIteratorReportError {
17241728 lifetime : lifetime. ident . span ,
17251729 ty : ty. span ( ) ,
1726- } ) ;
1730+ } )
17271731 } else {
17281732 self . r . dcx ( ) . emit_err ( errors:: AnonymousLivetimeNonGatReportError {
17291733 lifetime : lifetime. ident . span ,
1730- } ) ;
1734+ } )
17311735 }
17321736 } else {
17331737 self . r . dcx ( ) . emit_err ( errors:: ElidedAnonymousLivetimeReportError {
17341738 span : lifetime. ident . span ,
17351739 suggestion,
1736- } ) ;
1740+ } )
17371741 }
17381742 } else {
17391743 self . r . dcx ( ) . emit_err ( errors:: ExplicitAnonymousLivetimeReportError {
17401744 span : lifetime. ident . span ,
1741- } ) ;
1745+ } )
17421746 } ;
1743- self . record_lifetime_res ( lifetime. id , LifetimeRes :: Error , elision_candidate) ;
1747+ self . record_lifetime_res (
1748+ lifetime. id ,
1749+ LifetimeRes :: Error ( guar) ,
1750+ elision_candidate,
1751+ ) ;
17441752 return ;
17451753 }
17461754 LifetimeRibKind :: Elided ( res) => {
@@ -1749,7 +1757,11 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
17491757 }
17501758 LifetimeRibKind :: ElisionFailure => {
17511759 self . diag_metadata . current_elision_failures . push ( missing_lifetime) ;
1752- self . record_lifetime_res ( lifetime. id , LifetimeRes :: Error , elision_candidate) ;
1760+ self . record_lifetime_res (
1761+ lifetime. id ,
1762+ LifetimeRes :: Error ( self . r . dcx ( ) . delayed_bug ( "elision failure" ) ) ,
1763+ elision_candidate,
1764+ ) ;
17531765 return ;
17541766 }
17551767 LifetimeRibKind :: Item => break ,
@@ -1760,8 +1772,8 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
17601772 }
17611773 }
17621774 }
1763- self . record_lifetime_res ( lifetime . id , LifetimeRes :: Error , elision_candidate ) ;
1764- self . report_missing_lifetime_specifiers ( vec ! [ missing_lifetime ] , None ) ;
1775+ let guar = self . report_missing_lifetime_specifiers ( vec ! [ missing_lifetime ] , None ) ;
1776+ self . record_lifetime_res ( lifetime . id , LifetimeRes :: Error ( guar ) , elision_candidate ) ;
17651777 }
17661778
17671779 #[ instrument( level = "debug" , skip( self ) ) ]
@@ -1913,16 +1925,17 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
19131925 !segment. has_generic_args ,
19141926 elided_lifetime_span,
19151927 ) ;
1916- self . r . dcx ( ) . emit_err ( errors:: ImplicitElidedLifetimeNotAllowedHere {
1917- span : path_span,
1918- subdiag,
1919- } ) ;
1928+ let guar =
1929+ self . r . dcx ( ) . emit_err ( errors:: ImplicitElidedLifetimeNotAllowedHere {
1930+ span : path_span,
1931+ subdiag,
1932+ } ) ;
19201933 should_lint = false ;
19211934
19221935 for id in node_ids {
19231936 self . record_lifetime_res (
19241937 id,
1925- LifetimeRes :: Error ,
1938+ LifetimeRes :: Error ( guar ) ,
19261939 LifetimeElisionCandidate :: Named ,
19271940 ) ;
19281941 }
@@ -1958,7 +1971,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
19581971 for id in node_ids {
19591972 self . record_lifetime_res (
19601973 id,
1961- LifetimeRes :: Error ,
1974+ LifetimeRes :: Error ( self . r . dcx ( ) . delayed_bug ( "missing lifetime" ) ) ,
19621975 LifetimeElisionCandidate :: Ignore ,
19631976 ) ;
19641977 }
@@ -1969,14 +1982,15 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
19691982 // we simply resolve to an implicit lifetime, which will be checked later, at
19701983 // which point a suitable error will be emitted.
19711984 LifetimeRibKind :: AnonymousReportError | LifetimeRibKind :: Item => {
1985+ let guar =
1986+ self . report_missing_lifetime_specifiers ( vec ! [ missing_lifetime] , None ) ;
19721987 for id in node_ids {
19731988 self . record_lifetime_res (
19741989 id,
1975- LifetimeRes :: Error ,
1990+ LifetimeRes :: Error ( guar ) ,
19761991 LifetimeElisionCandidate :: Ignore ,
19771992 ) ;
19781993 }
1979- self . report_missing_lifetime_specifiers ( vec ! [ missing_lifetime] , None ) ;
19801994 break ;
19811995 }
19821996 LifetimeRibKind :: Generics { .. } | LifetimeRibKind :: ConstParamTy => { }
@@ -2011,6 +2025,9 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
20112025 candidate : LifetimeElisionCandidate ,
20122026 ) {
20132027 if let Some ( prev_res) = self . r . lifetimes_res_map . insert ( id, res) {
2028+ if let LifetimeRes :: Error ( _) = res {
2029+ return ;
2030+ }
20142031 panic ! ( "lifetime {id:?} resolved multiple times ({prev_res:?} before, {res:?} now)" )
20152032 }
20162033 match res {
@@ -2019,7 +2036,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
20192036 candidates. push ( ( res, candidate) ) ;
20202037 }
20212038 }
2022- LifetimeRes :: Infer | LifetimeRes :: Error | LifetimeRes :: ElidedAnchor { .. } => { }
2039+ LifetimeRes :: Infer | LifetimeRes :: Error ( _ ) | LifetimeRes :: ElidedAnchor { .. } => { }
20232040 }
20242041 }
20252042
@@ -2640,21 +2657,22 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
26402657 if let GenericParamKind :: Lifetime = param. kind
26412658 && let Some ( & original) = seen_lifetimes. get ( & ident)
26422659 {
2643- diagnostics:: signal_lifetime_shadowing ( self . r . tcx . sess , original, param. ident ) ;
2660+ let guar =
2661+ diagnostics:: signal_lifetime_shadowing ( self . r . tcx . sess , original, param. ident ) ;
26442662 // Record lifetime res, so lowering knows there is something fishy.
2645- self . record_lifetime_param ( param. id , LifetimeRes :: Error ) ;
2663+ self . record_lifetime_param ( param. id , LifetimeRes :: Error ( guar ) ) ;
26462664 continue ;
26472665 }
26482666
26492667 match seen_bindings. entry ( ident) {
26502668 Entry :: Occupied ( entry) => {
26512669 let span = * entry. get ( ) ;
26522670 let err = ResolutionError :: NameAlreadyUsedInParameterList ( ident. name , span) ;
2653- self . report_error ( param. ident . span , err) ;
2671+ let guar = self . report_error ( param. ident . span , err) ;
26542672 let rib = match param. kind {
26552673 GenericParamKind :: Lifetime => {
26562674 // Record lifetime res, so lowering knows there is something fishy.
2657- self . record_lifetime_param ( param. id , LifetimeRes :: Error ) ;
2675+ self . record_lifetime_param ( param. id , LifetimeRes :: Error ( guar ) ) ;
26582676 continue ;
26592677 }
26602678 GenericParamKind :: Type { .. } => & mut function_type_rib,
@@ -2672,21 +2690,22 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
26722690 }
26732691
26742692 if param. ident . name == kw:: UnderscoreLifetime {
2675- self . r
2693+ let guar = self
2694+ . r
26762695 . dcx ( )
26772696 . emit_err ( errors:: UnderscoreLifetimeIsReserved { span : param. ident . span } ) ;
26782697 // Record lifetime res, so lowering knows there is something fishy.
2679- self . record_lifetime_param ( param. id , LifetimeRes :: Error ) ;
2698+ self . record_lifetime_param ( param. id , LifetimeRes :: Error ( guar ) ) ;
26802699 continue ;
26812700 }
26822701
26832702 if param. ident . name == kw:: StaticLifetime {
2684- self . r . dcx ( ) . emit_err ( errors:: StaticLifetimeIsReserved {
2703+ let guar = self . r . dcx ( ) . emit_err ( errors:: StaticLifetimeIsReserved {
26852704 span : param. ident . span ,
26862705 lifetime : param. ident ,
26872706 } ) ;
26882707 // Record lifetime res, so lowering knows there is something fishy.
2689- self . record_lifetime_param ( param. id , LifetimeRes :: Error ) ;
2708+ self . record_lifetime_param ( param. id , LifetimeRes :: Error ( guar ) ) ;
26902709 continue ;
26912710 }
26922711
@@ -4056,9 +4075,15 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
40564075 /// A wrapper around [`Resolver::report_error`].
40574076 ///
40584077 /// This doesn't emit errors for function bodies if this is rustdoc.
4059- fn report_error ( & mut self , span : Span , resolution_error : ResolutionError < ' a > ) {
4078+ fn report_error (
4079+ & mut self ,
4080+ span : Span ,
4081+ resolution_error : ResolutionError < ' a > ,
4082+ ) -> ErrorGuaranteed {
40604083 if self . should_report_errs ( ) {
4061- self . r . report_error ( span, resolution_error) ;
4084+ self . r . report_error ( span, resolution_error)
4085+ } else {
4086+ self . r . tcx . dcx ( ) . has_errors ( ) . unwrap ( )
40624087 }
40634088 }
40644089
0 commit comments