Skip to content

Commit 04532e9

Browse files
Give me a way to emit all the delayed bugs
1 parent 68acb39 commit 04532e9

File tree

5 files changed

+58
-9
lines changed

5 files changed

+58
-9
lines changed

compiler/rustc_errors/src/lib.rs

+17-9
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,9 @@ pub struct DiagCtxtFlags {
527527
/// If Some, the Nth error-level diagnostic is upgraded to bug-level.
528528
/// (rustc: see `-Z treat-err-as-bug`)
529529
pub treat_err_as_bug: Option<NonZeroUsize>,
530+
/// Eagerly emit delayed bugs as errors, so that the compiler debugger may
531+
/// see all of the errors being emitted at once.
532+
pub eagerly_emit_delayed_bugs: bool,
530533
/// Show macro backtraces.
531534
/// (rustc: see `-Z macro-backtrace`)
532535
pub macro_backtrace: bool,
@@ -1269,16 +1272,21 @@ impl DiagCtxtInner {
12691272
}
12701273

12711274
if diagnostic.level == DelayedBug {
1272-
// FIXME(eddyb) this should check for `has_errors` and stop pushing
1273-
// once *any* errors were emitted (and truncate `span_delayed_bugs`
1274-
// when an error is first emitted, also), but maybe there's a case
1275-
// in which that's not sound? otherwise this is really inefficient.
1276-
let backtrace = std::backtrace::Backtrace::capture();
1277-
self.span_delayed_bugs
1278-
.push(DelayedDiagnostic::with_backtrace(diagnostic.clone(), backtrace));
1275+
if self.flags.eagerly_emit_delayed_bugs {
1276+
// Emit error as bug, rather than stashing it.
1277+
diagnostic.level = Error;
1278+
} else {
1279+
// FIXME(eddyb) this should check for `has_errors` and stop pushing
1280+
// once *any* errors were emitted (and truncate `span_delayed_bugs`
1281+
// when an error is first emitted, also), but maybe there's a case
1282+
// in which that's not sound? otherwise this is really inefficient.
1283+
let backtrace = std::backtrace::Backtrace::capture();
1284+
self.span_delayed_bugs
1285+
.push(DelayedDiagnostic::with_backtrace(diagnostic.clone(), backtrace));
12791286

1280-
#[allow(deprecated)]
1281-
return Some(ErrorGuaranteed::unchecked_claim_error_was_emitted());
1287+
#[allow(deprecated)]
1288+
return Some(ErrorGuaranteed::unchecked_claim_error_was_emitted());
1289+
}
12821290
}
12831291

12841292
if diagnostic.has_future_breakage() {

compiler/rustc_session/src/config.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,7 @@ impl UnstableOptions {
11461146
DiagCtxtFlags {
11471147
can_emit_warnings,
11481148
treat_err_as_bug: self.treat_err_as_bug,
1149+
eagerly_emit_delayed_bugs: self.eagerly_emit_delayed_bugs,
11491150
macro_backtrace: self.macro_backtrace,
11501151
deduplicate_diagnostics: self.deduplicate_diagnostics,
11511152
track_diagnostics: self.track_diagnostics,

compiler/rustc_session/src/options.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1583,6 +1583,9 @@ options! {
15831583
"version of DWARF debug information to emit (default: 2 or 4, depending on platform)"),
15841584
dylib_lto: bool = (false, parse_bool, [UNTRACKED],
15851585
"enables LTO for dylib crate type"),
1586+
eagerly_emit_delayed_bugs: bool = (false, parse_bool, [UNTRACKED],
1587+
"emit delayed bugs eagerly as errors instead of stashing them and emitting \
1588+
them only if an error has not been emitted"),
15861589
ehcont_guard: bool = (false, parse_bool, [TRACKED],
15871590
"generate Windows EHCont Guard tables"),
15881591
emit_stack_sizes: bool = (false, parse_bool, [UNTRACKED],
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// compile-flags: -Zeagerly-emit-delayed-bugs
2+
3+
trait Foo {}
4+
5+
fn main() {}
6+
7+
fn f() -> impl Foo {
8+
//~^ ERROR the trait bound `i32: Foo` is not satisfied
9+
//~| ERROR `report_selection_error` did not emit an error
10+
1i32
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error: `report_selection_error` did not emit an error
2+
--> $DIR/eagerly-emit.rs:7:11
3+
|
4+
LL | fn f() -> impl Foo {
5+
| ^^^^^^^^
6+
7+
error[E0277]: the trait bound `i32: Foo` is not satisfied
8+
--> $DIR/eagerly-emit.rs:7:11
9+
|
10+
LL | fn f() -> impl Foo {
11+
| ^^^^^^^^ the trait `Foo` is not implemented for `i32`
12+
...
13+
LL | 1i32
14+
| ---- return type was inferred to be `i32` here
15+
|
16+
help: this trait has no implementations, consider adding one
17+
--> $DIR/eagerly-emit.rs:3:1
18+
|
19+
LL | trait Foo {}
20+
| ^^^^^^^^^
21+
22+
error: expected fulfillment errors
23+
24+
error: aborting due to 3 previous errors
25+
26+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)