Skip to content

Commit 46753b1

Browse files
Convert to inline diagnostics in rustc_middle
1 parent 0a13b43 commit 46753b1

File tree

9 files changed

+102
-202
lines changed

9 files changed

+102
-202
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4262,7 +4262,6 @@ dependencies = [
42624262
"rustc_error_messages",
42634263
"rustc_errors",
42644264
"rustc_feature",
4265-
"rustc_fluent_macro",
42664265
"rustc_graphviz",
42674266
"rustc_hashes",
42684267
"rustc_hir",

compiler/rustc_driver_impl/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ pub static DEFAULT_LOCALE_RESOURCES: &[&str] = &[
121121
rustc_errors::DEFAULT_LOCALE_RESOURCE,
122122
rustc_hir_analysis::DEFAULT_LOCALE_RESOURCE,
123123
rustc_lint::DEFAULT_LOCALE_RESOURCE,
124-
rustc_middle::DEFAULT_LOCALE_RESOURCE,
125124
rustc_mir_build::DEFAULT_LOCALE_RESOURCE,
126125
rustc_parse::DEFAULT_LOCALE_RESOURCE,
127126
rustc_passes::DEFAULT_LOCALE_RESOURCE,

compiler/rustc_middle/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ rustc_data_structures = { path = "../rustc_data_structures" }
1818
rustc_error_messages = { path = "../rustc_error_messages" } # Used for intra-doc links
1919
rustc_errors = { path = "../rustc_errors" }
2020
rustc_feature = { path = "../rustc_feature" }
21-
rustc_fluent_macro = { path = "../rustc_fluent_macro" }
2221
rustc_graphviz = { path = "../rustc_graphviz" }
2322
rustc_hashes = { path = "../rustc_hashes" }
2423
rustc_hir = { path = "../rustc_hir" }

compiler/rustc_middle/messages.ftl

Lines changed: 0 additions & 133 deletions
This file was deleted.

compiler/rustc_middle/src/error.rs

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use rustc_span::{Span, Symbol};
99
use crate::ty::{Instance, Ty};
1010

1111
#[derive(Diagnostic)]
12-
#[diag(middle_drop_check_overflow, code = E0320)]
13-
#[note]
12+
#[diag("overflow while adding drop-check rules for `{$ty}`", code = E0320)]
13+
#[note("overflowed on `{$overflow_ty}`")]
1414
pub(crate) struct DropCheckOverflow<'tcx> {
1515
#[primary_span]
1616
pub span: Span,
@@ -19,33 +19,33 @@ pub(crate) struct DropCheckOverflow<'tcx> {
1919
}
2020

2121
#[derive(Diagnostic)]
22-
#[diag(middle_failed_writing_file)]
22+
#[diag("failed to write file {$path}: {$error}\"")]
2323
pub(crate) struct FailedWritingFile<'a> {
2424
pub path: &'a Path,
2525
pub error: io::Error,
2626
}
2727

2828
#[derive(Diagnostic)]
29-
#[diag(middle_opaque_hidden_type_mismatch)]
29+
#[diag("concrete type differs from previous defining opaque type use")]
3030
pub(crate) struct OpaqueHiddenTypeMismatch<'tcx> {
3131
pub self_ty: Ty<'tcx>,
3232
pub other_ty: Ty<'tcx>,
3333
#[primary_span]
34-
#[label]
34+
#[label("expected `{$self_ty}`, got `{$other_ty}`")]
3535
pub other_span: Span,
3636
#[subdiagnostic]
3737
pub sub: TypeMismatchReason,
3838
}
3939

4040
#[derive(Diagnostic)]
41-
#[diag(middle_unsupported_union)]
41+
#[diag("we don't support unions yet: '{$ty_name}'")]
4242
pub struct UnsupportedUnion {
4343
pub ty_name: String,
4444
}
4545

4646
// FIXME(autodiff): I should get used somewhere
4747
#[derive(Diagnostic)]
48-
#[diag(middle_autodiff_unsafe_inner_const_ref)]
48+
#[diag("reading from a `Duplicated` const {$ty} is unsafe")]
4949
pub struct AutodiffUnsafeInnerConstRef<'tcx> {
5050
#[primary_span]
5151
pub span: Span,
@@ -54,21 +54,23 @@ pub struct AutodiffUnsafeInnerConstRef<'tcx> {
5454

