Auto merge of #14604 - HKalbasi:dev3, r=Veykril

internal: Add minicore smoke test

fix #14501
This commit is contained in:
bors 2023-04-18 14:34:44 +00:00
commit 112464fd6b
4 changed files with 97 additions and 24 deletions

View File

@ -8,7 +8,7 @@
RootDatabase,
};
use stdx::trim_indent;
use test_utils::{assert_eq_text, extract_annotations};
use test_utils::{assert_eq_text, extract_annotations, MiniCore};
use crate::{DiagnosticsConfig, ExprFillDefaultMode, Severity};
@ -143,3 +143,23 @@ fn test_disabled_diagnostics() {
);
assert!(!diagnostics.is_empty());
}
#[test]
fn minicore_smoke_test() {
fn check(minicore: MiniCore) {
let source = minicore.source_code();
let mut config = DiagnosticsConfig::test_sample();
// This should be ignored since we conditionaly remove code which creates single item use with braces
config.disabled.insert("unnecessary-braces".to_string());
check_diagnostics_with_config(config, &source);
}
// Checks that there is no diagnostic in minicore for each flag.
for flag in MiniCore::available_flags() {
eprintln!("Checking minicore flag {flag}");
check(MiniCore::from_flags([flag]));
}
// And one time for all flags, to check codes which are behind multiple flags + prevent name collisions
eprintln!("Checking all minicore flags");
check(MiniCore::from_flags(MiniCore::available_flags()))
}

View File

@ -444,7 +444,7 @@ fn main() {
file_id: FileId(
1,
),
range: 5805..5813,
range: 5768..5776,
},
),
tooltip: "",
@ -457,7 +457,7 @@ fn main() {
file_id: FileId(
1,
),
range: 5837..5841,
range: 5800..5804,
},
),
tooltip: "",
@ -478,7 +478,7 @@ fn main() {
file_id: FileId(
1,
),
range: 5805..5813,
range: 5768..5776,
},
),
tooltip: "",
@ -491,7 +491,7 @@ fn main() {
file_id: FileId(
1,
),
range: 5837..5841,
range: 5800..5804,
},
),
tooltip: "",
@ -512,7 +512,7 @@ fn main() {
file_id: FileId(
1,
),
range: 5805..5813,
range: 5768..5776,
},
),
tooltip: "",
@ -525,7 +525,7 @@ fn main() {
file_id: FileId(
1,
),
range: 5837..5841,
range: 5800..5804,
},
),
tooltip: "",

View File

