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

Account for incorrect [].into_iter() in <2021 edition #85189

Closed
estebank opened this issue May 11, 2021 · 2 comments
Closed

Account for incorrect [].into_iter() in <2021 edition #85189

estebank opened this issue May 11, 2021 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-edition-2021 Area: The 2021 edition D-edition Diagnostics: An error or lint that should account for edition differences. P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@estebank
Copy link
Contributor

Currently uses of <[_; _] as _>::into_iter() emit a future compat warning:

warning: this method call currently resolves to `<&[T; N] as IntoIterator>::into_iter` (due to autoref coercions), but that might change in the future when `IntoIterator` impls for arrays are added.
 --> src/main.rs:2:23
  |
2 |     let _ = [1, 2, 3].into_iter();
  |                       ^^^^^^^^^ help: use `.iter()` instead of `.into_iter()` to avoid ambiguity: `iter`
  |
  = note: `#[warn(array_into_iter)]` on by default
  = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
  = note: for more information, see issue #66145 <https://github.com/rust-lang/rust/issues/66145>

but at some point this will cause ambiguity errors on 2015 and 2018 editions. On 2021 onwards, this case is handled by a special attribute and keeps the code compiling.

We should detect that case explicitly and provide guidance about what to write in the current edition, or to update to the new edition.

@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints P-low Low priority T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. D-edition Diagnostics: An error or lint that should account for edition differences. A-edition-2021 Area: The 2021 edition labels May 11, 2021
@est31
Copy link
Member

est31 commented May 11, 2021

cc #84513

See also the array docs.

@m-ou-se m-ou-se added this to Stable Blockers in 2021 Edition Blockers Aug 2, 2021
@m-ou-se
Copy link
Member

m-ou-se commented Aug 2, 2021

That code now produces:

warning: this method call resolves to `<&[T; N] as IntoIterator>::into_iter` (due to backwards compatibility), but will resolve to <[T; N] as IntoIterator>::into_iter in Rust 2021.
 --> src/main.rs:2:23
  |
2 |     let _ = [1, 2, 3].into_iter();
  |                       ^^^^^^^^^
  |
  = note: `#[warn(array_into_iter)]` on by default
  = warning: this changes meaning in Rust 2021
  = note: for more information, see issue #66145 <https://github.com/rust-lang/rust/issues/66145>
help: use `.iter()` instead of `.into_iter()` to avoid ambiguity
  |
2 |     let _ = [1, 2, 3].iter();
  |                       ^^^^
help: or use `IntoIterator::into_iter(..)` instead of `.into_iter()` to explicitly iterate by value
  |
2 |     let _ = IntoIterator::into_iter([1, 2, 3]);
  |             ^^^^^^^^^^^^^^^^^^^^^^^^         ^

@m-ou-se m-ou-se closed this as completed Aug 2, 2021
2021 Edition Blockers automation moved this from Stable Blockers to Completed items Aug 2, 2021
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 A-edition-2021 Area: The 2021 edition D-edition Diagnostics: An error or lint that should account for edition differences. P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
2021 Edition Blockers
  
Completed items
Development

No branches or pull requests

3 participants