aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/syntax_highlighting
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-08-12 14:20:18 +0100
committerGitHub <[email protected]>2020-08-12 14:20:18 +0100
commit11de7ac2fb6514484076217acb8d93eb36468681 (patch)
treeb727a8db741367634eebf4dc685e0f56fddb2a68 /crates/ra_ide/src/syntax_highlighting
parent2d41cc0ea323e3c4d97300e4d66de11d6b7148ef (diff)
parent72baf1acdd544c645fd69c16967b91be9e75371b (diff)
Merge #4743
4743: Add tracking of packed repr, use it to highlight unsafe refs r=matklad a=Nashenas88 Taking a reference to a misaligned field on a packed struct is an unsafe operation. Highlight that behavior. Currently, the misaligned part isn't tracked, so this highlight is a bit too aggressive. Fixes #4600 Co-authored-by: Paul Daniel Faria <[email protected]> Co-authored-by: Paul Daniel Faria <[email protected]> Co-authored-by: Paul Daniel Faria <[email protected]>
Diffstat (limited to 'crates/ra_ide/src/syntax_highlighting')
-rw-r--r--crates/ra_ide/src/syntax_highlighting/tests.rs33
1 files changed, 30 insertions, 3 deletions
diff --git a/crates/ra_ide/src/syntax_highlighting/tests.rs b/crates/ra_ide/src/syntax_highlighting/tests.rs
index 09062c38e..a8087635a 100644
--- a/crates/ra_ide/src/syntax_highlighting/tests.rs
+++ b/crates/ra_ide/src/syntax_highlighting/tests.rs
@@ -292,10 +292,24 @@ struct TypeForStaticMut {
292 292
293static mut global_mut: TypeForStaticMut = TypeForStaticMut { a: 0 }; 293static mut global_mut: TypeForStaticMut = TypeForStaticMut { a: 0 };
294 294
295#[repr(packed)]
296struct Packed {
297 a: u16,
298}
299
300trait DoTheAutoref {
301 fn calls_autoref(&self);
302}
303
304impl DoTheAutoref for u16 {
305 fn calls_autoref(&self) {}
306}
307
295fn main() { 308fn main() {
296 let x = &5 as *const usize; 309 let x = &5 as *const _ as *const usize;
297 let u = Union { b: 0 }; 310 let u = Union { b: 0 };
298 unsafe { 311 unsafe {
312 // unsafe fn and method calls
299 unsafe_fn(); 313 unsafe_fn();
300 let b = u.b; 314 let b = u.b;
301 match u { 315 match u {
@@ -303,9 +317,22 @@ fn main() {
303 Union { a } => (), 317 Union { a } => (),
304 } 318 }
305 HasUnsafeFn.unsafe_method(); 319 HasUnsafeFn.unsafe_method();
306 let y = *(x); 320
307 let z = -x; 321 // unsafe deref
322 let y = *x;
323
324 // unsafe access to a static mut
308 let a = global_mut.a; 325 let a = global_mut.a;
326
327 // unsafe ref of packed fields
328 let packed = Packed { a: 0 };
329 let a = &packed.a;
330 let ref a = packed.a;
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();
309 } 336 }
310} 337}
311"# 338"#