Skip to content

Commit c951093

Browse files
committed
Auto merge of rust-lang#14284 - Veykril:sem-derive-unresolved, r=Veykril
fix: Highlight unresolved derives as being unresolved Fixes rust-lang/rust-analyzer#11350
2 parents 6ebbd48 + b6e7cf3 commit c951093

File tree

4 files changed

+6
-4
lines changed

4 files changed

+6
-4
lines changed

crates/hir/src/semantics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,8 +538,8 @@ impl<'db> SemanticsImpl<'db> {
538538
}
539539

540540
fn expand_derive_as_pseudo_attr_macro(&self, attr: &ast::Attr) -> Option<SyntaxNode> {
541-
let src = self.wrap_node_infile(attr.clone());
542541
let adt = attr.syntax().parent().and_then(ast::Adt::cast)?;
542+
let src = self.wrap_node_infile(attr.clone());
543543
let call_id = self.with_ctx(|ctx| {
544544
ctx.attr_to_derive_macro_call(src.with_value(&adt), src).map(|(_, it, _)| it)
545545
})?;

crates/ide/src/syntax_highlighting/highlight.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,9 @@ fn highlight_name_ref(
217217
// to anything when used.
218218
// We can fix this for derive attributes since derive helpers are recorded, but not for
219219
// general attributes.
220-
None if name_ref.syntax().ancestors().any(|it| it.kind() == ATTR) => {
220+
None if name_ref.syntax().ancestors().any(|it| it.kind() == ATTR)
221+
&& !sema.hir_file_for(name_ref.syntax()).is_derive_attr_pseudo_expansion(sema.db) =>
222+
{
221223
return HlTag::Symbol(SymbolKind::Attribute).into();
222224
}
223225
None => return HlTag::UnresolvedReference.into(),

crates/ide/src/syntax_highlighting/test_data/highlight_attributes.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
<span class="comment">// This is another normal comment</span>
5454
<span class="comment documentation">/// This is another doc comment</span>
5555
<span class="comment">// This is another normal comment</span>
56-
<span class="attribute_bracket attribute">#</span><span class="attribute_bracket attribute">[</span><span class="attribute attribute default_library library">derive</span><span class="parenthesis attribute">(</span><span class="derive attribute default_library library">Copy</span><span class="parenthesis attribute">)</span><span class="attribute_bracket attribute">]</span>
56+
<span class="attribute_bracket attribute">#</span><span class="attribute_bracket attribute">[</span><span class="attribute attribute default_library library">derive</span><span class="parenthesis attribute">(</span><span class="derive attribute default_library library">Copy</span><span class="comma attribute">,</span> <span class="unresolved_reference attribute">Unresolved</span><span class="parenthesis attribute">)</span><span class="attribute_bracket attribute">]</span>
5757
<span class="comment">// The reason for these being here is to test AttrIds</span>
5858
<span class="keyword">struct</span> <span class="struct declaration">Foo</span><span class="semicolon">;</span></code></pre>

crates/ide/src/syntax_highlighting/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fn attributes() {
3434
// This is another normal comment
3535
/// This is another doc comment
3636
// This is another normal comment
37-
#[derive(Copy)]
37+
#[derive(Copy, Unresolved)]
3838
// The reason for these being here is to test AttrIds
3939
struct Foo;
4040
"#,

0 commit comments

Comments
 (0)