Cannot use or use constructor like fn

I want to write something like this:

use std::{iter, ops}; struct Idx(usize); fn get_inds() -> iter::Zip<iter::Map<ops::RangeFrom<usize>, fn(usize) -> Idx>, ops::RangeFrom<usize>> { (0..).map(Idx).zip(0..) } 

However, this does not compile:

 error: mismatched types [--explain E0308] --> src/main.rs:6:9 6 |> (0..).map(Idx).zip(0..) |> ^^^^^^^^^^^^^^^^^^^^^^^ expected fn pointer, found fn item note: expected type `std::iter::Zip<std::iter::Map<std::ops::RangeFrom<usize>, fn(usize) -> Idx>, std::ops::RangeFrom<usize>>` note: found type `std::iter::Zip<std::iter::Map<std::ops::RangeFrom<usize>, fn(usize) -> Idx {Idx::{{constructor}}}>, std::ops::RangeFrom<_>>` 

Then I will pass the function:

 fn get_inds() -> iter::Zip<iter::Map<ops::RangeFrom<usize>, fn(usize) -> Idx>, ops::RangeFrom<usize>> { (0..).map(Idx as fn(usize) -> Idx).zip(0..) } 

Which generates the following compiler warning. Why am I getting a warning? What is the correct way to use the constructor?

 warning: can't cast this type, #[warn(const_err)] on by default --> src/main.rs:6:19 6 |> (0..).map(Idx as fn(usize) -> Idx).zip(0..) |> ^^^^^^^^^^^^^^^^^^^^^^^ 
+6
source share
1 answer

This is a false warning caused by recent changes to the evaluation of the compiler constant. See # 33452 , # 33291 , etc. I wouldn’t want to worry about this, but it is worth putting an error in the Rust repository so that it can be fixed.

+2
source

All Articles