My contributions to the Rust project
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 an 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.
This particular feature made me wonder that it is generally easy to point out concerns, regardless if they are relevant, but it isn't generally easy to suggest options that will make things move forward. Worse yet, consensus requires work from the associated participants and available work is usually scarce among volunteers. In the grand scheme such a scenario creates, perhaps, ossification.
// 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.
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)6. cfg_select
Inspired by the cfg_if dependency, [https://github.com/rust-lang/rust/issues/115585] is so useful that it is surprising no one created it before. Same thing for a std Either enum but that is another topic.
cfg_select! {
unix => {
fn foo() { /* unix specific functionality */ }
}
target_pointer_width = "32" => {
fn foo() { /* non-unix, 32-bit functionality */ }
}
_ => {
fn foo() { /* fallback implementation */ }
}
}7. macro_metavar_expr_concat
Similarly to macro_metavar_expr, [https://github.com/rust-lang/rust/issues/124225] also allows operations that are currently impossible on stable and it is much more powerful than the concat_idents! macro.
macro_rules! many_idents {
($a:ident, $c:ident) => {
const ${concat($a, B, $c, D)}: i32 = 1;
};
}
fn main() {
many_idents!(A, C);
assert_eq!(ABCD, 1);
}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 to all the reviewers and mentors that helped me along the way with special mentions to petrochenkov, Centril and matthewjasper.