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

"Lift return out" produces invalid code for "else if" #4789

Closed
lancelote opened this issue Dec 26, 2019 · 0 comments · Fixed by #4805
Closed

"Lift return out" produces invalid code for "else if" #4789

lancelote opened this issue Dec 26, 2019 · 0 comments · Fixed by #4805
Assignees
Labels
bug subsystem::code insight General label for issues related to code understanding: highlighting, completion, annotation, etc.

Comments

@lancelote
Copy link
Member

Environment

  • IntelliJ Rust plugin version: 0.2.114.SNAPSHOT-193-dev
  • Rust toolchain version: 1.41.0-nightly (99b89533d 2019-12-16) x86_64-apple-darwin
  • IDE name and version: CLion 2019.3 (CL-193.5233.103)
  • Operating system: macOS 10.15

Problem description

"Lift return out of 'if'" intention action (from #4172) may produce an invalid code in case of else if construction.

Steps to reproduce

Consider

fn get_char(n: u32) -> char {
    if n == 0 {
        return 'a'
    } else if n == 1 {
        return 'b'
    } else {
        return 'c'
    }
}

Plugin suggests to lift out return from the second if resulting in

fn get_char(n: u32) -> char {
    if n == 0 {
        return 'a'
    } else return if n == 1 {
        'b'
    } else {
        'c'
    }
}
@lancelote lancelote added the bug label Dec 26, 2019
@Undin Undin added the subsystem::code insight General label for issues related to code understanding: highlighting, completion, annotation, etc. label Dec 27, 2019
bors bot added a commit that referenced this issue Dec 30, 2019
4805: INT: do not suggest "Lift return out" on 'if' in 'else' branch r=Undin a=t-kameyama

Fixes #4789

Co-authored-by: Toshiaki Kameyama <kmymtsak@gmail.com>
bors bot added a commit that referenced this issue Dec 30, 2019
4805: INT: do not suggest "Lift return out" on 'if' in 'else' branch r=Undin a=t-kameyama

Fixes #4789

Co-authored-by: Toshiaki Kameyama <kmymtsak@gmail.com>
bors bot added a commit that referenced this issue Dec 30, 2019
4805: INT: do not suggest "Lift return out" on 'if' in 'else' branch r=Undin a=t-kameyama

Fixes #4789

Co-authored-by: Toshiaki Kameyama <kmymtsak@gmail.com>
bors bot added a commit that referenced this issue Dec 30, 2019
4805: INT: do not suggest "Lift return out" on 'if' in 'else' branch r=Undin a=t-kameyama

Fixes #4789

Co-authored-by: Toshiaki Kameyama <kmymtsak@gmail.com>
@bors bors bot closed this as completed in 4613262 Dec 31, 2019
@bors bors bot closed this as completed in #4805 Dec 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug subsystem::code insight General label for issues related to code understanding: highlighting, completion, annotation, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants