about summary refs log tree commit diff
diff options
context:
space:
mode:
authorhkalbasi <hamidrezakalbasi@protonmail.com>2023-04-18 17:38:38 +0330
committerhkalbasi <hamidrezakalbasi@protonmail.com>2023-04-18 17:38:38 +0330
commitf05f7ab082c29edd182b25c27eafd21a6d9f6862 (patch)
tree8a7ea3b3d9a734bc318b64fc38f92d61a0f0b0db
parent9b835f334f2c61d66c8c6554ec90325992752ce3 (diff)
downloadrust-f05f7ab082c29edd182b25c27eafd21a6d9f6862.tar.gz
rust-f05f7ab082c29edd182b25c27eafd21a6d9f6862.zip
Add minicore smoke test
-rw-r--r--crates/ide-diagnostics/src/tests.rs22
-rw-r--r--crates/ide/src/inlay_hints/chaining.rs12
-rw-r--r--crates/test-utils/src/fixture.rs21
-rw-r--r--crates/test-utils/src/minicore.rs66
4 files changed, 97 insertions, 24 deletions
diff --git a/crates/ide-diagnostics/src/tests.rs b/crates/ide-diagnostics/src/tests.rs
index afa641c733e..413689561bc 100644
--- a/crates/ide-diagnostics/src/tests.rs
+++ b/crates/ide-diagnostics/src/tests.rs
@@ -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};
 
@@ -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()))
+}
diff --git a/crates/ide/src/inlay_hints/chaining.rs b/crates/ide/src/inlay_hints/chaining.rs
index 6db9b8b5443..069edaed665 100644
--- a/crates/ide/src/inlay_hints/chaining.rs
+++ b/crates/ide/src/inlay_hints/chaining.rs
@@ -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: "",
diff --git a/crates/test-utils/src/fixture.rs b/crates/test-utils/src/fixture.rs
index 29ab21ac1db..05f32f8e51e 100644
--- a/crates/test-utils/src/fixture.rs
+++ b/crates/test-utils/src/fixture.rs
@@ -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) {
@@ -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();
 
diff --git a/crates/test-utils/src/minicore.rs b/crates/test-utils/src/minicore.rs
index 308dc5892e5..2f0c086092e 100644
--- a/crates/test-utils/src/minicore.rs
+++ b/crates/test-utils/src/minicore.rs
@@ -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 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 {
@@ -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"]
@@ -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> {
@@ -499,6 +512,7 @@ pub mod ops {
             fn from_residual(x: Option<Infallible>) -> Self {
                 match x {
                     None => None,
+                    Some(_) => loop {},
                 }
             }
         }
@@ -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 {},
                 }
             }
         }
@@ -840,8 +855,6 @@ pub mod iter {
 
     mod traits {
         mod iterator {
-            use super::super::Take;
-
             pub trait Iterator {
                 type Item;
                 #[lang = "next"]
@@ -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> {
@@ -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 {
@@ -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
         };
     }