You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
diff --git a/async-await-echo/src/main.rs b/async-await-echo/src/main.rs
index 1531b22..a654e92 100644
--- a/async-await-echo/src/main.rs+++ b/async-await-echo/src/main.rs@@ -1,16 +1,4 @@
use {
- hyper::{- // Miscellaneous types from Hyper for working with HTTP.- Body, Client, Request, Response, Server, Uri,-- // This function turns a closure which returns a future into an- // implementation of the the Hyper `Service` trait, which is an- // asynchronous function from a generic `Request` to a `Response`.- service::service_fn,-- // A function which runs a future to completion using the Hyper runtime.- rt::run,- },
futures::{
// Extension trait for futures 0.1 futures, adding the `.compat()` method
// which allows us to use `.await` on 0.1 futures.
@@ -20,6 +8,22 @@ use {
// `TryFutureExt` adds methods to futures that return `Result` types.
future::{FutureExt, TryFutureExt},
},
+ hyper::{+ // A function which runs a future to completion using the Hyper runtime.+ rt::run,+ // This function turns a closure which returns a future into an+ // implementation of the the Hyper `Service` trait, which is an+ // asynchronous function from a generic `Request` to a `Response`.+ service::service_fn,++ // Miscellaneous types from Hyper for working with HTTP.+ Body,+ Client,+ Request,+ Response,+ Server,+ Uri,+ },
std::net::SocketAddr,
};
that rt::run, line could use an extra new line, me thinks.
I think this should require a configuration option, because it would be very hard to do in an expected manner with reordered imports. For example
use{// c and dC,D,// a and bA,B,}
Now it's not so clear if this should be reformatted with newlines or not (the "shape" of the original import statement could be used, but I think this would lead to poor formatting for imports that are not already in an almost-formatted state).
Confirming I can reproduce this with rustfmt 1.5.1-nightly (f2c31ba0 2022-07-19). The issue is that reorder_imports=true is the default and it would seem that we don't retain all whitespace when reordering.
Input
use{
hyper::{// Miscellaneous types from Hyper for working with HTTP.Body,Client,Request,Response,Server,Uri,// This function turns a closure which returns a future into an// implementation of the the Hyper `Service` trait, which is an// asynchronous function from a generic `Request` to a `Response`.
service::service_fn,// A function which runs a future to completion using the Hyper runtime.
rt::run,}};
Output with reorder_imports=true (the default)
use hyper::{// A function which runs a future to completion using the Hyper runtime.
rt::run,// This function turns a closure which returns a future into an// implementation of the the Hyper `Service` trait, which is an// asynchronous function from a generic `Request` to a `Response`.
service::service_fn,// Miscellaneous types from Hyper for working with HTTP.Body,Client,Request,Response,Server,Uri,};
Output with reorder_imports=false
use{
hyper::{// Miscellaneous types from Hyper for working with HTTP.Body,Client,Request,Response,Server,Uri,// This function turns a closure which returns a future into an// implementation of the the Hyper `Service` trait, which is an// asynchronous function from a generic `Request` to a `Response`.
service::service_fn,// A function which runs a future to completion using the Hyper runtime.
rt::run,},};
ytmimi
changed the title
extra new line would be good, in this case
Retain newlines when reordering imports
Jul 21, 2022
cargo-fmt
did this:that
rt::run,
line could use an extra new line, me thinks.rustfmt 1.4.8-nightly (6b0a447 2019-09-20)
code is from: https://rust-lang.github.io/async-book/01_getting_started/05_http_server_example.html
Thanks.
PS: someone could probably title this better to describe this case?
The text was updated successfully, but these errors were encountered: