Skip to content

Commit 36144f2

Browse files
authored
Rollup merge of #101021 - MingyuChen1:diagnostic, r=davidtwco
Migrate ``rustc_middle`` diagnostic Part of #100717
2 parents 3f22020 + a42c0d7 commit 36144f2

File tree

7 files changed

+84
-29
lines changed

7 files changed

+84
-29
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
middle_drop_check_overflow =
2+
overflow while adding drop-check rules for {$ty}
3+
.note = overflowed on {$overflow_ty}
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
14+
15+
middle_limit_invalid =
16+
`limit` must be a non-negative integer
17+
.label = {$error_str}

compiler/rustc_error_messages/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ fluent_messages! {
4747
interface => "../locales/en-US/interface.ftl",
4848
infer => "../locales/en-US/infer.ftl",
4949
lint => "../locales/en-US/lint.ftl",
50+
middle => "../locales/en-US/middle.ftl",
5051
monomorphize => "../locales/en-US/monomorphize.ftl",
5152
metadata => "../locales/en-US/metadata.ftl",
5253
parser => "../locales/en-US/parser.ftl",

compiler/rustc_middle/src/error.rs

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
use rustc_macros::SessionDiagnostic;
2+
use rustc_span::Span;
3+
4+
use crate::ty::Ty;
5+
6+
#[derive(SessionDiagnostic)]
7+
#[diag(middle::drop_check_overflow, code = "E0320")]
8+
#[note]
9+
pub struct DropCheckOverflow<'tcx> {
10+
#[primary_span]
11+
pub span: Span,
12+
pub ty: Ty<'tcx>,
13+
pub overflow_ty: Ty<'tcx>,
14+
}
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+
}
41+
42+
#[derive(SessionDiagnostic)]
43+
#[diag(middle::limit_invalid)]
44+
pub struct LimitInvalid<'a> {
45+
#[primary_span]
46+
pub span: Span,
47+
#[label]
48+
pub value_span: Span,
49+
pub error_str: &'a str,
50+
}

compiler/rustc_middle/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ pub mod query;
8686
pub mod arena;
8787
#[macro_use]
8888
pub mod dep_graph;
89+
pub(crate) mod error;
8990
pub mod hir;
9091
pub mod infer;
9192
pub mod lint;

compiler/rustc_middle/src/middle/limits.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//! just peeks and looks for that attribute.
1111
1212
use crate::bug;
13+
use crate::error::LimitInvalid;
1314
use crate::ty;
1415
use rustc_ast::Attribute;
1516
use rustc_session::Session;
@@ -56,9 +57,6 @@ fn get_limit(krate_attrs: &[Attribute], sess: &Session, name: Symbol, default: u
5657
match s.as_str().parse() {
5758
Ok(n) => return Limit::new(n),
5859
Err(e) => {
59-
let mut err =
60-
sess.struct_span_err(attr.span, "`limit` must be a non-negative integer");
61-
6260
let value_span = attr
6361
.meta()
6462
.and_then(|meta| meta.name_value_literal_span())
@@ -74,9 +72,7 @@ fn get_limit(krate_attrs: &[Attribute], sess: &Session, name: Symbol, default: u
7472
IntErrorKind::Zero => bug!("zero is a valid `limit`"),
7573
kind => bug!("unimplemented IntErrorKind variant: {:?}", kind),
7674
};
77-
78-
err.span_label(value_span, error_str);
79-
err.emit();
75+
sess.emit_err(LimitInvalid { span: attr.span, value_span, error_str });
8076
}
8177
}
8278
}

compiler/rustc_middle/src/traits/query.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
//! The providers for the queries defined here can be found in
66
//! `rustc_traits`.
77
8+
use crate::error::DropCheckOverflow;
89
use crate::infer::canonical::{Canonical, QueryResponse};
910
use crate::ty::error::TypeError;
1011
use crate::ty::subst::GenericArg;
1112
use crate::ty::{self, Ty, TyCtxt};
12-
use rustc_errors::struct_span_err;
1313
use rustc_span::source_map::Span;
1414
use std::iter::FromIterator;
1515

@@ -117,15 +117,7 @@ pub struct DropckOutlivesResult<'tcx> {
117117
impl<'tcx> DropckOutlivesResult<'tcx> {
118118
pub fn report_overflows(&self, tcx: TyCtxt<'tcx>, span: Span, ty: Ty<'tcx>) {
119119
if let Some(overflow_ty) = self.overflows.get(0) {
120-
let mut err = struct_span_err!(
121-
tcx.sess,
122-
span,
123-
E0320,
124-
"overflow while adding drop-check rules for {}",
125-
ty,
126-
);
127-
err.note(&format!("overflowed on {}", overflow_ty));
128-
err.emit();
120+
tcx.sess.emit_err(DropCheckOverflow { span, ty, overflow_ty: *overflow_ty });
129121
}
130122
}
131123

compiler/rustc_middle/src/ty/mod.rs

+11-13
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};
@@ -1179,20 +1180,17 @@ pub struct OpaqueHiddenType<'tcx> {
11791180
impl<'tcx> OpaqueHiddenType<'tcx> {
11801181
pub fn report_mismatch(&self, other: &Self, tcx: TyCtxt<'tcx>) {
11811182
// Found different concrete types for the opaque type.
1182-
let mut err = tcx.sess.struct_span_err(
1183-
other.span,
1184-
"concrete type differs from previous defining opaque type use",
1185-
);
1186-
err.span_label(other.span, format!("expected `{}`, got `{}`", self.ty, other.ty));
1187-
if self.span == other.span {
1188-
err.span_label(
1189-
self.span,
1190-
"this expression supplies two conflicting concrete types for the same opaque type",
1191-
);
1183+
let sub_diag = if self.span == other.span {
1184+
TypeMismatchReason::ConflictType { span: self.span }
11921185
} else {
1193-
err.span_note(self.span, "previous use here");
1194-
}
1195-
err.emit();
1186+
TypeMismatchReason::PreviousUse { span: self.span }
1187+
};
1188+
tcx.sess.emit_err(OpaqueHiddenTypeMismatch {
1189+
self_ty: self.ty,
1190+
other_ty: other.ty,
1191+
other_span: other.span,
1192+
sub: sub_diag,
1193+
});
11961194
}
11971195
}
11981196

0 commit comments

Comments
 (0)