Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Nemo157 opened this issue Apr 26, 2023 · 3 comments · Fixed by #111038
Closed

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

Nemo157 opened this issue Apr 26, 2023 · 3 comments · Fixed by #111038
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. P-medium Medium priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Nemo157
Copy link
Member

Nemo157 commented Apr 26, 2023

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)

@Nemo157 Nemo157 added C-bug Category: This is a bug. A-diagnostics Area: Messages for errors, warnings, and lints labels Apr 26, 2023
@Noratrieb Noratrieb added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Apr 26, 2023
@Noratrieb
Copy link
Member

Noratrieb commented Apr 26, 2023

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}");
  |              ^^^^^^^^

@Noratrieb Noratrieb added the regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. label Apr 26, 2023
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Apr 26, 2023
@Noratrieb
Copy link
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

@apiraino
Copy link
Contributor

WG-prioritization assigning priority (Zulip discussion).

@rustbot label -I-prioritize +P-medium

@rustbot rustbot added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Apr 27, 2023
@tmiasko tmiasko self-assigned this Apr 30, 2023
@bors bors closed this as completed in f835b13 May 2, 2023
@tmiasko tmiasko removed their assignment May 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. P-medium Medium priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants