Skip to content

Commit e82c245

Browse files
committed
address review comment
#1394 (comment)
1 parent f4803a7 commit e82c245

28 files changed

+178
-80
lines changed

Diff for: ci/date-check/src/main.rs

+128-43
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::{
88

99
use chrono::{Datelike as _, Month, TimeZone as _, Utc};
1010
use glob::glob;
11-
use regex::Regex;
11+
use regex::{Regex, RegexSet};
1212

1313
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
1414
struct Date {
@@ -36,41 +36,56 @@ impl fmt::Display for Date {
3636
}
3737
}
3838

39-
fn make_date_regex() -> Regex {
40-
Regex::new(r"[aA]s\s+of\s+(\w+)\s+(\d{4})").unwrap()
39+
fn make_date_regex() -> Vec<Regex> {
40+
let patterns = [
41+
r"<!--\s+date-check:\s+(\w+)\s+(\d+{4})\s+-->",
42+
r"<!--\s+date-check\s+-->\s+(\w+)\s+(\d+{4})",
43+
];
44+
let set = RegexSet::new(&patterns).unwrap();
45+
set.patterns()
46+
.iter()
47+
.map(|pattern| Regex::new(pattern).unwrap())
48+
.collect()
4149
}
4250

43-
fn collect_dates_from_file(date_regex: &Regex, text: &str) -> Vec<(usize, Date)> {
44-
let mut line = 1;
45-
let mut end_of_last_cap = 0;
46-
date_regex
47-
.captures_iter(text)
48-
.map(|cap| {
49-
(
50-
cap.get(0).unwrap().range(),
51-
Date {
52-
year: cap[2].parse().unwrap(),
53-
month: Month::from_str(&cap[1]).unwrap().number_from_month(),
54-
},
55-
)
56-
})
57-
.map(|(byte_range, date)| {
58-
line += text[end_of_last_cap..byte_range.end]
59-
.chars()
60-
.filter(|c| *c == '\n')
61-
.count();
62-
end_of_last_cap = byte_range.end;
63-
(line, date)
64-
})
65-
.collect()
51+
fn collect_dates_from_file(date_regexes: &[Regex], text: &str) -> Vec<(usize, Date)> {
52+
let mut output = Vec::new();
53+
for date_regex in date_regexes {
54+
let mut line = 1;
55+
let mut end_of_last_cap = 0;
56+
let results: Vec<_> = date_regex
57+
.captures_iter(text)
58+
.filter_map(|cap| {
59+
if let (Some(year), Some(month)) = (cap.get(2), cap.get(1)) {
60+
let year = year.as_str().parse().expect("year");
61+
let month = Month::from_str(month.as_str())
62+
.expect("month")
63+
.number_from_month();
64+
Some((cap.get(0).expect("all").range(), Date { year, month }))
65+
} else {
66+
None
67+
}
68+
})
69+
.map(|(byte_range, date)| {
70+
line += text[end_of_last_cap..byte_range.end]
71+
.chars()
72+
.filter(|c| *c == '\n')
73+
.count();
74+
end_of_last_cap = byte_range.end;
75+
(line, date)
76+
})
77+
.collect();
78+
output.extend(results);
79+
}
80+
output
6681
}
6782

6883
fn collect_dates(paths: impl Iterator<Item = PathBuf>) -> BTreeMap<PathBuf, Vec<(usize, Date)>> {
69-
let date_regex = make_date_regex();
84+
let date_regexes = make_date_regex();
7085
let mut data = BTreeMap::new();
7186
for path in paths {
7287
let text = fs::read_to_string(&path).unwrap();
73-
let dates = collect_dates_from_file(&date_regex, &text);
88+
let dates = collect_dates_from_file(&date_regexes, &text);
7489
if !dates.is_empty() {
7590
data.insert(path, dates);
7691
}
@@ -174,59 +189,129 @@ mod tests {
174189

175190
#[test]
176191
fn test_date_regex() {
177-
let regex = make_date_regex();
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"));
192+
let regexes = &make_date_regex();
193+
assert!(regexes[0].is_match("<!-- date-check: jan 2021 -->"));
194+
assert!(regexes[0].is_match("<!-- date-check: january 2021 -->"));
195+
assert!(regexes[0].is_match("<!-- date-check: Jan 2021 -->"));
196+
assert!(regexes[0].is_match("<!-- date-check: January 2021 -->"));
197+
assert!(regexes[1].is_match("<!-- date-check --> jan 2021"));
198+
assert!(regexes[1].is_match("<!-- date-check --> january 2021"));
199+
assert!(regexes[1].is_match("<!-- date-check --> Jan 2021"));
200+
assert!(regexes[1].is_match("<!-- date-check --> January 2021"));
183201
}
184202

185203
#[test]
186204
fn test_collect_dates_from_file() {
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\n\n may 2021\nTest8
205+
let text = r"
206+
Test1
207+
<!-- date-check: jan 2021 -->
208+
Test2
209+
Foo<!-- date-check: february 2021
210+
-->
211+
Test3
212+
Test4
213+
Foo<!-- date-check: Mar 2021 -->Bar
214+
<!-- date-check: April 2021
215+
-->
216+
Test5
217+
Test6
218+
Test7
219+
<!-- date-check:
220+
221+
may 2021 -->
222+
Test8
223+
Test1
224+
<!-- date-check --> jan 2021
225+
Test2
226+
Foo<!-- date-check
227+
--> february 2021
228+
Test3
229+
Test4
230+
Foo<!-- date-check --> mar 2021 Bar
231+
<!-- date-check
232+
--> apr 2021
233+
Test5
234+
Test6
235+
Test7
236+
<!-- date-check
237+
238+
--> may 2021
239+
Test8 \
190240
";
191241
assert_eq!(
192242
collect_dates_from_file(&make_date_regex(), text),
193243
vec![
194244
(
195-
2,
245+
3,
246+
Date {
247+
year: 2021,
248+
month: 1,
249+
}
250+
),
251+
(
252+
6,
253+
Date {
254+
year: 2021,
255+
month: 2,
256+
}
257+
),
258+
(
259+
9,
260+
Date {
261+
year: 2021,
262+
month: 3,
263+
}
264+
),
265+
(
266+
11,
267+
Date {
268+
year: 2021,
269+
month: 4,
270+
}
271+
),
272+
(
273+
17,
274+
Date {
275+
year: 2021,
276+
month: 5,
277+
}
278+
),
279+
(
280+
20,
196281
Date {
197282
year: 2021,
198283
month: 1,
199284
}
200285
),
201286
(
202-
4,
287+
23,
203288
Date {
204289
year: 2021,
205290
month: 2,
206291
}
207292
),
208293
(
209-
7,
294+
26,
210295
Date {
211296
year: 2021,
212297
month: 3,
213298
}
214299
),
215300
(
216-
8,
301+
28,
217302
Date {
218303
year: 2021,
219304
month: 4,
220305
}
221306
),
222307
(
223-
16,
308+
34,
224309
Date {
225310
year: 2021,
226311
month: 5,
227312
}
228313
),
229-
]
314+
],
230315
);
231316
}
232317
}

Diff for: 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 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

Diff for: 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

Diff for: 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 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,

Diff for: src/contributing.md

+18-6
Original file line numberDiff line numberDiff line change
@@ -437,17 +437,29 @@ 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-
We have a CI action (in `~/.github/workflows/date-check.yml`)
443-
that generates a monthly issue with any of these that are over 6 months old.
444-
445-
The following formats are accepted:
440+
or _"As of now, ..."_,
441+
consider adding the date, in one of the following formats:
446442
- Jan 2021
447443
- January 2021
448444
- jan 2021
449445
- january 2021
450446

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.
449+
450+
For the action to pick the date, add this annotation:
451+
452+
<!-- date-check -->
453+
454+
Example:
455+
456+
As of <!-- date-check --> Jul 2022, the foo did the bar.
457+
458+
For cases where the date should not be part of the visible rendered output,
459+
use the following instead:
460+
461+
<!-- date-check: Jul 2022 -->
462+
451463
- A link to a relevant WG, tracking issue, `rustc` rustdoc page, or similar, that may provide
452464
further explanation for the change process or a way to verify that the information is not
453465
outdated.

Diff for: src/conventions.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Formatting is checked by the `tidy` script. It runs automatically when you do
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 <!-- as of April 2022 --> `--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

Diff for: 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 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

Diff for: 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 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.

Diff for: 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 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

Diff for: 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 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

Diff for: 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 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

Diff for: src/llvm-coverage-instrumentation.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,10 @@ 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 December 2021)
225+
[^llvm-and-covmap-versions]: The Rust compiler (as of <!-- date-check --> December 2021)
226226
supports _LLVM Coverage Mapping Format_ Version 5 or 6. Version 5
227-
was introduced in _LLVM 12_, which is (as of this writing) the minimum LLVM
227+
was introduced in _LLVM 12_,
228+
which is (as of <!-- date-check: December 2021--> this writing) the minimum LLVM
228229
version supported by the current version of Rust. Version 6 was introduced in
229230
_LLVM 13_, which is currently the default LLVM version for Rust. The Rust
230231
compiler will automatically use the most up-to-date coverage mapping format

Diff for: src/opaque-types-type-alias-impl-trait.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ it implements `Bar`. Therefore, any of `Bar`'s interface can be used on a `Foo`,
1515
but nothing else (regardless of whether it implements any other traits).
1616

1717
Since there needs to be a concrete background type,
18-
you can (as of January 2021) express that type
18+
you can (as of <!-- date-check --> January 2021) express that type
1919
by using the opaque type in a "defining use site".
2020

2121
```rust,ignore

Diff for: src/overview.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ Moreover, the compiler wasn't originally built to use a query system; the query
292292
system has been retrofitted into the compiler, so parts of it are not query-fied
293293
yet. Also, LLVM isn't our code, so that isn't querified either. The plan is to
294294
eventually query-fy all of the steps listed in the previous section,
295-
but as of November 2021, only the steps between HIR and
295+
but as of <!-- date-check --> November 2021, only the steps between HIR and
296296
LLVM IR are query-fied. That is, lexing, parsing, name resolution, and macro
297297
expansion are done all at once for the whole program.
298298

0 commit comments

Comments
 (0)