aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2021-06-14 17:08:12 +0100
committerAleksey Kladov <[email protected]>2021-06-14 17:08:12 +0100
commit9fb67e7477a43fc91946f17c00205b7e31db00d8 (patch)
treed8bbae97eb17928ad524d9c16bb0c689119b478c /crates
parent26c978f258ed2af45a6979eefea9860c1eaeacda (diff)
internal: document rename challenges
Diffstat (limited to 'crates')
-rw-r--r--crates/ide/src/references/rename.rs18
-rw-r--r--crates/ide_db/src/rename.rs25
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#"
1777macro_rules! m { () => { fn f() {} } }
1778m!();
1779fn main() { f$0() }
1780"#,
1781 r#"
1782macro_rules! m { () => { fn f() {} } }
1783lol
1784fn 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 ¯\_(ツ)_/¯.
1use std::fmt; 23use std::fmt;
2 24
3use base_db::{AnchoredPathBuf, FileId, FileRange}; 25use 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) => {