Skip to content

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

Closed

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)

Activity

  1. added
    C-bugCategory: This is a bug.
    A-diagnosticsArea: Messages for errors, warnings, and lints
    on Apr 26, 2023
  2. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Apr 26, 2023
  3. Noratrieb commented on Apr 26, 2023

    @Noratrieb
    Member

    It also applies to way simpler code like: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=aeadbb4b94770923ec61da515e15e45c

        let mut x = String::from("hello");
        let z = &x;
        let y = &mut x;
        println!("{y}{z}");
    error[[E0502]](https://doc.rust-lang.org/nightly/error_codes/E0502.html): cannot borrow `x` as mutable because it is also borrowed as immutable
     --> src/main.rs:4:13
      |
    3 |     let z = &x;
      |             -- immutable borrow occurs here
    4 |     let y = &mut x;
      |             ^^^^^^ mutable borrow occurs here
    5 |     println!("{y}{z}");
      |                  --- immutable borrow later used here
    
    note: erroneous constant used
     --> src/main.rs:5:14
      |
    5 |     println!("{y}{z}");
      |              ^^^^^^^^
    
  4. added
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Apr 26, 2023
  5. Noratrieb commented on Apr 26, 2023

    @Noratrieb
    Member

    searched nightlies: from nightly-2023-04-01 to nightly-2023-04-26
    regressed nightly: nightly-2023-04-22
    searched commit range: 8bdcc62...fec9adc
    regressed commit: fa4cc63

    bisected with cargo-bisect-rustc v0.6.6

    Host triple: x86_64-unknown-linux-gnu
    Reproduce with:

    cargo bisect-rustc 2023-04-01 --prompt --access github

    Host triple: x86_64-unknown-linux-gnu
    Reproduce with:

    cargo bisect-rustc 2023-04-01 --prompt --access github

    #110107 @cjgillot

    Intestingly, the same day also contained two format_args PRs but I have bisected this twice (with manual promt) and const prop lint really does seem to be the cause:

    commit[0] 2023-04-20: Auto merge of #110616 - m-ou-se:fmt-lang-items, r=jyn514
    commit[1] 2023-04-20: Auto merge of #109999 - m-ou-se:flatten-format-args, r=oli-obk

  6. apiraino commented on Apr 27, 2023

    @apiraino
    Contributor

    WG-prioritization assigning priority (Zulip discussion).

    @rustbot label -I-prioritize +P-medium

  7. added and removed
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Apr 27, 2023
  8. self-assigned this
    on Apr 30, 2023
  9. added a commit that references this issue on May 1, 2023
    f835b13
  10. removed their assignment
    on May 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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