-
Notifications
You must be signed in to change notification settings - Fork 316
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
Itertools 0.13.0 breaks strum derive macros if both are in scope at the same time. #942
Comments
It's a classic macro hygiene issue in impl AIter {
fn get(&self, idx: usize) -> ::core::option::Option<A> {
match idx {
0usize => ::core::option::Option::Some(A::B),
1usize => ::core::option::Option::Some(A::C),
_ => ::core::option::Option::None,
}
}
} ...and calling it without using the fully-qualified syntax; e.g.: impl DoubleEndedIterator for AIter {
fn next_back(&mut self) -> ::core::option::Option<<Self as Iterator>::Item> {
let back_idx = self.back_idx + 1;
if self.idx + back_idx > 2usize {
self.back_idx = 2usize;
::core::option::Option::None
} else {
self.back_idx = back_idx;
self.get(2usize - self.back_idx)
}
}
} If my understanding of method resolution is correct, rustc first searches for an applicable The fix is for AIter::get(self, 2usize - self.back_idx) |
Fair enough, as a side note,
The only way to get rid of that warning is to use a fully qualified form, which of course breaks method chaining ( |
We opted for consistency with Especially given that there is a language-level solution to the problem of super trait method collisions on the horizon, I think it's very unlikely that we'd take the step of prefixing the names of all itertools methods. That would be a tremendous breaking change to pass on to our users. |
Feel free to close this issue (or maybe you want to keep it open for others to find over the next few days?) as there is nothing to do on the itertools side of thing. |
It would be nice if there was a clippy lint that would help authors of libraries like |
Good idea, though this is the wrong place to pursue that. Either the rust issue tracker or https://internals.rust-lang.org would be appropriate places for this. |
I hope you don't mind me adding to this. I don't think the following warrants a separate issue but I wanted to document this somewhere and figured this would be a good place if people come across this quirk:
So this example also requires qualified paths: #![feature(slice_index_methods)]
use core::slice::SliceIndex;
use itertools::Itertools;
fn main() {
let r = 0..10;
r.get(1..3);
// Disambiguation:
//Itertools::get(r, 1..3);
} I do think it's slightly unfortunate. However, |
Yes it's a bit unfortunate. However, I heard that ranges are discussed to not be iterators anymore but only EDIT: The fix has been merged in strum_macros 0.26.3. Unpinning this. |
This leads to the very strange following error if the mentioned line is uncommented:
I have no idea if this is a strum or itertools bug. As such I have reported this to both, see Peternator7/strum#358
Using rustc 1.78.0 (9b00956e5 2024-04-29).
The text was updated successfully, but these errors were encountered: