@@ -28,7 +28,7 @@ use rustc_session::lint::{self, BuiltinLintDiag};
28
28
use rustc_session:: parse:: feature_err;
29
29
use rustc_span:: source_map:: { respan, Spanned } ;
30
30
use rustc_span:: symbol:: { kw, sym, Ident , Symbol } ;
31
- use rustc_span:: { BytePos , Span , SyntaxContext } ;
31
+ use rustc_span:: { BytePos , ErrorGuaranteed , Span , SyntaxContext } ;
32
32
use smallvec:: { smallvec, SmallVec } ;
33
33
use tracing:: { debug, instrument, trace} ;
34
34
@@ -1621,19 +1621,19 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
1621
1621
match rib. kind {
1622
1622
LifetimeRibKind :: Item => break ,
1623
1623
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) ;
1625
1625
self . record_lifetime_res (
1626
1626
lifetime. id ,
1627
- LifetimeRes :: Error ,
1627
+ LifetimeRes :: Error ( guar ) ,
1628
1628
LifetimeElisionCandidate :: Ignore ,
1629
1629
) ;
1630
1630
return ;
1631
1631
}
1632
1632
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) ;
1634
1634
self . record_lifetime_res (
1635
1635
lifetime. id ,
1636
- LifetimeRes :: Error ,
1636
+ LifetimeRes :: Error ( guar ) ,
1637
1637
LifetimeElisionCandidate :: Ignore ,
1638
1638
) ;
1639
1639
return ;
@@ -1656,8 +1656,12 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
1656
1656
}
1657
1657
}
1658
1658
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
+ ) ;
1661
1665
}
1662
1666
1663
1667
#[ instrument( level = "debug" , skip( self ) ) ]
@@ -1689,7 +1693,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
1689
1693
) ;
1690
1694
}
1691
1695
LifetimeRibKind :: AnonymousReportError => {
1692
- if elided {
1696
+ let guar = if elided {
1693
1697
let mut suggestion = None ;
1694
1698
for rib in self . lifetime_ribs [ i..] . iter ( ) . rev ( ) {
1695
1699
if let LifetimeRibKind :: Generics {
@@ -1723,24 +1727,28 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
1723
1727
self . r . dcx ( ) . emit_err ( errors:: LendingIteratorReportError {
1724
1728
lifetime : lifetime. ident . span ,
1725
1729
ty : ty. span ( ) ,
1726
- } ) ;
1730
+ } )
1727
1731
} else {
1728
1732
self . r . dcx ( ) . emit_err ( errors:: AnonymousLivetimeNonGatReportError {
1729
1733
lifetime : lifetime. ident . span ,
1730
- } ) ;
1734
+ } )
1731
1735
}
1732
1736
} else {
1733
1737
self . r . dcx ( ) . emit_err ( errors:: ElidedAnonymousLivetimeReportError {
1734
1738
span : lifetime. ident . span ,
1735
1739
suggestion,
1736
- } ) ;
1740
+ } )
1737
1741
}
1738
1742
} else {
1739
1743
self . r . dcx ( ) . emit_err ( errors:: ExplicitAnonymousLivetimeReportError {
1740
1744
span : lifetime. ident . span ,
1741
- } ) ;
1745
+ } )
1742
1746
} ;
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
+ ) ;
1744
1752
return ;
1745
1753
}
1746
1754
LifetimeRibKind :: Elided ( res) => {
@@ -1749,7 +1757,11 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
1749
1757
}
1750
1758
LifetimeRibKind :: ElisionFailure => {
1751
1759
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
+ ) ;
1753
1765
return ;
1754
1766
}
1755
1767
LifetimeRibKind :: Item => break ,
@@ -1760,8 +1772,8 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
1760
1772
}
1761
1773
}
1762
1774
}
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 ) ;
1765
1777
}
1766
1778
1767
1779
#[ instrument( level = "debug" , skip( self ) ) ]
@@ -1913,16 +1925,17 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
1913
1925
!segment. has_generic_args ,
1914
1926
elided_lifetime_span,
1915
1927
) ;
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
+ } ) ;
1920
1933
should_lint = false ;
1921
1934
1922
1935
for id in node_ids {
1923
1936
self . record_lifetime_res (
1924
1937
id,
1925
- LifetimeRes :: Error ,
1938
+ LifetimeRes :: Error ( guar ) ,
1926
1939
LifetimeElisionCandidate :: Named ,
1927
1940
) ;
1928
1941
}
@@ -1958,7 +1971,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
1958
1971
for id in node_ids {
1959
1972
self . record_lifetime_res (
1960
1973
id,
1961
- LifetimeRes :: Error ,
1974
+ LifetimeRes :: Error ( self . r . dcx ( ) . delayed_bug ( "missing lifetime" ) ) ,
1962
1975
LifetimeElisionCandidate :: Ignore ,
1963
1976
) ;
1964
1977
}
@@ -1969,14 +1982,15 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
1969
1982
// we simply resolve to an implicit lifetime, which will be checked later, at
1970
1983
// which point a suitable error will be emitted.
1971
1984
LifetimeRibKind :: AnonymousReportError | LifetimeRibKind :: Item => {
1985
+ let guar =
1986
+ self . report_missing_lifetime_specifiers ( vec ! [ missing_lifetime] , None ) ;
1972
1987
for id in node_ids {
1973
1988
self . record_lifetime_res (
1974
1989
id,
1975
- LifetimeRes :: Error ,
1990
+ LifetimeRes :: Error ( guar ) ,
1976
1991
LifetimeElisionCandidate :: Ignore ,
1977
1992
) ;
1978
1993
}
1979
- self . report_missing_lifetime_specifiers ( vec ! [ missing_lifetime] , None ) ;
1980
1994
break ;
1981
1995
}
1982
1996
LifetimeRibKind :: Generics { .. } | LifetimeRibKind :: ConstParamTy => { }
@@ -2011,6 +2025,9 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
2011
2025
candidate : LifetimeElisionCandidate ,
2012
2026
) {
2013
2027
if let Some ( prev_res) = self . r . lifetimes_res_map . insert ( id, res) {
2028
+ if let LifetimeRes :: Error ( _) = res {
2029
+ return ;
2030
+ }
2014
2031
panic ! ( "lifetime {id:?} resolved multiple times ({prev_res:?} before, {res:?} now)" )
2015
2032
}
2016
2033
match res {
@@ -2019,7 +2036,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
2019
2036
candidates. push ( ( res, candidate) ) ;
2020
2037
}
2021
2038
}
2022
- LifetimeRes :: Infer | LifetimeRes :: Error | LifetimeRes :: ElidedAnchor { .. } => { }
2039
+ LifetimeRes :: Infer | LifetimeRes :: Error ( _ ) | LifetimeRes :: ElidedAnchor { .. } => { }
2023
2040
}
2024
2041
}
2025
2042
@@ -2640,21 +2657,22 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
2640
2657
if let GenericParamKind :: Lifetime = param. kind
2641
2658
&& let Some ( & original) = seen_lifetimes. get ( & ident)
2642
2659
{
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 ) ;
2644
2662
// 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 ) ) ;
2646
2664
continue ;
2647
2665
}
2648
2666
2649
2667
match seen_bindings. entry ( ident) {
2650
2668
Entry :: Occupied ( entry) => {
2651
2669
let span = * entry. get ( ) ;
2652
2670
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) ;
2654
2672
let rib = match param. kind {
2655
2673
GenericParamKind :: Lifetime => {
2656
2674
// 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 ) ) ;
2658
2676
continue ;
2659
2677
}
2660
2678
GenericParamKind :: Type { .. } => & mut function_type_rib,
@@ -2672,21 +2690,22 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
2672
2690
}
2673
2691
2674
2692
if param. ident . name == kw:: UnderscoreLifetime {
2675
- self . r
2693
+ let guar = self
2694
+ . r
2676
2695
. dcx ( )
2677
2696
. emit_err ( errors:: UnderscoreLifetimeIsReserved { span : param. ident . span } ) ;
2678
2697
// 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 ) ) ;
2680
2699
continue ;
2681
2700
}
2682
2701
2683
2702
if param. ident . name == kw:: StaticLifetime {
2684
- self . r . dcx ( ) . emit_err ( errors:: StaticLifetimeIsReserved {
2703
+ let guar = self . r . dcx ( ) . emit_err ( errors:: StaticLifetimeIsReserved {
2685
2704
span : param. ident . span ,
2686
2705
lifetime : param. ident ,
2687
2706
} ) ;
2688
2707
// 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 ) ) ;
2690
2709
continue ;
2691
2710
}
2692
2711
@@ -4056,9 +4075,15 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
4056
4075
/// A wrapper around [`Resolver::report_error`].
4057
4076
///
4058
4077
/// 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 {
4060
4083
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 ( )
4062
4087
}
4063
4088
}
4064
4089
0 commit comments