Skip to content

Commit cb01915

Browse files
authored
Unrolled build for #152252
Rollup merge of #152252 - JonathanBrouwer:port-tidy-checks, r=jdonszelmann Convert diagnostic style checks For #151366 r? @jdonszelmann
2 parents 56aaf58 + c1091da commit cb01915

38 files changed

+94
-379
lines changed

compiler/rustc_codegen_llvm/src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,5 +214,5 @@ pub(crate) struct FixedX18InvalidArch<'a> {
214214
}
215215

216216
#[derive(Diagnostic)]
217-
#[diag("`-Zsanitizer-kcfi-arity` requires LLVM 21.0.0 or later.")]
217+
#[diag("`-Zsanitizer-kcfi-arity` requires LLVM 21.0.0 or later")]
218218
pub(crate) struct SanitizerKcfiArityRequiresLLVM2100;

compiler/rustc_codegen_ssa/src/errors.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub(crate) struct MissingQueryDepGraph {
5959

6060
#[derive(Diagnostic)]
6161
#[diag(
62-
"found malformed codegen unit name `{$user_path}`. codegen units names must always start with the name of the crate (`{$crate_name}` in this case)."
62+
"found malformed codegen unit name `{$user_path}`. codegen units names must always start with the name of the crate (`{$crate_name}` in this case)"
6363
)]
6464
pub(crate) struct MalformedCguName {
6565
#[primary_span]
@@ -562,12 +562,12 @@ pub(crate) struct SelfContainedLinkerMissing;
562562

563563
#[derive(Diagnostic)]
564564
#[diag(
565-
"please ensure that Visual Studio 2017 or later, or Build Tools for Visual Studio were installed with the Visual C++ option."
565+
"please ensure that Visual Studio 2017 or later, or Build Tools for Visual Studio were installed with the Visual C++ option"
566566
)]
567567
pub(crate) struct CheckInstalledVisualStudio;
568568

569569
#[derive(Diagnostic)]
570-
#[diag("VS Code is a different product, and is not sufficient.")]
570+
#[diag("VS Code is a different product, and is not sufficient")]
571571
pub(crate) struct InsufficientVSCodeProduct;
572572

573573
#[derive(Diagnostic)]
@@ -610,13 +610,13 @@ pub(crate) struct LinkerFileStem;
610610

611611
#[derive(Diagnostic)]
612612
#[diag(
613-
"link against the following native artifacts when linking against this static library. The order and any duplication can be significant on some platforms."
613+
"link against the following native artifacts when linking against this static library. The order and any duplication can be significant on some platforms"
614614
)]
615615
pub(crate) struct StaticLibraryNativeArtifacts;
616616

617617
#[derive(Diagnostic)]
618618
#[diag(
619-
"native artifacts to link against have been written to {$path}. The order and any duplication can be significant on some platforms."
619+
"native artifacts to link against have been written to {$path}. The order and any duplication can be significant on some platforms"
620620
)]
621621
pub(crate) struct StaticLibraryNativeArtifactsToFile<'a> {
622622
pub path: &'a Path,

compiler/rustc_const_eval/src/errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ pub(crate) struct UnallowedHeapAllocations {
309309
pub span: Span,
310310
pub kind: ConstContext,
311311
#[note(
312-
"The runtime heap is not yet available at compile-time, so no runtime heap allocations can be created."
312+
"the runtime heap is not yet available at compile-time, so no runtime heap allocations can be created"
313313
)]
314314
pub teach: bool,
315315
}
@@ -347,7 +347,7 @@ pub(crate) struct InteriorMutableBorrowEscaping {
347347
#[diag("constant evaluation is taking a long time")]
348348
#[note(
349349
"this lint makes sure the compiler doesn't get stuck due to infinite loops in const eval.
350-
If your compilation actually takes a long time, you can safely allow the lint."
350+
If your compilation actually takes a long time, you can safely allow the lint"
351351
)]
352352
pub struct LongRunning {
353353
#[help("the constant being evaluated")]

compiler/rustc_driver_impl/src/session_diagnostics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub(crate) struct RlinkCorruptFile<'a> {
5151
}
5252

5353
#[derive(Diagnostic)]
54-
#[diag("the compiler unexpectedly panicked. this is a bug.")]
54+
#[diag("the compiler unexpectedly panicked. This is a bug")]
5555
pub(crate) struct Ice;
5656

5757
#[derive(Diagnostic)]

compiler/rustc_hir_typeck/src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1145,7 +1145,7 @@ pub(crate) struct CastThinPointerToWidePointer<'tcx> {
11451145
pub expr_ty: Ty<'tcx>,
11461146
pub cast_ty: Ty<'tcx>,
11471147
#[note(
1148-
"Thin pointers are \"simple\" pointers: they are purely a reference to a
1148+
"thin pointers are \"simple\" pointers: they are purely a reference to a
11491149
memory address.
11501150
11511151
Wide pointers are pointers referencing \"Dynamically Sized Types\" (also

compiler/rustc_incremental/src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ pub(crate) struct DeleteWorkProduct<'a> {
281281

282282
#[derive(Diagnostic)]
283283
#[diag(
284-
"corrupt incremental compilation artifact found at `{$path}`. This file will automatically be ignored and deleted. If you see this message repeatedly or can provoke it without manually manipulating the compiler's artifacts, please file an issue. The incremental compilation system relies on hardlinks and filesystem locks behaving correctly, and may not deal well with OS crashes, so whatever information you can provide about your filesystem or other state may be very relevant."
284+
"corrupt incremental compilation artifact found at `{$path}`. This file will automatically be ignored and deleted. If you see this message repeatedly or can provoke it without manually manipulating the compiler's artifacts, please file an issue. The incremental compilation system relies on hardlinks and filesystem locks behaving correctly, and may not deal well with OS crashes, so whatever information you can provide about your filesystem or other state may be very relevant"
285285
)]
286286
pub(crate) struct CorruptFile<'a> {
287287
pub path: &'a Path,

compiler/rustc_macros/src/diagnostics/message.rs

Lines changed: 57 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ impl Message {
2323
quote! { crate::fluent_generated::#slug }
2424
}
2525
Message::Inline(message_span, message) => {
26-
if let Some(variant) = variant {
27-
verify_fluent_message(*message_span, &message, variant);
28-
}
26+
verify_fluent_message(*message_span, &message, variant);
2927
quote! { rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed(#message)) }
3028
}
3129
}
@@ -86,30 +84,37 @@ impl Message {
8684
}
8785
}
8886

89-
fn verify_fluent_message(msg_span: Span, message: &str, variant: &VariantInfo<'_>) {
87+
fn verify_fluent_message(msg_span: Span, message_str: &str, variant: Option<&VariantInfo<'_>>) {
9088
// Parse the fluent message
9189
const GENERATED_MSG_ID: &str = "generated_msg";
92-
let resource = FluentResource::try_new(format!("{GENERATED_MSG_ID} = {message}\n")).unwrap();
90+
let resource =
91+
FluentResource::try_new(format!("{GENERATED_MSG_ID} = {message_str}\n")).unwrap();
9392
assert_eq!(resource.entries().count(), 1);
9493
let Some(fluent_syntax::ast::Entry::Message(message)) = resource.get_entry(0) else {
9594
panic!("Did not parse into a message")
9695
};
9796

9897
// Check if all variables are used
99-
let fields: Vec<String> = variant
100-
.bindings()
101-
.iter()
102-
.flat_map(|b| b.ast().ident.as_ref())
103-
.map(|id| id.to_string())
104-
.collect();
105-
for variable in variable_references(&message) {
106-
if !fields.iter().any(|f| f == variable) {
107-
span_err(msg_span.unwrap(), format!("Variable `{variable}` not found in diagnostic "))
98+
if let Some(variant) = variant {
99+
let fields: Vec<String> = variant
100+
.bindings()
101+
.iter()
102+
.flat_map(|b| b.ast().ident.as_ref())
103+
.map(|id| id.to_string())
104+
.collect();
105+
for variable in variable_references(&message) {
106+
if !fields.iter().any(|f| f == variable) {
107+
span_err(
108+
msg_span.unwrap(),
109+
format!("Variable `{variable}` not found in diagnostic "),
110+
)
108111
.help(format!("Available fields: {:?}", fields.join(", ")))
109112
.emit();
113+
}
110114
}
111-
// assert!(, );
112115
}
116+
117+
verify_message_style(msg_span, message_str);
113118
}
114119

115120
fn variable_references<'a>(msg: &fluent_syntax::ast::Message<&'a str>) -> Vec<&'a str> {
@@ -136,3 +141,40 @@ fn variable_references<'a>(msg: &fluent_syntax::ast::Message<&'a str>) -> Vec<&'
136141
}
137142
refs
138143
}
144+
145+
const ALLOWED_CAPITALIZED_WORDS: &[&str] = &[
146+
// tidy-alphabetical-start
147+
"ABI",
148+
"ABIs",
149+
"ADT",
150+
"C-variadic",
151+
"CGU-reuse",
152+
"Cargo",
153+
"Ferris",
154+
"GCC",
155+
"MIR",
156+
"NaNs",
157+
"OK",
158+
"VS",
159+
// tidy-alphabetical-end
160+
];
161+
162+
/// See: https://rustc-dev-guide.rust-lang.org/diagnostics.html#diagnostic-output-style-guide
163+
fn verify_message_style(msg_span: Span, message: &str) {
164+
// Verify that message starts with lowercase char
165+
let Some(first_word) = message.split_whitespace().next() else {
166+
span_err(msg_span.unwrap(), "message must not be empty").emit();
167+
return;
168+
};
169+
let first_char = first_word.chars().next().expect("Word is not empty");
170+
if first_char.is_uppercase() && !ALLOWED_CAPITALIZED_WORDS.contains(&first_word) {
171+
span_err(msg_span.unwrap(), "message `{value}` starts with an uppercase letter. Fix it or add it to `ALLOWED_CAPITALIZED_WORDS`").emit();
172+
return;
173+
}
174+
175+
// Verify that message does not end in `.`
176+
if message.ends_with(".") && !message.ends_with("...") {
177+
span_err(msg_span.unwrap(), "message `{value}` ends with a period").emit();
178+
return;
179+
}
180+
}

compiler/rustc_mir_build/src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ pub(crate) struct LowerRangeBoundMustBeLessThanOrEqualToUpper {
849849
#[label("lower bound larger than upper bound")]
850850
pub(crate) span: Span,
851851
#[note(
852-
"When matching against a range, the compiler verifies that the range is non-empty. Range patterns include both end-points, so this is equivalent to requiring the start of the range to be less than or equal to the end of the range."
852+
"when matching against a range, the compiler verifies that the range is non-empty. Range patterns include both end-points, so this is equivalent to requiring the start of the range to be less than or equal to the end of the range"
853853
)]
854854
pub(crate) teach: bool,
855855
}

src/tools/tidy/src/fluent_alphabetical.rs

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

src/tools/tidy/src/fluent_lowercase.rs

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

0 commit comments

Comments
 (0)