Skip to content

Commit 4843946

Browse files
authored
Rollup merge of #104780 - BoxyUwU:error_reported_not_be_bad, r=oli-obk
make `error_reported` check for delayed bugs Fixes #104768 `error_reported()` was only checking if there were errors emitted, not for `delay_bug`s which can also be a source of `ErrorGuaranteed`. I assume the same is true of `lint_err_count` but i dont know
2 parents d4e5418 + 72d8879 commit 4843946

File tree

8 files changed

+44
-10
lines changed

8 files changed

+44
-10
lines changed

compiler/rustc_errors/src/lib.rs

+18-3
Original file line numberDiff line numberDiff line change
@@ -1044,13 +1044,24 @@ impl Handler {
10441044
}
10451045
pub fn has_errors_or_lint_errors(&self) -> Option<ErrorGuaranteed> {
10461046
if self.inner.borrow().has_errors_or_lint_errors() {
1047-
Some(ErrorGuaranteed(()))
1047+
Some(ErrorGuaranteed::unchecked_claim_error_was_emitted())
1048+
} else {
1049+
None
1050+
}
1051+
}
1052+
pub fn has_errors_or_delayed_span_bugs(&self) -> Option<ErrorGuaranteed> {
1053+
if self.inner.borrow().has_errors_or_delayed_span_bugs() {
1054+
Some(ErrorGuaranteed::unchecked_claim_error_was_emitted())
10481055
} else {
10491056
None
10501057
}
10511058
}
1052-
pub fn has_errors_or_delayed_span_bugs(&self) -> bool {
1053-
self.inner.borrow().has_errors_or_delayed_span_bugs()
1059+
pub fn is_compilation_going_to_fail(&self) -> Option<ErrorGuaranteed> {
1060+
if self.inner.borrow().is_compilation_going_to_fail() {
1061+
Some(ErrorGuaranteed::unchecked_claim_error_was_emitted())
1062+
} else {
1063+
None
1064+
}
10541065
}
10551066

10561067
pub fn print_error_count(&self, registry: &Registry) {
@@ -1484,6 +1495,10 @@ impl HandlerInner {
14841495
self.err_count() > 0 || self.lint_err_count > 0 || self.warn_count > 0
14851496
}
14861497

1498+
fn is_compilation_going_to_fail(&self) -> bool {
1499+
self.has_errors() || self.lint_err_count > 0 || !self.delayed_span_bugs.is_empty()
1500+
}
1501+
14871502
fn abort_if_errors(&mut self) {
14881503
self.emit_stashed_diagnostics();
14891504

compiler/rustc_incremental/src/persist/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ pub fn finalize_session_directory(sess: &Session, svh: Svh) {
322322

323323
let incr_comp_session_dir: PathBuf = sess.incr_comp_session_dir().clone();
324324

325-
if sess.has_errors_or_delayed_span_bugs() {
325+
if let Some(_) = sess.has_errors_or_delayed_span_bugs() {
326326
// If there have been any errors during compilation, we don't want to
327327
// publish this session directory. Rather, we'll just delete it.
328328

compiler/rustc_incremental/src/persist/save.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub fn save_dep_graph(tcx: TyCtxt<'_>) {
2828
return;
2929
}
3030
// This is going to be deleted in finalize_session_directory, so let's not create it
31-
if sess.has_errors_or_delayed_span_bugs() {
31+
if let Some(_) = sess.has_errors_or_delayed_span_bugs() {
3232
return;
3333
}
3434

@@ -89,7 +89,7 @@ pub fn save_work_product_index(
8989
return;
9090
}
9191
// This is going to be deleted in finalize_session_directory, so let's not create it
92-
if sess.has_errors_or_delayed_span_bugs() {
92+
if let Some(_) = sess.has_errors_or_delayed_span_bugs() {
9393
return;
9494
}
9595

compiler/rustc_middle/src/ty/visit.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ pub trait TypeVisitable<'tcx>: fmt::Debug + Clone {
9797
}
9898
fn error_reported(&self) -> Result<(), ErrorGuaranteed> {
9999
if self.references_error() {
100-
if let Some(reported) = ty::tls::with(|tcx| tcx.sess.has_errors()) {
100+
if let Some(reported) = ty::tls::with(|tcx| tcx.sess.is_compilation_going_to_fail()) {
101101
Err(reported)
102102
} else {
103-
bug!("expect tcx.sess.has_errors return true");
103+
bug!("expect tcx.sess.is_compilation_going_to_fail return `Some`");
104104
}
105105
} else {
106106
Ok(())

compiler/rustc_query_system/src/dep_graph/graph.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ impl<K: DepKind> DepGraph<K> {
667667
None => {}
668668
}
669669

670-
if !qcx.dep_context().sess().has_errors_or_delayed_span_bugs() {
670+
if let None = qcx.dep_context().sess().has_errors_or_delayed_span_bugs() {
671671
panic!("try_mark_previous_green() - Forcing the DepNode should have set its color")
672672
}
673673

compiler/rustc_session/src/session.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -538,9 +538,12 @@ impl Session {
538538
pub fn has_errors(&self) -> Option<ErrorGuaranteed> {
539539
self.diagnostic().has_errors()
540540
}
541-
pub fn has_errors_or_delayed_span_bugs(&self) -> bool {
541+
pub fn has_errors_or_delayed_span_bugs(&self) -> Option<ErrorGuaranteed> {
542542
self.diagnostic().has_errors_or_delayed_span_bugs()
543543
}
544+
pub fn is_compilation_going_to_fail(&self) -> Option<ErrorGuaranteed> {
545+
self.diagnostic().is_compilation_going_to_fail()
546+
}
544547
pub fn abort_if_errors(&self) {
545548
self.diagnostic().abort_if_errors();
546549
}

src/test/ui/consts/issue-104768.rs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const A: &_ = 0_u32;
2+
//~^ ERROR: the placeholder `_` is not allowed within types on item signatures for constants
3+
4+
fn main() {}
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants
2+
--> $DIR/issue-104768.rs:1:10
3+
|
4+
LL | const A: &_ = 0_u32;
5+
| ^^
6+
| |
7+
| not allowed in type signatures
8+
| help: replace with the correct type: `u32`
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0121`.

0 commit comments

Comments
 (0)