Skip to content

Commit 43a89a8

Browse files
Rollup merge of rust-lang#152072 - JonathanBrouwer:convert_monomorphize, r=jdonszelmann
Convert to inline diagnostics in `rustc_monomorphize` For rust-lang#151366 r? @jdonszelmann
2 parents d74808d + d457ffd commit 43a89a8

File tree

7 files changed

+82
-116
lines changed

7 files changed

+82
-116
lines changed

Cargo.lock

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3799,7 +3799,6 @@ dependencies = [
37993799
"rustc_middle",
38003800
"rustc_mir_build",
38013801
"rustc_mir_transform",
3802-
"rustc_monomorphize",
38033802
"rustc_parse",
38043803
"rustc_passes",
38053804
"rustc_privacy",
@@ -4373,7 +4372,6 @@ dependencies = [
43734372
"rustc_abi",
43744373
"rustc_data_structures",
43754374
"rustc_errors",
4376-
"rustc_fluent_macro",
43774375
"rustc_hir",
43784376
"rustc_index",
43794377
"rustc_macros",

compiler/rustc_driver_impl/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ rustc_metadata = { path = "../rustc_metadata" }
3333
rustc_middle = { path = "../rustc_middle" }
3434
rustc_mir_build = { path = "../rustc_mir_build" }
3535
rustc_mir_transform = { path = "../rustc_mir_transform" }
36-
rustc_monomorphize = { path = "../rustc_monomorphize" }
3736
rustc_parse = { path = "../rustc_parse" }
3837
rustc_passes = { path = "../rustc_passes" }
3938
rustc_privacy = { path = "../rustc_privacy" }

compiler/rustc_driver_impl/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ pub static DEFAULT_LOCALE_RESOURCES: &[&str] = &[
130130
rustc_middle::DEFAULT_LOCALE_RESOURCE,
131131
rustc_mir_build::DEFAULT_LOCALE_RESOURCE,
132132
rustc_mir_transform::DEFAULT_LOCALE_RESOURCE,
133-
rustc_monomorphize::DEFAULT_LOCALE_RESOURCE,
134133
rustc_parse::DEFAULT_LOCALE_RESOURCE,
135134
rustc_passes::DEFAULT_LOCALE_RESOURCE,
136135
rustc_privacy::DEFAULT_LOCALE_RESOURCE,

compiler/rustc_monomorphize/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ edition = "2024"
88
rustc_abi = { path = "../rustc_abi" }
99
rustc_data_structures = { path = "../rustc_data_structures" }
1010
rustc_errors = { path = "../rustc_errors" }
11-
rustc_fluent_macro = { path = "../rustc_fluent_macro" }
1211
rustc_hir = { path = "../rustc_hir" }
1312
rustc_index = { path = "../rustc_index" }
1413
rustc_macros = { path = "../rustc_macros" }

compiler/rustc_monomorphize/messages.ftl

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

compiler/rustc_monomorphize/src/errors.rs

Lines changed: 82 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,51 +3,55 @@ use rustc_middle::ty::{Instance, Ty};
33
use rustc_span::{Span, Symbol};
44

55
#[derive(Diagnostic)]
6-
#[diag(monomorphize_recursion_limit)]
6+
#[diag("reached the recursion limit while instantiating `{$instance}`")]
77
pub(crate) struct RecursionLimit<'tcx> {
88
#[primary_span]
99
pub span: Span,
1010
pub instance: Instance<'tcx>,
11-
#[note]
11+
#[note("`{$def_path_str}` defined here")]
1212
pub def_span: Span,
1313
pub def_path_str: String,
1414
}
1515

1616
#[derive(Diagnostic)]
17-
#[diag(monomorphize_no_optimized_mir)]
17+
#[diag("missing optimized MIR for `{$instance}` in the crate `{$crate_name}`")]
1818
pub(crate) struct NoOptimizedMir {
19-
#[note]
19+
#[note(
20+
"missing optimized MIR for this item (was the crate `{$crate_name}` compiled with `--emit=metadata`?)"
21+
)]
2022
pub span: Span,
2123
pub crate_name: Symbol,
2224
pub instance: String,
2325
}
2426

2527
#[derive(LintDiagnostic)]
26-
#[diag(monomorphize_large_assignments)]
27-
#[note]
28+
#[diag("moving {$size} bytes")]
29+
#[note(
30+
"the current maximum size is {$limit}, but it can be customized with the move_size_limit attribute: `#![move_size_limit = \"...\"]`"
31+
)]
2832
pub(crate) struct LargeAssignmentsLint {
29-
#[label]
33+
#[label("value moved from here")]
3034
pub span: Span,
3135
pub size: u64,
3236
pub limit: u64,
3337
}
3438

3539
#[derive(Diagnostic)]
36-
#[diag(monomorphize_symbol_already_defined)]
40+
#[diag("symbol `{$symbol}` is already defined")]
3741
pub(crate) struct SymbolAlreadyDefined {
3842
#[primary_span]
3943
pub span: Option<Span>,
4044
pub symbol: String,
4145
}
4246

4347
#[derive(Diagnostic)]
44-
#[diag(monomorphize_couldnt_dump_mono_stats)]
48+
#[diag("unexpected error occurred while dumping monomorphization stats: {$error}")]
4549
pub(crate) struct CouldntDumpMonoStats {
4650
pub error: String,
4751
}
4852

4953
#[derive(Diagnostic)]
50-
#[diag(monomorphize_encountered_error_while_instantiating)]
54+
#[diag("the above error was encountered while instantiating `{$kind} {$instance}`")]
5155
pub(crate) struct EncounteredErrorWhileInstantiating<'tcx> {
5256
#[primary_span]
5357
pub span: Span,
@@ -56,23 +60,41 @@ pub(crate) struct EncounteredErrorWhileInstantiating<'tcx> {
5660
}
5761

5862
#[derive(Diagnostic)]
59-
#[diag(monomorphize_encountered_error_while_instantiating_global_asm)]
63+
#[diag("the above error was encountered while instantiating `global_asm`")]
6064
pub(crate) struct EncounteredErrorWhileInstantiatingGlobalAsm {
6165
#[primary_span]
6266
pub span: Span,
6367
}
6468

6569
#[derive(Diagnostic)]
66-
#[diag(monomorphize_start_not_found)]
67-
#[help]
70+
#[diag("using `fn main` requires the standard library")]
71+
#[help(
72+
"use `#![no_main]` to bypass the Rust generated entrypoint and declare a platform specific entrypoint yourself, usually with `#[no_mangle]`"
73+
)]
6874
pub(crate) struct StartNotFound;
6975

7076
#[derive(Diagnostic)]
71-
#[diag(monomorphize_abi_error_disabled_vector_type)]
72-
#[help]
77+
#[diag("this function {$is_call ->
78+
[true] call
79+
*[false] definition
80+
} uses {$is_scalable ->
81+
[true] scalable
82+
*[false] SIMD
83+
} vector type `{$ty}` which (with the chosen ABI) requires the `{$required_feature}` target feature, which is not enabled{$is_call ->
84+
[true] {\" \"}in the caller
85+
*[false] {\"\"}
86+
}")]
87+
#[help(
88+
"consider enabling it globally (`-C target-feature=+{$required_feature}`) or locally (`#[target_feature(enable=\"{$required_feature}\")]`)"
89+
)]
7390
pub(crate) struct AbiErrorDisabledVectorType<'a> {
7491
#[primary_span]
75-
#[label]
92+
#[label(
93+
"function {$is_call ->
94+
[true] called
95+
*[false] defined
96+
} here"
97+
)]
7698
pub span: Span,
7799
pub required_feature: &'a str,
78100
pub ty: Ty<'a>,
@@ -83,34 +105,67 @@ pub(crate) struct AbiErrorDisabledVectorType<'a> {
83105
}
84106

85107
#[derive(Diagnostic)]
86-
#[diag(monomorphize_abi_error_unsupported_unsized_parameter)]
87-
#[help]
108+
#[diag(
109+
"this function {$is_call ->
110+
[true] call
111+
*[false] definition
112+
} uses unsized type `{$ty}` which is not supported with the chosen ABI"
113+
)]
114+
#[help("only rustic ABIs support unsized parameters")]
88115
pub(crate) struct AbiErrorUnsupportedUnsizedParameter<'a> {
89116
#[primary_span]
90-
#[label]
117+
#[label(
118+
"function {$is_call ->
119+
[true] called
120+
*[false] defined
121+
} here"
122+
)]
91123
pub span: Span,
92124
pub ty: Ty<'a>,
93125
/// Whether this is a problem at a call site or at a declaration.
94126
pub is_call: bool,
95127
}
96128

97129
#[derive(Diagnostic)]
98-
#[diag(monomorphize_abi_error_unsupported_vector_type)]
130+
#[diag(
131+
"this function {$is_call ->
132+
[true] call
133+
*[false] definition
134+
} uses SIMD vector type `{$ty}` which is not currently supported with the chosen ABI"
135+
)]
99136
pub(crate) struct AbiErrorUnsupportedVectorType<'a> {
100137
#[primary_span]
101-
#[label]
138+
#[label(
139+
"function {$is_call ->
140+
[true] called
141+
*[false] defined
142+
} here"
143+
)]
102144
pub span: Span,
103145
pub ty: Ty<'a>,
104146
/// Whether this is a problem at a call site or at a declaration.
105147
pub is_call: bool,
106148
}
107149

108150
#[derive(Diagnostic)]
109-
#[diag(monomorphize_abi_required_target_feature)]
110-
#[help]
151+
#[diag("this function {$is_call ->
152+
[true] call
153+
*[false] definition
154+
} uses ABI \"{$abi}\" which requires the `{$required_feature}` target feature, which is not enabled{$is_call ->
155+
[true] {\" \"}in the caller
156+
*[false] {\"\"}
157+
}")]
158+
#[help(
159+
"consider enabling it globally (`-C target-feature=+{$required_feature}`) or locally (`#[target_feature(enable=\"{$required_feature}\")]`)"
160+
)]
111161
pub(crate) struct AbiRequiredTargetFeature<'a> {
112162
#[primary_span]
113-
#[label]
163+
#[label(
164+
"function {$is_call ->
165+
[true] called
166+
*[false] defined
167+
} here"
168+
)]
114169
pub span: Span,
115170
pub required_feature: &'a str,
116171
pub abi: &'a str,
@@ -119,12 +174,12 @@ pub(crate) struct AbiRequiredTargetFeature<'a> {
119174
}
120175

121176
#[derive(Diagnostic)]
122-
#[diag(monomorphize_static_initializer_cyclic)]
123-
#[note]
177+
#[diag("static initializer forms a cycle involving `{$head}`")]
178+
#[note("cyclic static initializers are not supported for target `{$target}`")]
124179
pub(crate) struct StaticInitializerCyclic<'a> {
125180
#[primary_span]
126181
pub span: Span,
127-
#[label]
182+
#[label("part of this cycle")]
128183
pub labels: Vec<Span>,
129184
pub head: &'a str,
130185
pub target: &'a str,

compiler/rustc_monomorphize/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ mod mono_checks;
2020
mod partitioning;
2121
mod util;
2222

23-
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
24-
2523
fn custom_coerce_unsize_info<'tcx>(
2624
tcx: TyCtxtAt<'tcx>,
2725
source_ty: Ty<'tcx>,

0 commit comments

Comments
 (0)