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

Incorrectly inferred never type of match expression with diverging arm #6749

Closed
artemmukhin opened this issue Jan 28, 2021 · 1 comment · Fixed by #7007
Closed

Incorrectly inferred never type of match expression with diverging arm #6749

artemmukhin opened this issue Jan 28, 2021 · 1 comment · Fixed by #7007
Assignees
Labels
bug subsystem::type inference & name resolution Issues related to name resolution and/or type inference

Comments

@artemmukhin
Copy link
Member

Environment

  • IntelliJ Rust plugin version: 0.3.140.3624-203-nightly
  • Rust toolchain version: 1.48.0 (7eac88abb 2020-11-16) x86_64-apple-darwin
  • IDE name and version: IntelliJ IDEA 2020.3.2 Preview Ultimate Edition (IU-203.7148.15)
  • Operating system: macOS 10.16
  • Macro expansion engine: new
  • Name resolution engine: new

Problem description

The inferred type of num2 in the following example should be i32, not !
Screenshot 2021-01-28 at 14 22 12

Might be related to #1743

Steps to reproduce

fn foo(x: i32) {}

fn main() {
    let num2 = match "42".parse() {
        Ok(v) => v,
        Err(e) => panic!(),
    }; // type of `num2` should be `i32`, not `!`
    foo(num2);
}
@artemmukhin
Copy link
Member Author

From #6829 (comment):

CoerceMany should be implemented in order to fix this issue. Currently, IJ Rust uses a simplified and rough approach to handle this (see RsTypeInferenceWalker#getMoreCompleteType).

@bors bors bot closed this as completed in 21ff1b0 Mar 23, 2021
bors bot added a commit that referenced this issue Mar 25, 2021
6829: INSP: Implement unreachable code detection r=dima74 a=ortem

This PR introduces `Unreachable code` inspection to detect and remove unreachable code.

![unreachable_code](https://user-images.githubusercontent.com/4854600/107639621-2ce9cc00-6c82-11eb-8a06-114953a733ab.gif)

Note that now it might produce some false-positive warnings due to #6749 and #6797, so probably it's better to try fixing these issues before merging this. 

Some implementation details:
* Based on the control-flow graph which is already used for several inspections (move analysis, liveness analysis)
* Found unreachable elements are cached by `org.rust.lang.core.types.ExtensionsKt#CONTROL_FLOW_KEY` as well as the  graph itself
* Does not highlight each unreachable element separately, but merges their text ranges instead in order to highlight the widest range

Part of #1612.

changelog: Add `Unreachable code` inspection and quick-fix

6969: COMP: Improve dependency completion when using crates local index r=ortem a=avrong

<img width="400" src="https://user-images.githubusercontent.com/6342851/111127949-6c5b4f00-8585-11eb-8a1f-e1284d32009d.gif">

changelog: Improve performance of dependencies completion in `Cargo.toml` using crates local index. This feature is disabled by default for now. To use it, enable `org.rust.crates.local.index` experimental feature


Co-authored-by: ortem <ortem00@gmail.com>
Co-authored-by: Aleksei Trifonov <avrong@avrong.me>
bors bot added a commit that referenced this issue Mar 25, 2021
6829: INSP: Implement unreachable code detection r=dima74 a=ortem

This PR introduces `Unreachable code` inspection to detect and remove unreachable code.

![unreachable_code](https://user-images.githubusercontent.com/4854600/107639621-2ce9cc00-6c82-11eb-8a06-114953a733ab.gif)

Note that now it might produce some false-positive warnings due to #6749 and #6797, so probably it's better to try fixing these issues before merging this. 

Some implementation details:
* Based on the control-flow graph which is already used for several inspections (move analysis, liveness analysis)
* Found unreachable elements are cached by `org.rust.lang.core.types.ExtensionsKt#CONTROL_FLOW_KEY` as well as the  graph itself
* Does not highlight each unreachable element separately, but merges their text ranges instead in order to highlight the widest range

Part of #1612.

changelog: Add `Unreachable code` inspection and quick-fix

Co-authored-by: ortem <ortem00@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug subsystem::type inference & name resolution Issues related to name resolution and/or type inference
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants