Open jaskij opened 6 days ago
That original code I posted can be further simplified, not sure if I should edit.
use num_traits::Bounded;
fn print_all<T>()
where
T: Bounded,
{
for v in T::min_value()..T::max_value() {
println!("{v}");
}
}
trait Bounded {
fn min_value() -> Self;
fn max_value() -> Self;
}
fn print_all<T>()
where
T: Bounded,
{
for v in T::min_value()..T::max_value() {}
}
I was typing this comment when the above appeared, but: further further minimized 😁
pub fn demo<T>(range: std::ops::Range<T>) {
for _ in range {}
}
No idea what the alternative is, if it's even possible to achieve what I want using stable Rust, but a stable compiler should not suggest using unstable features.
I don't know if the compiler could easily suggest this, but you can make your code work by adding where Range<T>: IntoIterator<Item = T>
.
thanks @cuviper , shepmaster helped me figure it out in the discord right after I made this issue
We currently don't suggest complex where
clauses, only restricting type parameters or associated types. We could suggest where Range<T>: IntoIterator<Item = T>
when T
is a type parameter... I'll prototype to get a sense of how noisy that would be. Edit: It wouldn't necessarily be too common, but the filtering needed to make it so would likely require a bit of a refactor to note_obligation_cause_code
...
Code
Current output
Desired output
No idea what the alternative is, if it's even possible to achieve what I want using stable Rust, but a stable compiler should not suggest using unstable features.
Rationale and extra context
No response
Other cases
Rust Version
Anything else?
Rust Playground