Repository navigation
MustUse Analyzer
Ferrous.Annotations ships Roslyn diagnostic FE0001, equivalent to Rust's #[must_use] lint—turning silently ignored return values into compile-time warnings (or errors under <FerrousPedantic>true</FerrousPedantic>).
Vanilla .NET lets you call any non-void method and silently drop its return value, which makes it easy to ignore errors, leak guards, or drop the result of an immutable fluent call:
// Vanilla C#: all three compile silently
SaveOrder(order); // Returns Result<Receipt, Error> — failure silently ignored
mutex.Lock(); // Returns MutexGuard<T> — lock immediately leaked
builder.WithTimeout(timeout); // Returns a NEW immutable builder — timeout silently lostAnnotate either the method or the type with [MustUse("...")] (Result<T, TError>, Option<T>, ScopeGuard, MutexGuard<T>, and AsyncMutexGuard<T> already carry [MustUse] out of the box):
using Ferrous;
[MustUse("WithTimeout returns a new immutable builder; assign the result.")]
public RequestBuilder WithTimeout(TimeSpan timeout) => this with { Timeout = timeout };
builder.WithTimeout(TimeSpan.FromSeconds(5));
// warning FE0001: unused value of 'WithTimeout()' that must be used
// (note: WithTimeout returns a new immutable builder; assign the result.);
// help: assign it to a variable or explicitly discard it with '_ = ...'FE0001 also unwraps await:
await FetchResultAsync(); // warning FE0001 because Task<Result<T, E>> unwraps to [MustUse] Result<T, E>When you genuinely want to discard a [MustUse] value, make it explicit with _ = ... (matching Rust's let _ = ...; Ferrous.CodeFixes provides a one-click IDE quick-fix):
_ = SaveOrder(order); // OKFerrous — Rust quality-of-life primitives, source generators, and analyzers for .NET (.NET 10 / .NET 11, NativeAOT-ready, MIT License).