Skip to content

Rollup of 15 pull requests #122008

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 42 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
1f2db3d
Add an example to demonstrate how Rc::into_inner works
Takashiidobe Feb 17, 2024
cb8ce9d
time complexity for push
20jasper Feb 16, 2024
bb6dca0
time complexity for push_within_capacity
20jasper Feb 16, 2024
0a5d684
time complexity for pop
20jasper Feb 16, 2024
d2f825f
time complexity for insert
20jasper Feb 18, 2024
ef1a584
intradoc link for vec
20jasper Feb 18, 2024
a9cfeb3
fix typo in push documentation
20jasper Feb 18, 2024
bc52e5d
Fix error in push docs
20jasper Feb 18, 2024
261da5f
Clarify/add `must_use` message for Rc/Arc/Weak::into_raw.
zachs18 Feb 19, 2024
74151cb
Make push docs more vague
20jasper Feb 25, 2024
e0a726c
Adjust error yield/await lowering
compiler-errors Feb 27, 2024
91322f4
Limit the number of names and values in check-cfg diagnostics
Urgau Feb 16, 2024
f5f11e1
Add regression test
oli-obk Mar 1, 2024
c3954b3
Add a tidy check that checks whether the fluent slugs only appear once
mu001999 Mar 2, 2024
d88c7ff
Remove unused fluent messages
mu001999 Mar 2, 2024
dd0004a
Don't panic when waiting on poisoned queries
Zoxc Aug 16, 2023
a9a9798
Removing absolute path in proc-macro
sundeep-kokkonda Mar 4, 2024
8364a06
Merge the impl trait in assoc type collector into the opaque type col…
oli-obk Mar 4, 2024
4e03c51
hir_analysis: enums return `None` in `find_field`
davidtwco Mar 4, 2024
640e99c
Fix duplicated path in the "not found dylib" error
GuillaumeGomez Mar 4, 2024
5e6e140
Add regression ui test for duplicated path in dylib error
GuillaumeGomez Mar 4, 2024
2af01a2
Abort on arity mismatch
Nadrieril Mar 4, 2024
fb91610
Avoid using unnecessary queries when printing the query stack in panics
Zoxc Mar 4, 2024
86e88fc
interpret/cast: make more matches on FloatTy properly exhaustive
RalfJung Mar 4, 2024
681dc38
typo
RalfJung Mar 4, 2024
4dbd256
Explain use of display adapters
CAD97 Feb 14, 2024
215a4b6
doc wording improvements
CAD97 Mar 5, 2024
6e85695
Rollup merge of #121065 - CAD97:display-i18n, r=cuviper
jhpratt Mar 5, 2024
7fb3b5e
Rollup merge of #121202 - Urgau:check-cfg-limit-diagnostics, r=pnkfelix
jhpratt Mar 5, 2024
7852ee9
Rollup merge of #121213 - Takashiidobe:takashi/example-for-rc-into-in…
jhpratt Mar 5, 2024
1dcdfb3
Rollup merge of #121262 - 20jasper:add-vector-time-complexity, r=cuviper
jhpratt Mar 5, 2024
f5d4a5d
Rollup merge of #121287 - zachs18:rc-into-raw-must-use, r=cuviper
jhpratt Mar 5, 2024
b4245e1
Rollup merge of #121664 - compiler-errors:adjust-error-yield-lowering…
jhpratt Mar 5, 2024
c850191
Rollup merge of #121838 - oli-obk:impl_trait_in_assoc_tys_fix, r=comp…
jhpratt Mar 5, 2024
1938ec0
Rollup merge of #121860 - mu001999:master, r=Nilstrieb
jhpratt Mar 5, 2024
0a6b60b
Rollup merge of #121913 - Zoxc:query-fix, r=compiler-errors
jhpratt Mar 5, 2024
8698b24
Rollup merge of #121959 - sundeep-kokkonda:patch-2, r=davidtwco
jhpratt Mar 5, 2024
d03f11d
Rollup merge of #121975 - davidtwco:issue-121757, r=petrochenkov
jhpratt Mar 5, 2024
a6ef0cc
Rollup merge of #121978 - GuillaumeGomez:dylib-duplicated-path, r=bjorn3
jhpratt Mar 5, 2024
425caf7
Rollup merge of #121987 - Nadrieril:abort-on-arity-mismatch, r=compil…
jhpratt Mar 5, 2024
ac4eb31
Rollup merge of #121993 - Zoxc:query-stack-panic-queries, r=compiler-…
jhpratt Mar 5, 2024
4a65a53
Rollup merge of #121997 - RalfJung:cast-float-ty, r=compiler-errors
jhpratt Mar 5, 2024
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
Prev Previous commit
Next Next commit
Add a tidy check that checks whether the fluent slugs only appear once
  • Loading branch information
mu001999 committed Mar 2, 2024
commit c3954b358f9e2be96d0dd553a8efaefc49f0bba7
58 changes: 52 additions & 6 deletions src/tools/tidy/src/fluent_alphabetical.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Checks that all Flunt files have messages in alphabetical order

