-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Tracking issue for future-incompatibility lint array_into_iter #66145
Copy link
Copy link
Open
Labels
A-arrayArea: `[T; N]`Area: `[T; N]`A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-future-incompatibilityCategory: Future-incompatibility lintsCategory: Future-incompatibility lintsC-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team
Metadata
Metadata
Assignees
Labels
A-arrayArea: `[T; N]`Area: `[T; N]`A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-future-incompatibilityCategory: Future-incompatibility lintsCategory: Future-incompatibility lintsC-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team
Type
Fields
Give feedbackNo fields configured for issues without a type.
Projects
Status
Idea
What is this lint about?
Method resolution is responsible for finding a fitting method for a method call expression
receiver.name(args). The expressionarray.into_iter()(wherearrayhas an array type[T; N]) currently resolves to either<&[T; N] as IntoIterator>::into_iter(for arrays smaller than 33) or<&[T] as IntoIterator>::into_iter(for larger arrays). In either way, an iterator over references to the array's elements is returned.In the future, we might want to add
impl IntoIterator for [T; N](for arrays by value). In that case, method resolution would prioritize<[T;N] as IntoIterator>::into_iteras that method call would not require an autoref-coercion. In other words: the receiver expression (left of the dot in the method call) fits the receiver type of the method perfectly, so that method is preferred. In the&[T; N]or&[T]case, coercions are necessary to make the method call work.Since the new method is prioritized over the old ones, some code can break. Usually that code looks somewhat like this:
Currently this works, as
into_iterreturns an iterator over references to the array's values, meaning thatnis indeed&{integer}and can be dereferenced. With the new impl, that code would stop compiling. The lint has been put in place to warn of this potentially upcoming breaking change.How to fix this warning/error
Replace
.into_iter()with.iter(). The latter is guaranteed to always resolve to an iterator over references to the elements.Current status
array.into_iter()#66017array_into_iterlint to also lint for boxed arrays #67524