Radish alpha
r
rad:zwTxygwuz5LDGBq255RA2CbNGrz8
Radicle CI broker
Radicle
Git
chore: deny clippy warning about unwrap being used
Merged liw opened 1 year ago

An unwrap (or unwrap_err, or their expect variants) can result in run time panics: unwrapping an Option that is None can’t return a useful result, so it panics. Similar for a Result. I’ve previously tried to grep for uses of unwrap, but the clippy warning is much more precise.

Add “deny(clippy::unwrap_used)” to the top of src/lib.rs, so it affects the whole crate. Then fix any places where unwrap is used.

It’s OK to use unwrap in tests: if the value is expected, but isn’t there, the test should fail, and panic is a fine way to fail the test.

Everywhere else it’s better to make sure unwrap can’t fail, and if it can, return a Result and have the caller handle that.

Signed-off-by: Lars Wirzenius liw@liw.fi

liw opened with revision 4bd4baa2 on base a9fea0fd +67 -22 1 year ago

An unwrap (or unwrap_err, or their expect variants) can result in run time panics: unwrapping an Option that is None can’t return a useful result, so it panics. Similar for a Result. I’ve previously tried to grep for uses of unwrap, but the clippy warning is much more precise.

Add “deny(clippy::unwrap_used)” to the top of src/lib.rs, so it affects the whole crate. Then fix any places where unwrap is used.

It’s OK to use unwrap in tests: if the value is expected, but isn’t there, the test should fail, and panic is a fine way to fail the test.

Everywhere else it’s better to make sure unwrap can’t fail, and if it can, return a Result and have the caller handle that.

Signed-off-by: Lars Wirzenius liw@liw.fi

liw merged revision 4bd4baa2 at 47064e57 1 year ago