Skip to content

Bogus trivial cast warning when comparing references cast to *const #23734

Closed
@sfackler

Description

@sfackler
fn main() {
    let a = &true;
    let b = &false;

    assert!(a as *const _ == b as *const _);
}
test.rs:5:30: 5:43 warning: trivial cast: `&bool` as `*const bool`, #[warn(trivial_casts)] on by default
test.rs:5     assert!(a as *const _ == b as *const _);
                                       ^~~~~~~~~~~~~
<std macros>:1:1: 5:46 note: in expansion of assert!
test.rs:5:5: 5:45 note: expansion site

But removing the second cast doesn't compile:

fn main() {
    let a = &true;
    let b = &false;

    assert!(a as *const _ == b);
}
test.rs:5:30: 5:31 error: mismatched types:
 expected `*const _`,
    found `&bool`
(expected *-ptr,
    found &-ptr) [E0308]
test.rs:5     assert!(a as *const _ == b);
                                       ^
<std macros>:1:1: 5:46 note: in expansion of assert!
test.rs:5:5: 5:33 note: expansion site
error: aborting due to previous error

cc @nrc

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions