Skip to content

eq_unspanned is incorrect #141522

Closed
Closed
@workingjubilee

Description

@workingjubilee

The following function is incorrect:

pub fn eq_unspanned(&self, other: &TokenStream) -> bool {
let mut iter1 = self.iter();
let mut iter2 = other.iter();
for (tt1, tt2) in iter::zip(&mut iter1, &mut iter2) {
if !tt1.eq_unspanned(tt2) {
return false;
}
}
iter1.next().is_none() && iter2.next().is_none()
}

Zipped iterators with uneven lengths will still consume an item from both sides of the zip on their final iteration (where one will return None and one will return Some). This allows for both iterators to be exhausted even though their lengths are unequal.

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions