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

When "use" lines are re-arranged, inline comments are placed on the wrong line #4739

Closed
Teknomancer opened this issue Mar 6, 2021 · 1 comment

Comments

@Teknomancer
Copy link

Teknomancer commented Mar 6, 2021

Describe the bug

When use lines are re-arranged by the formatter, comments are moved to the wrong line.

To Reproduce

  1. cargo new hello_world --bin
  2. cd hello_world
  3. Edit src/main.rs to have these exact lines (order of lines is important)
use std::convert::TryFrom;
use std::fmt;
use std::collections::{Vec, VecDeque};  // testing

fn main() {
    println!("Hello, world!");
}
  1. cargo fmt
  2. Check src/main.rs, the //testing comment has been moved from std::collections line to std::fmt line as shown below:
use std::collections::{Vec, VecDeque};
use std::convert::TryFrom;
use std::fmt; // testing

fn main() {
    println!("Hello, world!");
}

Expected behavior

The comments in use lines should stay with the same line when lines are re-arranged (I'm assuming it's done in alphabetical order). In the above example it would be:

use std::collections::{Vec, VecDeque};  // testing
use std::convert::TryFrom;
use std::fmt;

Meta

  • rustfmt version: rustfmt 1.4.25-stable (0f29ff6d 2020-11-11)
  • From where did you install rustfmt?: rustup component add rustfmt
  • How do you run rustfmt: cargo-fmt

I'm running this on Windows 10 (64-bit) host.

@Teknomancer Teknomancer added the bug Panic, non-idempotency, invalid code, etc. label Mar 6, 2021
@calebcartwright calebcartwright added duplicate and removed bug Panic, non-idempotency, invalid code, etc. labels Mar 6, 2021
@calebcartwright
Copy link
Member

Closing as duplicate of #4027/#3720

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