Skip to content

Format asm! macro calls #5191

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions Configurations.md
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,38 @@ macro_rules! foo {

See also [`format_macro_matchers`](#format_macro_matchers).

## `format_asm_macro`

Format ``asm!`` macro calls.

- **Default value**: `false`
- **Possible values**: `true`, `false`
- **Stable**: No (tracking issue: [#5210](https://github.com/rust-lang/rustfmt/issues/5210))

#### `false` (default):

```rust
fn main() {
let x: u64;
unsafe {
asm!("mov {}, 5", out(reg) x);
}
}
```

#### `true`:

```rust
fn main() {
let x: u64;
unsafe {
asm!(
"mov {}, 5",
out(reg) x
);
}
}
```

## `format_strings`

Expand Down
2 changes: 2 additions & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ create_config! {
normalize_doc_attributes: bool, false, false, "Normalize doc attributes as doc comments";
license_template_path: String, String::default(), false,
"Beginning of file must match license template";
format_asm_macro: bool, false, false, "Format asm! macro calls";
format_strings: bool, false, false, "Format string literals where necessary";
format_macro_matchers: bool, false, false,
"Format the metavariable matching patterns in macros";
Expand Down Expand Up @@ -567,6 +568,7 @@ comment_width = 80
normalize_comments = false
normalize_doc_attributes = false
license_template_path = ""
format_asm_macro = false
format_strings = false
format_macro_matchers = false
format_macro_bodies = true
Expand Down
4 changes: 1 addition & 3 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1859,11 +1859,9 @@ pub(crate) enum RhsAssignKind<'ast> {

impl<'ast> RhsAssignKind<'ast> {
// TODO(calebcartwright)
// Preemptive addition for handling RHS with chains, not yet utilized.
// It may make more sense to construct the chain first and then check
// whether there are actually chain elements.
#[allow(dead_code)]
fn is_chain(&self) -> bool {
pub(crate) fn is_chain(&self) -> bool {
match self {
RhsAssignKind::Expr(kind, _) => {
matches!(
Expand Down
Loading