Skip to content

internal: Allow minicore flags specification to be order independent #13357

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 27 additions & 26 deletions crates/test-utils/src/fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
//! "
//! ```

use std::iter;

use rustc_hash::FxHashMap;
use stdx::trim_indent;

Expand Down Expand Up @@ -259,7 +261,7 @@ impl MiniCore {
if res.has_flag(entry) {
panic!("duplicate minicore flag: {:?}", entry);
}
res.activated_flags.push(entry.to_string());
res.activated_flags.push(entry.to_owned());
}

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

let mut parsing_flags = false;
let mut implications = Vec::new();

// Parse `//!` preamble and extract flags and dependencies.
for line in lines.by_ref() {
let line = match line.strip_prefix("//!") {
Some(it) => it,
None => {
assert!(line.trim().is_empty());
break;
}
};

if parsing_flags {
let (flag, deps) = line.split_once(':').unwrap();
let flag = flag.trim();
self.valid_flags.push(flag.to_string());
for dep in deps.split(", ") {
let dep = dep.trim();
if !dep.is_empty() {
self.assert_valid_flag(dep);
implications.push((flag, dep));
}
}
let trim_doc: fn(&str) -> Option<&str> = |line| match line.strip_prefix("//!") {
Some(it) => Some(it),
None => {
assert!(line.trim().is_empty(), "expected empty line after minicore header");
None
}
};
for line in lines
.by_ref()
.map_while(trim_doc)
.skip_while(|line| !line.contains("Available flags:"))
.skip(1)
{
let (flag, deps) = line.split_once(':').unwrap();
let flag = flag.trim();

self.valid_flags.push(flag.to_string());
implications.extend(
iter::repeat(flag)
.zip(deps.split(", ").map(str::trim).filter(|dep| !dep.is_empty())),
);
}

if line.contains("Available flags:") {
parsing_flags = true;
}
for (_, dep) in &implications {
self.assert_valid_flag(dep);
}

for flag in &self.activated_flags {
Expand Down Expand Up @@ -332,7 +333,7 @@ impl MiniCore {
}
if let Some(region) = trimmed.strip_prefix("// endregion:") {
let prev = active_regions.pop().unwrap();
assert_eq!(prev, region);
assert_eq!(prev, region, "unbalanced region pairs");
continue;
}

Expand Down
48 changes: 24 additions & 24 deletions crates/test-utils/src/minicore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,36 @@
//! We then strip all the code marked with other flags.
//!
//! Available flags:
//! sized:
//! unsize: sized
//! add:
//! as_ref: sized
//! bool_impl: option, fn
//! clone: sized
//! coerce_unsized: unsize
//! slice:
//! range:
//! deref: sized
//! copy: clone
//! default: sized
//! deref_mut: deref
//! index: sized
//! deref: sized
//! derive:
//! drop:
//! eq: sized
//! fmt: result
//! fn:
//! try:
//! pin:
//! from: sized
//! future: pin
//! option:
//! result:
//! generator: pin
//! hash:
//! index: sized
//! iterator: option
//! iterators: iterator, fn
//! default: sized
//! hash:
//! clone: sized
//! copy: clone
//! from: sized
//! eq: sized
//! option:
//! ord: eq, option
//! derive:
//! fmt: result
//! bool_impl: option, fn
//! add:
//! as_ref: sized
//! drop:
//! generator: pin
//! pin:
//! range:
//! result:
//! sized:
//! slice:
//! try:
//! unsize: sized

pub mod marker {
// region:sized
Expand Down Expand Up @@ -584,7 +584,7 @@ pub mod iter {
}
}
}
pub use self::adapters::{Take, FilterMap};
pub use self::adapters::{FilterMap, Take};

mod sources {
mod repeat {
Expand Down