@ -254,10 +254,19 @@ fn parse_meta_line(meta: &str) -> Fixture {
}
impl MiniCore {
const RAW_SOURCE: &str = include_str!("./minicore.rs");
fn has_flag(&self, flag: &str) -> bool {
self.activated_flags.iter().any(|it| it == flag)
}
pub fn from_flags<'a>(flags: impl IntoIterator<Item = &'a str>) -> Self {
MiniCore {
activated_flags: flags.into_iter().map(|x| x.to_owned()).collect(),
valid_flags: Vec::new(),
}
}
#[track_caller]
fn assert_valid_flag(&self, flag: &str) {
if !self.valid_flags.iter().any(|it| it == flag) {
@ -278,13 +287,21 @@ fn parse(line: &str) -> MiniCore {
res
}
pub fn available_flags() -> impl Iterator<Item = &'static str> {
let lines = MiniCore::RAW_SOURCE.split_inclusive('\n');
lines
.map_while(|x| x.strip_prefix("//!"))
.skip_while(|line| !line.contains("Available flags:"))
.skip(1)
.map(|x| x.split_once(':').unwrap().0.trim())
}
/// Strips parts of minicore.rs which are flagged by inactive flags.
///
/// This is probably over-engineered to support flags dependencies.
pub fn source_code(mut self) -> String {
let mut buf = String::new();
let raw_mini_core = include_str!("./minicore.rs");
let mut lines = raw_mini_core.split_inclusive('\n');
let mut lines = MiniCore::RAW_SOURCE.split_inclusive('\n');
let mut implications = Vec::new();

View File

@ -32,8 +32,9 @@
//! iterator: option
//! iterators: iterator, fn
//! non_zero:
//! option:
//! option: panic
//! ord: eq, option
//! panic:
//! pin:
//! range:
//! result:
@ -191,6 +192,12 @@ pub enum Infallible {}
// endregion:infallible
}
// region:drop
pub mod mem {
pub fn drop<T>(_x: T) {}
}
// endregion:drop
pub mod ops {
// region:coerce_unsized
mod unsize {
@ -315,12 +322,6 @@ unsafe impl<T> SliceIndex<[T]> for usize {
pub use self::index::{Index, IndexMut};
// endregion:index
// region:drop
pub mod mem {
pub fn drop<T>(_x: T) {}
}
// endregion:drop
// region:range
mod range {
#[lang = "RangeFull"]
@ -473,12 +474,24 @@ pub trait Try: FromResidual<Self::Residual> {
impl<B, C> Try for ControlFlow<B, C> {
type Output = C;
type Residual = ControlFlow<B, Infallible>;
fn from_output(output: Self::Output) -> Self {}
fn branch(self) -> ControlFlow<Self::Residual, Self::Output> {}
fn from_output(output: Self::Output) -> Self {
ControlFlow::Continue(output)
}
fn branch(self) -> ControlFlow<Self::Residual, Self::Output> {
match self {
ControlFlow::Continue(x) => ControlFlow::Continue(x),
ControlFlow::Break(x) => ControlFlow::Break(ControlFlow::Break(x)),
}
}
}
impl<B, C> FromResidual for ControlFlow<B, C> {
fn from_residual(residual: ControlFlow<B, Infallible>) -> Self {}
fn from_residual(residual: ControlFlow<B, Infallible>) -> Self {
match residual {
ControlFlow::Break(b) => ControlFlow::Break(b),
ControlFlow::Continue(_) => loop {},
}
}
}
// region:option
impl<T> Try for Option<T> {
@ -499,6 +512,7 @@ impl<T> FromResidual for Option<T> {
fn from_residual(x: Option<Infallible>) -> Self {
match x {
None => None,
Some(_) => loop {},
}
}
}
@ -527,6 +541,7 @@ impl<T, E, F: From<E>> FromResidual<Result<Infallible, E>> for Result<T, F> {
fn from_residual(residual: Result<Infallible, E>) -> Self {
match residual {
Err(e) => Err(From::from(e)),
Ok(_) => loop {},
}
}
}
@ -840,8 +855,6 @@ fn next(&mut self) -> Option<A> {
mod traits {
mod iterator {
use super::super::Take;
pub trait Iterator {
type Item;
#[lang = "next"]
@ -903,7 +916,7 @@ pub struct IntoIter<T, const N: usize> {
type Item = T;
type IntoIter = IntoIter<T, N>;
fn into_iter(self) -> I {
IntoIter { data: self, range: IndexRange { start: 0, end: self.len() } }
IntoIter { data: self, range: IndexRange { start: 0, end: loop {} } }
}
}
impl<T, const N: usize> Iterator for IntoIter<T, N> {
@ -919,16 +932,38 @@ fn next(&mut self) -> Option<T> {
}
// endregion:iterator
// region:derive
// region:panic
mod panic {
pub macro panic_2021 {
($($t:tt)+) => (
/* Nothing yet */
),
}
}
// endregion:panic
mod macros {
// region:panic
#[macro_export]
#[rustc_builtin_macro(std_panic)]
macro_rules! panic {
($($arg:tt)*) => {
/* compiler built-in */
};
}
pub(crate) use panic;
// endregion:panic
// region:derive
pub(crate) mod builtin {
#[rustc_builtin_macro]
pub macro derive($item:item) {
/* compiler built-in */
}
}
// endregion:derive
}
// endregion:derive
// region:non_zero
pub mod num {
@ -983,6 +1018,7 @@ pub mod v1 {
ops::{Fn, FnMut, FnOnce}, // :fn
option::Option::{self, None, Some}, // :option
result::Result::{self, Err, Ok}, // :result
panic, // :panic
};
}