use crate::walk::{filter_dirs, walk};
use std::collections::HashMap;
use std::{fs::OpenOptions, io::Write, path::Path};

use regex::Regex;
Expand All @@ -13,11 +14,27 @@ fn filter_fluent(path: &Path) -> bool {
if let Some(ext) = path.extension() { ext.to_str() != Some("ftl") } else { true }
}

fn check_alphabetic(filename: &str, fluent: &str, bad: &mut bool) {
fn check_alphabetic(
filename: &str,
fluent: &str,
bad: &mut bool,
all_defined_msgs: &mut HashMap<String, String>,
) {
let mut matches = MESSAGE.captures_iter(fluent).peekable();
while let Some(m) = matches.next() {
let name = m.get(1).unwrap();
if let Some(defined_filename) = all_defined_msgs.get(name.as_str()) {
tidy_error!(
bad,
"{filename}: message `{}` is already defined in {}",
name.as_str(),
defined_filename,
);
}

all_defined_msgs.insert(name.as_str().to_owned(), filename.to_owned());

if let Some(next) = matches.peek() {
let name = m.get(1).unwrap();
let next = next.get(1).unwrap();
if name.as_str() > next.as_str() {
tidy_error!(
Expand All @@ -34,13 +51,29 @@ run `./x.py test tidy --bless` to sort the file correctly",
}
}

fn sort_messages(fluent: &str) -> String {
fn sort_messages(
filename: &str,
fluent: &str,
bad: &mut bool,
all_defined_msgs: &mut HashMap<String, String>,
) -> String {
let mut chunks = vec![];
let mut cur = String::new();
for line in fluent.lines() {
if MESSAGE.is_match(line) {
if let Some(name) = MESSAGE.find(line) {
if let Some(defined_filename) = all_defined_msgs.get(name.as_str()) {
tidy_error!(
bad,
"{filename}: message `{}` is already defined in {}",
name.as_str(),
defined_filename,
);
}

all_defined_msgs.insert(name.as_str().to_owned(), filename.to_owned());
chunks.push(std::mem::take(&mut cur));
}

cur += line;
cur.push('\n');
}
Expand All @@ -53,20 +86,33 @@ fn sort_messages(fluent: &str) -> String {
}

pub fn check(path: &Path, bless: bool, bad: &mut bool) {
let mut all_defined_msgs = HashMap::new();
walk(
path,
|path, is_dir| filter_dirs(path) || (!is_dir && filter_fluent(path)),
&mut |ent, contents| {
if bless {
let sorted = sort_messages(contents);
let sorted = sort_messages(
ent.path().to_str().unwrap(),
contents,
bad,
&mut all_defined_msgs,
);
if sorted != contents {
let mut f =
OpenOptions::new().write(true).truncate(true).open(ent.path()).unwrap();
f.write(sorted.as_bytes()).unwrap();
}
} else {
check_alphabetic(ent.path().to_str().unwrap(), contents, bad);
check_alphabetic(
ent.path().to_str().unwrap(),
contents,
bad,
&mut all_defined_msgs,
);
}
},
);

crate::fluent_used::check(path, all_defined_msgs, bad);
}
43 changes: 43 additions & 0 deletions src/tools/tidy/src/fluent_used.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//! Checks that all Fluent messages appear at least twice

use crate::walk::{filter_dirs, walk};
use regex::Regex;
use std::collections::HashMap;
use std::path::Path;

lazy_static::lazy_static! {
static ref WORD: Regex = Regex::new(r"\w+").unwrap();
}

fn filter_used_messages(
contents: &str,
msgs_not_appeared_yet: &mut HashMap<String, String>,
msgs_appeared_only_once: &mut HashMap<String, String>,
) {
// we don't just check messages never appear in Rust files,
// because messages can be used as parts of other fluent messages in Fluent files,
// so we do checking messages appear only once in all Rust and Fluent files.
let mut matches = WORD.find_iter(contents);
while let Some(name) = matches.next() {
if let Some((name, filename)) = msgs_not_appeared_yet.remove_entry(name.as_str()) {
// if one msg appears for the first time,
// remove it from `msgs_not_appeared_yet` and insert it into `msgs_appeared_only_once`.
msgs_appeared_only_once.insert(name, filename);
} else {
// if one msg appears for the second time,
// remove it from `msgs_appeared_only_once`.
msgs_appeared_only_once.remove(name.as_str());
}
}
}

pub fn check(path: &Path, mut all_defined_msgs: HashMap<String, String>, bad: &mut bool) {
let mut msgs_appear_only_once = HashMap::new();
walk(path, |path, _| filter_dirs(path), &mut |_, contents| {
filter_used_messages(contents, &mut all_defined_msgs, &mut msgs_appear_only_once);
});

for (name, filename) in msgs_appear_only_once {
tidy_error!(bad, "{filename}: message `{}` is not used", name,);
}
}
1 change: 1 addition & 0 deletions src/tools/tidy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ pub mod ext_tool_checks;
pub mod extdeps;
pub mod features;
pub mod fluent_alphabetical;
mod fluent_used;
pub(crate) mod iter_header;
pub mod mir_opt_tests;
pub mod pal;
Expand Down