aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/syntax_highlighting
diff options
context:
space:
mode:
authorPaul Daniel Faria <[email protected]>2020-06-27 22:11:43 +0100
committerPaul Daniel Faria <[email protected]>2020-08-10 13:44:54 +0100
commitd5f11e530dbf6edbdd0ca32d6cd5fafe634c8c4a (patch)
treeb348ea6d5552be08913ac3a451836cad5ac75c1a /crates/ra_ide/src/syntax_highlighting
parent38440d53d8329ac9f3f2013c6e32b3f69b069c72 (diff)
Unsafe borrow of packed fields: account for borrow through ref binding, auto ref function calls
Diffstat (limited to 'crates/ra_ide/src/syntax_highlighting')
-rw-r--r--crates/ra_ide/src/syntax_highlighting/tests.rs31
1 files changed, 16 insertions, 15 deletions
diff --git a/crates/ra_ide/src/syntax_highlighting/tests.rs b/crates/ra_ide/src/syntax_highlighting/tests.rs
index a7f5ad862..a8087635a 100644
--- a/crates/ra_ide/src/syntax_highlighting/tests.rs
+++ b/crates/ra_ide/src/syntax_highlighting/tests.rs
@@ -301,16 +301,7 @@ trait DoTheAutoref {
301 fn calls_autoref(&self); 301 fn calls_autoref(&self);
302} 302}
303 303
304struct NeedsAlign { 304impl DoTheAutoref for u16 {
305 a: u16
306}
307
308#[repr(packed)]
309struct HasAligned {
310 a: NeedsAlign
311}
312
313impl DoTheAutoref for NeedsAlign {
314 fn calls_autoref(&self) {} 305 fn calls_autoref(&self) {}
315} 306}
316 307
@@ -318,6 +309,7 @@ fn main() {
318 let x = &5 as *const _ as *const usize; 309 let x = &5 as *const _ as *const usize;
319 let u = Union { b: 0 }; 310 let u = Union { b: 0 };
320 unsafe { 311 unsafe {
312 // unsafe fn and method calls
321 unsafe_fn(); 313 unsafe_fn();
322 let b = u.b; 314 let b = u.b;
323 match u { 315 match u {
@@ -325,13 +317,22 @@ fn main() {
325 Union { a } => (), 317 Union { a } => (),
326 } 318 }
327 HasUnsafeFn.unsafe_method(); 319 HasUnsafeFn.unsafe_method();
328 let _y = *(x); 320
329 let z = -x; 321 // unsafe deref
322 let y = *x;
323
324 // unsafe access to a static mut
330 let a = global_mut.a; 325 let a = global_mut.a;
326
327 // unsafe ref of packed fields
331 let packed = Packed { a: 0 }; 328 let packed = Packed { a: 0 };
332 let _a = &packed.a; 329 let a = &packed.a;
333 let h = HasAligned{ a: NeedsAlign { a: 1 } }; 330 let ref a = packed.a;
334 h.a.calls_autoref(); 331 let Packed { ref a } = packed;
332 let Packed { a: ref _a } = packed;
333
334 // unsafe auto ref of packed field
335 packed.a.calls_autoref();
335 } 336 }
336} 337}
337"# 338"#