Skip to content

Added --format to rustc #7324

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

Closed
wants to merge 6 commits into from
Closed

Added --format to rustc #7324

wants to merge 6 commits into from

Conversation

MaikKlein
Copy link
Contributor

Usage: rustc filename.rs --format
It formats the the specified file with --pretty normal.

There are two problems with this PR.

1.) I am using "process_output" instead of hooking me up in pretty_print directly. I didn't want to step on someones toes.

2.) Pretty print doesn't do a partial format. This mean that the source file doesn't get formated if the source code contains syntax errors.

I am currently using this with sublime. Every time I press ctrl+s it automatically saves and formats my current file.

@MaikKlein
Copy link
Contributor Author

Thanks cmr I will do this.Also I received some feedback that "rust format file1.rs file2.rs .." would probably be better and I agree.

@MaikKlein MaikKlein closed this Jun 23, 2013
@MaikKlein MaikKlein reopened this Jun 23, 2013
@MaikKlein MaikKlein closed this Jun 23, 2013
@MaikKlein MaikKlein mentioned this pull request Jun 23, 2013
flip1995 pushed a commit to flip1995/rust that referenced this pull request Jun 17, 2021
flip1995 pushed a commit to flip1995/rust that referenced this pull request Jun 17, 2021
Fix false positive on `semicolon_if_nothing_returned`

Currently the [`semicolon_if_nothing_returned`](https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_if_nothing_returned) lint fires in unwanted situations where a block only spans one line. An example of this was given in rust-lang#7324. This code:

```rust
use std::mem::MaybeUninit;
use std::ptr;

fn main() {
    let mut s = MaybeUninit::<String>::uninit();
    let _d = || unsafe { ptr::drop_in_place(s.as_mut_ptr()) };
}
```

yields the following clippy error:
```
error: consider adding a `;` to the last statement for consistent formatting
 --> src/main.rs:6:26
  |
6 |     let _d = || unsafe { ptr::drop_in_place(s.as_mut_ptr()) };
  |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add a `;` here: `ptr::drop_in_place(s.as_mut_ptr());`
  |
  = note: `-D clippy::semicolon-if-nothing-returned` implied by `-D clippy::pedantic`
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_if_nothing_returned
```

I updated the lint to check if the statement is inside an `unsafe` block, a closure or a normal block and if the block only spans one line, in that case the lint is not emitted.

This closes rust-lang#7324.

changelog: enhanced semicolon if nothing returned according to  rust-lang#7324.
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.

4 participants