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

"Introduce constant" refactoring breaks outside of functions #5844

Closed
etaloof opened this issue Jul 31, 2020 · 0 comments · Fixed by #5857
Closed

"Introduce constant" refactoring breaks outside of functions #5844

etaloof opened this issue Jul 31, 2020 · 0 comments · Fixed by #5857
Assignees
Labels
bug subsystem::refactoring Issues related to refactorings

Comments

@etaloof
Copy link

etaloof commented Jul 31, 2020

Environment

  • IntelliJ Rust plugin version: 0.3.128.3256-202-nightly
  • Rust toolchain version: rustc 1.45.0 (5c1f21c3b 2020-07-13), stable-x86_64-pc-windows-msvc
  • IDE name and version: Clion 2020.2 (202.6397.106)
  • Operating system: Windows 10

Problem description

Applying the refactoring "Introduce constant"/"Introduce variable" to const slices length specifiers that are not located in a function yields a curious prompt. The options are (also shown in the screenshot):

  • Replace this occurrence only
  • Replace all 0 occurrences

img

This makes no sense, the options are contradictory. The number of occurrences for the length value is 0. It should be 2 for const BUFFER: [u8; 1000] = [0; 1000]; because 1000 appears twice in this line. The first option works fine and applying the second option does nothing.

Steps to reproduce

With the minimal example below:

  • Move your cursor to a 1000 literal in one of the examples below the comment "these don't"
  • Press Ctrl+Alt+V/Ctrl+Alt+C or right-click, Refactor, "Introduce constant" / "Introduce variable"
// these work as expected

fn main() {
    const BUFFER: [u8; 1000] = [0; 1000];
}

fn t() {
    const BUFFER: [u8; 1000] = [0; 1000];
}

// these don't

const BUFFER: [u8; 1000] = [0; 1000];

mod t {
    const BUFFER: [u8; 1000] = [0; 1000];
}

trait T {
    const BUFFER: [u8; 1000] = [0; 1000];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug subsystem::refactoring Issues related to refactorings
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants