rust-lang / rustfmt

Format Rust code
https://rust-lang.github.io/rustfmt/
Apache License 2.0
6.06k stars 892 forks source link

assignment is not formatted properly #6394

Closed BenjaminBrienen closed 1 week ago

BenjaminBrienen commented 1 week ago

"formatted" code:

    pub(crate) fn register_info<T: Bundle>(
        &mut self,
        components: &mut Components,
        storages: &mut Storages,
    ) -> BundleId {
        let bundle_infos = &mut self.bundle_infos;
        let id = *self.bundle_ids.entry(TypeId::of::<T>()).or_insert_with(|| {
            let mut component_ids= Vec::new();
            T::component_ids(components, storages, &mut |id| component_ids.push(id));
            let id = BundleId(bundle_infos.len());
            let bundle_info =
                // SAFETY: T::component_id ensures:
                // - its info was created
                // - appropriate storage for it has been initialized.
                // - it was created in the same order as the components in T
                unsafe { BundleInfo::new(core::any::type_name::<T>(), components, component_ids, id) };
            bundle_infos.push(bundle_info);
            id
        });
        id
    }

The focus:

let mut component_ids= Vec::new();

Expected:

let mut component_ids = Vec::new();
ytmimi commented 1 week ago

This line unsafe { BundleInfo::new(core::any::type_name::<T>(), components, component_ids, id) }; is 103 characters long, which exceeds the default max_width of 100. Because this is inside the .or_insert_with() call this is a duplicate of #3863. You can bump the max_width and rustfmt will be able to format this chained method call.