Skip to content

Commit 112464f

Browse files
committed
Auto merge of rust-lang#14604 - HKalbasi:dev3, r=Veykril
internal: Add minicore smoke test fix rust-lang#14501
2 parents e84781a + f05f7ab commit 112464f

File tree

4 files changed

+97
-24
lines changed

4 files changed

+97
-24
lines changed

crates/ide-diagnostics/src/tests.rs

+21-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use ide_db::{
88
RootDatabase,
99
};
1010
use stdx::trim_indent;
11-
use test_utils::{assert_eq_text, extract_annotations};
11+
use test_utils::{assert_eq_text, extract_annotations, MiniCore};
1212

1313
use crate::{DiagnosticsConfig, ExprFillDefaultMode, Severity};
1414

@@ -143,3 +143,23 @@ fn test_disabled_diagnostics() {
143143
);
144144
assert!(!diagnostics.is_empty());
145145
}
146+
147+
#[test]
148+
fn minicore_smoke_test() {
149+
fn check(minicore: MiniCore) {
150+
let source = minicore.source_code();
151+
let mut config = DiagnosticsConfig::test_sample();
152+
// This should be ignored since we conditionaly remove code which creates single item use with braces
153+
config.disabled.insert("unnecessary-braces".to_string());
154+
check_diagnostics_with_config(config, &source);
155+
}
156+
157+
// Checks that there is no diagnostic in minicore for each flag.
158+
for flag in MiniCore::available_flags() {
159+
eprintln!("Checking minicore flag {flag}");
160+
check(MiniCore::from_flags([flag]));
161+
}
162+
// And one time for all flags, to check codes which are behind multiple flags + prevent name collisions
163+
eprintln!("Checking all minicore flags");
164+
check(MiniCore::from_flags(MiniCore::available_flags()))
165+
}

crates/ide/src/inlay_hints/chaining.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ fn main() {
444444
file_id: FileId(
445445
1,
446446
),
447-
range: 5805..5813,
447+
range: 5768..5776,
448448
},
449449
),
450450
tooltip: "",
@@ -457,7 +457,7 @@ fn main() {
457457
file_id: FileId(
458458
1,
459459
),
460-
range: 5837..5841,
460+
range: 5800..5804,
461461
},
462462
),
463463
tooltip: "",
@@ -478,7 +478,7 @@ fn main() {
478478
file_id: FileId(
479479
1,
480480
),
481-
range: 5805..5813,
481+
range: 5768..5776,
482482
},
483483
),
484484
tooltip: "",
@@ -491,7 +491,7 @@ fn main() {
491491
file_id: FileId(
492492
1,
493493
),
494-
range: 5837..5841,
494+
range: 5800..5804,
495495
},
496496
),
497497
tooltip: "",
@@ -512,7 +512,7 @@ fn main() {
512512
file_id: FileId(
513513
1,
514514
),
515-
range: 5805..5813,
515+
range: 5768..5776,
516516
},
517517
),
518518
tooltip: "",
@@ -525,7 +525,7 @@ fn main() {
525525
file_id: FileId(
526526
1,
527527
),
528-
range: 5837..5841,
528+
range: 5800..5804,
529529
},
530530
),
531531
tooltip: "",

crates/test-utils/src/fixture.rs

+19-2
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,19 @@ impl FixtureWithProjectMeta {
254254
}
255255

256256
impl MiniCore {
257+
const RAW_SOURCE: &str = include_str!("./minicore.rs");
258+
257259
fn has_flag(&self, flag: &str) -> bool {
258260
self.activated_flags.iter().any(|it| it == flag)
259261
}
260262

263+
pub fn from_flags<'a>(flags: impl IntoIterator<Item = &'a str>) -> Self {
264+
MiniCore {
265+
activated_flags: flags.into_iter().map(|x| x.to_owned()).collect(),
266+
valid_flags: Vec::new(),
267+
}
268+
}
269+
261270
#[track_caller]
262271
fn assert_valid_flag(&self, flag: &str) {
263272
if !self.valid_flags.iter().any(|it| it == flag) {
@@ -278,13 +287,21 @@ impl MiniCore {
278287
res
279288
}
280289

290+
pub fn available_flags() -> impl Iterator<Item = &'static str> {
291+
let lines = MiniCore::RAW_SOURCE.split_inclusive('\n');
292+
lines
293+
.map_while(|x| x.strip_prefix("//!"))
294+
.skip_while(|line| !line.contains("Available flags:"))
295+
.skip(1)
296+
.map(|x| x.split_once(':').unwrap().0.trim())
297+
}
298+
281299
/// Strips parts of minicore.rs which are flagged by inactive flags.
282300
///
283301
/// This is probably over-engineered to support flags dependencies.
284302
pub fn source_code(mut self) -> String {
285303
let mut buf = String::new();
286-
let raw_mini_core = include_str!("./minicore.rs");
287-
let mut lines = raw_mini_core.split_inclusive('\n');
304+
let mut lines = MiniCore::RAW_SOURCE.split_inclusive('\n');
288305

289306
let mut implications = Vec::new();
290307

crates/test-utils/src/minicore.rs

+51-15
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@
3232
//! iterator: option
3333
//! iterators: iterator, fn
3434
//! non_zero:
35-
//! option:
35+
//! option: panic
3636
//! ord: eq, option
37+
//! panic:
3738
//! pin:
3839
//! range:
3940
//! result:
@@ -191,6 +192,12 @@ pub mod convert {
191192
// endregion:infallible
192193
}
193194

195+
// region:drop
196+
pub mod mem {
197+
pub fn drop<T>(_x: T) {}
198+
}
199+
// endregion:drop
200+
194201
pub mod ops {
195202
// region:coerce_unsized
196203
mod unsize {
@@ -315,12 +322,6 @@ pub mod ops {
315322
pub use self::index::{Index, IndexMut};
316323
// endregion:index
317324

318-
// region:drop
319-
pub mod mem {
320-
pub fn drop<T>(_x: T) {}
321-
}
322-
// endregion:drop
323-
324325
// region:range
325326
mod range {
326327
#[lang = "RangeFull"]
@@ -473,12 +474,24 @@ pub mod ops {
473474
impl<B, C> Try for ControlFlow<B, C> {
474475
type Output = C;
475476
type Residual = ControlFlow<B, Infallible>;
476-
fn from_output(output: Self::Output) -> Self {}
477-
fn branch(self) -> ControlFlow<Self::Residual, Self::Output> {}
477+
fn from_output(output: Self::Output) -> Self {
478+
ControlFlow::Continue(output)
479+
}
480+
fn branch(self) -> ControlFlow<Self::Residual, Self::Output> {
481+
match self {
482+
ControlFlow::Continue(x) => ControlFlow::Continue(x),
483+
ControlFlow::Break(x) => ControlFlow::Break(ControlFlow::Break(x)),
484+
}
485+
}
478486
}
479487

480488
impl<B, C> FromResidual for ControlFlow<B, C> {
481-
fn from_residual(residual: ControlFlow<B, Infallible>) -> Self {}
489+
fn from_residual(residual: ControlFlow<B, Infallible>) -> Self {
490+
match residual {
491+
ControlFlow::Break(b) => ControlFlow::Break(b),
492+
ControlFlow::Continue(_) => loop {},
493+
}
494+
}
482495
}
483496
// region:option
484497
impl<T> Try for Option<T> {
@@ -499,6 +512,7 @@ pub mod ops {
499512
fn from_residual(x: Option<Infallible>) -> Self {
500513
match x {
501514
None => None,
515+
Some(_) => loop {},
502516
}
503517
}
504518
}
@@ -527,6 +541,7 @@ pub mod ops {
527541
fn from_residual(residual: Result<Infallible, E>) -> Self {
528542
match residual {
529543
Err(e) => Err(From::from(e)),
544+
Ok(_) => loop {},
530545
}
531546
}
532547
}
@@ -840,8 +855,6 @@ pub mod iter {
840855

841856
mod traits {
842857
mod iterator {
843-
use super::super::Take;
844-
845858
pub trait Iterator {
846859
type Item;
847860
#[lang = "next"]
@@ -903,7 +916,7 @@ pub mod iter {
903916
type Item = T;
904917
type IntoIter = IntoIter<T, N>;
905918
fn into_iter(self) -> I {
906-
IntoIter { data: self, range: IndexRange { start: 0, end: self.len() } }
919+
IntoIter { data: self, range: IndexRange { start: 0, end: loop {} } }
907920
}
908921
}
909922
impl<T, const N: usize> Iterator for IntoIter<T, N> {
@@ -919,16 +932,38 @@ pub mod iter {
919932
}
920933
// endregion:iterator
921934

922-
// region:derive
935+
// region:panic
936+
mod panic {
937+
pub macro panic_2021 {
938+
($($t:tt)+) => (
939+
/* Nothing yet */
940+
),
941+
}
942+
}
943+
// endregion:panic
944+
923945
mod macros {
946+
// region:panic
947+
#[macro_export]
948+
#[rustc_builtin_macro(std_panic)]
949+
macro_rules! panic {
950+
($($arg:tt)*) => {
951+
/* compiler built-in */
952+
};
953+
}
954+
955+
pub(crate) use panic;
956+
// endregion:panic
957+
958+
// region:derive
924959
pub(crate) mod builtin {
925960
#[rustc_builtin_macro]
926961
pub macro derive($item:item) {
927962
/* compiler built-in */
928963
}
929964
}
965+
// endregion:derive
930966
}
931-
// endregion:derive
932967

933968
// region:non_zero
934969
pub mod num {
@@ -983,6 +1018,7 @@ pub mod prelude {
9831018
ops::{Fn, FnMut, FnOnce}, // :fn
9841019
option::Option::{self, None, Some}, // :option
9851020
result::Result::{self, Err, Ok}, // :result
1021+
panic, // :panic
9861022
};
9871023
}
9881024

0 commit comments

Comments
 (0)