Skip to content

Commit 2557089

Browse files
tshepangcamelid
andauthored
make date-check more lightweight (#1394)
* 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" * please clippy * update date-check docs * accept review suggestion Co-authored-by: Noah Lev <[email protected]> * address review comment #1394 (review) * accept review suggestion Co-authored-by: Noah Lev <[email protected]> * address review comment #1394 (review) * address review comment #1394 (comment) * this breaks markdown * address review comment #1394 (comment) This led to a more robust regex, though making the tool more picky. It also found a wrong date format that was missed. * address review comment #1394 (comment) * address review comment #1394 (comment) * accept review suggestion This was reverted by mistake Co-authored-by: Noah Lev <[email protected]> * address review comment #1394 (comment) * use a more simple fn * address review comment #1394 (comment) Much more clean * nit * accept review suggestion Co-authored-by: Noah Lev <[email protected]> * avoid a failed regex Also, test new shape * adjust to new regex (which uses named groups) New regex was introduced by 456008c Co-authored-by: Noah Lev <[email protected]>
1 parent 04f3cf0 commit 2557089

29 files changed

+201
-77
lines changed

ci/date-check/src/main.rs

+136-30
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

@@ -38,12 +39,18 @@ impl fmt::Display for Date {
3839
fn make_date_regex() -> Regex {
3940
Regex::new(
4041
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*-->",
42+
(<!--\s*
43+
date-check:\s*
44+
(?P<m1>\D+)\s+
45+
(?P<y1>\d{4})\s*-->
46+
)
47+
|
48+
(<!--\s*
49+
date-check\s*-->\s+
50+
(?P<m2>\D+)\s+
51+
(?P<y2>\d{4})\b
52+
)
53+
",
4754
)
4855
.unwrap()
4956
}
@@ -52,15 +59,22 @@ fn collect_dates_from_file(date_regex: &Regex, text: &str) -> Vec<(usize, Date)>
5259
let mut line = 1;
5360
let mut end_of_last_cap = 0;
5461
date_regex
55-
.captures_iter(&text)
56-
.map(|cap| {
57-
(
58-
cap.get(0).unwrap().range(),
59-
Date {
60-
year: cap["y"].parse().unwrap(),
61-
month: cap["m"].parse().unwrap(),
62-
},
63-
)
62+
.captures_iter(text)
63+
.filter_map(|cap| {
64+
if let (Some(month), Some(year), None, None) | (None, None, Some(month), Some(year)) = (
65+
cap.name("m1"),
66+
cap.name("y1"),
67+
cap.name("m2"),
68+
cap.name("y2"),
69+
) {
70+
let year = year.as_str().parse().expect("year");
71+
let month = Month::from_str(month.as_str())
72+
.expect("month")
73+
.number_from_month();
74+
Some((cap.get(0).expect("all").range(), Date { year, month }))
75+
} else {
76+
None
77+
}
6478
})
6579
.map(|(byte_range, date)| {
6680
line += text[end_of_last_cap..byte_range.end]
@@ -182,61 +196,153 @@ mod tests {
182196

183197
#[test]
184198
fn test_date_regex() {
185-
let regex = make_date_regex();
186-
assert!(regex.is_match("foo <!-- date: 2021-01 --> bar"));
199+
let regex = &make_date_regex();
200+
assert!(regex.is_match("<!-- date-check: jan 2021 -->"));
201+
assert!(regex.is_match("<!-- date-check: january 2021 -->"));
202+
assert!(regex.is_match("<!-- date-check: Jan 2021 -->"));
203+
assert!(regex.is_match("<!-- date-check: January 2021 -->"));
204+
assert!(regex.is_match("<!-- date-check --> jan 2021"));
205+
assert!(regex.is_match("<!-- date-check --> january 2021"));
206+
assert!(regex.is_match("<!-- date-check --> Jan 2021"));
207+
assert!(regex.is_match("<!-- date-check --> January 2021"));
208+
209+
assert!(regex.is_match("<!-- date-check --> jan 2021 "));
210+
assert!(regex.is_match("<!-- date-check --> jan 2021."));
187211
}
188212

189213
#[test]
190-
fn test_date_regex_capitalized() {
191-
let regex = make_date_regex();
192-
assert!(regex.is_match("foo <!-- Date: 2021-08 --> bar"));
214+
fn test_date_regex_fail() {
215+
let regexes = &make_date_regex();
216+
assert!(!regexes.is_match("<!-- date-check: jan 221 -->"));
217+
assert!(!regexes.is_match("<!-- date-check: jan 20221 -->"));
218+
assert!(!regexes.is_match("<!-- date-check: 01 2021 -->"));
219+
assert!(!regexes.is_match("<!-- date-check --> jan 221"));
220+
assert!(!regexes.is_match("<!-- date-check --> jan 20222"));
221+
assert!(!regexes.is_match("<!-- date-check --> 01 2021"));
193222
}
194223

195224
#[test]
196225
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
226+
let text = r"
227+
Test1
228+
<!-- date-check: jan 2021 -->
229+
Test2
230+
Foo<!-- date-check: february 2021
231+
-->
232+
Test3
233+
Test4
234+
Foo<!-- date-check: Mar 2021 -->Bar
235+
<!-- date-check:April 2021
236+
-->
237+
Test5
238+
Test6
239+
Test7
240+
<!-- date-check:
241+
242+
may 2021 -->
243+
Test8
244+
Test1
245+
<!-- date-check --> jan 2021
246+
Test2
247+
Foo<!-- date-check
248+
--> february 2021
249+
Test3
250+
Test4
251+
Foo<!-- date-check --> mar 2021 Bar
252+
<!-- date-check
253+
--> apr 2021
254+
Test5
255+
Test6
256+
Test7
257+
<!-- date-check
258+
259+
--> may 2021
260+
Test8
261+
<!--
262+
date-check
263+
--> june 2021.
200264
";
201265
assert_eq!(
202266
collect_dates_from_file(&make_date_regex(), text),
203267
vec![
204268
(
205-
2,
269+
3,
206270
Date {
207271
year: 2021,
208272
month: 1,
209273
}
210274
),
211275
(
212-
4,
276+
6,
213277
Date {
214278
year: 2021,
215279
month: 2,
216280
}
217281
),
218282
(
219-
7,
283+
9,
220284
Date {
221285
year: 2021,
222286
month: 3,
223287
}
224288
),
225289
(
226-
8,
290+
11,
227291
Date {
228292
year: 2021,
229293
month: 4,
230294
}
231295
),
232296
(
233-
14,
297+
17,
234298
Date {
235299
year: 2021,
236300
month: 5,
237301
}
238302
),
239-
]
303+
(
304+
20,
305+
Date {
306+
year: 2021,
307+
month: 1,
308+
}
309+
),
310+
(
311+
23,
312+
Date {
313+
year: 2021,
314+
month: 2,
315+
}
316+
),
317+
(
318+
26,
319+
Date {
320+
year: 2021,
321+
month: 3,
322+
}
323+
),
324+
(
325+
28,
326+
Date {
327+
year: 2021,
328+
month: 4,
329+
}
330+
),
331+
(
332+
34,
333+
Date {
334+
year: 2021,
335+
month: 5,
336+
}
337+
),
338+
(
339+
38,
340+
Date {
341+
year: 2021,
342+
month: 6,
343+
}
344+
),
345+
],
240346
);
241347
}
242348
}

src/backend/backend-agnostic.md

+1-1
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 <!-- date-check --> 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/backend/updating-llvm.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ Example PRs look like:
6666

6767
## Feature updates
6868

69-
> Note that this information is as of the time of this writing <!-- date:
70-
2021-10 --> (October 2021). The process for updating LLVM changes with
69+
> Note that this information is as of the time of this writing, <!--
70+
date-check --> October 2021. The process for updating LLVM changes with
7171
practically all LLVM updates, so this may be out of date!
7272

7373
Unlike bugfixes, updating to pick up a new feature of LLVM typically requires a

src/borrow_check/region_inference/member_constraints.md

+1-1
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 <!-- date-check --> 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/building/suggested.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ You can also install the hook as a step of running `./x.py setup`!
2222
a file. By default, `rust-analyzer` runs the `cargo check` and `rustfmt`
2323
commands, but you can override these commands to use more adapted versions
2424
of these tools when hacking on `rustc`. For example, for Visual Studio Code,
25-
you can write: <!-- date: 2022-04 --><!-- the date comment is for the edition below -->
25+
you can write: <!-- date-check: apr 2022 --><!-- the date comment is for the edition below -->
2626

2727
```JSON
2828
{

src/contributing.md

+27-10
Original file line numberDiff line numberDiff line change
@@ -437,17 +437,35 @@ Just a few things to keep in mind:
437437
the project.
438438

439439
- The date the comment was added, e.g. instead of writing _"Currently, ..."_
440-
or _"As of now, ..."_, consider writing
441-
_"As of January 2021, ..."_.
442-
Try to format the date as `<MONTH> <YEAR>` to ease search.
440+
or _"As of now, ..."_,
441+
consider adding the date, in one of the following formats:
442+
- Jan 2021
443+
- January 2021
444+
- jan 2021
445+
- january 2021
443446

444-
- Additionally, include a machine-readable comment of the form `<!-- date:
445-
2022-04 -->` (if the current month is April 2022). We have an automated
446-
tool that uses these (in `ci/date-check`).
447+
There is a CI action (in `~/.github/workflows/date-check.yml`)
448+
that generates a monthly issue with any of these that are over 6 months old.
447449

448-
So, for the month of April 2022, the comment would look like: `As of <!--
449-
date: 2022-04 --> April 2022`. Make sure to put the comment *between* `as of`
450-
and `April 2022`; see [PR #1066][rdg#1066] for the rationale.
450+
For the action to pick the date,
451+
add a special annotation before specifying the date:
452+
453+
```md
454+
<!-- date-check --> Jul 2022
455+
```
456+
457+
Example:
458+
459+
```md
460+
As of <!-- date-check --> Jul 2022, the foo did the bar.
461+
```
462+
463+
For cases where the date should not be part of the visible rendered output,
464+
use the following instead:
465+
466+
```md
467+
<!-- date-check: Jul 2022 -->
468+
```
451469

452470
- A link to a relevant WG, tracking issue, `rustc` rustdoc page, or similar, that may provide
453471
further explanation for the change process or a way to verify that the information is not
@@ -459,7 +477,6 @@ Just a few things to keep in mind:
459477

460478
[rdg]: https://rustc-dev-guide.rust-lang.org/
461479
[rdgrepo]: https://github.com/rust-lang/rustc-dev-guide
462-
[rdg#1066]: https://github.com/rust-lang/rustc-dev-guide/pull/1066
463480

464481
## Issue Triage
465482

src/conventions.md

+2-2
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 <!-- date-check: 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

+1-1
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 <!-- date-check --> 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

+1-1
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 <!-- date-check --> 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

+1-1
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 <!-- date-check --> 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

+1-1
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 <!-- date-check --> June 2022, there are no locale bundles
221221
distributed with the compiler, but mechanisms are implemented for loading
222222
bundles.
223223

src/git.md

+1-1
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 <!-- date-check --> 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

0 commit comments

Comments
 (0)