-
Notifications
You must be signed in to change notification settings - Fork 126
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
Conversation
There was a problem hiding this 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.
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; |
There was a problem hiding this comment.
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.
#[cfg(not(target_arch = "wasm32"))] | ||
use std::time::Instant; | ||
#[cfg(target_arch = "wasm32")] | ||
use web_time::Instant; |
There was a problem hiding this comment.
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.
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; |
There was a problem hiding this comment.
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.
pub use self::image::Image; | ||
use crate::{Affine, Size}; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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; |
There was a problem hiding this comment.
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.
For the re-export special casing I found rustfmt#4070 but there isn't really much going on there. For the 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? |
Note that we already do run ( 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. |
I created website#87 to track the shortcomings of |
Then I'm closing this in favor of #848. |
This PR applies Rust fmt with these two options uncommented:
I'm creating it as a support for explaining the problems I have with the second option.