Skip to content

erroneous note: erroneous constant used emitted for non-compiling format_args! usage #110856

Closed
@Nemo157

Description

@Nemo157

I tried this code:

format_args!("{:?}", { let [_a] = *(&[] as &[Vec<i32>]) else { return }; });

I expected to see this happen: an error about not being able to move out of a slice

Instead, this happened: the error and a bunch of note: erroneous constant used

error[E0508]: cannot move out of type `[Vec<i32>]`, a non-copy slice
 --> src/main.rs:2:35
  |
2 | format_args!("{:?}", { let [_a] = *(&[] as &[Vec<i32>]) else { return }; });
  |                             --    ^^^^^^^^^^^^^^^^^^^^^ cannot move out of here
  |                             |
  |                             data moved here
  |                             move occurs because `_a` has type `Vec<i32>`, which does not implement the `Copy` trait
  |
help: consider borrowing the pattern binding
  |
2 | format_args!("{:?}", { let [ref _a] = *(&[] as &[Vec<i32>]) else { return }; });
  |                             +++

note: erroneous constant used
 --> src/main.rs:2:14
  |
2 | format_args!("{:?}", { let [_a] = *(&[] as &[Vec<i32>]) else { return }; });
  |              ^^^^^^

note: erroneous constant used
 --> src/main.rs:2:37
  |
2 | format_args!("{:?}", { let [_a] = *(&[] as &[Vec<i32>]) else { return }; });
  |                                     ^^^

note: erroneous constant used
 --> src/main.rs:2:22
  |
2 | format_args!("{:?}", { let [_a] = *(&[] as &[Vec<i32>]) else { return }; });
  |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: this note originates in the macro `format_args` (in Nightly builds, run with -Z macro-backtrace for more info)

Meta

Fails on 1.71.0-nightly (2023-04-25 458d4dae845ec155b285), works fine on 1.70.0-beta.1 (2023-04-19 1b7dd2252b99671ce5d1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions