Skip to content

Commit d871755

Browse files
authored
Merge pull request #2642 from rust-lang/tshepang/sembr
sembr stabilization_guide.md and improve it a bit
2 parents 2430eb8 + a2fda4a commit d871755

File tree

2 files changed

+81
-41
lines changed

2 files changed

+81
-41
lines changed

ci/sembr/src/main.rs

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@ struct Cli {
2222
show_diff: bool,
2323
}
2424

25-
static REGEX_IGNORE: LazyLock<Regex> =
26-
LazyLock::new(|| Regex::new(r"^\s*(\d\.|\-|\*)\s+").unwrap());
2725
static REGEX_IGNORE_END: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"(\.|\?|;|!)$").unwrap());
2826
static REGEX_IGNORE_LINK_TARGETS: LazyLock<Regex> =
2927
LazyLock::new(|| Regex::new(r"^\[.+\]: ").unwrap());
3028
static REGEX_SPLIT: LazyLock<Regex> =
31-
LazyLock::new(|| Regex::new(r"([^\.]\.|[^r]\?|;|!)\s+").unwrap());
29+
LazyLock::new(|| Regex::new(r"([^\.\d\-\*]\.|[^r]\?|;|!)\s").unwrap());
30+
// list elements, numbered (1.) or not (- and *)
31+
static REGEX_LIST_ENTRY: LazyLock<Regex> =
32+
LazyLock::new(|| Regex::new(r"^\s*(\d\.|\-|\*)\s+").unwrap());
3233

