Skip to content

Migrate rustc_middle diagnostic #101021

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Migrate OpaqueHiddenType mismatch
  • Loading branch information
MingyuChen1 committed Sep 1, 2022
commit 00cd965046f6f3e9fcf937bf1f6fec4d7f8d50ca
10 changes: 10 additions & 0 deletions compiler/rustc_error_messages/locales/en-US/middle.ftl
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
middle_drop_check_overflow =
overflow while adding drop-check rules for {$ty}
.note = {$note}

middle_opaque_hidden_type_mismatch =
concrete type differs from previous defining opaque type use
.label = expected `{$self_ty}`, got `{$other_ty}`

middle_conflict_types =
this expression supplies two conflicting concrete types for the same opaque type

middle_previous_use_here =
previous use here
26 changes: 26 additions & 0 deletions compiler/rustc_middle/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,29 @@ pub struct DropCheckOverflow<'tcx> {
pub ty: Ty<'tcx>,
pub note: String,
}

#[derive(SessionDiagnostic)]
#[diag(middle::opaque_hidden_type_mismatch)]
pub struct OpaqueHiddenTypeMismatch<'tcx> {
pub self_ty: Ty<'tcx>,
pub other_ty: Ty<'tcx>,
#[primary_span]
#[label]
pub other_span: Span,
#[subdiagnostic]
pub sub: TypeMismatchReason,
}

#[derive(SessionSubdiagnostic)]
pub enum TypeMismatchReason {
#[label(middle::conflict_types)]
ConflictType {
#[primary_span]
span: Span,
},
#[note(middle::previous_use_here)]
PreviousUse {
#[primary_span]
span: Span,
},
}
24 changes: 11 additions & 13 deletions compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub use self::AssocItemContainer::*;
pub use self::BorrowKind::*;
pub use self::IntVarValue::*;
pub use self::Variance::*;
use crate::error::{OpaqueHiddenTypeMismatch, TypeMismatchReason};
use crate::metadata::ModChild;
use crate::middle::privacy::AccessLevels;
use crate::mir::{Body, GeneratorLayout};
Expand Down Expand Up @@ -1184,20 +1185,17 @@ pub struct OpaqueHiddenType<'tcx> {
impl<'tcx> OpaqueHiddenType<'tcx> {
pub fn report_mismatch(&self, other: &Self, tcx: TyCtxt<'tcx>) {
// Found different concrete types for the opaque type.
let mut err = tcx.sess.struct_span_err(
other.span,
"concrete type differs from previous defining opaque type use",
);
err.span_label(other.span, format!("expected `{}`, got `{}`", self.ty, other.ty));
if self.span == other.span {
err.span_label(
self.span,
"this expression supplies two conflicting concrete types for the same opaque type",
);
let sub_diag = if self.span == other.span {
TypeMismatchReason::ConflictType { span: self.span }
} else {
err.span_note(self.span, "previous use here");
}
err.emit();
TypeMismatchReason::PreviousUse { span: self.span }
};
tcx.sess.emit_err(OpaqueHiddenTypeMismatch {
self_ty: self.ty,
other_ty: other.ty,
other_span: other.span,
sub: sub_diag,
});
}
}

Expand Down