@@ -720,6 +720,19 @@ impl DiagCtxt {
720
720
self . inner . borrow_mut ( ) . emit_stashed_diagnostics ( )
721
721
}
722
722
723
+ /// Construct a builder at the `Bug` level at the given `span` and with the `msg`.
724
+ #[ rustc_lint_diagnostics]
725
+ #[ track_caller]
726
+ pub fn struct_span_bug (
727
+ & self ,
728
+ span : impl Into < MultiSpan > ,
729
+ msg : impl Into < DiagnosticMessage > ,
730
+ ) -> DiagnosticBuilder < ' _ , BugAbort > {
731
+ let mut result = self . struct_bug ( msg) ;
732
+ result. set_span ( span) ;
733
+ result
734
+ }
735
+
723
736
/// Construct a builder at the `Warning` level at the given `span` and with the `msg`.
724
737
///
725
738
/// Attempting to `.emit()` the builder will only emit if either:
@@ -965,7 +978,7 @@ impl DiagCtxt {
965
978
}
966
979
967
980
pub fn span_bug ( & self , span : impl Into < MultiSpan > , msg : impl Into < DiagnosticMessage > ) -> ! {
968
- self . inner . borrow_mut ( ) . span_bug ( span, msg)
981
+ self . struct_span_bug ( span, msg) . emit ( )
969
982
}
970
983
971
984
/// For documentation on this, see `Session::span_delayed_bug`.
@@ -978,14 +991,14 @@ impl DiagCtxt {
978
991
sp : impl Into < MultiSpan > ,
979
992
msg : impl Into < DiagnosticMessage > ,
980
993
) -> ErrorGuaranteed {
981
- let mut inner = self . inner . borrow_mut ( ) ;
982
- if inner . treat_next_err_as_bug ( ) {
994
+ let treat_next_err_as_bug = self . inner . borrow ( ) . treat_next_err_as_bug ( ) ;
995
+ if treat_next_err_as_bug {
983
996
// FIXME: don't abort here if report_delayed_bugs is off
984
- inner . span_bug ( sp, msg) ;
997
+ self . span_bug ( sp, msg) ;
985
998
}
986
999
let mut diagnostic = Diagnostic :: new ( Level :: DelayedBug , msg) ;
987
1000
diagnostic. set_span ( sp) ;
988
- inner . emit_diagnostic ( diagnostic) . unwrap ( )
1001
+ self . emit_diagnostic ( diagnostic) . unwrap ( )
989
1002
}
990
1003
991
1004
// FIXME(eddyb) note the comment inside `impl Drop for DiagCtxtInner`, that's
@@ -1515,14 +1528,6 @@ impl DiagCtxtInner {
1515
1528
self . err_count > 0
1516
1529
}
1517
1530
1518
- #[ track_caller]
1519
- fn span_bug ( & mut self , sp : impl Into < MultiSpan > , msg : impl Into < DiagnosticMessage > ) -> ! {
1520
- let mut diag = Diagnostic :: new ( Bug , msg) ;
1521
- diag. set_span ( sp) ;
1522
- self . emit_diagnostic ( diag) ;
1523
- panic:: panic_any ( ExplicitBug ) ;
1524
- }
1525
-
1526
1531
fn failure_note ( & mut self , msg : impl Into < DiagnosticMessage > ) {
1527
1532
self . emit_diagnostic ( Diagnostic :: new ( FailureNote , msg) ) ;
1528
1533
}
0 commit comments