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

Foreign function blocks dropped #4313

Closed
ayazhafiz opened this issue Jul 10, 2020 · 0 comments · Fixed by #4314
Closed

Foreign function blocks dropped #4313

ayazhafiz opened this issue Jul 10, 2020 · 0 comments · Fixed by #4314
Labels
bug Panic, non-idempotency, invalid code, etc.

Comments

@ayazhafiz
Copy link
Contributor

Describe the bug

rustfmt drops block associated with a foreign function

To Reproduce

Formatting

extern "C" {
    fn f() {
        fn g() {}
    }
}

gives

extern "C" {
    fn f();
}

Context: rust-lang/rust#74204

Expected behavior

The formatting makes the code semantically correct, but causes a loss of information. I think rustfmt should preserve the block, if it has access to it.

Meta

  • rustfmt version: 37ec56d
  • From where did you install rustfmt?: from source
  • How do you run rustfmt: binary from source
@ayazhafiz ayazhafiz added the bug Panic, non-idempotency, invalid code, etc. label Jul 10, 2020
ayazhafiz added a commit to ayazhafiz/rustfmt that referenced this issue Jul 10, 2020
A code like

```rust
extern "C" {
    fn f() {
        fn g() {}
    }
}
```

is incorrect and does not compile. Today rustfmt formats this in a way
that is correct:

```rust
extern "C" {
    fn f();
}
```

But this loses information, and doesn't have to be done because we know
the content of the block if it is present. During development I don't
think rustfmt should drop the block in this context.

Closes rust-lang#4313
dtolnay pushed a commit to dtolnay-contrib/rustfmt that referenced this issue Nov 29, 2020
A code like

```rust
extern "C" {
    fn f() {
        fn g() {}
    }
}
```

is incorrect and does not compile. Today rustfmt formats this in a way
that is correct:

```rust
extern "C" {
    fn f();
}
```

But this loses information, and doesn't have to be done because we know
the content of the block if it is present. During development I don't
think rustfmt should drop the block in this context.

Closes rust-lang#4313
calebcartwright pushed a commit that referenced this issue Nov 29, 2020
A code like

```rust
extern "C" {
    fn f() {
        fn g() {}
    }
}
```

is incorrect and does not compile. Today rustfmt formats this in a way
that is correct:

```rust
extern "C" {
    fn f();
}
```

But this loses information, and doesn't have to be done because we know
the content of the block if it is present. During development I don't
think rustfmt should drop the block in this context.

Closes #4313
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Panic, non-idempotency, invalid code, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant