aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-05-23 13:40:14 +0100
committerGitHub <[email protected]>2021-05-23 13:40:14 +0100
commit064ff633f6055ed35022222c89af01d3f9943e3c (patch)
tree395729f98518d6f4ac5996d3cbfd4b65d04a85f1
parent57eedd906688d6cfa332bd40bca5234043e7293e (diff)
parent4d4dbcfead82eb6af1f4ef781b197a6926788b15 (diff)
Merge #8940
8940: Give ‘unsafe’ semantic token modifier to unsafe traits r=Veykril a=arzg Hi! This is my first pull request that touches rust-analyzer itself beyond a search-and-replace, so please tell me if I should change anything or do anything differently. :) Co-authored-by: Aramis Razzaghipour <[email protected]>
-rw-r--r--crates/hir/src/lib.rs4
-rw-r--r--crates/ide/src/syntax_highlighting/highlight.rs9
-rw-r--r--crates/ide/src/syntax_highlighting/tags.rs2
-rw-r--r--crates/ide/src/syntax_highlighting/test_data/highlighting.html5
-rw-r--r--crates/ide/src/syntax_highlighting/tests.rs3
5 files changed, 20 insertions, 3 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index 800101c91..a7c42ca1e 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -1085,6 +1085,10 @@ impl Trait {
1085 pub fn is_auto(self, db: &dyn HirDatabase) -> bool { 1085 pub fn is_auto(self, db: &dyn HirDatabase) -> bool {
1086 db.trait_data(self.id).is_auto 1086 db.trait_data(self.id).is_auto
1087 } 1087 }
1088
1089 pub fn is_unsafe(&self, db: &dyn HirDatabase) -> bool {
1090 db.trait_data(self.id).is_unsafe
1091 }
1088} 1092}
1089 1093
1090impl HasVisibility for Trait { 1094impl HasVisibility for Trait {
diff --git a/crates/ide/src/syntax_highlighting/highlight.rs b/crates/ide/src/syntax_highlighting/highlight.rs
index baed8e217..058e37ff0 100644
--- a/crates/ide/src/syntax_highlighting/highlight.rs
+++ b/crates/ide/src/syntax_highlighting/highlight.rs
@@ -338,7 +338,14 @@ fn highlight_def(db: &RootDatabase, def: Definition) -> Highlight {
338 338
339 return h; 339 return h;
340 } 340 }
341 hir::ModuleDef::Trait(_) => HlTag::Symbol(SymbolKind::Trait), 341 hir::ModuleDef::Trait(trait_) => {
342 let mut h = Highlight::new(HlTag::Symbol(SymbolKind::Trait));
343
344 if trait_.is_unsafe(db) {
345 h |= HlMod::Unsafe;
346 }
347 return h;
348 }
342 hir::ModuleDef::TypeAlias(type_) => { 349 hir::ModuleDef::TypeAlias(type_) => {
343 let mut h = Highlight::new(HlTag::Symbol(SymbolKind::TypeAlias)); 350 let mut h = Highlight::new(HlTag::Symbol(SymbolKind::TypeAlias));
344 if let Some(item) = type_.as_assoc_item(db) { 351 if let Some(item) = type_.as_assoc_item(db) {
diff --git a/crates/ide/src/syntax_highlighting/tags.rs b/crates/ide/src/syntax_highlighting/tags.rs
index f4a2e7506..27473a2f9 100644
--- a/crates/ide/src/syntax_highlighting/tags.rs
+++ b/crates/ide/src/syntax_highlighting/tags.rs
@@ -68,7 +68,7 @@ pub enum HlMod {
68 /// Used with keywords like `async` and `await`. 68 /// Used with keywords like `async` and `await`.
69 Async, 69 Async,
70 // Keep this last! 70 // Keep this last!
71 /// Used for unsafe functions, mutable statics, union accesses and unsafe operations. 71 /// Used for unsafe functions, unsafe traits, mutable statics, union accesses and unsafe operations.
72 Unsafe, 72 Unsafe,
73} 73}
74 74
diff --git a/crates/ide/src/syntax_highlighting/test_data/highlighting.html b/crates/ide/src/syntax_highlighting/test_data/highlighting.html
index 0d325f3f3..878431b56 100644
--- a/crates/ide/src/syntax_highlighting/test_data/highlighting.html
+++ b/crates/ide/src/syntax_highlighting/test_data/highlighting.html
@@ -245,4 +245,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
245 <span class="keyword">let</span> <span class="variable declaration">f1</span> <span class="operator">=</span> <span class="function async">learn_and_sing</span><span class="parenthesis">(</span><span class="parenthesis">)</span><span class="semicolon">;</span> 245 <span class="keyword">let</span> <span class="variable declaration">f1</span> <span class="operator">=</span> <span class="function async">learn_and_sing</span><span class="parenthesis">(</span><span class="parenthesis">)</span><span class="semicolon">;</span>
246 <span class="keyword">let</span> <span class="variable declaration">f2</span> <span class="operator">=</span> <span class="unresolved_reference">dance</span><span class="parenthesis">(</span><span class="parenthesis">)</span><span class="semicolon">;</span> 246 <span class="keyword">let</span> <span class="variable declaration">f2</span> <span class="operator">=</span> <span class="unresolved_reference">dance</span><span class="parenthesis">(</span><span class="parenthesis">)</span><span class="semicolon">;</span>
247 futures::<span class="macro">join!</span><span class="parenthesis">(</span>f1<span class="comma">,</span> f2<span class="parenthesis">)</span><span class="semicolon">;</span> 247 futures::<span class="macro">join!</span><span class="parenthesis">(</span>f1<span class="comma">,</span> f2<span class="parenthesis">)</span><span class="semicolon">;</span>
248<span class="brace">}</span></code></pre> \ No newline at end of file 248<span class="brace">}</span>
249
250<span class="keyword unsafe">unsafe</span> <span class="keyword">trait</span> <span class="trait declaration unsafe">Dangerous</span> <span class="brace">{</span><span class="brace">}</span>
251<span class="keyword">impl</span> <span class="trait unsafe">Dangerous</span> <span class="keyword">for</span> <span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span></code></pre> \ No newline at end of file
diff --git a/crates/ide/src/syntax_highlighting/tests.rs b/crates/ide/src/syntax_highlighting/tests.rs
index 8c8878d36..9ce26e930 100644
--- a/crates/ide/src/syntax_highlighting/tests.rs
+++ b/crates/ide/src/syntax_highlighting/tests.rs
@@ -219,6 +219,9 @@ async fn async_main() {
219 let f2 = dance(); 219 let f2 = dance();
220 futures::join!(f1, f2); 220 futures::join!(f1, f2);
221} 221}
222
223unsafe trait Dangerous {}
224impl Dangerous for () {}
222"# 225"#
223 .trim(), 226 .trim(),
224 expect_file!["./test_data/highlighting.html"], 227 expect_file!["./test_data/highlighting.html"],