rustfmt icon indicating copy to clipboard operation
rustfmt copied to clipboard

Weird new-line that does not shrink line width

Open Robbepop opened this issue 9 months ago • 0 comments

Version: rustfmt 1.8.0-nightly (75530e9f72 2025-03-18)

In my Wasmi project I have got the following Rust line of code:

    /// Executes an [`Instruction::CallImported`].
    pub fn execute_call_imported<T>(
        &mut self,
        store: &mut Store<T>,
        results: RegSpan,
        func: index::Func,
    ) -> Result<(), Error> {
        let func = self.get_func(func);
        _ = self.execute_call_imported_impl::<marker::NestedCall, T>(store, Some(results), &func)?;
        Ok(())
    }

And rustfmt decided to re-format this the assignment line to this:

        _ =
            self.execute_call_imported_impl::<marker::NestedCall, T>(store, Some(results), &func)?;

Note that rustfmt probably did this to reduce the line-width, however, given that _ = is so short and we are using 4 whitespaces for indentation, this change did not actually reduce the line's width and just introduced an unnecessary new-line which also made to code less readable in my opinion.

PR where I first saw this: https://github.com/wasmi-labs/wasmi/pull/1398

Robbepop avatar Mar 19 '25 10:03 Robbepop