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

allow refs in our constant folder #6144

Merged
merged 1 commit into from
Oct 9, 2020
Merged

allow refs in our constant folder #6144

merged 1 commit into from
Oct 9, 2020

Conversation

llogiq
Copy link
Contributor

@llogiq llogiq commented Oct 8, 2020

This helps with #3804 (but won't completely fix it).


changelog: none

@rust-highfive
Copy link

r? @matthiaskrgr

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Oct 8, 2020
@ebroto ebroto assigned ebroto and unassigned matthiaskrgr Oct 9, 2020
Copy link
Member

@ebroto ebroto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though this is a nice improvement in the constant folder, and catches some false positives in the float_cmp lint, assert_eq is still linted when it shouldn't.

This example:

const ZERO: f32 = 0.0;

fn main() {
    let offset = ZERO;
    assert_eq!(offset, ZERO);
}

(playground)

expands to:

// ...
const ZERO: f32 = 0.0;

fn main() {
    let offset = ZERO;
    {
        match (&offset, &ZERO) {
            (left_val, right_val) => {
                if !(*left_val == *right_val) {
                    // panicking code
                }
            }
        }
    };
}

So to fix this the constant folder should be taught about the intermediate bindings of the match.

Would you be willing to add this enhancement in this PR so we can close that issue? We can also land this as is for the moment, as I said it's already an improvement.

@ebroto ebroto added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Oct 9, 2020
@llogiq
Copy link
Contributor Author

llogiq commented Oct 9, 2020

I'll add deref, but match is a lot more complex; this will require introducing binding scope. I'd like to leave this to a follow-up PR.

@llogiq
Copy link
Contributor Author

llogiq commented Oct 9, 2020

@ebroto r?

Copy link
Member

@ebroto ebroto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add deref, but match is a lot more complex; this will require introducing binding scope. I'd like to leave this to a follow-up PR.

Seems fair. Thanks for the enhancement!

@ebroto
Copy link
Member

ebroto commented Oct 9, 2020

@bors r+

@ebroto ebroto removed the S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) label Oct 9, 2020
@bors
Copy link
Collaborator

bors commented Oct 9, 2020

📌 Commit 26e4de9 has been approved by ebroto

@bors
Copy link
Collaborator

bors commented Oct 9, 2020

⌛ Testing commit 26e4de9 with merge 0b86340...

@bors
Copy link
Collaborator

bors commented Oct 9, 2020

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: ebroto
Pushing 0b86340 to master...

@bors bors merged commit 0b86340 into master Oct 9, 2020
@ebroto ebroto deleted the float-cmp-ref branch October 9, 2020 23:16
@llogiq llogiq mentioned this pull request Oct 24, 2020
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

Successfully merging this pull request may close these issues.

5 participants