Open
Description
I tried this code:
type U32Iter = impl Iterator<Item = u32>;
struct Foo {
iter: U32Iter,
}
impl From<u32> for Foo {
fn from(value: u32) -> Self {
Self {
iter: std::iter::once(value),
}
}
}
I expected to see this happen: Compiles
Instead, this happened:
12 | iter: std::iter::once(value),
| ^^^^^^^^^^^^^^^^^^^^^^ expected opaque type, found `Once<u32>`
Meta
rustc --version --verbose
:
rustc 1.84.0 (9fc6b4312 2025-01-07)
binary: rustc
commit-hash: 9fc6b43126469e3858e2fe86cafb4f0fd5068869
commit-date: 2025-01-07
host: x86_64-unknown-linux-gnu
release: 1.84.0
LLVM version: 19.1.5
Backtrace
Compiling smth v0.1.0 (/tmp/smth)
error[E0308]: mismatched types
--> src/main.rs:12:19
|
3 | type U32Iter = impl Iterator<Item = u32>;
| ------------------------- the expected opaque type
...
12 | iter: std::iter::once(value),
| ^^^^^^^^^^^^^^^^^^^^^^ expected opaque type, found `Once<u32>`
|
= note: expected opaque type `U32Iter`
found struct `std::iter::Once<u32>`
note: this item must have the opaque type in its signature in order to be able to register hidden types
--> src/main.rs:10:8
|
10 | fn from(value: u32) -> Self {
| ^^^^
For more information about this error, try `rustc --explain E0308`.
error: could not compile `smth` (bin "smth") due to 1 previous error