Closed
Description
Code
use std::collections::HashSet;
use std::hash::Hash;
use num_traits::Bounded;
fn for_each_value_with_skip<T>(skipped: &HashSet<T>, func: impl Fn(T))
where
T: Bounded + Hash + Eq,
{
for v in T::min_value()..T::max_value() {
if skipped.contains(&v) {
continue;
}
func(v);
}
}
Current output
error[E0277]: the trait bound `T: Step` is not satisfied
--> s7-comm/src/tests/helpers.rs:11:14
|
11 | for v in T::min_value()..T::max_value() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Step` is not implemented for `T`, which is required by `std::ops::Range<T>: IntoIterator`
|
= note: required for `std::ops::Range<T>` to implement `Iterator`
= note: required for `std::ops::Range<T>` to implement `IntoIterator`
help: consider further restricting this bound
|
9 | T: Bounded + Hash + Eq + std::iter::Step,
| +++++++++++++++++
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
$ rustc --version
rustc 1.82.0 (f6e511eec 2024-10-15)
Activity
[-]Stable rustc 1.82 suggests using unstable features[/-][+]Stable rustc 1.82 suggests using an usntable trait[/+][-]Stable rustc 1.82 suggests using an usntable trait[/-][+]Stable rustc 1.82 suggests using an unstable trait[/+]jaskij commentedon Nov 26, 2024
That original code I posted can be further simplified, not sure if I should edit.
playground link
estebank commentedon Nov 27, 2024
Further minimized:
clubby789 commentedon Nov 27, 2024
I was typing this comment when the above appeared, but: further further minimized 😁
cuviper commentedon Nov 28, 2024
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>
.jaskij commentedon Nov 28, 2024
thanks @cuviper , shepmaster helped me figure it out in the discord right after I made this issue
estebank commentedon Nov 28, 2024
We currently don't suggest complex
where
clauses, only restricting type parameters or associated types. We could suggestwhere Range<T>: IntoIterator<Item = T>
whenT
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 tonote_obligation_cause_code
...Rollup merge of rust-lang#133522 - estebank:dont-suggest-unstable-tra…
Rollup merge of rust-lang#133522 - estebank:dont-suggest-unstable-tra…
Rollup merge of rust-lang#133522 - estebank:dont-suggest-unstable-tra…
Rollup merge of rust-lang#133522 - estebank:dont-suggest-unstable-tra…
2 remaining items