diff options
author | Paul Daniel Faria <[email protected]> | 2020-08-07 00:58:37 +0100 |
---|---|---|
committer | Paul Daniel Faria <[email protected]> | 2020-08-07 00:58:37 +0100 |
commit | 6be528da0de45606498a9755ad2c54f3bc41dc6c (patch) | |
tree | d626ea2b13f1cf7a8134e7e9ad41224271325db7 /crates/ra_ide | |
parent | f1d507270c7d915ef0177feca7b6745d95169ac8 (diff) |
Add test for accessing static mut
Diffstat (limited to 'crates/ra_ide')
-rw-r--r-- | crates/ra_ide/src/syntax_highlighting/tests.rs | 7 | ||||
-rw-r--r-- | crates/ra_ide/test_data/highlight_unsafe.html | 7 |
2 files changed, 14 insertions, 0 deletions
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 | "# |
diff --git a/crates/ra_ide/test_data/highlight_unsafe.html b/crates/ra_ide/test_data/highlight_unsafe.html index b81b6f1c3..7c519ef5e 100644 --- a/crates/ra_ide/test_data/highlight_unsafe.html +++ b/crates/ra_ide/test_data/highlight_unsafe.html | |||
@@ -43,6 +43,12 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
43 | <span class="keyword unsafe">unsafe</span> <span class="keyword">fn</span> <span class="function declaration unsafe">unsafe_method</span><span class="punctuation">(</span><span class="operator">&</span><span class="self_keyword">self</span><span class="punctuation">)</span> <span class="punctuation">{</span><span class="punctuation">}</span> | 43 | <span class="keyword unsafe">unsafe</span> <span class="keyword">fn</span> <span class="function declaration unsafe">unsafe_method</span><span class="punctuation">(</span><span class="operator">&</span><span class="self_keyword">self</span><span class="punctuation">)</span> <span class="punctuation">{</span><span class="punctuation">}</span> |
44 | <span class="punctuation">}</span> | 44 | <span class="punctuation">}</span> |
45 | 45 | ||
46 | <span class="keyword">struct</span> <span class="struct declaration">TypeForStaticMut</span> <span class="punctuation">{</span> | ||
47 | <span class="field declaration">a</span><span class="punctuation">:</span> <span class="builtin_type">u8</span> | ||
48 | <span class="punctuation">}</span> | ||
49 | |||
50 | <span class="keyword">static</span> <span class="keyword">mut</span> <span class="static declaration mutable">global_mut</span><span class="punctuation">:</span> <span class="struct">TypeForStaticMut</span> <span class="operator">=</span> <span class="struct">TypeForStaticMut</span> <span class="punctuation">{</span> <span class="field">a</span><span class="punctuation">:</span> <span class="numeric_literal">0</span> <span class="punctuation">}</span><span class="punctuation">;</span> | ||
51 | |||
46 | <span class="keyword">fn</span> <span class="function declaration">main</span><span class="punctuation">(</span><span class="punctuation">)</span> <span class="punctuation">{</span> | 52 | <span class="keyword">fn</span> <span class="function declaration">main</span><span class="punctuation">(</span><span class="punctuation">)</span> <span class="punctuation">{</span> |
47 | <span class="keyword">let</span> <span class="variable declaration">x</span> <span class="operator">=</span> <span class="operator">&</span><span class="numeric_literal">5</span> <span class="keyword">as</span> <span class="keyword">*</span><span class="keyword">const</span> <span class="builtin_type">usize</span><span class="punctuation">;</span> | 53 | <span class="keyword">let</span> <span class="variable declaration">x</span> <span class="operator">=</span> <span class="operator">&</span><span class="numeric_literal">5</span> <span class="keyword">as</span> <span class="keyword">*</span><span class="keyword">const</span> <span class="builtin_type">usize</span><span class="punctuation">;</span> |
48 | <span class="keyword unsafe">unsafe</span> <span class="punctuation">{</span> | 54 | <span class="keyword unsafe">unsafe</span> <span class="punctuation">{</span> |
@@ -50,5 +56,6 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
50 | <span class="struct">HasUnsafeFn</span><span class="punctuation">.</span><span class="function unsafe">unsafe_method</span><span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">;</span> | 56 | <span class="struct">HasUnsafeFn</span><span class="punctuation">.</span><span class="function unsafe">unsafe_method</span><span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">;</span> |
51 | <span class="keyword">let</span> <span class="variable declaration">y</span> <span class="operator">=</span> <span class="operator unsafe">*</span><span class="punctuation">(</span><span class="variable">x</span><span class="punctuation">)</span><span class="punctuation">;</span> | 57 | <span class="keyword">let</span> <span class="variable declaration">y</span> <span class="operator">=</span> <span class="operator unsafe">*</span><span class="punctuation">(</span><span class="variable">x</span><span class="punctuation">)</span><span class="punctuation">;</span> |
52 | <span class="keyword">let</span> <span class="variable declaration">z</span> <span class="operator">=</span> <span class="numeric_literal">-</span><span class="variable">x</span><span class="punctuation">;</span> | 58 | <span class="keyword">let</span> <span class="variable declaration">z</span> <span class="operator">=</span> <span class="numeric_literal">-</span><span class="variable">x</span><span class="punctuation">;</span> |
59 | <span class="keyword">let</span> <span class="variable declaration">a</span> <span class="operator">=</span> <span class="static mutable">global_mut</span><span class="punctuation">.</span><span class="field">a</span><span class="punctuation">;</span> | ||
53 | <span class="punctuation">}</span> | 60 | <span class="punctuation">}</span> |
54 | <span class="punctuation">}</span></code></pre> \ No newline at end of file | 61 | <span class="punctuation">}</span></code></pre> \ No newline at end of file |