LukeMathWalker / wiremock-rs

HTTP mocking to test Rust applications.
Apache License 2.0
607 stars 69 forks source link

Add `must_use` attribute to `Mock` #135

Closed avandesa closed 7 months ago

avandesa commented 7 months ago

Description of changes:

It's easy to forget to mount a mock to a server, even though the docs call this out. This commit tags the Mock struct with #[must_use], so that Rust itself can warn users when they forget to mount their mocks. The help string

Here's the warning emitted:

warning: unused `Mock` that must be used
 --> examples\must_use.rs:9:5
  |
9 |     Mock::given(method("GET")).respond_with(response.clone());
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `Mock`s have to be mounted or registered with a `MockServer` to become effective
  = note: `#[warn(unused_must_use)]` on by default
help: use `let _ = ...` to ignore the resulting value
  |
9 |     let _ = Mock::given(method("GET")).respond_with(response.clone());
  |     +++++++

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

avandesa commented 7 months ago

Guessing these are new lints, pretty sure they're not related to my change. Might be able to make a pr fixing them for you this evening if you want.

LukeMathWalker commented 7 months ago

That'd be nice if you have the time!