Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ codegen_ssa_cpu_required = target requires explicitly specifying a cpu with `-C
codegen_ssa_create_temp_dir = couldn't create a temp dir: {$error}
codegen_ssa_dlltool_fail_import_library =
Dlltool could not create import library with {$dlltool_path} {$dlltool_args}:
dlltool could not create import library with {$dlltool_path} {$dlltool_args}:
{$stdout}
{$stderr}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_passes/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ passes_const_stable_not_stable =
.label = attribute specified here
passes_custom_mir_incompatible_dialect_and_phase =
The {$dialect} dialect is not compatible with the {$phase} phase
the {$dialect} dialect is not compatible with the {$phase} phase
.dialect_span = this dialect...
.phase_span = ... is not compatible with this phase
Expand Down
64 changes: 64 additions & 0 deletions src/tools/tidy/src/fluent_lowercase.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//! Checks that the error messages start with a lowercased letter (except when allowed to).

use std::path::Path;

use fluent_syntax::ast::{Entry, Message, PatternElement};

use crate::walk::{filter_dirs, walk};

#[rustfmt::skip]
const ALLOWED_CAPITALIZED_WORDS: &[&str] = &[
// tidy-alphabetical-start
"ABI",
"ABIs",
"ADT",
"C",
"CGU",
"Ferris",
"MIR",
"OK",
"Rust",
"VS", // VS Code
// tidy-alphabetical-end
];

fn filter_fluent(path: &Path) -> bool {
if let Some(ext) = path.extension() { ext.to_str() != Some("ftl") } else { true }
}

fn is_allowed_capitalized_word(msg: &str) -> bool {
ALLOWED_CAPITALIZED_WORDS.iter().any(|word| {
msg.strip_prefix(word)
.map(|tail| tail.chars().next().map(|c| c == '-' || c.is_whitespace()).unwrap_or(true))
.unwrap_or_default()
})
}

fn check_lowercase(filename: &str, contents: &str, bad: &mut bool) {
let (Ok(parse) | Err((parse, _))) = fluent_syntax::parser::parse(contents);

for entry in &parse.body {
if let Entry::Message(msg) = entry
&& let Message { value: Some(pattern), .. } = msg
&& let [first_pattern, ..] = &pattern.elements[..]
&& let PatternElement::TextElement { value } = first_pattern
&& value.chars().next().is_some_and(char::is_uppercase)
&& !is_allowed_capitalized_word(value)
{
tidy_error!(
bad,
"{filename}: message `{value}` starts with an uppercase letter. Fix it or add it to `ALLOWED_CAPITALIZED_WORDS`"
);
}
}
}

pub fn check(path: &Path, bad: &mut bool) {
walk(
path,
|path, is_dir| filter_dirs(path) || (!is_dir && filter_fluent(path)),
&mut |ent, contents| {
check_lowercase(ent.path().to_str().unwrap(), contents, bad);
},
Comment on lines +60 to +62
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

q: doesn't this get called for dirs? if so, you should probably add a check for them here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is not called on dirs because we filter out dirs right before that:

        |path, is_dir| filter_dirs(path) || (!is_dir && filter_fluent(path)),

);
}
1 change: 1 addition & 0 deletions src/tools/tidy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ pub mod extra_checks;
pub mod features;
pub mod filenames;
pub mod fluent_alphabetical;
pub mod fluent_lowercase;
pub mod fluent_period;
mod fluent_used;
pub mod gcc_submodule;
Expand Down
1 change: 1 addition & 0 deletions src/tools/tidy/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ fn main() {
check!(error_codes, &root_path, &[&compiler_path, &librustdoc_path], verbose, &ci_info);
check!(fluent_alphabetical, &compiler_path, bless);
check!(fluent_period, &compiler_path);
check!(fluent_lowercase, &compiler_path);
check!(target_policy, &root_path);
check!(gcc_submodule, &root_path, &compiler_path);

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/linkage-attr/raw-dylib/windows/dlltool-failed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ pub fn lib_main() {
unsafe { f(42); }
}

//~? ERROR Dlltool could not create import library with
//~? ERROR dlltool could not create import library with
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: Dlltool could not create import library with $DLLTOOL -d $DEF_FILE -D foo.dll -l $LIB_FILE $TARGET_MACHINE $ASM_FLAGS --no-leading-underscore $TEMP_PREFIX:
error: dlltool could not create import library with $DLLTOOL -d $DEF_FILE -D foo.dll -l $LIB_FILE $TARGET_MACHINE $ASM_FLAGS --no-leading-underscore $TEMP_PREFIX:

$DLLTOOL: Syntax error in def file $DEF_FILE:1␍

Expand Down
Loading