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

tab_spaces = 2 not work with match statement #6263

Closed
getong opened this issue Aug 3, 2024 · 4 comments
Closed

tab_spaces = 2 not work with match statement #6263

getong opened this issue Aug 3, 2024 · 4 comments

Comments

@getong
Copy link

getong commented Aug 3, 2024

cat ~/.config/rustfmt/rustfmt.toml 
edition = "2021"

format_strings = true
spaces_around_ranges = true
tab_spaces = 2

But the config does not work with match statement
see https://github.com/getong/rust_example/blob/10feae81e5a636da18427c5eb2036b2d7f6e3fd1/libp2p_workspace_example/libp2p_authenticate_example/src/main.rs#L98-L116

  match swarm.select_next_some().await {
            SwarmEvent::NewListenAddr { listener_id, address } => info!("NewListenAddr: {listener_id:?} | {address:?}"),
            SwarmEvent::ConnectionEstablished {
                peer_id,
                connection_id,
                endpoint,
                num_established,
                concurrent_dial_errors,
                established_in } => info!("ConnectionEstablished: {peer_id} | {connection_id} | {endpoint:?} | {num_established} | {concurrent_dial_errors:?} | {established_in:?}"),
            SwarmEvent::Dialing { peer_id, connection_id } => info!("Dialing: {peer_id:?} | {connection_id}"),
            SwarmEvent::Behaviour(AgentEvent::Identify(event)) => match event {
                IdentifyEvent::Sent { peer_id, .. } => info!("IdentifyEvent:Sent: {peer_id}"),
                IdentifyEvent::Pushed { peer_id, info, .. } => info!("IdentifyEvent:Pushed: {peer_id} | {info:?}"),
                IdentifyEvent::Received { peer_id, info, .. } => {
                    info!("IdentifyEvent:Received: {peer_id} | {info:?}");
                    peers.insert(peer_id, info.clone().listen_addrs);

                    for addr in info.clone().listen_addrs {
                        let agent_routing = swarm.behaviour_mut().register_addr_kad(&peer_id, addr.clone());

which should be

  match swarm.select_next_some().await {
    SwarmEvent::NewListenAddr { listener_id, address } => info!("NewListenAddr: {listener_id:?} | {address:?}"),
    SwarmEvent::ConnectionEstablished {
        peer_id,
        connection_id,
        endpoint,
        num_established,
        concurrent_dial_errors,
        established_in } => info!("ConnectionEstablished: {peer_id} | {connection_id} | {endpoint:?} | {num_established} | {concurrent_dial_errors:?} | {established_in:?}"),
    SwarmEvent::Dialing { peer_id, connection_id } => info!("Dialing: {peer_id:?} | {connection_id}"),
    SwarmEvent::Behaviour(AgentEvent::Identify(event)) => match event {
        IdentifyEvent::Sent { peer_id, .. } => info!("IdentifyEvent:Sent: {peer_id}"),
        IdentifyEvent::Pushed { peer_id, info, .. } => info!("IdentifyEvent:Pushed: {peer_id} | {info:?}"),
        IdentifyEvent::Received { peer_id, info, .. } => {
          info!("IdentifyEvent:Received: {peer_id} | {info:?}");
          peers.insert(peer_id, info.clone().listen_addrs);

          for addr in info.clone().listen_addrs {
              let agent_routing = swarm.behaviour_mut().register_addr_kad(&peer_id, addr.clone());
@calebcartwright
Copy link
Member

Thanks but going to close as a duplicate of #3416/#3863/etc.

You'll either want to manually break up that that long string arg to the info! call (on the second arm of the top level match expression), or give rustfmt permission to do it for you by setting format_strings=true

@calebcartwright calebcartwright closed this as not planned Won't fix, can't repro, duplicate, stale Aug 4, 2024
@getong
Copy link
Author

getong commented Aug 4, 2024

I already set it with format_strings=true, you can see it at the beginning of this issue text.

@calebcartwright
Copy link
Member

I already set it with format_strings=true, you can see it at the beginning of this issue text.

so you do (though no indication of which version & toolchain you're using, sometimes people attempt to use unstable options from stable which aren't operative). however, there's other issues with your input and "should be" output that are indicative of broader skipped formatting; it's not just the opening indentation on each line.

I'd bet that if you made some more noticeable changes that were intentionally misformatted then you'll notice that the match expression is being skipped, e.g.

match                                swarm               .              select_next_some()        .await {

if you are on nightly then you may need to try version=Two to get access to some newer formatting as well

@getong
Copy link
Author

getong commented Aug 4, 2024

$ cat ~/.config/rustfmt/rustfmt.toml 
edition = "2021"

format_strings = true
spaces_around_ranges = true
tab_spaces = 2
version=Two
$ rustc --version
rustc 1.80.0 (051478957 2024-07-21)
$ cargo fmt 
$ rustup default nightly            
info: using existing install for 'nightly-x86_64-apple-darwin'
info: default toolchain set to 'nightly-x86_64-apple-darwin'

  nightly-x86_64-apple-darwin unchanged - rustc 1.82.0-nightly (2cbbe8b8b 2024-07-28)
$ rustc --version
rustc 1.82.0-nightly (2cbbe8b8b 2024-07-28)
$ cargo fmt

nothing happen
https://github.com/getong/rust_example/blob/10feae81e5a636da18427c5eb2036b2d7f6e3fd1/libp2p_workspace_example/libp2p_authenticate_example/src/main.rs#L98-L116

You can clone and test the source file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants