diff --git a/crates/ide/src/syntax_highlighting/highlight.rs b/crates/ide/src/syntax_highlighting/highlight.rs index f82566d978e..dba0636930f 100644 --- a/crates/ide/src/syntax_highlighting/highlight.rs +++ b/crates/ide/src/syntax_highlighting/highlight.rs @@ -286,7 +286,9 @@ fn highlight_name_ref( Definition::ModuleDef(hir::ModuleDef::Trait(trait_)) if trait_.is_unsafe(db) => { - if ast::Impl::for_trait_name_ref(&name_ref).is_some() { + if ast::Impl::for_trait_name_ref(&name_ref) + .map_or(false, |impl_| impl_.unsafe_token().is_some()) + { h |= HlMod::Unsafe; } } diff --git a/crates/ide/src/syntax_highlighting/html.rs b/crates/ide/src/syntax_highlighting/html.rs index 6064ef45176..5af73e6976d 100644 --- a/crates/ide/src/syntax_highlighting/html.rs +++ b/crates/ide/src/syntax_highlighting/html.rs @@ -69,6 +69,8 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .function.unsafe { color: #BC8383; } .trait.unsafe { color: #BC8383; } .operator.unsafe { color: #BC8383; } +.mutable.unsafe { color: #BC8383; text-decoration: underline; } +.keyword.unsafe { color: #BC8383; font-weight: bold; } .parameter { color: #94BFF3; } .text { color: #DCDCCC; } .type { color: #7CB8BB; } @@ -85,7 +87,6 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .mutable { text-decoration: underline; } .escape_sequence { color: #94BFF3; } .keyword { color: #F0DFAF; font-weight: bold; } -.keyword.unsafe { color: #BC8383; font-weight: bold; } .control { font-style: italic; } .reference { font-style: italic; font-weight: bold; } diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_assoc_functions.html b/crates/ide/src/syntax_highlighting/test_data/highlight_assoc_functions.html index a5d2ba31ee5..0d0c21cb0c7 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_assoc_functions.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_assoc_functions.html @@ -17,6 +17,8 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .function.unsafe { color: #BC8383; } .trait.unsafe { color: #BC8383; } .operator.unsafe { color: #BC8383; } +.mutable.unsafe { color: #BC8383; text-decoration: underline; } +.keyword.unsafe { color: #BC8383; font-weight: bold; } .parameter { color: #94BFF3; } .text { color: #DCDCCC; } .type { color: #7CB8BB; } @@ -33,7 +35,6 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .mutable { text-decoration: underline; } .escape_sequence { color: #94BFF3; } .keyword { color: #F0DFAF; font-weight: bold; } -.keyword.unsafe { color: #BC8383; font-weight: bold; } .control { font-style: italic; } .reference { font-style: italic; font-weight: bold; } diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html b/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html index a5af8a6c86a..f54af2d92e4 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html @@ -17,6 +17,8 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .function.unsafe { color: #BC8383; } .trait.unsafe { color: #BC8383; } .operator.unsafe { color: #BC8383; } +.mutable.unsafe { color: #BC8383; text-decoration: underline; } +.keyword.unsafe { color: #BC8383; font-weight: bold; } .parameter { color: #94BFF3; } .text { color: #DCDCCC; } .type { color: #7CB8BB; } @@ -33,7 +35,6 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .mutable { text-decoration: underline; } .escape_sequence { color: #94BFF3; } .keyword { color: #F0DFAF; font-weight: bold; } -.keyword.unsafe { color: #BC8383; font-weight: bold; } .control { font-style: italic; } .reference { font-style: italic; font-weight: bold; } diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_extern_crate.html b/crates/ide/src/syntax_highlighting/test_data/highlight_extern_crate.html index e49de797b37..9c01832e754 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_extern_crate.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_extern_crate.html @@ -17,6 +17,8 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .function.unsafe { color: #BC8383; } .trait.unsafe { color: #BC8383; } .operator.unsafe { color: #BC8383; } +.mutable.unsafe { color: #BC8383; text-decoration: underline; } +.keyword.unsafe { color: #BC8383; font-weight: bold; } .parameter { color: #94BFF3; } .text { color: #DCDCCC; } .type { color: #7CB8BB; } @@ -33,7 +35,6 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .mutable { text-decoration: underline; } .escape_sequence { color: #94BFF3; } .keyword { color: #F0DFAF; font-weight: bold; } -.keyword.unsafe { color: #BC8383; font-weight: bold; } .control { font-style: italic; } .reference { font-style: italic; font-weight: bold; } diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_injection.html b/crates/ide/src/syntax_highlighting/test_data/highlight_injection.html index 0c1aa1fe118..88380bdfe12 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_injection.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_injection.html @@ -17,6 +17,8 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .function.unsafe { color: #BC8383; } .trait.unsafe { color: #BC8383; } .operator.unsafe { color: #BC8383; } +.mutable.unsafe { color: #BC8383; text-decoration: underline; } +.keyword.unsafe { color: #BC8383; font-weight: bold; } .parameter { color: #94BFF3; } .text { color: #DCDCCC; } .type { color: #7CB8BB; } @@ -33,7 +35,6 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .mutable { text-decoration: underline; } .escape_sequence { color: #94BFF3; } .keyword { color: #F0DFAF; font-weight: bold; } -.keyword.unsafe { color: #BC8383; font-weight: bold; } .control { font-style: italic; } .reference { font-style: italic; font-weight: bold; } diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_strings.html b/crates/ide/src/syntax_highlighting/test_data/highlight_strings.html index e519b22007a..9c20c8ae4b8 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_strings.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_strings.html @@ -17,6 +17,8 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .function.unsafe { color: #BC8383; } .trait.unsafe { color: #BC8383; } .operator.unsafe { color: #BC8383; } +.mutable.unsafe { color: #BC8383; text-decoration: underline; } +.keyword.unsafe { color: #BC8383; font-weight: bold; } .parameter { color: #94BFF3; } .text { color: #DCDCCC; } .type { color: #7CB8BB; } @@ -33,7 +35,6 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .mutable { text-decoration: underline; } .escape_sequence { color: #94BFF3; } .keyword { color: #F0DFAF; font-weight: bold; } -.keyword.unsafe { color: #BC8383; font-weight: bold; } .control { font-style: italic; } .reference { font-style: italic; font-weight: bold; } diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_unsafe.html b/crates/ide/src/syntax_highlighting/test_data/highlight_unsafe.html index 987f06a23ab..2b86340efd7 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_unsafe.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_unsafe.html @@ -17,6 +17,8 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .function.unsafe { color: #BC8383; } .trait.unsafe { color: #BC8383; } .operator.unsafe { color: #BC8383; } +.mutable.unsafe { color: #BC8383; text-decoration: underline; } +.keyword.unsafe { color: #BC8383; font-weight: bold; } .parameter { color: #94BFF3; } .text { color: #DCDCCC; } .type { color: #7CB8BB; } @@ -33,31 +35,25 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .mutable { text-decoration: underline; } .escape_sequence { color: #94BFF3; } .keyword { color: #F0DFAF; font-weight: bold; } -.keyword.unsafe { color: #BC8383; font-weight: bold; } .control { font-style: italic; } .reference { font-style: italic; font-weight: bold; } .unresolved_reference { color: #FC5555; text-decoration: wavy underline; } -
unsafe fn unsafe_fn() {}
+static mut MUT_GLOBAL: Struct = Struct { field: 0 };
+static GLOBAL: Struct = Struct { field: 0 };
+unsafe fn unsafe_fn() {}
union Union {
a: u32,
b: f32,
}
-struct HasUnsafeFn;
-
-impl HasUnsafeFn {
+struct Struct { field: i32 }
+impl Struct {
unsafe fn unsafe_method(&self) {}
}
-struct TypeForStaticMut {
- a: u8
-}
-
-static mut global_mut: TypeForStaticMut = TypeForStaticMut { a: 0 };
-
#[repr(packed)]
struct Packed {
a: u16,
@@ -65,8 +61,9 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
unsafe trait UnsafeTrait {}
unsafe impl UnsafeTrait for Packed {}
+impl !UnsafeTrait for () {}
-fn require_unsafe_trait<T: UnsafeTrait>(_: T) {}
+fn unsafe_trait_bound<T: UnsafeTrait>(_: T) {}
trait DoTheAutoref {
fn calls_autoref(&self);
@@ -87,13 +84,14 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
Union { b: 0 } => (),
Union { a } => (),
}
- HasUnsafeFn.unsafe_method();
+ Struct { field: 0 }.unsafe_method();
// unsafe deref
- let y = *x;
+ *x;
// unsafe access to a static mut
- let a = global_mut.a;
+ MUT_GLOBAL.field;
+ GLOBAL.field;
// unsafe ref of packed fields
let packed = Packed { a: 0 };
diff --git a/crates/ide/src/syntax_highlighting/test_data/highlighting.html b/crates/ide/src/syntax_highlighting/test_data/highlighting.html
index 448b30aa849..ae5016b8d83 100644
--- a/crates/ide/src/syntax_highlighting/test_data/highlighting.html
+++ b/crates/ide/src/syntax_highlighting/test_data/highlighting.html
@@ -17,6 +17,8 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
.function.unsafe { color: #BC8383; }
.trait.unsafe { color: #BC8383; }
.operator.unsafe { color: #BC8383; }
+.mutable.unsafe { color: #BC8383; text-decoration: underline; }
+.keyword.unsafe { color: #BC8383; font-weight: bold; }
.parameter { color: #94BFF3; }
.text { color: #DCDCCC; }
.type { color: #7CB8BB; }
@@ -33,7 +35,6 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
.mutable { text-decoration: underline; }
.escape_sequence { color: #94BFF3; }
.keyword { color: #F0DFAF; font-weight: bold; }
-.keyword.unsafe { color: #BC8383; font-weight: bold; }
.control { font-style: italic; }
.reference { font-style: italic; font-weight: bold; }
@@ -116,8 +117,6 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
str();
}
-static mut STATIC_MUT: i32 = 0;
-
fn foo<'a, T>() -> T {
foo::<'a, i32>()
}
@@ -185,10 +184,6 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
let x = 92;
vec.push(Foo { x, y: 1 });
}
- unsafe {
- vec.set_len(0);
- STATIC_MUT = 1;
- }
for e in vec {
// Do nothing
@@ -256,9 +251,6 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
futures::join!(f1, f2);
}
-unsafe trait Dangerous {}
-impl Dangerous for () {}
-
fn use_foo_items() {
let bob = foo::Person {
name: "Bob",
diff --git a/crates/ide/src/syntax_highlighting/test_data/injection.html b/crates/ide/src/syntax_highlighting/test_data/injection.html
index afb32746f14..28c2bed768a 100644
--- a/crates/ide/src/syntax_highlighting/test_data/injection.html
+++ b/crates/ide/src/syntax_highlighting/test_data/injection.html
@@ -17,6 +17,8 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
.function.unsafe { color: #BC8383; }
.trait.unsafe { color: #BC8383; }
.operator.unsafe { color: #BC8383; }
+.mutable.unsafe { color: #BC8383; text-decoration: underline; }
+.keyword.unsafe { color: #BC8383; font-weight: bold; }
.parameter { color: #94BFF3; }
.text { color: #DCDCCC; }
.type { color: #7CB8BB; }
@@ -33,7 +35,6 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
.mutable { text-decoration: underline; }
.escape_sequence { color: #94BFF3; }
.keyword { color: #F0DFAF; font-weight: bold; }
-.keyword.unsafe { color: #BC8383; font-weight: bold; }
.control { font-style: italic; }
.reference { font-style: italic; font-weight: bold; }
diff --git a/crates/ide/src/syntax_highlighting/test_data/rainbow_highlighting.html b/crates/ide/src/syntax_highlighting/test_data/rainbow_highlighting.html
index f0c96412f11..30c4bf40f4e 100644
--- a/crates/ide/src/syntax_highlighting/test_data/rainbow_highlighting.html
+++ b/crates/ide/src/syntax_highlighting/test_data/rainbow_highlighting.html
@@ -17,6 +17,8 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
.function.unsafe { color: #BC8383; }
.trait.unsafe { color: #BC8383; }
.operator.unsafe { color: #BC8383; }
+.mutable.unsafe { color: #BC8383; text-decoration: underline; }
+.keyword.unsafe { color: #BC8383; font-weight: bold; }
.parameter { color: #94BFF3; }
.text { color: #DCDCCC; }
.type { color: #7CB8BB; }
@@ -33,7 +35,6 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
.mutable { text-decoration: underline; }
.escape_sequence { color: #94BFF3; }
.keyword { color: #F0DFAF; font-weight: bold; }
-.keyword.unsafe { color: #BC8383; font-weight: bold; }
.control { font-style: italic; }
.reference { font-style: italic; font-weight: bold; }
diff --git a/crates/ide/src/syntax_highlighting/tests.rs b/crates/ide/src/syntax_highlighting/tests.rs
index 6b08e916a95..dbb8de24277 100644
--- a/crates/ide/src/syntax_highlighting/tests.rs
+++ b/crates/ide/src/syntax_highlighting/tests.rs
@@ -89,8 +89,6 @@ fn str() {
str();
}
-static mut STATIC_MUT: i32 = 0;
-
fn foo<'a, T>() -> T {
foo::<'a, i32>()
}
@@ -158,10 +156,6 @@ fn main() {
let x = 92;
vec.push(Foo { x, y: 1 });
}
- unsafe {
- vec.set_len(0);
- STATIC_MUT = 1;
- }
for e in vec {
// Do nothing
@@ -229,9 +223,6 @@ async fn async_main() {
futures::join!(f1, f2);
}
-unsafe trait Dangerous {}
-impl Dangerous for () {}
-
fn use_foo_items() {
let bob = foo::Person {
name: "Bob",
@@ -514,6 +505,8 @@ fn main() {
fn test_unsafe_highlighting() {
check_highlighting(
r#"
+static mut MUT_GLOBAL: Struct = Struct { field: 0 };
+static GLOBAL: Struct = Struct { field: 0 };
unsafe fn unsafe_fn() {}
union Union {
@@ -521,18 +514,11 @@ union Union {
b: f32,
}
-struct HasUnsafeFn;
-
-impl HasUnsafeFn {
+struct Struct { field: i32 }
+impl Struct {
unsafe fn unsafe_method(&self) {}
}
-struct TypeForStaticMut {
- a: u8
-}
-
-static mut global_mut: TypeForStaticMut = TypeForStaticMut { a: 0 };
-
#[repr(packed)]
struct Packed {
a: u16,
@@ -540,8 +526,9 @@ struct Packed {
unsafe trait UnsafeTrait {}
unsafe impl UnsafeTrait for Packed {}
+impl !UnsafeTrait for () {}
-fn require_unsafe_trait(_: T) {}
+fn unsafe_trait_bound(_: T) {}
trait DoTheAutoref {
fn calls_autoref(&self);
@@ -562,13 +549,14 @@ fn main() {
Union { b: 0 } => (),
Union { a } => (),
}
- HasUnsafeFn.unsafe_method();
+ Struct { field: 0 }.unsafe_method();
// unsafe deref
- let y = *x;
+ *x;
// unsafe access to a static mut
- let a = global_mut.a;
+ MUT_GLOBAL.field;
+ GLOBAL.field;
// unsafe ref of packed fields
let packed = Packed { a: 0 };