diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-08-07 13:20:13 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-08-07 13:20:13 +0100 |
commit | 911ef38b24efc3e273f7395578c10e05ceb0cd7b (patch) | |
tree | 86064e398c02cb4eff29200cbc0ae10e324be1a1 /crates/ra_ide/src | |
parent | ae1197accd6150b9ba5e6273794ec7f7500acdc8 (diff) | |
parent | 8e657f663d519771ac8ffcd4b52ded8cb381b918 (diff) |
Merge #5678
5678: Static mut unsafe semantic highlighting r=jonas-schievink a=Nashenas88
This marks static mutable names as unsafe, since accessing or modifying a static mut is an unsafe operation.
Co-authored-by: Paul Daniel Faria <[email protected]>
Diffstat (limited to 'crates/ra_ide/src')
-rw-r--r-- | crates/ra_ide/src/syntax_highlighting.rs | 1 | ||||
-rw-r--r-- | crates/ra_ide/src/syntax_highlighting/tests.rs | 7 |
2 files changed, 8 insertions, 0 deletions
diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index a32ae0165..89efe71da 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs | |||
@@ -677,6 +677,7 @@ fn highlight_name(db: &RootDatabase, def: Definition) -> Highlight { | |||
677 | let mut h = Highlight::new(HighlightTag::Static); | 677 | let mut h = Highlight::new(HighlightTag::Static); |
678 | if s.is_mut(db) { | 678 | if s.is_mut(db) { |
679 | h |= HighlightModifier::Mutable; | 679 | h |= HighlightModifier::Mutable; |
680 | h |= HighlightModifier::Unsafe; | ||
680 | } | 681 | } |
681 | return h; | 682 | return h; |
682 | } | 683 | } |
diff --git a/crates/ra_ide/src/syntax_highlighting/tests.rs b/crates/ra_ide/src/syntax_highlighting/tests.rs index 2deee404c..b9b358022 100644 --- a/crates/ra_ide/src/syntax_highlighting/tests.rs +++ b/crates/ra_ide/src/syntax_highlighting/tests.rs | |||
@@ -281,6 +281,12 @@ impl HasUnsafeFn { | |||
281 | unsafe fn unsafe_method(&self) {} | 281 | unsafe fn unsafe_method(&self) {} |
282 | } | 282 | } |
283 | 283 | ||
284 | struct TypeForStaticMut { | ||
285 | a: u8 | ||
286 | } | ||
287 | |||
288 | static mut global_mut: TypeForStaticMut = TypeForStaticMut { a: 0 }; | ||
289 | |||
284 | fn main() { | 290 | fn main() { |
285 | let x = &5 as *const usize; | 291 | let x = &5 as *const usize; |
286 | unsafe { | 292 | unsafe { |
@@ -288,6 +294,7 @@ fn main() { | |||
288 | HasUnsafeFn.unsafe_method(); | 294 | HasUnsafeFn.unsafe_method(); |
289 | let y = *(x); | 295 | let y = *(x); |
290 | let z = -x; | 296 | let z = -x; |
297 | let a = global_mut.a; | ||
291 | } | 298 | } |
292 | } | 299 | } |
293 | "# | 300 | "# |