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

Compiler should take more care about literal representation #1252

Closed
marijnh opened this issue Dec 2, 2011 · 2 comments
Closed

Compiler should take more care about literal representation #1252

marijnh opened this issue Dec 2, 2011 · 2 comments

Comments

@marijnh
Copy link
Contributor

marijnh commented Dec 2, 2011

Literals should probably be represented in high-precision, with literal arithmetic evaluated outside of LLVM, and only the result used as an LLVM constant.

Currently lit_int is represented by an int, making -2147483648 (or the 64-bit equivalent) lossy. The machine ints are all represented by int. For u32, i64, and u64, this is not enough. For i32, the problem mentioned above still comes up.

@ghost ghost assigned marijnh Dec 2, 2011
@jdm
Copy link
Contributor

jdm commented Dec 2, 2011

This is a less specific form of #974, yes?

@marijnh
Copy link
Contributor Author

marijnh commented Dec 2, 2011

Right.

@marijnh marijnh closed this as completed in e3eca91 Dec 7, 2011
@marijnh marijnh removed their assignment Jun 16, 2014
flip1995 added a commit to flip1995/rust that referenced this issue Dec 6, 2020
Add Collapsible match lint

changelog: Add collapsible_match lint

Closes rust-lang#1252
Closes rust-lang#2521

This lint finds nested `match` or `if let` patterns that can be squashed together. It is designed to be very conservative to only find cases where merging the patterns would most likely reduce cognitive complexity.

Example:

```rust
match result {
    Ok(opt) => match opt {
        Some(x) => x,
        _ => return,
    }
    _ => return,
}
```
to
```rust
match result {
    Ok(Some(x)) => x,
    _ => return,
}
```

These criteria must be met for the lint to fire:

* The inner match has exactly 2 branches.
* Both the outer and inner match have a "wild" branch like `_ => ..`. There is a special case for `None => ..` to also be considered "wild-like".
* The contents of the wild branches are identical.
* The binding which "links" the matches is never used elsewhere.

Thanks to the hir, `if let`'s are easily included with this lint since they are desugared into equivalent `match`'es.

I think this would fit into the style category, but I would also understand changing it to pedantic.
bjorn3 added a commit to bjorn3/rust that referenced this issue Aug 24, 2022
coastalwhite pushed a commit to coastalwhite/rust that referenced this issue Aug 5, 2023
celinval pushed a commit to celinval/rust-dev that referenced this issue Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants