Rustfmt sometimes fails to format lambdas with eprintln! · Issue #4624 · rust-lang/rustfmt (original) (raw)

The following is not formatted correctly (e.g. line with incorrect spacing is untouched). This is the smallest example I could make:

fn get_cursor_head_oid(&self) -> Option<git2::Oid> {
    self.events[0..1].iter().find_map(|event| -> Option<git2::Oid> {
        // Obviously bad formatting, should be fixed.
        match       &event        {
            Event::RefUpdateEvent { .. } => {
                match git2::Oid::from_str(&new_ref) {
                    Ok(oid) => Some(oid),
                    Err(_) => {
                        // Try commenting out the below line. Commenting out certain other lines also works.
                        eprintln!("Expected HEAD new_ref to point to an OID; instead pointed to: {:?}", new_ref);
                        None
                    }
                }
            }
        }
    })
}

Playground

Removing the eprintln! line, or removing various other syntax elements (such as-> Option<git2::Oid>) causes the lambda contents to be formatted.

Expected formatting should fix the spacing on the first match line.

Playground rustfmt version: 1.4.30-nightly (2020-12-20 acd9486)