rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
96.91k stars 12.53k forks source link

Nightly regression: ndarray 0.9.1 stops compiling: temporary value dropped while borrowed #98616

Closed tbu- closed 2 years ago

tbu- commented 2 years ago

ndarray 0.9.1 compiles with rustc 1.61.0 but not with rustc 1.64.0-nightly (2f3ddd9f5 2022-06-27).

Code

Put this into a Cargo.toml of a new project:

[package]
name = "test-ndarray"
version = "0.1.0"
edition = "2021"

[dependencies]
ndarray = "0.9.1"

rustc stable <= 1.61.0 compiles the crate fine, rustc nightly gives the following error:

error[E0716]: temporary value dropped while borrowed
  --> .cargo/registry/src/github.com-1ecc6299db9ec823/ndarray-0.9.1/src/layout/layoutfmt.rs:29:24
   |
25 |                        .format_with(" | ", |i, f| {
   |                                                - has type `&mut dyn FnMut(&'1 (dyn std::fmt::Display + '1)) -> Result<(), std::fmt::Error>`
...
29 |                     f(&format_args!("0x{:x}", i))
   |                     ---^^^^^^^^^^^^^^^^^^^^^^^^^-
   |                     |  |
   |                     |  creates a temporary which is freed while still in use
   |                     argument requires that borrow lasts for `'1`
30 |                 }
   |                 - temporary value is freed at the end of this statement
   |
   = note: this error originates in the macro `format_args` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0597]: `i` does not live long enough
  --> .cargo/registry/src/github.com-1ecc6299db9ec823/ndarray-0.9.1/src/layout/layoutfmt.rs:29:47
   |
25 |                        .format_with(" | ", |i, f| {
   |                                                - has type `&mut dyn FnMut(&'1 (dyn std::fmt::Display + '1)) -> Result<(), std::fmt::Error>`
...
29 |                     f(&format_args!("0x{:x}", i))
   |                     --------------------------^--
   |                     |                         |
   |                     |                         borrowed value does not live long enough
   |                     argument requires that `i` is borrowed for `'1`
30 |                 }
31 |             }))
   |             - `i` dropped here while still borrowed
   |
   = note: this error originates in the macro `format_args` (in Nightly builds, run with -Z macro-backtrace for more info)

Some errors have detailed explanations: E0597, E0716.
For more information about an error, try `rustc --explain E0597`.
error: could not compile `ndarray` due to 2 previous errors

Version it worked on

$ rustc --version --verbose
rustc 1.61.0 (fe5b13d68 2022-05-18)
binary: rustc
commit-hash: fe5b13d681f25ee6474be29d748c65adcd91f69e
commit-date: 2022-05-18
host: x86_64-unknown-linux-gnu
release: 1.61.0
LLVM version: 14.0.0

Version with regression

$ rustc +nightly --version --verbose
rustc 1.64.0-nightly (2f3ddd9f5 2022-06-27)
binary: rustc
commit-hash: 2f3ddd9f594adf9773547aa7cedb43c4ac8ffd2f
commit-date: 2022-06-27
host: x86_64-unknown-linux-gnu
release: 1.64.0-nightly
LLVM version: 14.0.6

@rustbot modify labels: +regression-from-stable-to-nightly -regression-untriaged

apiraino commented 2 years ago

Just adding a note. The issue seems to be an old version of num-complex that ndarray used to use back in v0.9.1

``` $ cargo +nightly build Compiling autocfg v1.1.0 Compiling matrixmultiply v0.1.15 Compiling ndarray v0.12.1 Compiling rawpointer v0.1.0 Compiling either v1.6.1 Compiling itertools v0.7.11 Compiling num-traits v0.2.15 Compiling num-complex v0.2.4 error[E0716]: temporary value dropped while borrowed --> /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/ndarray-0.12.1/src/layout/layoutfmt.rs:29:24 | 25 | .format_with(" | ", |i, f| { | - has type `&mut dyn FnMut(&'1 (dyn std::fmt::Display + '1)) -> Result<(), std::fmt::Error>` ... 29 | f(&format_args!("0x{:x}", i)) | ---^^^^^^^^^^^^^^^^^^^^^^^^^- | | | | | creates a temporary which is freed while still in use | argument requires that borrow lasts for `'1` 30 | } | - temporary value is freed at the end of this statement | = note: this error originates in the macro `format_args` (in Nightly builds, run with -Z macro-backtrace for more info) ```

The crate ndarray from v0.13.0 (released in sept. 2019) compiles fine also on latest Rust nightly

apiraino commented 2 years ago

bisection seems to point to commit 10f4ce324baf7cfb7ce2b2096662b82b79204944 cc @cjgillot

searched nightlies: from nightly-2022-04-01 to nightly-2022-06-28 regressed nightly: nightly-2022-06-23 searched commits: from https://github.com/rust-lang/rust/commit/dc80ca78b6ec2b6bba02560470347433bcd0bb3c to https://github.com/rust-lang/rust/commit/10f4ce324baf7cfb7ce2b2096662b82b79204944 regressed commit: https://github.com/rust-lang/rust/commit/10f4ce324baf7cfb7ce2b2096662b82b79204944

bisected with cargo-bisect-rustc v0.6.0 Host triple: x86_64-unknown-linux-gnu Reproduce with: ```bash cargo bisect-rustc --start=2022-04-01 ```

(unsure if this regression may hit other more recent crates)

cjgillot commented 2 years ago

I've been suspecting this bug for a few days, but unable to reproduce it. I think I have a patch, will confirm once I manage to MCVE.

apiraino commented 2 years ago

WG-prioritization assigning priority (Zulip discussion).

@rustbot label -I-prioritize +P-high