From 3e834a7a6295127fe2a5dd8605c7903ad7e5918d Mon Sep 17 00:00:00 2001 From: 111 Date: Fri, 26 Aug 2022 11:24:09 +0800 Subject: [PATCH] Migrate DropCheckOverflow --- .../rustc_error_messages/locales/en-US/middle.ftl | 3 +++ compiler/rustc_error_messages/src/lib.rs | 1 + compiler/rustc_middle/src/error.rs | 14 ++++++++++++++ compiler/rustc_middle/src/lib.rs | 1 + compiler/rustc_middle/src/traits/query.rs | 13 +++---------- 5 files changed, 22 insertions(+), 10 deletions(-) create mode 100644 compiler/rustc_error_messages/locales/en-US/middle.ftl create mode 100644 compiler/rustc_middle/src/error.rs diff --git a/compiler/rustc_error_messages/locales/en-US/middle.ftl b/compiler/rustc_error_messages/locales/en-US/middle.ftl new file mode 100644 index 00000000000..f2864ec4922 --- /dev/null +++ b/compiler/rustc_error_messages/locales/en-US/middle.ftl @@ -0,0 +1,3 @@ +middle_drop_check_overflow = + overflow while adding drop-check rules for {$ty} + .note = {$note} diff --git a/compiler/rustc_error_messages/src/lib.rs b/compiler/rustc_error_messages/src/lib.rs index 8f47be25db9..ebd56b4e084 100644 --- a/compiler/rustc_error_messages/src/lib.rs +++ b/compiler/rustc_error_messages/src/lib.rs @@ -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", diff --git a/compiler/rustc_middle/src/error.rs b/compiler/rustc_middle/src/error.rs new file mode 100644 index 00000000000..d81eb524169 --- /dev/null +++ b/compiler/rustc_middle/src/error.rs @@ -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, +} diff --git a/compiler/rustc_middle/src/lib.rs b/compiler/rustc_middle/src/lib.rs index be9e5865e54..1e3a6bcfc7d 100644 --- a/compiler/rustc_middle/src/lib.rs +++ b/compiler/rustc_middle/src/lib.rs @@ -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; diff --git a/compiler/rustc_middle/src/traits/query.rs b/compiler/rustc_middle/src/traits/query.rs index 1f9b474ade1..8002f928613 100644 --- a/compiler/rustc_middle/src/traits/query.rs +++ b/compiler/rustc_middle/src/traits/query.rs @@ -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 }); } }