This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +34
-3
lines changed Expand file tree Collapse file tree 4 files changed +34
-3
lines changed Original file line number Diff line number Diff line change @@ -978,6 +978,7 @@ impl Handler {
978978 self . inner . borrow_mut ( ) . span_bug ( span, msg)
979979 }
980980
981+ /// For documentation on this, see `Session::delay_span_bug`.
981982 #[ track_caller]
982983 pub fn delay_span_bug (
983984 & self ,
@@ -1529,6 +1530,7 @@ impl HandlerInner {
15291530 self . emit_diagnostic ( diag. set_span ( sp) ) ;
15301531 }
15311532
1533+ /// For documentation on this, see `Session::delay_span_bug`.
15321534 #[ track_caller]
15331535 fn delay_span_bug (
15341536 & mut self ,
Original file line number Diff line number Diff line change 1+ /// A macro for triggering an ICE.
2+ /// Calling `bug` instead of panicking will result in a nicer error message and should
3+ /// therefore be prefered over `panic`/`unreachable` or others.
4+ ///
5+ /// If you have a span available, you should use [`span_bug`] instead.
6+ ///
7+ /// If the bug should only be emitted when compilation didn't fail, [`Session::delay_span_bug`] may be useful.
8+ ///
9+ /// [`Session::delay_span_bug`]: rustc_session::Session::delay_span_bug
10+ /// [`span_bug`]: crate::span_bug
111#[ macro_export]
212macro_rules! bug {
313 ( ) => ( $crate:: bug!( "impossible case reached" ) ) ;
@@ -8,6 +18,14 @@ macro_rules! bug {
818 } ) ;
919}
1020
21+ /// A macro for triggering an ICE with a span.
22+ /// Calling `span_bug!` instead of panicking will result in a nicer error message and point
23+ /// at the code the compiler was compiling when it ICEd. This is the preferred way to trigger
24+ /// ICEs.
25+ ///
26+ /// If the bug should only be emitted when compilation didn't fail, [`Session::delay_span_bug`] may be useful.
27+ ///
28+ /// [`Session::delay_span_bug`]: rustc_session::Session::delay_span_bug
1129#[ macro_export]
1230macro_rules! span_bug {
1331 ( $span: expr, $msg: expr) => ( { $crate:: util:: bug:: span_bug_fmt( $span, :: std:: format_args!( $msg) ) } ) ;
Original file line number Diff line number Diff line change @@ -35,8 +35,7 @@ fn opt_span_bug_fmt<S: Into<MultiSpan>>(
3535 ( Some ( tcx) , None ) => tcx. sess . diagnostic ( ) . bug ( & msg) ,
3636 ( None , _) => panic_any ( msg) ,
3737 }
38- } ) ;
39- unreachable ! ( ) ;
38+ } )
4039}
4140
4241/// A query to trigger a `delay_span_bug`. Clearly, if one has a `tcx` one can already trigger a
Original file line number Diff line number Diff line change @@ -590,7 +590,19 @@ impl Session {
590590 pub fn warn ( & self , msg : impl Into < DiagnosticMessage > ) {
591591 self . diagnostic ( ) . warn ( msg)
592592 }
593- /// Delay a span_bug() call until abort_if_errors()
593+
594+ /// Ensures that compilation cannot succeed.
595+ ///
596+ /// If this function has been called but no errors have been emitted and
597+ /// compilation succeeds, it will cause an internal compiler error (ICE).
598+ ///
599+ /// This can be used in code paths that should never run on successful compilations.
600+ /// For example, it can be used to create an [`ErrorGuaranteed`]
601+ /// (but you should prefer threading through the [`ErrorGuaranteed`] from an error emission directly).
602+ ///
603+ /// If no span is available, use [`DUMMY_SP`].
604+ ///
605+ /// [`DUMMY_SP`]: rustc_span::DUMMY_SP
594606 #[ track_caller]
595607 pub fn delay_span_bug < S : Into < MultiSpan > > (
596608 & self ,
You can’t perform that action at this time.
0 commit comments