5555
#[derive(Subdiagnostic)]
5656
pub enum TypeMismatchReason {
57-
#[label(middle_conflict_types)]
57+
#[label("this expression supplies two conflicting concrete types for the same opaque type")]
5858
ConflictType {
5959
#[primary_span]
6060
span: Span,
6161
},
62-
#[note(middle_previous_use_here)]
62+
#[note("previous use here")]
6363
PreviousUse {
6464
#[primary_span]
6565
span: Span,
6666
},
6767
}
6868

6969
#[derive(Diagnostic)]
70-
#[diag(middle_recursion_limit_reached)]
71-
#[help]
70+
#[diag("reached the recursion limit finding the struct tail for `{$ty}`")]
71+
#[help(
72+
"consider increasing the recursion limit by adding a `#![recursion_limit = \"{$suggested_limit}\"]`"
73+
)]
7274
pub(crate) struct RecursionLimitReached<'tcx> {
7375
#[primary_span]
7476
pub span: Span,
@@ -77,31 +79,35 @@ pub(crate) struct RecursionLimitReached<'tcx> {
7779
}
7880

7981
#[derive(Diagnostic)]
80-
#[diag(middle_const_eval_non_int)]
82+
#[diag("constant evaluation of enum discriminant resulted in non-integer")]
8183
pub(crate) struct ConstEvalNonIntError {
8284
#[primary_span]
8385
pub span: Span,
8486
}
8587

8688
#[derive(Diagnostic)]
87-
#[diag(middle_strict_coherence_needs_negative_coherence)]
89+
#[diag(
90+
"to use `strict_coherence` on this trait, the `with_negative_coherence` feature must be enabled"
91+
)]
8892
pub(crate) struct StrictCoherenceNeedsNegativeCoherence {
8993
#[primary_span]
9094
pub span: Span,
91-
#[label]
95+
#[label("due to this attribute")]
9296
pub attr_span: Option<Span>,
9397
}
9498

9599
#[derive(Diagnostic)]
96-
#[diag(middle_requires_lang_item)]
100+
#[diag("requires `{$name}` lang_item")]
97101
pub(crate) struct RequiresLangItem {
98102
#[primary_span]
99103
pub span: Span,
100104
pub name: Symbol,
101105
}
102106

103107
#[derive(Diagnostic)]
104-
#[diag(middle_const_not_used_in_type_alias)]
108+
#[diag(
109+
"const parameter `{$ct}` is part of concrete type but not used in parameter list for the `impl Trait` type alias"
110+
)]
105111
pub(super) struct ConstNotUsedTraitAlias {
106112
pub ct: String,
107113
#[primary_span]
@@ -133,41 +139,41 @@ impl fmt::Debug for CustomSubdiagnostic<'_> {
133139

134140
#[derive(Diagnostic)]
135141
pub enum LayoutError<'tcx> {
136-
#[diag(middle_layout_unknown)]
142+
#[diag("the type `{$ty}` has an unknown layout")]
137143
Unknown { ty: Ty<'tcx> },
138144

139-
#[diag(middle_layout_too_generic)]
145+
#[diag("the type `{$ty}` does not have a fixed layout")]
140146
TooGeneric { ty: Ty<'tcx> },
141147

142-
#[diag(middle_layout_size_overflow)]
148+
#[diag("values of the type `{$ty}` are too big for the target architecture")]
143149
Overflow { ty: Ty<'tcx> },
144150

145-
#[diag(middle_layout_simd_too_many)]
151+
#[diag("the SIMD type `{$ty}` has more elements than the limit {$max_lanes}")]
146152
SimdTooManyLanes { ty: Ty<'tcx>, max_lanes: u64 },
147153

148-
#[diag(middle_layout_simd_zero_length)]
154+
#[diag("the SIMD type `{$ty}` has zero elements")]
149155
SimdZeroLength { ty: Ty<'tcx> },
150156

151-
#[diag(middle_layout_normalization_failure)]
157+
#[diag("unable to determine layout for `{$ty}` because `{$failure_ty}` cannot be normalized")]
152158
NormalizationFailure { ty: Ty<'tcx>, failure_ty: String },
153159

154-
#[diag(middle_layout_cycle)]
160+
#[diag("a cycle occurred during layout computation")]
155161
Cycle,
156162

157-
#[diag(middle_layout_references_error)]
163+
#[diag("the type has an unknown layout")]
158164
ReferencesError,
159165
}
160166

161167
#[derive(Diagnostic)]
162-
#[diag(middle_erroneous_constant)]
168+
#[diag("erroneous constant encountered")]
163169
pub(crate) struct ErroneousConstant {
164170
#[primary_span]
165171
pub span: Span,
166172
}
167173

168174
#[derive(Diagnostic)]
169-
#[diag(middle_type_length_limit)]
170-
#[help(middle_consider_type_length_limit)]
175+
#[diag("reached the type-length limit while instantiating `{$instance}`")]
176+
#[help("consider adding a `#![type_length_limit=\"{$type_length}\"]` attribute to your crate")]
171177
pub(crate) struct TypeLengthLimit<'tcx> {
172178
#[primary_span]
173179
pub span: Span,
@@ -176,16 +182,16 @@ pub(crate) struct TypeLengthLimit<'tcx> {
176182
}
177183

178184
#[derive(Diagnostic)]
179-
#[diag(middle_max_num_nodes_in_valtree)]
185+
#[diag("maximum number of nodes exceeded in constant {$global_const_id}")]
180186
pub(crate) struct MaxNumNodesInValtree {
181187
#[primary_span]
182188
pub span: Span,
183189
pub global_const_id: String,
184190
}
185191

186192
#[derive(Diagnostic)]
187-
#[diag(middle_invalid_const_in_valtree)]
188-
#[note]
193+
#[diag("constant {$global_const_id} cannot be used as pattern")]
194+
#[note("constants that reference mutable or external memory cannot be used as patterns")]
189195
pub(crate) struct InvalidConstInValtree {
190196
#[primary_span]
191197
pub span: Span,

compiler/rustc_middle/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,3 @@ pub mod dep_graph;
9191

9292
// Allows macros to refer to this crate as `::rustc_middle`
9393
extern crate self as rustc_middle;
94-
95-
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }

compiler/rustc_middle/src/middle/stability.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use std::num::NonZero;
55

66
use rustc_ast::NodeId;
7-
use rustc_errors::{Applicability, Diag, EmissionGuarantee, LintBuffer};
7+
use rustc_errors::{Applicability, Diag, EmissionGuarantee, LintBuffer, inline_fluent};
88
use rustc_feature::GateIssue;
99
use rustc_hir::attrs::{DeprecatedSince, Deprecation};
1010
use rustc_hir::def_id::{DefId, LocalDefId};
@@ -103,7 +103,7 @@ fn deprecation_lint(is_in_effect: bool) -> &'static Lint {
103103

104104
#[derive(Subdiagnostic)]
105105
#[suggestion(
106-
middle_deprecated_suggestion,
106+
"replace the use of the deprecated {$kind}",
107107
code = "{suggestion}",
108108
style = "verbose",
109109
applicability = "machine-applicable"
@@ -128,10 +128,19 @@ pub struct Deprecated {
128128
impl<'a, G: EmissionGuarantee> rustc_errors::LintDiagnostic<'a, G> for Deprecated {
129129
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, G>) {
130130
diag.primary_message(match &self.since_kind {
131-
DeprecatedSinceKind::InEffect => crate::fluent_generated::middle_deprecated,
132-
DeprecatedSinceKind::InFuture => crate::fluent_generated::middle_deprecated_in_future,
131+
DeprecatedSinceKind::InEffect => inline_fluent!("use of deprecated {$kind} `{$path}`{$has_note ->
132+
[true] : {$note}
133+
*[other] {\"\"}
134+
}"),
135+
DeprecatedSinceKind::InFuture => inline_fluent!("use of {$kind} `{$path}` that will be deprecated in a future Rust version{$has_note ->
136+
[true] : {$note}
137+
*[other] {\"\"}
138+
}"),
133139
DeprecatedSinceKind::InVersion(_) => {
134-
crate::fluent_generated::middle_deprecated_in_version
140+
inline_fluent!("use of {$kind} `{$path}` that will be deprecated in future version {$version}{$has_note ->
141+
[true] : {$note}
142+
*[other] {\"\"}
143+
}")
135144
}
136145
});
137146
diag.arg("kind", self.kind);

0 commit comments

Comments
 (0)