Skip to content

Added format to rust #7326

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 1 commit into from
Closed

Added format to rust #7326

wants to merge 1 commit into from

Conversation

MaikKlein
Copy link
Contributor

This is a follow up from #7324

I am sorry I somehow messed up the first PR.

usage: "rust format file1.rs file2.rs file3.rs" aborts on error. Or "rust format --force file1.rs file2.rs file3.rs"

// If we have a writer in our result then we write the source code to it.
for args.iter().advance |path| {
let source_code =
core::run::process_output("rustc", &[copy *path, ~"--pretty"]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unfortunate that you have to shell out here to invoke rustc, that's the whole reason they're built as shared libraries. Can you file an issue for being able to redirect the output of rustc? Ideally you could capture the output that way (instead of having to fork a process)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this was just intended to be a showcase. I know it is a dirty little hack. I am already reading though pretty_printer to make a proper hook.
I just wanted to hear what people think of this feature before I put too much effort in something that won't be needed.

You are saying that it shouldn't even possible to capture the output of --pretty with run_process?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh this works just fine, and I think that this is a great place for the format command (you could even alias it to fmt). What you have here will definitely work, I just think it'd be a lot cleaner for the driver intput to take something like io::Writer to write output to (or an option which defaults to stdout). That way you can capture the output no matter who you are.

@MaikKlein MaikKlein closed this Jul 18, 2013
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.

2 participants