From 6be528da0de45606498a9755ad2c54f3bc41dc6c Mon Sep 17 00:00:00 2001 From: Paul Daniel Faria Date: Thu, 6 Aug 2020 19:58:37 -0400 Subject: Add test for accessing static mut --- crates/ra_ide/src/syntax_highlighting/tests.rs | 7 +++++++ crates/ra_ide/test_data/highlight_unsafe.html | 7 +++++++ 2 files changed, 14 insertions(+) (limited to 'crates/ra_ide') 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 { unsafe fn unsafe_method(&self) {} } +struct TypeForStaticMut { + a: u8 +} + +static mut global_mut: TypeForStaticMut = TypeForStaticMut { a: 0 }; + fn main() { let x = &5 as *const usize; unsafe { @@ -288,6 +294,7 @@ fn main() { HasUnsafeFn.unsafe_method(); let y = *(x); let z = -x; + let a = global_mut.a; } } "# 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 unsafe fn unsafe_method(&self) {} } +struct TypeForStaticMut { + a: u8 +} + +static mut global_mut: TypeForStaticMut = TypeForStaticMut { a: 0 }; + fn main() { let x = &5 as *const usize; unsafe { @@ -50,5 +56,6 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd HasUnsafeFn.unsafe_method(); let y = *(x); let z = -x; + let a = global_mut.a; } } \ No newline at end of file -- cgit v1.2.3 From 8e657f663d519771ac8ffcd4b52ded8cb381b918 Mon Sep 17 00:00:00 2001 From: Paul Daniel Faria Date: Thu, 6 Aug 2020 20:07:42 -0400 Subject: Mark static mutable names as unsafe --- crates/ra_ide/src/syntax_highlighting.rs | 1 + crates/ra_ide/test_data/highlight_unsafe.html | 4 ++-- crates/ra_ide/test_data/highlighting.html | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) (limited to 'crates/ra_ide') 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 { let mut h = Highlight::new(HighlightTag::Static); if s.is_mut(db) { h |= HighlightModifier::Mutable; + h |= HighlightModifier::Unsafe; } return h; } diff --git a/crates/ra_ide/test_data/highlight_unsafe.html b/crates/ra_ide/test_data/highlight_unsafe.html index 7c519ef5e..87d8c1556 100644 --- a/crates/ra_ide/test_data/highlight_unsafe.html +++ b/crates/ra_ide/test_data/highlight_unsafe.html @@ -47,7 +47,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd a: u8 } -static mut global_mut: TypeForStaticMut = TypeForStaticMut { a: 0 }; +static mut global_mut: TypeForStaticMut = TypeForStaticMut { a: 0 }; fn main() { let x = &5 as *const usize; @@ -56,6 +56,6 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd HasUnsafeFn.unsafe_method(); let y = *(x); let z = -x; - let a = global_mut.a; + let a = global_mut.a; } } \ No newline at end of file diff --git a/crates/ra_ide/test_data/highlighting.html b/crates/ra_ide/test_data/highlighting.html index 23c25ad8c..8e0160eee 100644 --- a/crates/ra_ide/test_data/highlighting.html +++ b/crates/ra_ide/test_data/highlighting.html @@ -64,7 +64,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd } } -static mut STATIC_MUT: i32 = 0; +static mut STATIC_MUT: i32 = 0; fn foo<'a, T>() -> T { foo::<'a, i32>() @@ -97,7 +97,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd } unsafe { vec.set_len(0); - STATIC_MUT = 1; + STATIC_MUT = 1; } for e in vec { -- cgit v1.2.3