diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-02-13 21:12:49 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-02-13 21:12:49 +0000 |
commit | 7f751d6413aaaf7b36c02a76ac99077da529db75 (patch) | |
tree | 70c0617a36afdad641b95bf16295925ae04d9a25 /crates | |
parent | 3fdc556632e39145678219ace8476e12d7d70d41 (diff) | |
parent | 403a63d2b49a5dc080d10bbd6bbb48acc6e15d55 (diff) |
Merge #7665
7665: Don't classify attribute macros as their path unless it's a function with the proc_macro_attribute attribute r=Veykril a=Veykril
bors r+
Closes #6389
Co-authored-by: Lukas Wirth <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ide/src/references.rs | 35 | ||||
-rw-r--r-- | crates/ide_db/src/defs.rs | 14 |
2 files changed, 46 insertions, 3 deletions
diff --git a/crates/ide/src/references.rs b/crates/ide/src/references.rs index c7cefb3b6..17086f7d4 100644 --- a/crates/ide/src/references.rs +++ b/crates/ide/src/references.rs | |||
@@ -1127,4 +1127,39 @@ impl Foo { | |||
1127 | "#]], | 1127 | "#]], |
1128 | ); | 1128 | ); |
1129 | } | 1129 | } |
1130 | |||
1131 | #[test] | ||
1132 | fn test_attr_differs_from_fn_with_same_name() { | ||
1133 | check( | ||
1134 | r#" | ||
1135 | #[test] | ||
1136 | fn test$0() { | ||
1137 | test(); | ||
1138 | } | ||
1139 | "#, | ||
1140 | expect![[r#" | ||
1141 | test Function FileId(0) 0..33 11..15 | ||
1142 | |||
1143 | FileId(0) 24..28 | ||
1144 | "#]], | ||
1145 | ); | ||
1146 | } | ||
1147 | |||
1148 | #[test] | ||
1149 | fn test_attr_matches_proc_macro_fn() { | ||
1150 | check( | ||
1151 | r#" | ||
1152 | #[proc_macro_attribute] | ||
1153 | fn my_proc_macro() {} | ||
1154 | |||
1155 | #[my_proc_macro$0] | ||
1156 | fn test() {} | ||
1157 | "#, | ||
1158 | expect![[r#" | ||
1159 | my_proc_macro Function FileId(0) 0..45 27..40 | ||
1160 | |||
1161 | FileId(0) 49..62 | ||
1162 | "#]], | ||
1163 | ); | ||
1164 | } | ||
1130 | } | 1165 | } |
diff --git a/crates/ide_db/src/defs.rs b/crates/ide_db/src/defs.rs index a8091dbee..ff612b7d0 100644 --- a/crates/ide_db/src/defs.rs +++ b/crates/ide_db/src/defs.rs | |||
@@ -6,8 +6,8 @@ | |||
6 | // FIXME: this badly needs rename/rewrite (matklad, 2020-02-06). | 6 | // FIXME: this badly needs rename/rewrite (matklad, 2020-02-06). |
7 | 7 | ||
8 | use hir::{ | 8 | use hir::{ |
9 | db::HirDatabase, Crate, Field, GenericParam, HasVisibility, Impl, Label, Local, MacroDef, | 9 | db::HirDatabase, Crate, Field, GenericParam, HasAttrs, HasVisibility, Impl, Label, Local, |
10 | Module, ModuleDef, Name, PathResolution, Semantics, Visibility, | 10 | MacroDef, Module, ModuleDef, Name, PathResolution, Semantics, Visibility, |
11 | }; | 11 | }; |
12 | use syntax::{ | 12 | use syntax::{ |
13 | ast::{self, AstNode, PathSegmentKind}, | 13 | ast::{self, AstNode, PathSegmentKind}, |
@@ -366,7 +366,15 @@ impl NameRefClass { | |||
366 | 366 | ||
367 | if let Some(path) = name_ref.syntax().ancestors().find_map(ast::Path::cast) { | 367 | if let Some(path) = name_ref.syntax().ancestors().find_map(ast::Path::cast) { |
368 | if let Some(resolved) = sema.resolve_path(&path) { | 368 | if let Some(resolved) = sema.resolve_path(&path) { |
369 | return Some(NameRefClass::Definition(resolved.into())); | 369 | if path.syntax().parent().and_then(ast::Attr::cast).is_some() { |
370 | if let PathResolution::Def(ModuleDef::Function(func)) = resolved { | ||
371 | if func.attrs(sema.db).by_key("proc_macro_attribute").exists() { | ||
372 | return Some(NameRefClass::Definition(resolved.into())); | ||
373 | } | ||
374 | } | ||
375 | } else { | ||
376 | return Some(NameRefClass::Definition(resolved.into())); | ||
377 | } | ||
370 | } | 378 | } |
371 | } | 379 | } |
372 | 380 | ||