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

Allow forcing unsafe blocks to be on a new line #145

Open
aclysma opened this issue Dec 1, 2019 · 0 comments
Open

Allow forcing unsafe blocks to be on a new line #145

aclysma opened this issue Dec 1, 2019 · 0 comments

Comments

@aclysma
Copy link

aclysma commented Dec 1, 2019

I'd like for unsafe blocks to be forced onto new lines, both before the unsafe and after the "unsafe {". (Possibly with an exception in simple let statements.)

The motivation for asking for this is that I have some rendering code that calls out to Vulkan. When I ran cargo fmt, I didn't like how the unsafe blocks got collapsed into a statement. I felt that it made it a bit less clear that there was unsafe code being called. There are lots of calls so it wouldn't be practical to decorate every call with #[rustfmt::skip].

Current Behavior

semaphors.push(unsafe { vkCreateSemaphore() });

let x = unsafe { get_x() };

Desired Behavior

semaphors.push(
    unsafe { 
        vkCreateSemaphore() 
    }
);

let x = unsafe { 
    get_x() 
};

Rationale

I'd prefer that unsafe code is as conspicuous as possible. While IDEs can certainly highlight the unsafe keyword, code is rendered in places other than IDEs, and a structural change in code layout is an additional form of visual feedback.

I ended up avoiding this undesired formatting by using a temporary variable to simplify the statement, and maybe that's the best solution, but it gave me pause to using auto-formatting and seemed like something worth considering.

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

No branches or pull requests

1 participant