Skip to content

Commit

Permalink
Auto merge of rust-lang#14604 - HKalbasi:dev3, r=Veykril
Browse files Browse the repository at this point in the history
internal: Add minicore smoke test

fix rust-lang#14501
  • Loading branch information
bors committed Apr 18, 2023
2 parents e84781a + f05f7ab commit 112464f
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 24 deletions.
22 changes: 21 additions & 1 deletion crates/ide-diagnostics/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use ide_db::{
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};

Expand Down Expand Up @@ -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()))
}
12 changes: 6 additions & 6 deletions crates/ide/src/inlay_hints/chaining.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ fn main() {
file_id: FileId(
1,
),
range: 5805..5813,
range: 5768..5776,
},
),
tooltip: "",
Expand All @@ -457,7 +457,7 @@ fn main() {
file_id: FileId(
1,
),
range: 5837..5841,
range: 5800..5804,
},
),
tooltip: "",
Expand All @@ -478,7 +478,7 @@ fn main() {
file_id: FileId(
1,
),
range: 5805..5813,
range: 5768..5776,
},
),
tooltip: "",
Expand All @@ -491,7 +491,7 @@ fn main() {
file_id: FileId(
1,
),
range: 5837..5841,
range: 5800..5804,
},
),
tooltip: "",
Expand All @@ -512,7 +512,7 @@ fn main() {
file_id: FileId(
1,
),
range: 5805..5813,
range: 5768..5776,
},
),
tooltip: "",
Expand All @@ -525,7 +525,7 @@ fn main() {
file_id: FileId(
1,
),
range: 5837..5841,
range: 5800..5804,
},
),
tooltip: "",
Expand Down
21 changes: 19 additions & 2 deletions crates/test-utils/src/fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,19 @@ impl FixtureWithProjectMeta {
}

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) {
Expand All @@ -278,13 +287,21 @@ impl 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();

Expand Down
66 changes: 51 additions & 15 deletions crates/test-utils/src/minicore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@
//! iterator: option
//! iterators: iterator, fn
//! non_zero:
//! option:
//! option: panic
//! ord: eq, option
//! panic:
//! pin:
//! range:
//! result:
Expand Down Expand Up @@ -191,6 +192,12 @@ pub mod convert {
// endregion:infallible
}

// region:drop
pub mod mem {
pub fn drop<T>(_x: T) {}
}
// endregion:drop

pub mod ops {
// region:coerce_unsized
mod unsize {
Expand Down Expand Up @@ -315,12 +322,6 @@ pub mod ops {
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"]
Expand Down Expand Up @@ -473,12 +474,24 @@ pub mod ops {
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> {
Expand All @@ -499,6 +512,7 @@ pub mod ops {
fn from_residual(x: Option<Infallible>) -> Self {
match x {
None => None,
Some(_) => loop {},
}
}
}
Expand Down Expand Up @@ -527,6 +541,7 @@ pub mod ops {
fn from_residual(residual: Result<Infallible, E>) -> Self {
match residual {
Err(e) => Err(From::from(e)),
Ok(_) => loop {},
}
}
}
Expand Down Expand Up @@ -840,8 +855,6 @@ pub mod iter {

mod traits {
mod iterator {
use super::super::Take;

pub trait Iterator {
type Item;
#[lang = "next"]
Expand Down Expand Up @@ -903,7 +916,7 @@ pub mod iter {
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> {
Expand All @@ -919,16 +932,38 @@ pub mod iter {
}
// 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 {
Expand Down Expand Up @@ -983,6 +1018,7 @@ pub mod prelude {
ops::{Fn, FnMut, FnOnce}, // :fn
option::Option::{self, None, Some}, // :option
result::Result::{self, Err, Ok}, // :result
panic, // :panic
};
}

Expand Down

0 comments on commit 112464f

Please sign in to comment.