Skip to content

rustfmt breaks code by removing unsafe #2171

Closed
@japaric

Description

@japaric

STR

fn main() {}

pub struct Peripherals {}

static mut PERIPHERALS: bool = false;

impl Peripherals {
    pub fn all() {
        foo(|| unsafe {
            if PERIPHERALS {
                loop {}
            } else {
                PERIPHERALS = true;
            }
        })
    }
}

fn foo<F>(_f: F)
where
    F: FnOnce(),
{
}
$ cargo check && echo OK
OK

$ rustfmt src/main.rs

$ cargo check
error[E0133]: use of mutable static requires unsafe function or block
(..)

$ cat src/main.rs
fn main() {}

pub struct Peripherals {}

static mut PERIPHERALS: bool = false;

impl Peripherals {
    pub fn all() {
        foo(|| {
            if PERIPHERALS {
                loop {}
            } else {
                PERIPHERALS = true;
            }
        })
    }
}

fn foo<F>(_f: F)
where
    F: FnOnce(),
{
}

Meta

$ rustfmt -V
0.2.15-nightly (f987946 2017-11-20)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugPanic, non-idempotency, invalid code, etc.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions