Repository navigation
Pedantic Analyzers
Ferrous.Pedantic brings Rust clippy::pedantic discipline to .NET (FE0400–FE0427) plus a one-line <FerrousPedantic>true</FerrousPedantic> MSBuild preset that elevates all FE* warnings (FE0001, FE0200–FE0203, FE0300–FE0303, FE0400–FE0427, FE0500–FE0503) to build errors. Test projects (<IsTestProject>true</IsTestProject>) automatically relax FE0401, FE0406, FE0424, and FE0426 (opt out with <FerrousRelaxInTests>false</FerrousRelaxInTests>).
Even with <Nullable>enable</Nullable>, a single ! (user!, null!, default!) disables the compiler's null check and reintroduces NullReferenceException—just like .unwrap() in Rust. FE0406 bans ! so nullability must be handled via pattern matching, guards, or Option<T>.
-
async void(FE0407): Unhandled exceptions inasync voidmethods orlist.ForEach(async x => ...)lambdas crash the entire process instead of faulting aTask. -
Unawaited
Task/ValueTask(FE0408): C#'s built-inCS4014only fires insideasyncmethods—callingSendEmailAsync()inside a synchronous controller/handler silently drops exceptions.FE0408catches unawaitedTask/ValueTaskstatements everywhere. -
Sync-over-Async (
FE0409): Calling.Result,.Wait(),.GetAwaiter().GetResult(), orThread.Sleep(...)inside anasyncmethod risks thread-pool starvation and deadlocks.
In C#, every struct implicitly has a zero-initialized default value—even when zero is illegal (e.g., Result<T, TError>, [DiscriminatedUnion], NonZeroUserId). Marking a struct [NoDefault] causes FE0404 to reject default, parameterless new(), and uninitialized new T[n] arrays at compile time.
- Adding a new member to an
enumwon't silently fall through aswitch; with[Exhaustive], even_ =>catch-alls are flagged until every member is explicitly handled. -
FE0405flagslock (this),lock (typeof(...)), andlock ("literal")(which deadlock across unrelated components), recommending a privateSystem.Threading.Lockor data-owningMutex<T>.
| ID | Default | Rust / Clippy Equivalent | Description |
|---|---|---|---|
FE0400 |
Warning | exhaustive_enums |
Non-exhaustive switch on an enum (even with _ => on [Exhaustive] enums) or [Closed] / C# 15 closed (IsClosedTypeAttribute) abstract class/record hierarchy. |
FE0401 |
Warning | clippy::unwrap_used |
.Unwrap(), .UnwrapErr(), .Expect(), .ExpectErr() on Result<T, TError> / Option<T>. |
FE0402 |
Warning | clippy::panic_in_result_fn |
throw inside [NoThrow] or Result<T, TError>-returning methods. |
FE0403 |
Warning | Zero-alloc closure lint | Capturing lambda passed to ScopeGuard.Defer(Action) (suggests ScopeGuard.Defer(state, static s => ...)). |
FE0404 |
Error | Uninitialized struct guard |
default, parameterless new(), or uninitialized new T[n] on Result<T, TError>, [DiscriminatedUnion], or [NoDefault] structs. |
FE0405 |
Warning | Safe lock target lint |
lock (this), lock (typeof(...)), or lock ("literal") instead of Lock / Mutex<T>. |
FE0406 |
Warning | No .unwrap() null bypass |
Null-forgiving operator (!, null!, default!) bypassing #nullable enable. |
FE0407 |
Warning | No detached panic tasks |
async void methods and lambdas. |
FE0408 |
Warning |
unused_must_use for Futures |
Unawaited Task / ValueTask expression statements in sync or async code. |
FE0409 |
Warning | Async blocking guard | Sync-over-async blocking (.Result, .Wait(), .GetAwaiter().GetResult(), Thread.Sleep) inside async methods. |
FE0410 |
Warning | Panic-free BCL guard | Calls to throwing BCL APIs (int.Parse, First(), Single(), Dictionary[key], Nullable<T>.Value, Convert.To*) inside [NoThrow] or Result-returning methods. |
FE0411 |
Warning | Explicit error handling | Empty catch { } / catch (Exception) { } blocks that swallow exceptions. |
FE0412 |
Warning |
&T vs &mut T copy guard |
Hidden defensive struct copy when calling non-readonly members on readonly struct fields, in parameters, or ref readonly locals. |
FE0413 |
Warning | Zero-alloc discipline | Heap new, array creation, implicit params arrays, struct boxing, or capturing closures inside [NoAlloc] methods. |
FE0414 |
Warning | Checked arithmetic | Unchecked integer +, -, * inside [Checked] scopes (suggests checked(...) or CheckedMath.Checked*/Saturating*). |
FE0415 |
Warning | clippy::cast_possible_truncation |
Unchecked lossy or sign-changing explicit numeric casts ((int)longVal, (uint)intVal, (int)doubleVal). |
FE0416 |
Warning | clippy::float_cmp |
Direct ==/!= on float/double and floating-point Dictionary / HashSet keys. |
FE0417 |
Warning | clippy::undocumented_unsafe_blocks |
unsafe blocks or Unsafe.* / MemoryMarshal.* / Marshal.* calls missing a // SAFETY: comment, or overbroad unsafe modifiers on types/methods. |
FE0418 |
Warning |
&T deep immutability |
Property/field/indexer setters or mutating collection calls on [Immutable] parameters, fields, or properties (and nested members). |
FE0419 |
Warning | RAII drop-order leak guard | Locally created ScopeGuard or IDisposable handles that may exit scope or early-return without being disposed (handles using, return, [Consuming], and leaveOpen). |
FE0420 |
Warning | clippy::indexing_slicing |
Unchecked arr[i] / list[i] / span[i] / str[i] indexing inside [NoThrow] or Result-returning methods (recognizes proven for loops, if/&& guards, (uint) range checks, and early-return guards). |
FE0421 |
Warning | Inter-procedural [NoThrow]
|
Calling an internal/private helper that transitively throws inside a [NoThrow] or Result-returning method. |
FE0422 |
Warning | Inter-procedural [NoAlloc]
|
Calling an internal/private helper that transitively allocates on the heap inside a [NoAlloc] method. |
FE0423 |
Warning | clippy::large_enum_variant |
Oversized inline [DiscriminatedUnion] struct (> 8 inline payload fields across variants; suggests abstract partial record or boxing large payloads). |
FE0424 |
Warning | clippy::todo |
throw new NotImplementedException() stubs in production code (auto-relaxed in test projects). |
FE0425 |
Warning | clippy::needless_collect |
Needless .ToList()/.ToArray() before .Count/.Length/.Any(), or .Count() > 0 instead of .Any(). |
FE0426 |
Warning | clippy::print_stdout |
Stray Console.Write* calls inside class libraries (OutputType == Library; auto-relaxed in test projects). |
FE0427 |
Warning | clippy::unnecessary_unwrap |
Calling .Unwrap() / .UnwrapErr() inside an if (x.IsOk) / IsSome / IsErr guard instead of TryGetOk / TryGetValue / TryGetErr. |
One-click IDE fixes are included for FE0001, FE0301, FE0400, FE0401, FE0403, FE0407, FE0408, FE0409, FE0410, FE0414, FE0415, FE0417, FE0419, FE0420, and FE0501.
Add <FerrousPedantic>true</FerrousPedantic> to your .csproj or Directory.Build.props to elevate all FE* warnings to build errors:
<PropertyGroup>
<FerrousPedantic>true</FerrousPedantic>
</PropertyGroup>Ferrous — Rust quality-of-life primitives, source generators, and analyzers for .NET (.NET 10 / .NET 11, NativeAOT-ready, MIT License).