What does _ mean in type errors in Rust?

I got this error:

error: mismatched types [E0308]
                         process(s);
                                 ^
help: run `rustc --explain E0308` to see a detailed explanation
note: expected type `&(u32, u32, image::Luma<u8>)`
note:    found type `&mut (u32, u32, &mut _)`

but I do not understand what it means _.

+4
source share
2 answers

_ is just a placeholder that can mean anything and helps clarify the error message.

In this case, he said that he was expecting image::Luma<u8>, but actually found a variable reference ( &mut). It doesn't matter what it is; he can &mut <something>never be matched with image::Luma<i>.

If instead he said ...found type &mut (u32, u32, &mut T: SomeTrait)or similar, I think it will be harder to bring closer to the immediate problem.

You cannot pass a link to a function that expects a copied (or moved) full object.

+4
source

Rust _ , . :

  • let _ = ...; ( , #[must_use])
  • _ ( , , , , , )

, , , . , - , ( ).


: .

: &(u32, u32, Type), &mut (u32, u32, &mut Type).

( ), a &mut Type a Type .

+4

All Articles