Skip to content

Tracking issue for release notes of #122661: Change the desugaring of assert! for better error output #141089

@rustbot

Description

@rustbot

This issue tracks the release notes text for #122661.

cc @estebank, @BurntSushi -- original issue/PR authors and assignees for drafting text

See the forge.rust-lang.org chapter about release notes for an overview of how the release team makes use of these tracking issues.

Release notes text

This section should be edited to specify the correct category(s) for the change, with succinct description(s) of what changed. Some things worth considering:

  • Does this need an additional compat notes section?
  • Was this a libs stabilization that should have additional headers to list new APIs under Stabilized APIs and Const Stabilized APIs?
# Compatibility Notes
- [Changed the expansion of the `assert!` macro](https://github.com/rust-lang/rust/pull/122661): The macro now expands to a `match` expression instead of an `if !cond { .. }`, which provides better error output when misused, but breaks `assert!` invocations which rely on a custom `Not` trait implementation.

Tip

Use the previous releases for inspiration on how to write the release notes text and which categories to pick.

Release blog section

If this change is notable enough for inclusion in the blog post then this section should be edited to contain a draft for the blog post. Otherwise leave it empty.

[The `assert!` macro now expands to a `match` expression](https://github.com/rust-lang/rust/pull/122661) instead of an `if !cond { .. }`, which provides better error output when misused, but breaks `assert!` invocations which rely on a custom `Not` trait implementation. For example, the following contrived code will stop working:

```rust
struct True;

impl core::ops::Not for True {
    type Output = bool;
    fn not(self) -> bool {
        false
    }
}

fn example() {
    assert!(True);
}
```

but that it will *not* break uses of `&bool`, such as:

```rust
struct Struct {
    valid: bool,
}

fn example(s: &Struct) {
    let Struct { valid } = s;
    assert!(valid);
}
```

In return, we get diagnostics that make more sense when misusing the macro:

```text
error[E0308]: mismatched types
  --> $DIR/issue-28308.rs:2:13
   |
LL |     assert!("foo");
   |             ^^^^^ expected `bool`, found `str`
```

Instead of the previous diagnostic which would mention the expression needing to implement the `Not` trait:

```text
error[E0600]: cannot apply unary operator `!` to type `&'static str`
  --> $DIR/issue-28308.rs:2:5
   |
LL |     assert!("foo");
   |     ^^^^^^^^^^^^^^ cannot apply unary operator `!`
```

Note

If a blog post section is required the release-blog-post label should be added (@rustbot label +release-blog-post) to this issue as otherwise it may be missed by the release team.

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.release-blog-postMarks issues tracking what text to put in the release blog post.relnotesMarks issues that should be documented in the release notes of the next release.relnotes-tracking-issueMarks issues tracking what text to put in release notes.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions