rust-lang / rust

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

array::IntoIter::new deprecation warning suggestion may lead to compilation error on 2015 and 2018 editions #127983

Open zakarumych opened 1 month ago

zakarumych commented 1 month ago

Code

std::array::IntoIter::new(array)

Current output

warning: use of deprecated associated function `std::array::IntoIter::<T, N>::new`: use `IntoIterator::into_iter` instead

Desired output

No warning on editions 2015 and 2018

Rationale and extra context

In many cases array.into_iter() will use <&[T; N] as IntoIterator>::into_iter on editions 2015 and 2018.

Other cases

No response

Rust Version

rustc 1.79.0 (129f3b996 2024-06-10)
binary: rustc
commit-hash: 129f3b9964af4d4a709d1383930ade12dfe7c081
commit-date: 2024-06-10
host: x86_64-pc-windows-msvc
release: 1.79.0
LLVM version: 18.1.7

Anything else?

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=f15a8e22d23c8b20ed3a21c6f3b4ab01

zachs18 commented 1 month ago

Note that IntoIterator::into_iter(array) works on all editions (since Rust 1.53.0). Regardless, new will not be removed within the Rust 1.X era, so users can just #[allow(deprecated)] on their uses of this if they need to support specifically Rust version 1.52.0 or 1.51.0 and newer versions where new is deprecated, with no warnings (or if they don't need to support old Rust versions, change to using Edition 2021(+) and use array.into_iter()).

zakarumych commented 1 month ago

I agree with all suggested fixes. The only problem is error message. Maybe simply mention this caveat?