Skip to content

Commit 5d49951

Browse files
committed
Auto merge of rust-lang#13357 - Veykril:minicore, r=Veykril
internal: Allow minicore flags specification to be order independent
2 parents 21319d1 + 28c21bc commit 5d49951

File tree

2 files changed

+51
-50
lines changed

2 files changed

+51
-50
lines changed

crates/test-utils/src/fixture.rs

+27-26
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161
//! "
6262
//! ```
6363
64+
use std::iter;
65+
6466
use rustc_hash::FxHashMap;
6567
use stdx::trim_indent;
6668

@@ -259,7 +261,7 @@ impl MiniCore {
259261
if res.has_flag(entry) {
260262
panic!("duplicate minicore flag: {:?}", entry);
261263
}
262-
res.activated_flags.push(entry.to_string());
264+
res.activated_flags.push(entry.to_owned());
263265
}
264266

265267
res
@@ -273,35 +275,34 @@ impl MiniCore {
273275
let raw_mini_core = include_str!("./minicore.rs");
274276
let mut lines = raw_mini_core.split_inclusive('\n');
275277

276-
let mut parsing_flags = false;
277278
let mut implications = Vec::new();
278279

279280
// Parse `//!` preamble and extract flags and dependencies.
280-
for line in lines.by_ref() {
281-
let line = match line.strip_prefix("//!") {
282-
Some(it) => it,
283-
None => {
284-
assert!(line.trim().is_empty());
285-
break;
286-
}
287-
};
288-
289-
if parsing_flags {
290-
let (flag, deps) = line.split_once(':').unwrap();
291-
let flag = flag.trim();
292-
self.valid_flags.push(flag.to_string());
293-
for dep in deps.split(", ") {
294-
let dep = dep.trim();
295-
if !dep.is_empty() {
296-
self.assert_valid_flag(dep);
297-
implications.push((flag, dep));
298-
}
299-
}
281+
let trim_doc: fn(&str) -> Option<&str> = |line| match line.strip_prefix("//!") {
282+
Some(it) => Some(it),
283+
None => {
284+
assert!(line.trim().is_empty(), "expected empty line after minicore header");
285+
None
300286
}
287+
};
288+
for line in lines
289+
.by_ref()
290+
.map_while(trim_doc)
291+
.skip_while(|line| !line.contains("Available flags:"))
292+
.skip(1)
293+
{
294+
let (flag, deps) = line.split_once(':').unwrap();
295+
let flag = flag.trim();
296+
297+
self.valid_flags.push(flag.to_string());
298+
implications.extend(
299+
iter::repeat(flag)
300+
.zip(deps.split(", ").map(str::trim).filter(|dep| !dep.is_empty())),
301+
);
302+
}
301303

302-
if line.contains("Available flags:") {
303-
parsing_flags = true;
304-
}
304+
for (_, dep) in &implications {
305+
self.assert_valid_flag(dep);
305306
}
306307

307308
for flag in &self.activated_flags {
@@ -332,7 +333,7 @@ impl MiniCore {
332333
}
333334
if let Some(region) = trimmed.strip_prefix("// endregion:") {
334335
let prev = active_regions.pop().unwrap();
335-
assert_eq!(prev, region);
336+
assert_eq!(prev, region, "unbalanced region pairs");
336337
continue;
337338
}
338339

crates/test-utils/src/minicore.rs

+24-24
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,36 @@
88
//! We then strip all the code marked with other flags.
99
//!
1010
//! Available flags:
11-
//! sized:
12-
//! unsize: sized
11+
//! add:
12+
//! as_ref: sized
13+
//! bool_impl: option, fn
14+
//! clone: sized
1315
//! coerce_unsized: unsize
14-
//! slice:
15-
//! range:
16-
//! deref: sized
16+
//! copy: clone
17+
//! default: sized
1718
//! deref_mut: deref
18-
//! index: sized
19+
//! deref: sized
20+
//! derive:
21+
//! drop:
22+
//! eq: sized
23+
//! fmt: result
1924
//! fn:
20-
//! try:
21-
//! pin:
25+
//! from: sized
2226
//! future: pin
23-
//! option:
24-
//! result:
27+
//! generator: pin
28+
//! hash:
29+
//! index: sized
2530
//! iterator: option
2631
//! iterators: iterator, fn
27-
//! default: sized
28-
//! hash:
29-
//! clone: sized
30-
//! copy: clone
31-
//! from: sized
32-
//! eq: sized
32+
//! option:
3333
//! ord: eq, option
34-
//! derive:
35-
//! fmt: result
36-
//! bool_impl: option, fn
37-
//! add:
38-
//! as_ref: sized
39-
//! drop:
40-
//! generator: pin
34+
//! pin:
35+
//! range:
36+
//! result:
37+
//! sized:
38+
//! slice:
39+
//! try:
40+
//! unsize: sized
4141
4242
pub mod marker {
4343
// region:sized
@@ -584,7 +584,7 @@ pub mod iter {
584584
}
585585
}
586586
}
587-
pub use self::adapters::{Take, FilterMap};
587+
pub use self::adapters::{FilterMap, Take};
588588

589589
mod sources {
590590
mod repeat {

0 commit comments

Comments
 (0)