3334
fn main() -> Result<()> {
3435
let cli = Cli::parse();
@@ -99,7 +100,6 @@ fn ignore(line: &str, in_code_block: bool) -> bool {
99100
|| line.trim_start().starts_with('>')
100101
|| line.starts_with('#')
101102
|| line.trim().is_empty()
102-
|| REGEX_IGNORE.is_match(line)
103103
|| REGEX_IGNORE_LINK_TARGETS.is_match(line)
104104
}
105105

@@ -120,11 +120,19 @@ fn comply(content: &str) -> String {
120120
continue;
121121
}
122122
if REGEX_SPLIT.is_match(&line) {
123-
let indent = line.find(|ch: char| !ch.is_whitespace()).unwrap();
124-
let new_lines: Vec<_> = line
125-
.split_inclusive(&*REGEX_SPLIT)
126-
.map(|portion| format!("{:indent$}{}", "", portion.trim()))
123+
let indent = if let Some(regex_match) = REGEX_LIST_ENTRY.find(&line) {
124+
regex_match.len()
125+
} else {
126+
line.find(|ch: char| !ch.is_whitespace()).unwrap()
127+
};
128+
let mut newly_split_lines = line.split_inclusive(&*REGEX_SPLIT);
129+
let first = newly_split_lines.next().unwrap().trim_end().to_owned();
130+
let mut remaining: Vec<_> = newly_split_lines
131+
.map(|portion| format!("{:indent$}{}", "", portion.trim_end()))
127132
.collect();
133+
let mut new_lines = Vec::new();
134+
new_lines.push(first);
135+
new_lines.append(&mut remaining);
128136
new_content.splice(new_n..=new_n, new_lines.clone());
129137
new_n += new_lines.len() - 1;
130138
}
@@ -182,42 +190,47 @@ fn lengthen_lines(content: &str, limit: usize) -> String {
182190

183191
#[test]
184192
fn test_sembr() {
185-
let original = "\
193+
let original = "
186194
# some. heading
187-
must! be; split? and. normalizes space
188-
1. ignore numbered
195+
must! be; split?
196+
1. ignore a dot after number. but no further
189197
ignore | tables
190198
ignore e.g. and
191199
ignore i.e. and
192200
ignore E.g. too
193-
- ignore. list
194-
* ignore. list
201+
- list. entry
202+
* list. entry
195203
```
196204
some code. block
197205
```
198206
sentence with *italics* should not be ignored. truly.
199207
git log main.. compiler
208+
foo. bar. baz
200209
";
201-
let expected = "\
210+
let expected = "
202211
# some. heading
203212
must!
204213
be;
205214
split?
206-
and.
207-
normalizes space
208-
1. ignore numbered
215+
1. ignore a dot after number.
216+
but no further
209217
ignore | tables
210218
ignore e.g. and
211219
ignore i.e. and
212220
ignore E.g. too
213-
- ignore. list
214-
* ignore. list
221+
- list.
222+
entry
223+
* list.
224+
entry
215225
```
216226
some code. block
217227
```
218228
sentence with *italics* should not be ignored.
219229
truly.
220230
git log main.. compiler
231+
foo.
232+
bar.
233+
baz
221234
";
222235
assert_eq!(expected, comply(original));
223236
}
@@ -263,13 +276,13 @@ fn test_prettify_ignore_link_targets() {
263276

264277
#[test]
265278
fn test_sembr_then_prettify() {
266-
let original = "\
279+
let original = "
267280
hi there. do
268281
not split
269282
short sentences.
270283
hi again.
271284
";
272-
let expected = "\
285+
let expected = "
273286
hi there.
274287
do
275288
not split
@@ -278,15 +291,15 @@ hi again.
278291
";
279292
let processed = comply(original);
280293
assert_eq!(expected, processed);
281-
let expected = "\
294+
let expected = "
282295
hi there.
283296
do not split
284297
short sentences.
285298
hi again.
286299
";
287300
let processed = lengthen_lines(&processed, 50);
288301
assert_eq!(expected, processed);
289-
let expected = "\
302+
let expected = "
290303
hi there.
291304
do not split short sentences.
292305
hi again.
@@ -297,12 +310,12 @@ hi again.
297310

298311
#[test]
299312
fn test_sembr_question_mark() {
300-
let original = "\
313+
let original = "
301314
o? whatever
302315
r? @reviewer
303316
r? @reviewer
304317
";
305-
let expected = "\
318+
let expected = "
306319
o?
307320
whatever
308321
r? @reviewer

src/stabilization_guide.md

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# Request for stabilization
22

3-
**NOTE**: This page is about stabilizing *language* features. For stabilizing *library* features, see [Stabilizing a library feature].
3+
**NOTE**: This page is about stabilizing *language* features.
4+
For stabilizing *library* features, see [Stabilizing a library feature].
45

56
[Stabilizing a library feature]: ./stability.md#stabilizing-a-library-feature
67

7-
Once an unstable feature has been well-tested with no outstanding concerns, anyone may push for its stabilization, though involving the people who have worked on it is prudent. Follow these steps:
8+
Once an unstable feature has been well-tested with no outstanding concerns, anyone may push for its stabilization, though involving the people who have worked on it is prudent.
9+
Follow these steps:
810

911
## Write an RFC, if needed
1012

@@ -16,16 +18,23 @@ If the feature was part of a [lang experiment], the lang team generally will wan
1618

1719
<a id="updating-documentation"></a>
1820

19-
The feature might be documented in the [`Unstable Book`], located at [`src/doc/unstable-book`]. Remove the page for the feature gate if it exists. Integrate any useful parts of that documentation in other places.
21+
The feature might be documented in the [`Unstable Book`], located at [`src/doc/unstable-book`].
22+
Remove the page for the feature gate if it exists.
23+
Integrate any useful parts of that documentation in other places.
2024

2125
Places that may need updated documentation include:
2226

2327
- [The Reference]: This must be updated, in full detail, and a member of the lang-docs team must review and approve the PR before the stabilization can be merged.
24-
- [The Book]: This is updated as needed. If you're not sure, please open an issue on this repository and it can be discussed.
25-
- Standard library documentation: This is updated as needed. Language features often don't need this, but if it's a feature that changes how idiomatic examples are written, such as when `?` was added to the language, updating these in the library documentation is important. Review also the keyword documentation and ABI documentation in the standard library, as these sometimes needs updates for language changes.
28+
- [The Book]: This is updated as needed.
29+
If you're not sure, please open an issue on this repository and it can be discussed.
30+
- Standard library documentation: This is updated as needed.
31+
Language features often don't need this, but if it's a feature that changes how idiomatic examples are written, such as when `?` was added to the language, updating these in the library documentation is important.
32+
Review also the keyword documentation and ABI documentation in the standard library, as these sometimes need updates for language changes.
2633
- [Rust by Example]: This is updated as needed.
2734

28-
Prepare PRs to update documentation involving this new feature for the repositories mentioned above. Maintainers of these repositories will keep these PRs open until the whole stabilization process has completed. Meanwhile, we can proceed to the next step.
35+
Prepare PRs to update documentation involving this new feature for the repositories mentioned above.
36+
Maintainers of these repositories will keep these PRs open until the whole stabilization process has completed.
37+
Meanwhile, we can proceed to the next step.
2938

3039
## Write a stabilization report
3140

@@ -34,7 +43,8 @@ Author a stabilization report using the [template found in this repository][srt]
3443
The stabilization reports summarizes:
3544

3645
- The main design decisions and deviations since the RFC was accepted, including both decisions that were FCP'd or otherwise accepted by the language team as well as those being presented to the lang team for the first time.
37-
- Often, the final stabilized language feature has significant design deviations from the original RFC. That's OK, but these deviations must be highlighted and explained carefully.
46+
- Often, the final stabilized language feature has significant design deviations from the original RFC.
47+
That's OK, but these deviations must be highlighted and explained carefully.
3848
- The work that has been done since the RFC was accepted, acknowledging the main contributors that helped drive the language feature forward.
3949

4050
The [*Stabilization Template*][srt] includes a series of questions that aim to surface connections between this feature and lang's subteams (e.g. types, opsem, lang-docs, etc.) and to identify items that are commonly overlooked.
@@ -51,14 +61,19 @@ Before the stabilization will be considered by the lang team, there must be a co
5161

5262
### Updating the feature-gate listing
5363

54-
There is a central listing of unstable feature-gates in [`compiler/rustc_feature/src/unstable.rs`]. Search for the `declare_features!` macro. There should be an entry for the feature you are aiming to stabilize, something like (this example is taken from [rust-lang/rust#32409]:
64+
There is a central listing of unstable feature-gates in [`compiler/rustc_feature/src/unstable.rs`].
65+
Search for the `declare_features!` macro.
66+
There should be an entry for the feature you are aiming to stabilize,
67+
something like the following (taken from [rust-lang/rust#32409]:
5568

5669
```rust,ignore
5770
// pub(restricted) visibilities (RFC 1422)
5871
(unstable, pub_restricted, "CURRENT_RUSTC_VERSION", Some(32409)),
5972
```
6073

61-
The above line should be moved to [`compiler/rustc_feature/src/accepted.rs`]. Entries in the `declare_features!` call are sorted, so find the correct place. When it is done, it should look like:
74+
The above line should be moved to [`compiler/rustc_feature/src/accepted.rs`].
75+
Entries in the `declare_features!` call are sorted, so find the correct place.
76+
When it is done, it should look like:
6277

6378
```rust,ignore
6479
// pub(restricted) visibilities (RFC 1422)
@@ -70,27 +85,36 @@ The above line should be moved to [`compiler/rustc_feature/src/accepted.rs`]. En
7085

7186
### Removing existing uses of the feature-gate
7287

73-
Next, search for the feature string (in this case, `pub_restricted`) in the codebase to find where it appears. Change uses of `#![feature(XXX)]` from the `std` and any rustc crates (this includes test folders under `library/` and `compiler/` but not the toplevel `tests/` one) to be `#![cfg_attr(bootstrap, feature(XXX))]`. This includes the feature-gate only for stage0, which is built using the current beta (this is needed because the feature is still unstable in the current beta).
88+
Next, search for the feature string (in this case, `pub_restricted`) in the codebase to find where it appears.
89+
Change uses of `#![feature(XXX)]` from the `std` and any rustc crates
90+
(which includes test folders under `library/` and `compiler/` but not the toplevel `tests/` one)
91+
to be `#![cfg_attr(bootstrap, feature(XXX))]`.
92+
This includes the feature-gate only for stage0, which is built using the current beta (this is needed because the feature is still unstable in the current beta).
7493

7594
Also, remove those strings from any tests (e.g. under `tests/`). If there are tests specifically targeting the feature-gate (i.e., testing that the feature-gate is required to use the feature, but nothing else), simply remove the test.
7695

7796
### Do not require the feature-gate to use the feature
7897

79-
Most importantly, remove the code which flags an error if the feature-gate is not present (since the feature is now considered stable). If the feature can be detected because it employs some new syntax, then a common place for that code to be is in `compiler/rustc_ast_passes/src/feature_gate.rs`. For example, you might see code like this:
98+
Most importantly, remove the code which flags an error if the feature-gate is not present (since the feature is now considered stable).
99+
If the feature can be detected because it employs some new syntax, then a common place for that code to be is in `compiler/rustc_ast_passes/src/feature_gate.rs`.
100+
For example, you might see code like this:
80101

81102
```rust,ignore
82103
gate_all!(pub_restricted, "`pub(restricted)` syntax is experimental");
83104
```
84105

85-
The `gate_all!` macro reports an error if the `pub_restricted` feature is not enabled. It is not needed now that `pub(restricted)` is stable.
106+
The `gate_all!` macro reports an error if the `pub_restricted` feature is not enabled.
107+
It is not needed now that `pub(restricted)` is stable.
86108

87109
For more subtle features, you may find code like this:
88110

89111
```rust,ignore
90112
if self.tcx.features().async_fn_in_dyn_trait() { /* XXX */ }
91113
```
92114

93-
This `pub_restricted` field (named after the feature) would ordinarily be false if the feature flag is not present and true if it is. So transform the code to assume that the field is true. In this case, that would mean removing the `if` and leaving just the `/* XXX */`.
115+
This `pub_restricted` field (named after the feature) would ordinarily be false if the feature flag is not present and true if it is.
116+
So, transform the code to assume that the field is true.
117+
In this case, that would mean removing the `if` and leaving just the `/* XXX */`.
94118

95119
```rust,ignore
96120
if self.tcx.sess.features.borrow().pub_restricted { /* XXX */ }
@@ -126,7 +150,8 @@ When opening the stabilization PR, CC the lang team and its advisors (`@rust-lan
126150
- `@rust-lang/libs-api`, for changes to the standard library API or its guarantees.
127151
- `@rust-lang/lang-docs`, for questions about how this should be documented in the Reference.
128152

129-
After the stabilization PR is opened with the stabilization report, wait a bit for any immediate comments. When such comments "simmer down" and you feel the PR is ready for consideration by the lang team, [nominate the PR](https://lang-team.rust-lang.org/how_to/nominate.html) to get it on the agenda for consideration in an upcoming lang meeting.
153+
After the stabilization PR is opened with the stabilization report, wait a bit for any immediate comments.
154+
When such comments "simmer down" and you feel the PR is ready for consideration by the lang team, [nominate the PR](https://lang-team.rust-lang.org/how_to/nominate.html) to get it on the agenda for consideration in an upcoming lang meeting.
130155

131156
If you are not a `rust-lang` organization member, you can ask your assigned reviewer to CC the relevant teams on your behalf.
132157

@@ -138,7 +163,8 @@ After the lang team and other relevant teams review the stabilization, and after
138163
@rfcbot fcp merge
139164
```
140165

141-
Once enough team members have reviewed, the PR will move into a "final comment period" (FCP). If no new concerns are raised, this period will complete and the PR can be merged after implementation review in the usual way.
166+
Once enough team members have reviewed, the PR will move into a "final comment period" (FCP).
167+
If no new concerns are raised, this period will complete and the PR can be merged after implementation review in the usual way.
142168

143169
## Reviewing and merging stabilizations
144170

@@ -151,4 +177,5 @@ On a stabilization, before giving it the `r+`, ensure that the PR:
151177
- Has sufficient tests to convincingly demonstrate these things.
152178
- Is accompanied by a PR to the Reference than has been reviewed and approved by a member of lang-docs.
153179

154-
In particular, when reviewing the PR, keep an eye out for any user-visible details that the lang team failed to consider and specify. If you find one, describe it and nominate the PR for the lang team.
180+
In particular, when reviewing the PR, keep an eye out for any user-visible details that the lang team failed to consider and specify.
181+
If you find one, describe it and nominate the PR for the lang team.

0 commit comments

Comments
 (0)