Skip to content
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

Refactor / Rename implicit named arguments in macro formatting #8854

Open
blueglyph opened this issue May 19, 2022 · 3 comments
Open

Refactor / Rename implicit named arguments in macro formatting #8854

blueglyph opened this issue May 19, 2022 · 3 comments
Labels
improvement subsystem::refactoring Issues related to refactorings

Comments

@blueglyph
Copy link

blueglyph commented May 19, 2022

Environment

  • IntelliJ Rust plugin version: 0.4.170.4627-221
  • Rust toolchain version: 1.60.0 (7737e0b5c 2022-04-04) x86_64-pc-windows-msvc
  • IDE name and version: PyCharm 2022.1.1 Professional Edition (PY-221.5591.52)
  • Operating system: Windows 10 10.0
  • Macro expansion engine: new
  • Name resolution engine: new

Problem description

Variables that are captured in strings, for ex. "The value is {value}", are not renamed as expected.

Steps to reproduce

  • Enter the following program:
fn main() {
    for i in ["One", "Two", "", "Last"] {
        if !i.is_empty() {
            println!("Hello, world! {i}");
            println!("This was {}", i)
        }
    }
}
  • select the loop variable i
  • Refactor / Rename, and rename to "name"
    => the resulting program is below, note that i was not renamed in println!("Hello, world! {i}").
fn main() {
    for name in ["One", "Two", "", "Last"] {
        if !name.is_empty() {
            println!("Hello, world! {i}");
            println!("This was {}", name)
        }
    }
}

The same problem occurs with normal 'let' variables and constants.

@neonaot neonaot added improvement subsystem::refactoring Issues related to refactorings labels May 20, 2022
@rsalmei
Copy link

rsalmei commented Jun 2, 2022

I think it is more than refactoring. I got warnings that variables are not used:
image
The same with the r in the last match arm... It is also "unused"...

And they are not highlighted:
image

Thanks!

@blueglyph
Copy link
Author

Yes, I think that's for the same reason. The grammar used by the plugin (Java bytecode, whether from ANTLR, hand-crafted or LEX/YACC port) is unlikely from the same source as the compiler (written in Rust).

When RFC 2795 was implemented, it was probably not integrated into the plugin's grammar.

This issue must be linked to the issue: #7338

@blueglyph blueglyph changed the title Refactor / Rename forgets variables captured in strings Refactor / Rename implicit named arguments in macro formatting Jun 2, 2022
@blueglyph
Copy link
Author

See also the pull request here (WIP): #8561 but I'm not sure there isn't more work to do for the refactoring once the grammar is fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement subsystem::refactoring Issues related to refactorings
Projects
None yet
Development

No branches or pull requests

3 participants