]> 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 9ce26e930eb7becf3ea7a716030ea216335690a7..f5f7d8fe95166be533bcf619f3daf003a0d34cee 100644 (file)
@@ -10,6 +10,8 @@
 fn test_highlighting() {
     check_highlighting(
         r#"
+//- proc_macros: identity, mirror
+//- /main.rs crate:main deps:foo
 use inner::{self as inner_mod};
 mod inner {}
 
@@ -22,6 +24,7 @@ pub mod marker {
     pub trait Copy {}
 }
 
+#[proc_macros::identity]
 pub mod ops {
     #[lang = "fn_once"]
     pub trait FnOnce<Args> {}
@@ -33,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: {
@@ -86,8 +90,6 @@ fn str() {
     str();
 }
 
-static mut STATIC_MUT: i32 = 0;
-
 fn foo<'a, T>() -> T {
     foo::<'a, i32>()
 }
@@ -121,6 +123,10 @@ fn bar() -> u32 {
     }
 }
 
+macro_rules! dont_color_me_braces {
+    () => {0}
+}
+
 macro_rules! noop {
     ($expr:expr) => {
         $expr
@@ -144,16 +150,13 @@ macro_rules! keyword_frag {
 // comment
 fn main() {
     println!("Hello, {}!", 92);
+    dont_color_me_braces!();
 
     let mut vec = Vec::new();
     if true {
         let x = 92;
         vec.push(Foo { x, y: 1 });
     }
-    unsafe {
-        vec.set_len(0);
-        STATIC_MUT = 1;
-    }
 
     for e in vec {
         // Do nothing
@@ -162,6 +165,7 @@ fn main() {
     noop!(noop!(1));
 
     let mut x = 42;
+    x += 1;
     let y = &mut x;
     let z = &y;
 
@@ -183,8 +187,8 @@ fn main() {
     let a = |x| x;
     let bar = Foo::baz;
 
-    let baz = -42;
-    let baz = -baz;
+    let baz = (-42,);
+    let baz = -baz.0;
 
     let _ = !true;
 
@@ -220,8 +224,56 @@ async fn async_main() {
     futures::join!(f1, f2);
 }
 
-unsafe trait Dangerous {}
-impl Dangerous for () {}
+fn use_foo_items() {
+    let bob = foo::Person {
+        name: "Bob",
+        age: foo::consts::NUMBER,
+    };
+
+    let control_flow = foo::identity(foo::ControlFlow::Continue);
+
+    if control_flow.should_die() {
+        foo::die!();
+    }
+}
+
+pub enum Bool { True, False }
+
+impl Bool {
+    pub const fn to_primitive(self) -> bool {
+        matches!(self, Self::True)
+    }
+}
+const USAGE_OF_BOOL:bool = Bool::True.to_primitive();
+
+//- /foo.rs crate:foo
+pub struct Person {
+    pub name: &'static str,
+    pub age: u8,
+}
+
+pub enum ControlFlow {
+    Continue,
+    Die,
+}
+
+impl ControlFlow {
+    pub fn should_die(self) -> bool {
+        matches!(self, ControlFlow::Die)
+    }
+}
+
+pub fn identity<T>(x: T) -> T { x }
+
+pub mod consts {
+    pub const NUMBER: i64 = 92;
+}
+
+macro_rules! die {
+    () => {
+        panic!();
+    };
+}
 "#
         .trim(),
         expect_file!["./test_data/highlighting.html"],
@@ -321,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]
@@ -341,7 +393,7 @@ struct Foo {
         .highlight_range(FileRange { file_id, range: TextRange::at(45.into(), 1.into()) })
         .unwrap();
 
-    assert_eq!(&highlights[0].highlight.to_string(), "field.declaration");
+    assert_eq!(&highlights[0].highlight.to_string(), "field.declaration.public");
 }
 
 #[test]
@@ -389,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() {
@@ -443,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"],
@@ -454,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 {
@@ -461,23 +557,22 @@ 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,
 }
 
+unsafe trait UnsafeTrait {}
+unsafe impl UnsafeTrait for Packed {}
+impl !UnsafeTrait for () {}
+
+fn unsafe_trait_bound<T: UnsafeTrait>(_: T) {}
+
 trait DoTheAutoref {
     fn calls_autoref(&self);
 }
@@ -497,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 };