]> git.lizzy.rs Git - rust.git/blobdiff - crates/ide/src/syntax_highlighting/tests.rs
Work around tidy check
[rust.git] / crates / ide / src / syntax_highlighting / tests.rs
index 502a88af258142030f54620ebe6b1cfe364a0b3b..f5f7d8fe95166be533bcf619f3daf003a0d34cee 100644 (file)
@@ -10,6 +10,7 @@
 fn test_highlighting() {
     check_highlighting(
         r#"
+//- proc_macros: identity, mirror
 //- /main.rs crate:main deps:foo
 use inner::{self as inner_mod};
 mod inner {}
@@ -23,6 +24,7 @@ pub mod marker {
     pub trait Copy {}
 }
 
+#[proc_macros::identity]
 pub mod ops {
     #[lang = "fn_once"]
     pub trait FnOnce<Args> {}
@@ -34,10 +36,11 @@ pub trait FnMut<Args>: FnOnce<Args> {}
     pub trait Fn<Args>: FnMut<Args> {}
 }
 
-
-struct Foo {
-    pub x: i32,
-    pub y: i32,
+proc_macros::mirror! {
+    {
+        ,i32 :x pub
+        ,i32 :y pub
+    } Foo struct
 }
 
 trait Bar where Self: {
@@ -87,8 +90,6 @@ fn str() {
     str();
 }
 
-static mut STATIC_MUT: i32 = 0;
-
 fn foo<'a, T>() -> T {
     foo::<'a, i32>()
 }
@@ -156,10 +157,6 @@ fn main() {
         let x = 92;
         vec.push(Foo { x, y: 1 });
     }
-    unsafe {
-        vec.set_len(0);
-        STATIC_MUT = 1;
-    }
 
     for e in vec {
         // Do nothing
@@ -168,6 +165,7 @@ fn main() {
     noop!(noop!(1));
 
     let mut x = 42;
+    x += 1;
     let y = &mut x;
     let z = &y;
 
@@ -226,9 +224,6 @@ async fn async_main() {
     futures::join!(f1, f2);
 }
 
-unsafe trait Dangerous {}
-impl Dangerous for () {}
-
 fn use_foo_items() {
     let bob = foo::Person {
         name: "Bob",
@@ -378,7 +373,7 @@ fn benchmark_syntax_highlighting_parser() {
             .filter(|it| it.highlight.tag == HlTag::Symbol(SymbolKind::Function))
             .count()
     };
-    assert_eq!(hash, 1632);
+    assert_eq!(hash, 1616);
 }
 
 #[test]
@@ -446,9 +441,46 @@ macro_rules! println {
     })
 }
 #[rustc_builtin_macro]
-macro_rules! format_args_nl {
-    ($fmt:expr) => {{ /* compiler built-in */ }};
-    ($fmt:expr, $($args:tt)*) => {{ /* compiler built-in */ }};
+#[macro_export]
+macro_rules! format_args {}
+#[rustc_builtin_macro]
+#[macro_export]
+macro_rules! const_format_args {}
+#[rustc_builtin_macro]
+#[macro_export]
+macro_rules! format_args_nl {}
+
+mod panic {
+    pub macro panic_2015 {
+        () => (
+            $crate::panicking::panic("explicit panic")
+        ),
+        ($msg:literal $(,)?) => (
+            $crate::panicking::panic($msg)
+        ),
+        // Use `panic_str` instead of `panic_display::<&str>` for non_fmt_panic lint.
+        ($msg:expr $(,)?) => (
+            $crate::panicking::panic_str($msg)
+        ),
+        // Special-case the single-argument case for const_panic.
+        ("{}", $arg:expr $(,)?) => (
+            $crate::panicking::panic_display(&$arg)
+        ),
+        ($fmt:expr, $($arg:tt)+) => (
+            $crate::panicking::panic_fmt($crate::const_format_args!($fmt, $($arg)+))
+        ),
+    }
+}
+
+#[rustc_builtin_macro(std_panic)]
+#[macro_export]
+macro_rules! panic {}
+#[rustc_builtin_macro]
+macro_rules! assert {}
+
+macro_rules! toho {
+    () => ($crate::panic!("not yet implemented"));
+    ($($arg:tt)+) => ($crate::panic!("not yet implemented: {}", $crate::format_args!($($arg)+)));
 }
 
 fn main() {
@@ -500,6 +532,11 @@ fn main() {
     println!("{ничоси}", ничоси = 92);
 
     println!("{:x?} {} ", thingy, n2);
+    panic!("{}", 0);
+    panic!("more {}", 1);
+    assert!(true, "{}", 1);
+    assert!(true, "{} asdasd", 1);
+    toho!("{}fmt", 0);
 }"#
         .trim(),
         expect_file!["./test_data/highlight_strings.html"],
@@ -511,6 +548,8 @@ fn main() {
 fn test_unsafe_highlighting() {
     check_highlighting(
         r#"
+static mut MUT_GLOBAL: Struct = Struct { field: 0 };
+static GLOBAL: Struct = Struct { field: 0 };
 unsafe fn unsafe_fn() {}
 
 union Union {
@@ -518,18 +557,11 @@ union Union {
     b: f32,
 }
 
-struct HasUnsafeFn;
-
-impl HasUnsafeFn {
+struct Struct { field: i32 }
+impl Struct {
     unsafe fn unsafe_method(&self) {}
 }
 
-struct TypeForStaticMut {
-    a: u8
-}
-
-static mut global_mut: TypeForStaticMut = TypeForStaticMut { a: 0 };
-
 #[repr(packed)]
 struct Packed {
     a: u16,
@@ -537,8 +569,9 @@ struct Packed {
 
 unsafe trait UnsafeTrait {}
 unsafe impl UnsafeTrait for Packed {}
+impl !UnsafeTrait for () {}
 
-fn require_unsafe_trait<T: UnsafeTrait>(_: T) {}
+fn unsafe_trait_bound<T: UnsafeTrait>(_: T) {}
 
 trait DoTheAutoref {
     fn calls_autoref(&self);
@@ -559,13 +592,14 @@ fn main() {
             Union { b: 0 } => (),
             Union { a } => (),
         }
-        HasUnsafeFn.unsafe_method();
+        Struct { field: 0 }.unsafe_method();
 
         // unsafe deref
-        let y = *x;
+        *x;
 
         // unsafe access to a static mut
-        let a = global_mut.a;
+        MUT_GLOBAL.field;
+        GLOBAL.field;
 
         // unsafe ref of packed fields
         let packed = Packed { a: 0 };