diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ide/src/references/rename.rs | 18 | ||||
-rw-r--r-- | crates/ide_db/src/rename.rs | 25 |
2 files changed, 42 insertions, 1 deletions
diff --git a/crates/ide/src/references/rename.rs b/crates/ide/src/references/rename.rs index 88b6b1260..cec1d4552 100644 --- a/crates/ide/src/references/rename.rs +++ b/crates/ide/src/references/rename.rs | |||
@@ -1767,4 +1767,22 @@ fn f() { <()>::BAR$0; }"#, | |||
1767 | res, | 1767 | res, |
1768 | ); | 1768 | ); |
1769 | } | 1769 | } |
1770 | |||
1771 | #[test] | ||
1772 | fn macros_are_broken_lol() { | ||
1773 | cov_mark::check!(macros_are_broken_lol); | ||
1774 | check( | ||
1775 | "lol", | ||
1776 | r#" | ||
1777 | macro_rules! m { () => { fn f() {} } } | ||
1778 | m!(); | ||
1779 | fn main() { f$0() } | ||
1780 | "#, | ||
1781 | r#" | ||
1782 | macro_rules! m { () => { fn f() {} } } | ||
1783 | lol | ||
1784 | fn main() { lol() } | ||
1785 | "#, | ||
1786 | ) | ||
1787 | } | ||
1770 | } | 1788 | } |
diff --git a/crates/ide_db/src/rename.rs b/crates/ide_db/src/rename.rs index 877650df0..d77602453 100644 --- a/crates/ide_db/src/rename.rs +++ b/crates/ide_db/src/rename.rs | |||
@@ -1,3 +1,25 @@ | |||
1 | //! Rename infrastructure for rust-analyzer. It is used primarily for the | ||
2 | //! literal "rename" in the ide (look for tests there), but it is also available | ||
3 | //! as a general-purpose service. For example, it is used by the fix for the | ||
4 | //! "incorrect case" diagnostic. | ||
5 | //! | ||
6 | //! It leverages the [`crate::search`] functionality to find what needs to be | ||
7 | //! renamed. The actual renames are tricky -- field shorthands need special | ||
8 | //! attention, and, when renaming modules, you also want to rename files on the | ||
9 | //! file system. | ||
10 | //! | ||
11 | //! Another can of worms are macros: | ||
12 | //! | ||
13 | //! ``` | ||
14 | //! macro_rules! m { () => { fn f() {} } } | ||
15 | //! m!(); | ||
16 | //! fn main() { | ||
17 | //! f() // <- rename me | ||
18 | //! } | ||
19 | //! ``` | ||
20 | //! | ||
21 | //! The correct behavior in such cases is probably to show a dialog to the user. | ||
22 | //! Our current behavior is ¯\_(ツ)_/¯. | ||
1 | use std::fmt; | 23 | use std::fmt; |
2 | 24 | ||
3 | use base_db::{AnchoredPathBuf, FileId, FileRange}; | 25 | use base_db::{AnchoredPathBuf, FileId, FileRange}; |
@@ -64,7 +86,8 @@ impl Definition { | |||
64 | // incorrect for renames. The safe behavior would be to return an error for | 86 | // incorrect for renames. The safe behavior would be to return an error for |
65 | // such cases. The correct behavior would be to return an auxiliary list of | 87 | // such cases. The correct behavior would be to return an auxiliary list of |
66 | // "can't rename these occurrences in macros" items, and then show some kind | 88 | // "can't rename these occurrences in macros" items, and then show some kind |
67 | // of a dialog to the user. | 89 | // of a dialog to the user. See: |
90 | cov_mark::hit!(macros_are_broken_lol); | ||
68 | 91 | ||
69 | let res = match self { | 92 | let res = match self { |
70 | Definition::Macro(mac) => { | 93 | Definition::Macro(mac) => { |