Skip to content

Commit 00cd965

Browse files
committed
Migrate OpaqueHiddenType mismatch
1 parent 3e834a7 commit 00cd965

File tree

3 files changed

+47
-13
lines changed

3 files changed

+47
-13
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
11
middle_drop_check_overflow =
22
overflow while adding drop-check rules for {$ty}
33
.note = {$note}
4+
5+
middle_opaque_hidden_type_mismatch =
6+
concrete type differs from previous defining opaque type use
7+
.label = expected `{$self_ty}`, got `{$other_ty}`
8+
9+
middle_conflict_types =
10+
this expression supplies two conflicting concrete types for the same opaque type
11+
12+
middle_previous_use_here =
13+
previous use here

compiler/rustc_middle/src/error.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,29 @@ pub struct DropCheckOverflow<'tcx> {
1212
pub ty: Ty<'tcx>,
1313
pub note: String,
1414
}
15+
16+
#[derive(SessionDiagnostic)]
17+
#[diag(middle::opaque_hidden_type_mismatch)]
18+
pub struct OpaqueHiddenTypeMismatch<'tcx> {
19+
pub self_ty: Ty<'tcx>,
20+
pub other_ty: Ty<'tcx>,
21+
#[primary_span]
22+
#[label]
23+
pub other_span: Span,
24+
#[subdiagnostic]
25+
pub sub: TypeMismatchReason,
26+
}
27+
28+
#[derive(SessionSubdiagnostic)]
29+
pub enum TypeMismatchReason {
30+
#[label(middle::conflict_types)]
31+
ConflictType {
32+
#[primary_span]
33+
span: Span,
34+
},
35+
#[note(middle::previous_use_here)]
36+
PreviousUse {
37+
#[primary_span]
38+
span: Span,
39+
},
40+
}

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub use self::AssocItemContainer::*;
1515
pub use self::BorrowKind::*;
1616
pub use self::IntVarValue::*;
1717
pub use self::Variance::*;
18+
use crate::error::{OpaqueHiddenTypeMismatch, TypeMismatchReason};
1819
use crate::metadata::ModChild;
1920
use crate::middle::privacy::AccessLevels;
2021
use crate::mir::{Body, GeneratorLayout};
@@ -1184,20 +1185,17 @@ pub struct OpaqueHiddenType<'tcx> {
11841185
impl<'tcx> OpaqueHiddenType<'tcx> {
11851186
pub fn report_mismatch(&self, other: &Self, tcx: TyCtxt<'tcx>) {
11861187
// Found different concrete types for the opaque type.
1187-
let mut err = tcx.sess.struct_span_err(
1188-
other.span,
1189-
"concrete type differs from previous defining opaque type use",
1190-
);
1191-
err.span_label(other.span, format!("expected `{}`, got `{}`", self.ty, other.ty));
1192-
if self.span == other.span {
1193-
err.span_label(
1194-
self.span,
1195-
"this expression supplies two conflicting concrete types for the same opaque type",
1196-
);
1188+
let sub_diag = if self.span == other.span {
1189+
TypeMismatchReason::ConflictType { span: self.span }
11971190
} else {
1198-
err.span_note(self.span, "previous use here");
1199-
}
1200-
err.emit();
1191+
TypeMismatchReason::PreviousUse { span: self.span }
1192+
};
1193+
tcx.sess.emit_err(OpaqueHiddenTypeMismatch {
1194+
self_ty: self.ty,
1195+
other_ty: other.ty,
1196+
other_span: other.span,
1197+
sub: sub_diag,
1198+
});
12011199
}
12021200
}
12031201

0 commit comments

Comments
 (0)