You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I return a direct type that is must_use, I get a helpful compiler warning:
use std::iter::{self,Empty,Skip};fnx() -> Skip<Empty<i32>>{
iter::empty().skip(1)}fnmain(){x();}
warning: unused `std::iter::Skip` which must be used
--> src/main.rs:8:5
|
8 | x();
| ^^^^
|
= note: #[warn(unused_must_use)] on by default
= note: iterator adaptors are lazy and do nothing unless consumed
The equivalent (and I believe preferred) code using impl Trait gives no such useful feedback:
use std::iter;fnx() -> implIterator<Item = i32>{
iter::empty().skip(1)}fnmain(){x();}
Amusingly, this isn't a new problem, as returning a boxed trait object also has the same problem. It's arguably worse there because you've performed an allocation for no good reason, but it's also less likely because people are more reluctant to introduce unneeded allocations.