Skip to content

Commit 6d20dea

Browse files
committed
make date-check lightweight
This avoids having to write the date twice when updating date-check. Before "As of <-- 2022-07 --> July 2022" After "As of July 2022"
1 parent 0eb86d9 commit 6d20dea

26 files changed

+45
-55
lines changed

ci/date-check/src/main.rs

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ use std::{
33
convert::TryInto as _,
44
env, fmt, fs,
55
path::{Path, PathBuf},
6+
str::FromStr,
67
};
78

8-
use chrono::{Datelike as _, TimeZone as _, Utc};
9+
use chrono::{Datelike as _, Month, TimeZone as _, Utc};
910
use glob::glob;
1011
use regex::Regex;
1112

@@ -36,16 +37,7 @@ impl fmt::Display for Date {
3637
}
3738

3839
fn make_date_regex() -> Regex {
39-
Regex::new(
40-
r"(?x) # insignificant whitespace mode
41-
<!--\s*
42-
[dD]ate:\s*
43-
(?P<y>\d{4}) # year
44-
-
45-
(?P<m>\d{2}) # month
46-
\s*-->",
47-
)
48-
.unwrap()
40+
Regex::new(r"[aA]s of (\w+) (\d{4})").unwrap()
4941
}
5042

5143
fn collect_dates_from_file(date_regex: &Regex, text: &str) -> Vec<(usize, Date)> {
@@ -57,8 +49,8 @@ fn collect_dates_from_file(date_regex: &Regex, text: &str) -> Vec<(usize, Date)>
5749
(
5850
cap.get(0).unwrap().range(),
5951
Date {
60-
year: cap["y"].parse().unwrap(),
61-
month: cap["m"].parse().unwrap(),
52+
year: cap[2].parse().unwrap(),
53+
month: Month::from_str(&cap[1]).unwrap().number_from_month(),
6254
},
6355
)
6456
})
@@ -183,20 +175,18 @@ mod tests {
183175
#[test]
184176
fn test_date_regex() {
185177
let regex = make_date_regex();
186-
assert!(regex.is_match("foo <!-- date: 2021-01 --> bar"));
187-
}
188-
189-
#[test]
190-
fn test_date_regex_capitalized() {
191-
let regex = make_date_regex();
192-
assert!(regex.is_match("foo <!-- Date: 2021-08 --> bar"));
178+
assert!(regex.is_match("As of July 2022"));
179+
assert!(regex.is_match("As of Jul 2022"));
180+
assert!(regex.is_match("As of july 2022"));
181+
assert!(regex.is_match("As of jul 2022"));
182+
assert!(regex.is_match("as of jul 2022"));
193183
}
194184

195185
#[test]
196186
fn test_collect_dates_from_file() {
197-
let text = "Test1\n<!-- date: 2021-01 -->\nTest2\nFoo<!-- date: 2021-02 \
198-
-->\nTest3\nTest4\nFoo<!-- date: 2021-03 -->Bar\n<!-- date: 2021-04 \
199-
-->\nTest5\nTest6\nTest7\n<!-- date: \n\n2021-05 -->\nTest8
187+
let text = "Test1\nAs of Jan 2021\nTest2\nAs of Feb 2021 \
188+
\nTest3\nTest4\nAs of march 2021Bar\nas of apr 2021 \
189+
\nTest5\nTest6\nTest7\n\n\nas of may 2021\nTest8
200190
";
201191
assert_eq!(
202192
collect_dates_from_file(&make_date_regex(), text),

src/backend/backend-agnostic.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<!-- toc -->
44

5-
As of <!-- date: 2021-10 --> October 2021, `rustc_codegen_ssa` provides an
5+
As of October 2021, `rustc_codegen_ssa` provides an
66
abstract interface for all backends to implement, to allow other codegen
77
backends (e.g. [Cranelift]).
88

src/borrow_check/region_inference/member_constraints.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ member constraints come in.
9494
## Choices are always lifetime parameters
9595

9696
At present, the "choice" regions from a member constraint are always lifetime
97-
parameters from the current function. As of <!-- date: 2021-10 --> October 2021,
97+
parameters from the current function. As of October 2021,
9898
this falls out from the placement of impl Trait, though in the future it may not
9999
be the case. We take some advantage of this fact, as it simplifies the current
100100
code. In particular, we don't have to consider a case like `'0 member of ['1,

src/conventions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ special config, so this may result in different style from normal [`rustfmt`].
1414
Therefore, formatting this repository using `cargo fmt` is not recommended.
1515

1616
Instead, formatting should be done using `./x.py fmt`. It's a good habit to run
17-
`./x.py fmt` before every commit, as this reduces conflicts later.
17+
`./x.py fmt` before every commit, as this reduces conflicts later.
1818

1919
Formatting is checked by the `tidy` script. It runs automatically when you do
2020
`./x.py test` and can be run in isolation with `./x.py fmt --check`.
2121

2222
If you want to use format-on-save in your editor, the pinned version of
2323
`rustfmt` is built under `build/<target>/stage0/bin/rustfmt`. You'll have to
24-
pass the <!-- date: 2022-04 --> `--edition=2021` argument yourself when calling
24+
pass the <!-- as of April 2022 --> `--edition=2021` argument yourself when calling
2525
`rustfmt` directly.
2626

2727
[fmt]: https://github.com/rust-dev-tools/fmt-rfcs

src/crates-io.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ reasons:
1212
- The dependency may have transitive dependencies that have one of the above
1313
problems.
1414

15-
As of <!-- date: 2022-02 --> February 2022, there is no official policy for vetting
15+
As of February 2022, there is no official policy for vetting
1616
new dependencies to the compiler. Generally, new dependencies are not added
1717
to the compiler unless there is a good reason to do so.
1818

src/diagnostics/diagnostic-items.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ A new diagnostic item can be added with these two steps:
4343
For the naming conventions of diagnostic items, please refer to
4444
[*Naming Conventions*](#naming-conventions).
4545

46-
2. As of <!-- date: 2022-02 --> February 2022, diagnostic items in code are
46+
2. As of February 2022, diagnostic items in code are
4747
accessed via symbols in [`rustc_span::symbol::sym`]. To add your newly
4848
created diagnostic item simply open the module file and add the name (In
4949
this case `Cat`) at the correct point in the list.

src/diagnostics/lintstore.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ default lint level and other metadata come from. These are normally defined by
1717
way of the [`declare_lint!`] macro, which boils down to a static with type
1818
`&rustc_session::lint::Lint`.
1919

20-
As of <!-- date: 2022-02 --> February 2022, we lint against direct declarations
20+
As of February 2022, we lint against direct declarations
2121
without the use of the macro today (although this may change in the future, as
2222
the macro is somewhat unwieldy to add new fields to, like all macros).
2323

src/diagnostics/translation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ returned by `Emitter::fluent_bundle`. This bundle is used preferentially when
217217
translating messages, the fallback bundle is only used if the primary bundle is
218218
missing a message or not provided.
219219

220-
As of <!-- date: 2022-06 --> June 2022, there are no locale bundles
220+
As of June 2022, there are no locale bundles
221221
distributed with the compiler, but mechanisms are implemented for loading
222222
bundles.
223223

src/git.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ no changes added to commit (use "git add" and/or "git commit -a")
157157
These changes are not changes to files: they are changes to submodules (more on
158158
this [later](#git-submodules)). To get rid of those, run `git submodule update`
159159
(or run any `x.py` command, which will automatically update the submodules).
160-
Note that there is (as of <!-- date: 2022-02 --> February 2022) a [bug][#77620] if you use
160+
Note that there is (as of February 2022) a [bug][#77620] if you use
161161
worktrees, submodules, and `x.py` in a commit hook. If you run into an error
162162
like:
163163

src/llvm-coverage-instrumentation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ properly-configured variables in LLVM IR, according to very specific
222222
details of the [_LLVM Coverage Mapping Format_][coverage-mapping-format]
223223
(Version 6).[^llvm-and-covmap-versions]
224224

225-
[^llvm-and-covmap-versions]: The Rust compiler (as of <!-- date: 2021-12 -->
226-
December 2021) supports _LLVM Coverage Mapping Format_ Version 5 or 6. Version 5
225+
[^llvm-and-covmap-versions]: The Rust compiler (as of December 2021)
226+
supports _LLVM Coverage Mapping Format_ Version 5 or 6. Version 5
227227
was introduced in _LLVM 12_, which is (as of this writing) the minimum LLVM
228228
version supported by the current version of Rust. Version 6 was introduced in
229229
_LLVM 13_, which is currently the default LLVM version for Rust. The Rust

0 commit comments

Comments
 (0)