-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Renames are allowed to change the meaning of the program, due to shadowing. #10713
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hm, if this was blocked I'd want a way to force it to happen anyway as sometimes I really do want semantic changes. Visual Studio's C# rename preview highlights name conflicts in red, but lets you do it anyway, which seems the best of both worlds. |
Can you give an example of a situation where this behavior would be desirable? |
Sure! It happens pretty often to me that one is a typo of the other, and renaming the two variables to be the same is the whole point. |
That` is a good point; perhaps the best behavior would be to warn, or to offer different commands for "safe rename" vs. "force rename" (I'm not sure whether this is possible in the LSP protocol, though) |
The LSP spec(3.16.0+) supports user confirmation for specified renames with a description as to why confirmation is requested, that could be used in this case, that is if the rename creates name collisions we could add a confirmation via a |
Has this been solved? I just stumbled into the same problem in a less evident context: imagine something like fn main() {
let mut v = vec![0; 5];
let node = 0;
let mut iter = (0..5).into_iter();
while let Some(curr) = iter.next() {
v[curr] = node;
}
println!("{:?}", v);
} but more complicated. If you rename the loop variable One vote for default behavior being to warn the user. Refactorings should not, by definition, change the program semantics. |
For example:
if
x
is renamed toy
, this becomeswhich prints a different number. Rust-analyzer should probably refuse to rename
x
in this case.The text was updated successfully, but these errors were encountered: