My contributions to the Rust project

Introduction
Photo by Roman Synkevych on Unsplash

All started with https://github.com/rust-lang/rust/issues/60406#issuecomment-488306461 around ~4 years ago and since then I didn't stop contributing to the Rust compiler as well as other related projects like Clippy in my free time.

Besides the technical skills learned, the things that stood out the most were the concentration of knowledge in the hands of few busy individuals that eventually parted away and a noticeable amount of good contributors passing through sensible financial problems but these are matters for another post.

Without further ado, let's list all my major contributions in chronological order.

1. Attributes in formal function parameter position

More-or-less like a introduction to the internals of the project, https://github.com/rust-lang/rust/issues/60406 wasn't very difficult to implement because all necessary pieces were already available for utilization.

// Snippet extracted from the Juniper project

#[graphql_object]
impl Person {
  fn field(
    &self,
    #[graphql(default)] arg: i32
  ) -> String {
    ...
  }
}

2. Easily create arrays with custom elements

Unfortunately https://github.com/rust-lang/rust/pull/75644 took one year to be reviewed but at least one subset was stabilized on version 1.63.

// Snippet extracted from the Arbitrary project

fn size_hint(d: usize) -> (usize, Option<usize>) {
  crate::size_hint::and_all(&array::from_fn::<_, N, _>(|_| {
    <T as Arbitrary>::size_hint(d)
  }))
}

3. Formally implement let chains

The toughest contribution, no doubt about that. https://github.com/rust-lang/rust/pull/88642 was very challenging both technically and mentally.

// Snippet extracted from the Clippy project

if let FormatArgsPiece::Placeholder(placeholder) = piece
  && let Ok(index) = placeholder.argument.index
  && let Some(arg) = format_args.arguments.all_args().get(index)
{
  ...
}

Hopefully the remaining concerns involving dropping order will be resolved in the near future to allow a possible stabilization.

4. Macro meta-variable expressions

https://github.com/rust-lang/rust/issues/83527 is really useful and allows operations that are currently impossible on stable. Despite my attempts, some questions were raised and they need to be addressed before stabilization.

// Snippet extracted from the Rust project

impl<$($T: PartialEq),+> PartialEq for ($($T,)+)
where
  last_type!($($T,)+): ?Sized
{
  #[inline]
  fn eq(&self, other: &($($T,)+)) -> bool {
    $( ${ignore(T)} self.${index()} == other.${index()} )&&+
  }

  ...
}

5. Nicer assert messages

https://github.com/rust-lang/rust/issues/44838 depends on work on the constant evaluation front which unfortunately is not my specialty. Hope that I will be able to hack the missing pieces in the next months.

fn fun(a: Option<i32>, b: Option<i32>, c: Option<i32>) {
  assert!(
    [matches!(a, None), matches!(b, Some(1)] == [true, true] && matches!(c, Some(x) if x == 2)
  );
}

fn main() {
  fun(Some(1), None, Some(2));
}

// Assertion failed: [matches!(a, None), matches!(b, Some(1)] == [true, true] && matches!(c, Some(x) if x == 2)
//
// With captures:
//   a = Some(1)
//   b = None
//   c = Some(2)

Final words

With this brief summary and other non-listed PRs, I think I made a small but positive impact on the ecosystem. Thank you very much for all the reviewers and mentors that helped me along the way with special mentions to petrochenkov, Centril and matthewjasper.