Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply rustfmt to entire project #847

Closed
wants to merge 1 commit into from
Closed

Conversation

PoignardAzur
Copy link
Contributor

This PR applies Rust fmt with these two options uncommented:

imports_granularity = "Module"
group_imports = "StdExternalCrate"

I'm creating it as a support for explaining the problems I have with the second option.

Copy link
Contributor Author

@PoignardAzur PoignardAzur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After writing this, I think my main objection is that rustfmt's grouping ignores the visibility level of use directives. If they added a setting that let you split imports and re-exports then 90% of my objections go away.

Comment on lines +181 to 191
pub use kurbo::{Affine, Insets, Point, Rect, Size, Vec2};
pub use paint_scene_helpers::UnitPoint;
pub use parley::layout::Alignment as TextAlignment;
pub use parley::style::FontWeight;
pub use render_root::{RenderRoot, RenderRootOptions, RenderRootSignal, WindowSizePolicy};
pub use util::{AsAny, Handled};
pub use vello::kurbo;
pub use vello::peniko::color::palette;
pub use vello::peniko::{Color, Gradient};
pub use widget::widget::{AllowRawMut, FromDynWidget, Widget, WidgetId};
pub use widget::WidgetPod;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This paragraph mixes exports of local symbols and re-exports of other crates' symbols.

Comment on lines -15 to 16
#[cfg(not(target_arch = "wasm32"))]
use std::time::Instant;
#[cfg(target_arch = "wasm32")]
use web_time::Instant;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having the two versions of Instant imported as a single paragraph was nice, it's annoying that rustfmt splits it up.

I'll admit this one is pretty minor, though.

Comment on lines 55 to 61
pub use textbox::Textbox;
pub use variable_label::VariableLabel;
pub(crate) use widget_arena::WidgetArena;
pub use widget_mut::WidgetMut;
pub(crate) use widget_pod::CreateWidget;
pub use widget_pod::WidgetPod;
pub use widget_ref::WidgetRef;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This paragraph mixes pub and pub(crate) re-exports, which I feel hurts readability.

Comment on lines +65 to 66
pub use self::image::Image;
use crate::{Affine, Size};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The re-export of Image is split from the other re-exports and bundled with non-exported imports.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could probably address that by factoring ObjectFit out (thus removing the use crate:: part) and doing pub use self:: for all the other re-exports.

Comment on lines 143 to +154
use masonry::dpi::LogicalSize;
pub use masonry::event_loop_runner::{EventLoop, EventLoopBuilder};
pub use masonry::widget::LineBreaking;
use masonry::widget::{RootWidget, WidgetMut};
pub use masonry::{dpi, palette, Affine, Color, FontWeight, TextAlignment, Vec2};
use masonry::{event_loop_runner, FromDynWidget, Widget, WidgetId, WidgetPod};
/// Tokio is the async runner used with Xilem.
pub use tokio;
use view::{transformed, Transformed};
use winit::error::EventLoopError;
use winit::window::{Window, WindowAttributes};
pub use xilem_core as core;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pub re-exports are mixed with imports.

@xStrom
Copy link
Member

xStrom commented Jan 23, 2025

For the re-export special casing I found rustfmt#4070 but there isn't really much going on there.

For the pub(crate) situation there's a bit more activity and so maybe eventually it'll get addressed.

Improvements to this autoformatting would definitely be nice. Now the question is, are these problems big enough to not do any autoformatting? Do you consider the current state of these features unacceptable?

@PoignardAzur
Copy link
Contributor Author

Note that we already do run cargo fmt in CI in basically all our projects. The question is a bit narrower than "do we auto-format", it's "do we use group_imports = "StdExternalCrate" in our rustfmt.tom files?".

(imports_granularity = "Module" is fine)

And in any case, the answer is "No" because it's an unstable setting, for pretty much the reasons I listed and others.

So the question is "do we use an always-commented version of that setting that people will occasionally apply manually?", which is more or less the status quo with the Xilem repo.

I guess we could just always include a comment with a link to this PR in our standard rustfmt config.

@xStrom
Copy link
Member

xStrom commented Jan 23, 2025

I created website#87 to track the shortcomings of group_imports = "StdExternalCrate".

@PoignardAzur PoignardAzur marked this pull request as ready for review January 23, 2025 18:20
@PoignardAzur PoignardAzur marked this pull request as draft January 23, 2025 18:21
@PoignardAzur
Copy link
Contributor Author

Then I'm closing this in favor of #848.

@DJMcNab DJMcNab deleted the apply_rustfmt_final branch January 23, 2025 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants