Skip to content

Pre-emptive assumption of inequality while optimizations make equality.  #79759

Closed
@OptimisticPeach

Description

@OptimisticPeach

I tried this code:

fn compare(a: fn(usize) -> u32, b: fn(u64) -> u32) {
    if a as usize == b as usize {
        println!("a == b: {} & {}", a as usize, b as usize);
    } else {
        println!("a != b: {} & {}", a as usize, b as usize);
    }
}

fn foo<T>(_: T) -> u32 {
    0
}

fn main() {
    compare(foo::<usize>, foo::<u64>);
}

Playground

I expected to see this happen:

Either it would say a == b and provide equal addresses, or print a != b and provide different addresses.

Instead, this happened:

The playground prints this on December the 6th 2020:

a != b: 94588183998880 & 94588183998880

Meta

This bug also seems to occur on the beta channel available on the playground and the nightly available there too.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions