Migrate DropCheckOverflow

This commit is contained in:
111 2022-08-26 11:24:09 +08:00
parent 4f9898a794
commit 3e834a7a62
5 changed files with 22 additions and 10 deletions

View File

@ -0,0 +1,3 @@
middle_drop_check_overflow =
overflow while adding drop-check rules for {$ty}
.note = {$note}

View File

@ -45,6 +45,7 @@ fluent_messages! {
interface => "../locales/en-US/interface.ftl",
infer => "../locales/en-US/infer.ftl",
lint => "../locales/en-US/lint.ftl",
middle => "../locales/en-US/middle.ftl",
monomorphize => "../locales/en-US/monomorphize.ftl",
parser => "../locales/en-US/parser.ftl",
passes => "../locales/en-US/passes.ftl",

View File

@ -0,0 +1,14 @@
use rustc_macros::SessionDiagnostic;
use rustc_span::Span;
use crate::ty::Ty;
#[derive(SessionDiagnostic)]
#[diag(middle::drop_check_overflow, code = "E0320")]
#[note]
pub struct DropCheckOverflow<'tcx> {
#[primary_span]
pub span: Span,
pub ty: Ty<'tcx>,
pub note: String,
}

View File

@ -86,6 +86,7 @@ pub mod query;
pub mod arena;
#[macro_use]
pub mod dep_graph;
pub(crate) mod error;
pub mod hir;
pub mod infer;
pub mod lint;

View File

@ -5,11 +5,11 @@
//! The providers for the queries defined here can be found in
//! `rustc_traits`.
use crate::error::DropCheckOverflow;
use crate::infer::canonical::{Canonical, QueryResponse};
use crate::ty::error::TypeError;
use crate::ty::subst::GenericArg;
use crate::ty::{self, Ty, TyCtxt};
use rustc_errors::struct_span_err;
use rustc_span::source_map::Span;
use std::iter::FromIterator;
@ -117,15 +117,8 @@ pub struct DropckOutlivesResult<'tcx> {
impl<'tcx> DropckOutlivesResult<'tcx> {
pub fn report_overflows(&self, tcx: TyCtxt<'tcx>, span: Span, ty: Ty<'tcx>) {
if let Some(overflow_ty) = self.overflows.get(0) {
let mut err = struct_span_err!(
tcx.sess,
span,
E0320,
"overflow while adding drop-check rules for {}",
ty,
);
err.note(&format!("overflowed on {}", overflow_ty));
err.emit();
let note = format!("overflowed on {}", overflow_ty);
tcx.sess.emit_err(DropCheckOverflow { span, ty, note });
}
}