Skip to content

Commit f9c1ceb

Browse files
committed
Don't cancel stashed OpaqueHiddenTypeMismatch errors.
This gives one extra error message on one test, but is necessary to fix bigger problems caused by the cancellation of stashed errors. (Note: why not just avoid stashing altogether? Because that resulted in additional output changes.)
1 parent 1e4f9e3 commit f9c1ceb

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

compiler/rustc_middle/src/ty/mod.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -846,12 +846,17 @@ impl<'tcx> OpaqueHiddenType<'tcx> {
846846
opaque_def_id: LocalDefId,
847847
tcx: TyCtxt<'tcx>,
848848
) -> Result<DiagnosticBuilder<'tcx>, ErrorGuaranteed> {
849+
849850
if let Some(diag) = tcx
850851
.sess
851852
.dcx()
852853
.steal_diagnostic(tcx.def_span(opaque_def_id), StashKey::OpaqueHiddenTypeMismatch)
853854
{
854-
diag.cancel();
855+
// We used to cancel here for slightly better error messages, but
856+
// cancelling stashed diagnostics is no longer allowed because it
857+
// causes problems when tracking whether errors have actually
858+
// occurred.
859+
diag.emit();
855860
}
856861
(self.ty, other.ty).error_reported()?;
857862
// Found different concrete types for the opaque type.

tests/ui/type-alias-impl-trait/different_defining_uses_never_type-2.rs

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ fn foo<'a, 'b>() -> Tait<'a> {
1111
}
1212
let x: Tait<'a> = ();
1313
x
14+
//~^ ERROR concrete type differs from previous defining opaque type use
1415
}
1516

1617
fn main() {}

tests/ui/type-alias-impl-trait/different_defining_uses_never_type-2.stderr

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
error: concrete type differs from previous defining opaque type use
2+
--> $DIR/different_defining_uses_never_type-2.rs:13:5
3+
|
4+
LL | x
5+
| ^ expected `i32`, got `()`
6+
|
7+
note: previous use here
8+
--> $DIR/different_defining_uses_never_type-2.rs:8:31
9+
|
10+
LL | let y: Tait<'b> = 1i32;
11+
| ^^^^
12+
113
error: concrete type differs from previous defining opaque type use
214
--> $DIR/different_defining_uses_never_type-2.rs:8:31
315
|
@@ -10,5 +22,5 @@ note: previous use here
1022
LL | if { return } {
1123
| ^^^^^^
1224

13-
error: aborting due to 1 previous error
25+
error: aborting due to 2 previous errors
1426

0 commit comments

Comments
 (0)