File tree 4 files changed +34
-3
lines changed
4 files changed +34
-3
lines changed Original file line number Diff line number Diff line change @@ -973,6 +973,7 @@ impl Handler {
973
973
self . inner . borrow_mut ( ) . span_bug ( span, msg)
974
974
}
975
975
976
+ /// For documentation on this, see `Session::delay_span_bug`.
976
977
#[ track_caller]
977
978
pub fn delay_span_bug (
978
979
& self ,
@@ -1518,6 +1519,7 @@ impl HandlerInner {
1518
1519
self . emit_diagnostic ( diag. set_span ( sp) ) ;
1519
1520
}
1520
1521
1522
+ /// For documentation on this, see `Session::delay_span_bug`.
1521
1523
#[ track_caller]
1522
1524
fn delay_span_bug (
1523
1525
& 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
1
11
#[ macro_export]
2
12
macro_rules! bug {
3
13
( ) => ( $crate:: bug!( "impossible case reached" ) ) ;
@@ -8,6 +18,14 @@ macro_rules! bug {
8
18
} ) ;
9
19
}
10
20
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
11
29
#[ macro_export]
12
30
macro_rules! span_bug {
13
31
( $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>>(
35
35
( Some ( tcx) , None ) => tcx. sess . diagnostic ( ) . bug ( & msg) ,
36
36
( None , _) => panic_any ( msg) ,
37
37
}
38
- } ) ;
39
- unreachable ! ( ) ;
38
+ } )
40
39
}
41
40
42
41
/// 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 {
590
590
pub fn warn ( & self , msg : impl Into < DiagnosticMessage > ) {
591
591
self . diagnostic ( ) . warn ( msg)
592
592
}
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
594
606
#[ track_caller]
595
607
pub fn delay_span_bug < S : Into < MultiSpan > > (
596
608
& self ,
You can’t perform that action at this time.
0 commit comments