mirror of
https://github.com/qdrant/qdrant.git
synced 2026-07-23 11:11:00 -05:00
2.2 KiB
2.2 KiB
Rules for AI Code Review
-
Prefer explicit
SomeType::from(x)over implicitx.into(). -
In new code, don't use
transmute_from_u8,transmute_to_u8,transmute_from_u8_to_slice,transmute_from_u8_to_mut_slice,transmute_to_u8_slice. Usebytemuckorzerocopycrates instead. -
Prefer explicit exhaustive matches over catch-all
_arm, so we don't miss handling new enum variants when they are added later.// good match my_enum { MyEnum::Foo(x) => handle_variant1(x), MyEnum::Bar(x, y) => handle_variant2(x, y), MyEnum::Baz(..) => {} MyEnum::Qux(..) => {} } // bad match my_enum { MyEnum::Variant1(x) => handle_variant1(x), MyEnum::Variant2(x, y) => handle_variant2(x, y), _ => {} }Exceptions:
- Code in tests and benchmarks.
- It's OK if you are sure that newly added enum variants will not affect the logic.
-
Similarly, prefer explicit field ignoring using
: _over using...// good let MyStruct { a, b, c: _, d: _ } = my_struct; // bad let MyStruct { a, b, .. } = my_struct;Exceptions:
- Code in tests and benchmarks.
- It's OK if you are sure that newly added fields will not affect the logic.
// OK (per the exception above) let status_code = match &my_error { MyError::BadInput { .. } => StatusCode::BAD_REQUEST, MyError::NotFound { .. } => StatusCode::NOT_FOUND, MyError::ServiceError { .. } => StatusCode::INTERNAL_SERVER_ERROR, };
Negative rules
Rules that are intended to reduce noise in AI code review and are not considered as issues.
-
We don't mind using
.unwrap()andpanic!()in tests and benchmarks. -
For Rust, checking whether the code compiles is out of scope of AI code review. In particular:
- Don't report mising imports for
size_oforalign_of. The prelude used in Rust 1.80+ includes these functions. - Don't report that some method is used but not implemented for a type. Most likely, it is.
- Some versions of the
randcrate provide methods namedrandom_*, and some providegen_*, e.g.,random_rangevsgen_range. Don't report that a "wrong" method is used, it's a compiler job. - Any other reports related to compiler errors or warnings.
- Don't report mising imports for