aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_hir/src/code_model.rs4
-rw-r--r--crates/ra_ide/src/snapshots/highlight_injection.html2
-rw-r--r--crates/ra_ide/src/snapshots/highlight_strings.html2
-rw-r--r--crates/ra_ide/src/snapshots/highlight_unsafe.html53
-rw-r--r--crates/ra_ide/src/snapshots/highlighting.html2
-rw-r--r--crates/ra_ide/src/snapshots/rainbow_highlighting.html2
-rw-r--r--crates/ra_ide/src/syntax_highlighting.rs8
-rw-r--r--crates/ra_ide/src/syntax_highlighting/html.rs2
-rw-r--r--crates/ra_ide/src/syntax_highlighting/tags.rs8
-rw-r--r--crates/ra_ide/src/syntax_highlighting/tests.rs31
10 files changed, 10 insertions, 104 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index 9e3b4a2d8..6aa7251b5 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -671,10 +671,6 @@ impl Function {
671 db.function_data(self.id).params.clone() 671 db.function_data(self.id).params.clone()
672 } 672 }
673 673
674 pub fn is_unsafe(self, db: &dyn HirDatabase) -> bool {
675 db.function_data(self.id).is_unsafe
676 }
677
678 pub fn diagnostics(self, db: &dyn HirDatabase, sink: &mut DiagnosticSink) { 674 pub fn diagnostics(self, db: &dyn HirDatabase, sink: &mut DiagnosticSink) {
679 let _p = profile("Function::diagnostics"); 675 let _p = profile("Function::diagnostics");
680 let infer = db.infer(self.id.into()); 676 let infer = db.infer(self.id.into());
diff --git a/crates/ra_ide/src/snapshots/highlight_injection.html b/crates/ra_ide/src/snapshots/highlight_injection.html
index 3ac6c4ae5..748f07625 100644
--- a/crates/ra_ide/src/snapshots/highlight_injection.html
+++ b/crates/ra_ide/src/snapshots/highlight_injection.html
@@ -13,7 +13,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
13.field { color: #94BFF3; } 13.field { color: #94BFF3; }
14.function { color: #93E0E3; } 14.function { color: #93E0E3; }
15.function.unsafe { color: #E28C14; } 15.function.unsafe { color: #E28C14; }
16.operator.unsafe { color: #BC8383; } 16.operator.unsafe { color: #E28C14; }
17.parameter { color: #94BFF3; } 17.parameter { color: #94BFF3; }
18.text { color: #DCDCCC; } 18.text { color: #DCDCCC; }
19.type { color: #7CB8BB; } 19.type { color: #7CB8BB; }
diff --git a/crates/ra_ide/src/snapshots/highlight_strings.html b/crates/ra_ide/src/snapshots/highlight_strings.html
index 8556eb850..12a68ce62 100644
--- a/crates/ra_ide/src/snapshots/highlight_strings.html
+++ b/crates/ra_ide/src/snapshots/highlight_strings.html
@@ -13,7 +13,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
13.field { color: #94BFF3; } 13.field { color: #94BFF3; }
14.function { color: #93E0E3; } 14.function { color: #93E0E3; }
15.function.unsafe { color: #E28C14; } 15.function.unsafe { color: #E28C14; }
16.operator.unsafe { color: #BC8383; } 16.operator.unsafe { color: #E28C14; }
17.parameter { color: #94BFF3; } 17.parameter { color: #94BFF3; }
18.text { color: #DCDCCC; } 18.text { color: #DCDCCC; }
19.type { color: #7CB8BB; } 19.type { color: #7CB8BB; }
diff --git a/crates/ra_ide/src/snapshots/highlight_unsafe.html b/crates/ra_ide/src/snapshots/highlight_unsafe.html
deleted file mode 100644
index 692307280..000000000
--- a/crates/ra_ide/src/snapshots/highlight_unsafe.html
+++ /dev/null
@@ -1,53 +0,0 @@
1
2<style>
3body { margin: 0; }
4pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padding: 0.4em; }
5
6.lifetime { color: #DFAF8F; font-style: italic; }
7.comment { color: #7F9F7F; }
8.documentation { color: #629755; }
9.injected { opacity: 0.65 ; }
10.struct, .enum { color: #7CB8BB; }
11.enum_variant { color: #BDE0F3; }
12.string_literal { color: #CC9393; }
13.field { color: #94BFF3; }
14.function { color: #93E0E3; }
15.function.unsafe { color: #E28C14; }
16.operator.unsafe { color: #BC8383; }
17.parameter { color: #94BFF3; }
18.text { color: #DCDCCC; }
19.type { color: #7CB8BB; }
20.builtin_type { color: #8CD0D3; }
21.type_param { color: #DFAF8F; }
22.attribute { color: #94BFF3; }
23.numeric_literal { color: #BFEBBF; }
24.bool_literal { color: #BFE6EB; }
25.macro { color: #94BFF3; }
26.module { color: #AFD8AF; }
27.variable { color: #DCDCCC; }
28.format_specifier { color: #CC696B; }
29.mutable { text-decoration: underline; }
30.unresolved_reference { color: #FC5555; }
31.escape_sequence { color: #94BFF3; }
32
33.keyword { color: #F0DFAF; font-weight: bold; }
34.keyword.unsafe { color: #BC8383; font-weight: bold; }
35.control { font-style: italic; }
36</style>
37<pre><code><span class="keyword unsafe">unsafe</span> <span class="keyword">fn</span> <span class="function declaration unsafe">unsafe_fn</span>() {}
38
39<span class="keyword">struct</span> <span class="struct declaration">HasUnsafeFn</span>;
40
41<span class="keyword">impl</span> <span class="struct">HasUnsafeFn</span> {
42 <span class="keyword unsafe">unsafe</span> <span class="keyword">fn</span> <span class="function declaration unsafe">unsafe_method</span>(&<span class="self_keyword">self</span>) {}
43}
44
45<span class="keyword">fn</span> <span class="function declaration">main</span>() {
46 <span class="keyword">let</span> <span class="variable declaration">x</span> = &<span class="numeric_literal">5</span> <span class="keyword">as</span> *<span class="keyword">const</span> <span class="builtin_type">usize</span>;
47 <span class="keyword unsafe">unsafe</span> {
48 <span class="function unsafe">unsafe_fn</span>();
49 <span class="struct">HasUnsafeFn</span>.<span class="function unsafe">unsafe_method</span>();
50 <span class="keyword">let</span> <span class="variable declaration">y</span> = <span class="function unsafe">*</span><span class="variable">x</span>;
51 <span class="keyword">let</span> <span class="variable declaration">z</span> = -<span class="variable">x</span>;
52 }
53}</code></pre> \ No newline at end of file
diff --git a/crates/ra_ide/src/snapshots/highlighting.html b/crates/ra_ide/src/snapshots/highlighting.html
index 47403b367..d093a6266 100644
--- a/crates/ra_ide/src/snapshots/highlighting.html
+++ b/crates/ra_ide/src/snapshots/highlighting.html
@@ -13,7 +13,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
13.field { color: #94BFF3; } 13.field { color: #94BFF3; }
14.function { color: #93E0E3; } 14.function { color: #93E0E3; }
15.function.unsafe { color: #E28C14; } 15.function.unsafe { color: #E28C14; }
16.operator.unsafe { color: #BC8383; } 16.operator.unsafe { color: #E28C14; }
17.parameter { color: #94BFF3; } 17.parameter { color: #94BFF3; }
18.text { color: #DCDCCC; } 18.text { color: #DCDCCC; }
19.type { color: #7CB8BB; } 19.type { color: #7CB8BB; }
diff --git a/crates/ra_ide/src/snapshots/rainbow_highlighting.html b/crates/ra_ide/src/snapshots/rainbow_highlighting.html
index f5fb96f55..192d564a6 100644
--- a/crates/ra_ide/src/snapshots/rainbow_highlighting.html
+++ b/crates/ra_ide/src/snapshots/rainbow_highlighting.html
@@ -13,7 +13,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
13.field { color: #94BFF3; } 13.field { color: #94BFF3; }
14.function { color: #93E0E3; } 14.function { color: #93E0E3; }
15.function.unsafe { color: #E28C14; } 15.function.unsafe { color: #E28C14; }
16.operator.unsafe { color: #BC8383; } 16.operator.unsafe { color: #E28C14; }
17.parameter { color: #94BFF3; } 17.parameter { color: #94BFF3; }
18.text { color: #DCDCCC; } 18.text { color: #DCDCCC; }
19.type { color: #7CB8BB; } 19.type { color: #7CB8BB; }
diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs
index 028b55902..fb4f2ce38 100644
--- a/crates/ra_ide/src/syntax_highlighting.rs
+++ b/crates/ra_ide/src/syntax_highlighting.rs
@@ -605,13 +605,7 @@ fn highlight_name(db: &RootDatabase, def: Definition) -> Highlight {
605 Definition::Field(_) => HighlightTag::Field, 605 Definition::Field(_) => HighlightTag::Field,
606 Definition::ModuleDef(def) => match def { 606 Definition::ModuleDef(def) => match def {
607 hir::ModuleDef::Module(_) => HighlightTag::Module, 607 hir::ModuleDef::Module(_) => HighlightTag::Module,
608 hir::ModuleDef::Function(func) => { 608 hir::ModuleDef::Function(_) => HighlightTag::Function,
609 let mut h = HighlightTag::Function.into();
610 if func.is_unsafe(db) {
611 h |= HighlightModifier::Unsafe;
612 }
613 return h;
614 }
615 hir::ModuleDef::Adt(hir::Adt::Struct(_)) => HighlightTag::Struct, 609 hir::ModuleDef::Adt(hir::Adt::Struct(_)) => HighlightTag::Struct,
616 hir::ModuleDef::Adt(hir::Adt::Enum(_)) => HighlightTag::Enum, 610 hir::ModuleDef::Adt(hir::Adt::Enum(_)) => HighlightTag::Enum,
617 hir::ModuleDef::Adt(hir::Adt::Union(_)) => HighlightTag::Union, 611 hir::ModuleDef::Adt(hir::Adt::Union(_)) => HighlightTag::Union,
diff --git a/crates/ra_ide/src/syntax_highlighting/html.rs b/crates/ra_ide/src/syntax_highlighting/html.rs
index ed007c382..3477610e5 100644
--- a/crates/ra_ide/src/syntax_highlighting/html.rs
+++ b/crates/ra_ide/src/syntax_highlighting/html.rs
@@ -72,7 +72,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
72.field { color: #94BFF3; } 72.field { color: #94BFF3; }
73.function { color: #93E0E3; } 73.function { color: #93E0E3; }
74.function.unsafe { color: #E28C14; } 74.function.unsafe { color: #E28C14; }
75.operator.unsafe { color: #BC8383; } 75.operator.unsafe { color: #E28C14; }
76.parameter { color: #94BFF3; } 76.parameter { color: #94BFF3; }
77.text { color: #DCDCCC; } 77.text { color: #DCDCCC; }
78.type { color: #7CB8BB; } 78.type { color: #7CB8BB; }
diff --git a/crates/ra_ide/src/syntax_highlighting/tags.rs b/crates/ra_ide/src/syntax_highlighting/tags.rs
index e8e251cfc..b9bea4729 100644
--- a/crates/ra_ide/src/syntax_highlighting/tags.rs
+++ b/crates/ra_ide/src/syntax_highlighting/tags.rs
@@ -25,7 +25,6 @@ pub enum HighlightTag {
25 EnumVariant, 25 EnumVariant,
26 EscapeSequence, 26 EscapeSequence,
27 Field, 27 Field,
28 FormatSpecifier,
29 Function, 28 Function,
30 Generic, 29 Generic,
31 Keyword, 30 Keyword,
@@ -33,7 +32,6 @@ pub enum HighlightTag {
33 Macro, 32 Macro,
34 Module, 33 Module,
35 NumericLiteral, 34 NumericLiteral,
36 Operator,
37 SelfKeyword, 35 SelfKeyword,
38 SelfType, 36 SelfType,
39 Static, 37 Static,
@@ -45,6 +43,8 @@ pub enum HighlightTag {
45 Union, 43 Union,
46 Local, 44 Local,
47 UnresolvedReference, 45 UnresolvedReference,
46 FormatSpecifier,
47 Operator,
48} 48}
49 49
50#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] 50#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
@@ -77,7 +77,6 @@ impl HighlightTag {
77 HighlightTag::EnumVariant => "enum_variant", 77 HighlightTag::EnumVariant => "enum_variant",
78 HighlightTag::EscapeSequence => "escape_sequence", 78 HighlightTag::EscapeSequence => "escape_sequence",
79 HighlightTag::Field => "field", 79 HighlightTag::Field => "field",
80 HighlightTag::FormatSpecifier => "format_specifier",
81 HighlightTag::Function => "function", 80 HighlightTag::Function => "function",
82 HighlightTag::Generic => "generic", 81 HighlightTag::Generic => "generic",
83 HighlightTag::Keyword => "keyword", 82 HighlightTag::Keyword => "keyword",
@@ -85,7 +84,6 @@ impl HighlightTag {
85 HighlightTag::Macro => "macro", 84 HighlightTag::Macro => "macro",
86 HighlightTag::Module => "module", 85 HighlightTag::Module => "module",
87 HighlightTag::NumericLiteral => "numeric_literal", 86 HighlightTag::NumericLiteral => "numeric_literal",
88 HighlightTag::Operator => "operator",
89 HighlightTag::SelfKeyword => "self_keyword", 87 HighlightTag::SelfKeyword => "self_keyword",
90 HighlightTag::SelfType => "self_type", 88 HighlightTag::SelfType => "self_type",
91 HighlightTag::Static => "static", 89 HighlightTag::Static => "static",
@@ -97,6 +95,8 @@ impl HighlightTag {
97 HighlightTag::Union => "union", 95 HighlightTag::Union => "union",
98 HighlightTag::Local => "variable", 96 HighlightTag::Local => "variable",
99 HighlightTag::UnresolvedReference => "unresolved_reference", 97 HighlightTag::UnresolvedReference => "unresolved_reference",
98 HighlightTag::FormatSpecifier => "format_specifier",
99 HighlightTag::Operator => "operator",
100 } 100 }
101 } 101 }
102} 102}
diff --git a/crates/ra_ide/src/syntax_highlighting/tests.rs b/crates/ra_ide/src/syntax_highlighting/tests.rs
index facdc42b7..b7fad9719 100644
--- a/crates/ra_ide/src/syntax_highlighting/tests.rs
+++ b/crates/ra_ide/src/syntax_highlighting/tests.rs
@@ -370,34 +370,3 @@ fn check_highlighting(ra_fixture: &str, snapshot: &str, rainbow: bool) {
370 fs::write(dst_file, &actual_html).unwrap(); 370 fs::write(dst_file, &actual_html).unwrap();
371 assert_eq_text!(expected_html, actual_html); 371 assert_eq_text!(expected_html, actual_html);
372} 372}
373
374#[test]
375fn test_unsafe_highlighting() {
376 let (analysis, file_id) = single_file(
377 r#"
378unsafe fn unsafe_fn() {}
379
380struct HasUnsafeFn;
381
382impl HasUnsafeFn {
383 unsafe fn unsafe_method(&self) {}
384}
385
386fn main() {
387 let x = &5 as *const usize;
388 unsafe {
389 unsafe_fn();
390 HasUnsafeFn.unsafe_method();
391 let y = *x;
392 let z = -x;
393 }
394}
395"#
396 .trim(),
397 );
398 let dst_file = project_dir().join("crates/ra_ide/src/snapshots/highlight_unsafe.html");
399 let actual_html = &analysis.highlight_as_html(file_id, false).unwrap();
400 let expected_html = &read_text(&dst_file);
401 fs::write(dst_file, &actual_html).unwrap();
402 assert_eq_text!(expected_html, actual_html);
403}