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 it's not a bug then I think the error message should probably be improved, because I have absolutely no idea what it's trying to tell me.
I've got a (hopefully short enough) MWE here:
$ cargo clippy -V
clippy 0.0.212 (265318d 2019-05-17)
$ tree
.
├── Cargo.toml
└── src
└── main.rs
1 directory, 2 files
$ cat Cargo.toml
[package]
name = "clippy_mwe"
version = "0.1.0"
authors = []
edition = "2018"
[dependencies]
$ cat src/main.rs
fn main() {
print_paths().unwrap();
}
fn maybe_get_iter(v: &[f64]) -> Result<impl Iterator<Item=&f64>, usize> {
if v.len() > 1 {
Ok(v.iter())
} else {
Err(v.len())
}
}
fn print_paths() -> Result<(), u64> {
let v = vec![1.0, 2.0, 3.0, 4.0];
for path in maybe_get_iter(&v).map_err(|e| e as u64)? {
println!("{:?}", path);
}
Ok(())
}
$ cargo run
Compiling clippy_mwe v0.1.0 (/tmp/tmp.sA6y5tSSr9/clippy_mwe)
Finished dev [unoptimized + debuginfo] target(s) in 0.36s
Running `target/debug/clippy_mwe`
1.0
2.0
3.0
4.0
$ cargo clippy
Checking clippy_mwe v0.1.0 (/tmp/tmp.sA6y5tSSr9/clippy_mwe)
warning: identical conversion
--> src/main.rs:15:14
|
15 | for path in maybe_get_iter(&v).map_err(|e| e as u64)? {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `maybe_get_iter(&v).map_err(|e| e as u64)?()`: `maybe_get_iter(&v).map_err(|e| e as u64)?`
|
= note: #[warn(clippy::identity_conversion)] on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#identity_conversion
Finished dev [unoptimized + debuginfo] target(s) in 0.34s
From my experimentation so far it looks like you need a function that returns an iterator as the Ok variant of a Result, to use map_err on that result, and then to use the ? operator. If you don't have all three of those things then clippy seems to be fine with it.
The text was updated successfully, but these errors were encountered:
If it's not a bug then I think the error message should probably be improved, because I have absolutely no idea what it's trying to tell me.
I've got a (hopefully short enough) MWE here:
From my experimentation so far it looks like you need a function that returns an iterator as the
Ok
variant of aResult
, to usemap_err
on that result, and then to use the?
operator. If you don't have all three of those things thenclippy
seems to be fine with it.The text was updated successfully, but these errors were encountered: