Skip to content

manual_assert must not duplicate ending ";" inside impl #12505

Closed
@matthiaskrgr

Description

@matthiaskrgr

Summary

looks like a simple off-by-one error; the span is just outside of the ; but then we add the new expr with ANOTHER ; resulting in ;; and rustc doesnt like that :D

Reproducer

I tried this code:

//@ build-pass

// issue 122301 - currently the only way to supress
// const eval and codegen of code conditional on some other const
#![allow(clippy::all)]
#![warn(clippy::manual_assert)]


struct Foo<T, const N: usize>(T);

impl<T, const N: usize> Foo<T, N> {
    const BAR: () = if N == 0 {
        panic!()
    };
}


fn main() {

}

I expected to see this happen:
build pass
Instead, this happened:

error: non-item in item list
  --> src/main.rs:12:42
   |
11 | impl<T, const N: usize> Foo<T, N> {
   |                                   - item list starts here
12 |     const BAR: () = assert!(!(N == 0), );;
   |                                          ^ non-item starts here
13 | }
   | - item list ends here

Version

rustc 1.79.0-nightly (3cdcdaf31 2024-03-18)
binary: rustc
commit-hash: 3cdcdaf31b45f8045164aae9604573d23091970b
commit-date: 2024-03-18
host: x86_64-unknown-linux-gnu
release: 1.79.0-nightly
LLVM version: 18.1.2

Additional Labels

No response

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions