From c692b5d76d7a9c01643f1f4be3fa8c777a9b0adb Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 28 Aug 2020 14:47:14 +0200 Subject: :arrow_up: expect-test --- .../test_data/highlight_unsafe.html | 99 ++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 crates/ide/src/syntax_highlighting/test_data/highlight_unsafe.html (limited to 'crates/ide/src/syntax_highlighting/test_data/highlight_unsafe.html') diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_unsafe.html b/crates/ide/src/syntax_highlighting/test_data/highlight_unsafe.html new file mode 100644 index 000000000..552fea668 --- /dev/null +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_unsafe.html @@ -0,0 +1,99 @@ + + +
unsafe fn unsafe_fn() {}
+
+union Union {
+    a: u32,
+    b: f32,
+}
+
+struct HasUnsafeFn;
+
+impl HasUnsafeFn {
+    unsafe fn unsafe_method(&self) {}
+}
+
+struct TypeForStaticMut {
+    a: u8
+}
+
+static mut global_mut: TypeForStaticMut = TypeForStaticMut { a: 0 };
+
+#[repr(packed)]
+struct Packed {
+    a: u16,
+}
+
+trait DoTheAutoref {
+    fn calls_autoref(&self);
+}
+
+impl DoTheAutoref for u16 {
+    fn calls_autoref(&self) {}
+}
+
+fn main() {
+    let x = &5 as *const _ as *const usize;
+    let u = Union { b: 0 };
+    unsafe {
+        // unsafe fn and method calls
+        unsafe_fn();
+        let b = u.b;
+        match u {
+            Union { b: 0 } => (),
+            Union { a } => (),
+        }
+        HasUnsafeFn.unsafe_method();
+
+        // unsafe deref
+        let y = *x;
+
+        // unsafe access to a static mut
+        let a = global_mut.a;
+
+        // unsafe ref of packed fields
+        let packed = Packed { a: 0 };
+        let a = &packed.a;
+        let ref a = packed.a;
+        let Packed { ref a } = packed;
+        let Packed { a: ref _a } = packed;
+
+        // unsafe auto ref of packed field
+        packed.a.calls_autoref();
+    }
+}
\ No newline at end of file -- cgit v1.2.3