Closed xelephas closed 4 years ago
I think this is a bug of rustfmt
: https://github.com/rust-lang/rustfmt/issues/4037
Closing this issue.
Actually, Could rust-mode
handle this more gracefully, than opening up a stdin? Because I think this is quite confusing for the user.
Looks like #357 still alive.
For me problem occurs when I try to code bellow. rust-mode 20200322.1749 GNU Emacs 26.3 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.10) of 2019-08-29
/// input data
/// output parity data
pub fn encode(data: [u8; 8]) -> u8 {
let data = u64::from_le_bytes(data);
let mut ret = 0u8;
for (i, mask) in generated::PARITY_BITS_MASK.iter().enumerate() {
let parity_bit = ((data & mask).count_ones() & 1) as u8;
ret |= parity_bit << i;
}
ret = ((data.count_ones() & 1) as u8) << 7;
ret
}
/// correct input data if there is one bit error,
/// return Err(()) if double bit error was detected
pub fn decode(data: &mut [u8; 8], parity: u8) -> Result<(), ()> {
let data = u64::from_le_bytes(data);
let overall_parity = ((data.count_ones() & 1) as u8) << 7;
let overall_expected = (parity >> 7) & 1;
let overall_correct =
let mut index_of_error = 0;
for (i, mask) in generated::PARITY_BITS_MASK.iter().enumerate() {
let parity = ((data & mask).count_ones() & 1) as u8;
let expected = (parity >> i) & 1;
if parity != expected {
index_of_error |= 1u8 << i;
}
}
unimplemented!()
}
mod generated {
pub const PARITY_BITS_MASK: [u64; 7] = [
0xab55555556aaad5b,
0xcd9999999b33366d,
0xf1e1e1e1e3c3c78e,
0x1fe01fe03fc07f0,
0x1fffe0003fff800,
0x1fffffffc000000,
0xfe00000000000000,
];
}
This problem happens again.
If run rustfmt in terminal I got:
$ rustfmt parser.rs
error[internal]: left behind trailing whitespace
--> parser.rs:122:122:0
|
122 |
| ^^^^^^^^^^^^
|
warning: rustfmt has failed to format. See previous 1 errors.
May be just revert a36c96ab556ddf9cd098ab0109acfdd94b106675 ? cc @nikodemus @mookid
I confirm I can reproduce the bug. I'll try to find some time to fix it this weekend.
Thanks for the report, please test.
Seems like I couldn't save the following code if I have
(rust-format-on-save t)
. It always leads to a "stdin" buffer. I think it's because of the empty lines (with spaces) between thearg
blocks. If I remove them, it works fine.The
*rustfmt*
buffer says:Below is my environment: