mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 04:23:25 +00:00
Add test for accessing static mut
This commit is contained in:
parent
f1d507270c
commit
6be528da0d
2 changed files with 14 additions and 0 deletions
|
@ -281,6 +281,12 @@ impl HasUnsafeFn {
|
||||||
unsafe fn unsafe_method(&self) {}
|
unsafe fn unsafe_method(&self) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct TypeForStaticMut {
|
||||||
|
a: u8
|
||||||
|
}
|
||||||
|
|
||||||
|
static mut global_mut: TypeForStaticMut = TypeForStaticMut { a: 0 };
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let x = &5 as *const usize;
|
let x = &5 as *const usize;
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -288,6 +294,7 @@ fn main() {
|
||||||
HasUnsafeFn.unsafe_method();
|
HasUnsafeFn.unsafe_method();
|
||||||
let y = *(x);
|
let y = *(x);
|
||||||
let z = -x;
|
let z = -x;
|
||||||
|
let a = global_mut.a;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"#
|
"#
|
||||||
|
|
|
@ -43,6 +43,12 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
||||||
<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>
|
<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>
|
||||||
<span class="punctuation">}</span>
|
<span class="punctuation">}</span>
|
||||||
|
|
||||||
|
<span class="keyword">struct</span> <span class="struct declaration">TypeForStaticMut</span> <span class="punctuation">{</span>
|
||||||
|
<span class="field declaration">a</span><span class="punctuation">:</span> <span class="builtin_type">u8</span>
|
||||||
|
<span class="punctuation">}</span>
|
||||||
|
|
||||||
|
<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>
|
||||||
|
|
||||||
<span class="keyword">fn</span> <span class="function declaration">main</span><span class="punctuation">(</span><span class="punctuation">)</span> <span class="punctuation">{</span>
|
<span class="keyword">fn</span> <span class="function declaration">main</span><span class="punctuation">(</span><span class="punctuation">)</span> <span class="punctuation">{</span>
|
||||||
<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>
|
<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>
|
||||||
<span class="keyword unsafe">unsafe</span> <span class="punctuation">{</span>
|
<span class="keyword unsafe">unsafe</span> <span class="punctuation">{</span>
|
||||||
|
@ -50,5 +56,6 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
||||||
<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>
|
<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>
|
||||||
<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>
|
<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>
|
||||||
<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>
|
<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>
|
||||||
|
<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>
|
||||||
<span class="punctuation">}</span>
|
<span class="punctuation">}</span>
|
||||||
<span class="punctuation">}</span></code></pre>
|
<span class="punctuation">}</span></code></pre>
|
Loading…
Reference in a new issue