mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
internal: document rename challenges
This commit is contained in:
parent
26c978f258
commit
9fb67e7477
2 changed files with 42 additions and 1 deletions
|
@ -1767,4 +1767,22 @@ fn f() { <()>::BAR$0; }"#,
|
||||||
res,
|
res,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn macros_are_broken_lol() {
|
||||||
|
cov_mark::check!(macros_are_broken_lol);
|
||||||
|
check(
|
||||||
|
"lol",
|
||||||
|
r#"
|
||||||
|
macro_rules! m { () => { fn f() {} } }
|
||||||
|
m!();
|
||||||
|
fn main() { f$0() }
|
||||||
|
"#,
|
||||||
|
r#"
|
||||||
|
macro_rules! m { () => { fn f() {} } }
|
||||||
|
lol
|
||||||
|
fn main() { lol() }
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,25 @@
|
||||||
|
//! Rename infrastructure for rust-analyzer. It is used primarily for the
|
||||||
|
//! literal "rename" in the ide (look for tests there), but it is also available
|
||||||
|
//! as a general-purpose service. For example, it is used by the fix for the
|
||||||
|
//! "incorrect case" diagnostic.
|
||||||
|
//!
|
||||||
|
//! It leverages the [`crate::search`] functionality to find what needs to be
|
||||||
|
//! renamed. The actual renames are tricky -- field shorthands need special
|
||||||
|
//! attention, and, when renaming modules, you also want to rename files on the
|
||||||
|
//! file system.
|
||||||
|
//!
|
||||||
|
//! Another can of worms are macros:
|
||||||
|
//!
|
||||||
|
//! ```
|
||||||
|
//! macro_rules! m { () => { fn f() {} } }
|
||||||
|
//! m!();
|
||||||
|
//! fn main() {
|
||||||
|
//! f() // <- rename me
|
||||||
|
//! }
|
||||||
|
//! ```
|
||||||
|
//!
|
||||||
|
//! The correct behavior in such cases is probably to show a dialog to the user.
|
||||||
|
//! Our current behavior is ¯\_(ツ)_/¯.
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
use base_db::{AnchoredPathBuf, FileId, FileRange};
|
use base_db::{AnchoredPathBuf, FileId, FileRange};
|
||||||
|
@ -64,7 +86,8 @@ impl Definition {
|
||||||
// incorrect for renames. The safe behavior would be to return an error for
|
// incorrect for renames. The safe behavior would be to return an error for
|
||||||
// such cases. The correct behavior would be to return an auxiliary list of
|
// such cases. The correct behavior would be to return an auxiliary list of
|
||||||
// "can't rename these occurrences in macros" items, and then show some kind
|
// "can't rename these occurrences in macros" items, and then show some kind
|
||||||
// of a dialog to the user.
|
// of a dialog to the user. See:
|
||||||
|
cov_mark::hit!(macros_are_broken_lol);
|
||||||
|
|
||||||
let res = match self {
|
let res = match self {
|
||||||
Definition::Macro(mac) => {
|
Definition::Macro(mac) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue