Skip to content

Tracking Issue for assert_eq in constants #74925

Closed
@oli-obk

Description

@oli-obk

In order to use assert_eq! in constants, we first need to have panic! with formatting (#51999) and const fn PartialEq::eq implementations (#67792) implemented and stabilized. If you look at the desugaring of assert_eq!, this quickly becomes obvious:

assert_eq!(a, b);

desugars to

        match (&a, &b) {
            (left_val, right_val) => {
                if !(*left_val == *right_val) {
                    // The reborrows below are intentional. Without them, the stack slot for the
                    // borrow is initialized even before the values are compared, leading to a
                    // noticeable slow down.
                    panic!(r#"assertion failed: `(left == right)`
  left: `{:?}`,
 right: `{:?}`"#, &*left_val, &*right_val)
                }
            }
        }

where the == operation will desugar to PartialEq::eq(left_val, right_val) for all non-primites. If we want to, we can support assert_eq! for primitives (integers, chars, bools) with only panicking with formatting.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions