Skip to content

Commit

Permalink
Don't cancel stashed OpaqueHiddenTypeMismatch errors.
Browse files Browse the repository at this point in the history
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.)
  • Loading branch information
nnethercote committed Feb 27, 2024
1 parent 829308e commit a1b356a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
7 changes: 6 additions & 1 deletion compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -846,12 +846,17 @@ impl<'tcx> OpaqueHiddenType<'tcx> {
opaque_def_id: LocalDefId,
tcx: TyCtxt<'tcx>,
) -> Result<DiagnosticBuilder<'tcx>, ErrorGuaranteed> {

if let Some(diag) = tcx
.sess
.dcx()
.steal_diagnostic(tcx.def_span(opaque_def_id), StashKey::OpaqueHiddenTypeMismatch)
{
diag.cancel();
// We used to cancel here for slightly better error messages, but
// cancelling stashed diagnostics is no longer allowed because it
// causes problems when tracking whether errors have actually
// occurred.
diag.emit();
}
(self.ty, other.ty).error_reported()?;
// Found different concrete types for the opaque type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ fn foo<'a, 'b>() -> Tait<'a> {
}
let x: Tait<'a> = ();
x
//~^ ERROR concrete type differs from previous defining opaque type use
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
error: concrete type differs from previous defining opaque type use
--> $DIR/different_defining_uses_never_type-2.rs:13:5
|
LL | x
| ^ expected `i32`, got `()`
|
note: previous use here
--> $DIR/different_defining_uses_never_type-2.rs:8:31
|
LL | let y: Tait<'b> = 1i32;
| ^^^^

error: concrete type differs from previous defining opaque type use
--> $DIR/different_defining_uses_never_type-2.rs:8:31
|
Expand All @@ -10,5 +22,5 @@ note: previous use here
LL | if { return } {
| ^^^^^^

error: aborting due to 1 previous error
error: aborting due to 2 previous errors

0 comments on commit a1b356a

Please sign in to comment.