diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 8 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/tests.rs | 5 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/unsafe_validation.rs | 17 | ||||
-rw-r--r-- | crates/ra_ide/src/snapshots/highlight_injection.html | 4 | ||||
-rw-r--r-- | crates/ra_ide/src/snapshots/highlight_strings.html | 4 | ||||
-rw-r--r-- | crates/ra_ide/src/snapshots/highlight_unsafe.html | 53 | ||||
-rw-r--r-- | crates/ra_ide/src/snapshots/highlighting.html | 4 | ||||
-rw-r--r-- | crates/ra_ide/src/snapshots/rainbow_highlighting.html | 4 | ||||
-rw-r--r-- | crates/ra_ide/src/syntax_highlighting.rs | 8 | ||||
-rw-r--r-- | crates/ra_ide/src/syntax_highlighting/html.rs | 4 | ||||
-rw-r--r-- | crates/ra_ide/src/syntax_highlighting/tags.rs | 4 |
11 files changed, 83 insertions, 32 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 6aa7251b5..27e94b7fe 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -27,9 +27,9 @@ use hir_ty::{ | |||
27 | display::{HirDisplayError, HirFormatter}, | 27 | display::{HirDisplayError, HirFormatter}, |
28 | expr::ExprValidator, | 28 | expr::ExprValidator, |
29 | method_resolution, | 29 | method_resolution, |
30 | method_resolution, ApplicationTy, Canonical, InEnvironment, Substs, TraitEnvironment, Ty, | ||
31 | TyDefId, TypeCtor, | ||
32 | unsafe_validation::UnsafeValidator, | 30 | unsafe_validation::UnsafeValidator, |
31 | ApplicationTy, Canonical, GenericPredicate, InEnvironment, Substs, TraitEnvironment, Ty, | ||
32 | TyDefId, TypeCtor, | ||
33 | }; | 33 | }; |
34 | use ra_db::{CrateId, CrateName, Edition, FileId}; | 34 | use ra_db::{CrateId, CrateName, Edition, FileId}; |
35 | use ra_prof::profile; | 35 | use ra_prof::profile; |
@@ -671,6 +671,10 @@ 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 | |||
674 | pub fn diagnostics(self, db: &dyn HirDatabase, sink: &mut DiagnosticSink) { | 678 | pub fn diagnostics(self, db: &dyn HirDatabase, sink: &mut DiagnosticSink) { |
675 | let _p = profile("Function::diagnostics"); | 679 | let _p = profile("Function::diagnostics"); |
676 | let infer = db.infer(self.id.into()); | 680 | let infer = db.infer(self.id.into()); |
diff --git a/crates/ra_hir_ty/src/tests.rs b/crates/ra_hir_ty/src/tests.rs index 496cb428b..2a85ce85d 100644 --- a/crates/ra_hir_ty/src/tests.rs +++ b/crates/ra_hir_ty/src/tests.rs | |||
@@ -580,7 +580,6 @@ fn missing_unsafe() { | |||
580 | fn missing_unsafe_diagnostic_with_unsafe_method_call() { | 580 | fn missing_unsafe_diagnostic_with_unsafe_method_call() { |
581 | let diagnostics = TestDB::with_files( | 581 | let diagnostics = TestDB::with_files( |
582 | r" | 582 | r" |
583 | //- /lib.rs | ||
584 | struct HasUnsafe; | 583 | struct HasUnsafe; |
585 | 584 | ||
586 | impl HasUnsafe { | 585 | impl HasUnsafe { |
@@ -606,7 +605,6 @@ fn missing_unsafe() { | |||
606 | fn no_missing_unsafe_diagnostic_with_raw_ptr_in_unsafe_block() { | 605 | fn no_missing_unsafe_diagnostic_with_raw_ptr_in_unsafe_block() { |
607 | let diagnostics = TestDB::with_files( | 606 | let diagnostics = TestDB::with_files( |
608 | r" | 607 | r" |
609 | //- /lib.rs | ||
610 | fn nothing_to_see_move_along() { | 608 | fn nothing_to_see_move_along() { |
611 | let x = &5 as *const usize; | 609 | let x = &5 as *const usize; |
612 | unsafe { | 610 | unsafe { |
@@ -625,7 +623,6 @@ fn nothing_to_see_move_along() { | |||
625 | fn missing_unsafe_diagnostic_with_raw_ptr_outside_unsafe_block() { | 623 | fn missing_unsafe_diagnostic_with_raw_ptr_outside_unsafe_block() { |
626 | let diagnostics = TestDB::with_files( | 624 | let diagnostics = TestDB::with_files( |
627 | r" | 625 | r" |
628 | //- /lib.rs | ||
629 | fn nothing_to_see_move_along() { | 626 | fn nothing_to_see_move_along() { |
630 | let x = &5 as *const usize; | 627 | let x = &5 as *const usize; |
631 | unsafe { | 628 | unsafe { |
@@ -645,7 +642,6 @@ fn nothing_to_see_move_along() { | |||
645 | fn no_missing_unsafe_diagnostic_with_unsafe_call_in_unsafe_block() { | 642 | fn no_missing_unsafe_diagnostic_with_unsafe_call_in_unsafe_block() { |
646 | let diagnostics = TestDB::with_files( | 643 | let diagnostics = TestDB::with_files( |
647 | r" | 644 | r" |
648 | //- /lib.rs | ||
649 | unsafe fn unsafe_fn() { | 645 | unsafe fn unsafe_fn() { |
650 | let x = &5 as *const usize; | 646 | let x = &5 as *const usize; |
651 | let y = *x; | 647 | let y = *x; |
@@ -668,7 +664,6 @@ fn nothing_to_see_move_along() { | |||
668 | fn no_missing_unsafe_diagnostic_with_unsafe_method_call_in_unsafe_block() { | 664 | fn no_missing_unsafe_diagnostic_with_unsafe_method_call_in_unsafe_block() { |
669 | let diagnostics = TestDB::with_files( | 665 | let diagnostics = TestDB::with_files( |
670 | r" | 666 | r" |
671 | //- /lib.rs | ||
672 | struct HasUnsafe; | 667 | struct HasUnsafe; |
673 | 668 | ||
674 | impl HasUnsafe { | 669 | impl HasUnsafe { |
diff --git a/crates/ra_hir_ty/src/unsafe_validation.rs b/crates/ra_hir_ty/src/unsafe_validation.rs index f3ce7112a..e2353404b 100644 --- a/crates/ra_hir_ty/src/unsafe_validation.rs +++ b/crates/ra_hir_ty/src/unsafe_validation.rs | |||
@@ -3,7 +3,11 @@ | |||
3 | 3 | ||
4 | use std::sync::Arc; | 4 | use std::sync::Arc; |
5 | 5 | ||
6 | use hir_def::{DefWithBodyId, FunctionId}; | 6 | use hir_def::{ |
7 | body::Body, | ||
8 | expr::{Expr, ExprId, UnaryOp}, | ||
9 | DefWithBodyId, FunctionId, | ||
10 | }; | ||
7 | use hir_expand::diagnostics::DiagnosticSink; | 11 | use hir_expand::diagnostics::DiagnosticSink; |
8 | 12 | ||
9 | use crate::{ | 13 | use crate::{ |
@@ -11,13 +15,6 @@ use crate::{ | |||
11 | InferenceResult, Ty, TypeCtor, | 15 | InferenceResult, Ty, TypeCtor, |
12 | }; | 16 | }; |
13 | 17 | ||
14 | use rustc_hash::FxHashSet; | ||
15 | |||
16 | use hir_def::{ | ||
17 | body::Body, | ||
18 | expr::{Expr, ExprId, UnaryOp}, | ||
19 | }; | ||
20 | |||
21 | pub struct UnsafeValidator<'a, 'b: 'a> { | 18 | pub struct UnsafeValidator<'a, 'b: 'a> { |
22 | func: FunctionId, | 19 | func: FunctionId, |
23 | infer: Arc<InferenceResult>, | 20 | infer: Arc<InferenceResult>, |
@@ -75,13 +72,9 @@ pub fn unsafe_expressions( | |||
75 | def: DefWithBodyId, | 72 | def: DefWithBodyId, |
76 | ) -> Vec<UnsafeExpr> { | 73 | ) -> Vec<UnsafeExpr> { |
77 | let mut unsafe_exprs = vec![]; | 74 | let mut unsafe_exprs = vec![]; |
78 | let mut unsafe_block_exprs = FxHashSet::default(); | ||
79 | let body = db.body(def); | 75 | let body = db.body(def); |
80 | for (id, expr) in body.exprs.iter() { | 76 | for (id, expr) in body.exprs.iter() { |
81 | match expr { | 77 | match expr { |
82 | Expr::Unsafe { .. } => { | ||
83 | unsafe_block_exprs.insert(id); | ||
84 | } | ||
85 | Expr::Call { callee, .. } => { | 78 | Expr::Call { callee, .. } => { |
86 | let ty = &infer[*callee]; | 79 | let ty = &infer[*callee]; |
87 | if let &Ty::Apply(ApplicationTy { | 80 | if let &Ty::Apply(ApplicationTy { |
diff --git a/crates/ra_ide/src/snapshots/highlight_injection.html b/crates/ra_ide/src/snapshots/highlight_injection.html index 748f07625..1b0349bae 100644 --- a/crates/ra_ide/src/snapshots/highlight_injection.html +++ b/crates/ra_ide/src/snapshots/highlight_injection.html | |||
@@ -12,8 +12,8 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
12 | .string_literal { color: #CC9393; } | 12 | .string_literal { color: #CC9393; } |
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: #BC8383; } |
16 | .operator.unsafe { color: #E28C14; } | 16 | .operator.unsafe { color: #BC8383; } |
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 12a68ce62..d184b5691 100644 --- a/crates/ra_ide/src/snapshots/highlight_strings.html +++ b/crates/ra_ide/src/snapshots/highlight_strings.html | |||
@@ -12,8 +12,8 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
12 | .string_literal { color: #CC9393; } | 12 | .string_literal { color: #CC9393; } |
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: #BC8383; } |
16 | .operator.unsafe { color: #E28C14; } | 16 | .operator.unsafe { color: #BC8383; } |
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 new file mode 100644 index 000000000..6936e949f --- /dev/null +++ b/crates/ra_ide/src/snapshots/highlight_unsafe.html | |||
@@ -0,0 +1,53 @@ | |||
1 | |||
2 | <style> | ||
3 | body { margin: 0; } | ||
4 | pre { 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: #BC8383; } | ||
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="operator 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 d093a6266..8d0b38f95 100644 --- a/crates/ra_ide/src/snapshots/highlighting.html +++ b/crates/ra_ide/src/snapshots/highlighting.html | |||
@@ -12,8 +12,8 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
12 | .string_literal { color: #CC9393; } | 12 | .string_literal { color: #CC9393; } |
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: #BC8383; } |
16 | .operator.unsafe { color: #E28C14; } | 16 | .operator.unsafe { color: #BC8383; } |
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 192d564a6..9516c7441 100644 --- a/crates/ra_ide/src/snapshots/rainbow_highlighting.html +++ b/crates/ra_ide/src/snapshots/rainbow_highlighting.html | |||
@@ -12,8 +12,8 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
12 | .string_literal { color: #CC9393; } | 12 | .string_literal { color: #CC9393; } |
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: #BC8383; } |
16 | .operator.unsafe { color: #E28C14; } | 16 | .operator.unsafe { color: #BC8383; } |
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 fb4f2ce38..028b55902 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs | |||
@@ -605,7 +605,13 @@ 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(_) => HighlightTag::Function, | 608 | hir::ModuleDef::Function(func) => { |
609 | let mut h = HighlightTag::Function.into(); | ||
610 | if func.is_unsafe(db) { | ||
611 | h |= HighlightModifier::Unsafe; | ||
612 | } | ||
613 | return h; | ||
614 | } | ||
609 | hir::ModuleDef::Adt(hir::Adt::Struct(_)) => HighlightTag::Struct, | 615 | hir::ModuleDef::Adt(hir::Adt::Struct(_)) => HighlightTag::Struct, |
610 | hir::ModuleDef::Adt(hir::Adt::Enum(_)) => HighlightTag::Enum, | 616 | hir::ModuleDef::Adt(hir::Adt::Enum(_)) => HighlightTag::Enum, |
611 | hir::ModuleDef::Adt(hir::Adt::Union(_)) => HighlightTag::Union, | 617 | 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 3477610e5..0c74f7370 100644 --- a/crates/ra_ide/src/syntax_highlighting/html.rs +++ b/crates/ra_ide/src/syntax_highlighting/html.rs | |||
@@ -71,8 +71,8 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
71 | .string_literal { color: #CC9393; } | 71 | .string_literal { color: #CC9393; } |
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: #BC8383; } |
75 | .operator.unsafe { color: #E28C14; } | 75 | .operator.unsafe { color: #BC8383; } |
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 b9bea4729..13d9dd195 100644 --- a/crates/ra_ide/src/syntax_highlighting/tags.rs +++ b/crates/ra_ide/src/syntax_highlighting/tags.rs | |||
@@ -77,6 +77,7 @@ 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", | ||
80 | HighlightTag::Function => "function", | 81 | HighlightTag::Function => "function", |
81 | HighlightTag::Generic => "generic", | 82 | HighlightTag::Generic => "generic", |
82 | HighlightTag::Keyword => "keyword", | 83 | HighlightTag::Keyword => "keyword", |
@@ -84,6 +85,7 @@ impl HighlightTag { | |||
84 | HighlightTag::Macro => "macro", | 85 | HighlightTag::Macro => "macro", |
85 | HighlightTag::Module => "module", | 86 | HighlightTag::Module => "module", |
86 | HighlightTag::NumericLiteral => "numeric_literal", | 87 | HighlightTag::NumericLiteral => "numeric_literal", |
88 | HighlightTag::Operator => "operator", | ||
87 | HighlightTag::SelfKeyword => "self_keyword", | 89 | HighlightTag::SelfKeyword => "self_keyword", |
88 | HighlightTag::SelfType => "self_type", | 90 | HighlightTag::SelfType => "self_type", |
89 | HighlightTag::Static => "static", | 91 | HighlightTag::Static => "static", |
@@ -95,8 +97,6 @@ impl HighlightTag { | |||
95 | HighlightTag::Union => "union", | 97 | HighlightTag::Union => "union", |
96 | HighlightTag::Local => "variable", | 98 | HighlightTag::Local => "variable", |
97 | HighlightTag::UnresolvedReference => "unresolved_reference", | 99 | HighlightTag::UnresolvedReference => "unresolved_reference", |
98 | HighlightTag::FormatSpecifier => "format_specifier", | ||
99 | HighlightTag::Operator => "operator", | ||
100 | } | 100 | } |
101 | } | 101 | } |
102 | } | 102 | } |