Skip to content

Commit 177bc5e

Browse files
authored
Update to bitflags 2.3.3 and remove workarounds. (#707)
Bitflags 2.3.3 fixes `-=` to behave the same as `-` and `=` separately, so we can now remove the workarounds. Fixes #695.
1 parent 2be32b3 commit 177bc5e

File tree

4 files changed

+23
-35
lines changed

4 files changed

+23
-35
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ rust-version = "1.63"
1919
cc = { version = "1.0.68", optional = true }
2020

2121
[dependencies]
22-
bitflags = "2.3.0"
22+
bitflags = "2.3.3"
2323
itoa = { version = "1.0.1", default-features = false, optional = true }
2424

2525
# Special dependencies used in rustc-dep-of-std mode.

src/backend/libc/termios/syscalls.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,7 @@ pub(crate) fn set_speed(termios: &mut Termios, arbitrary_speed: u32) -> io::Resu
233233

234234
debug_assert_eq!(encoded_speed & !c::CBAUD, 0);
235235

236-
// Use `=` and `-` because `-=` behaves differently.
237-
termios.control_modes =
238-
termios.control_modes - ControlModes::from_bits_retain(c::CBAUD | c::CIBAUD);
236+
termios.control_modes -= ControlModes::from_bits_retain(c::CBAUD | c::CIBAUD);
239237
termios.control_modes |=
240238
ControlModes::from_bits_retain(encoded_speed | (encoded_speed << c::IBSHIFT));
241239

@@ -277,8 +275,7 @@ pub(crate) fn set_output_speed(termios: &mut Termios, arbitrary_speed: u32) -> i
277275

278276
debug_assert_eq!(encoded_speed & !c::CBAUD, 0);
279277

280-
// Use `=` and `-` because `-=` behaves differently.
281-
termios.control_modes = termios.control_modes - ControlModes::from_bits_retain(c::CBAUD);
278+
termios.control_modes -= ControlModes::from_bits_retain(c::CBAUD);
282279
termios.control_modes |= ControlModes::from_bits_retain(encoded_speed);
283280

284281
termios.output_speed = arbitrary_speed;
@@ -318,8 +315,7 @@ pub(crate) fn set_input_speed(termios: &mut Termios, arbitrary_speed: u32) -> io
318315

319316
debug_assert_eq!(encoded_speed & !c::CBAUD, 0);
320317

321-
// Use `=` and `-` because `-=` behaves differently.
322-
termios.control_modes = termios.control_modes - ControlModes::from_bits_retain(c::CIBAUD);
318+
termios.control_modes -= ControlModes::from_bits_retain(c::CIBAUD);
323319
termios.control_modes |= ControlModes::from_bits_retain(encoded_speed << c::IBSHIFT);
324320

325321
termios.input_speed = arbitrary_speed;

src/backend/linux_raw/fs/syscalls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub(crate) fn openat2(
8585
// Enable support for large files, but not with `O_PATH` because
8686
// `openat2` doesn't like those flags together.
8787
if !flags.contains(OFlags::PATH) {
88-
flags = flags | OFlags::from_bits_retain(c::O_LARGEFILE);
88+
flags |= OFlags::from_bits_retain(c::O_LARGEFILE);
8989
}
9090

9191
unsafe {

src/backend/linux_raw/termios/syscalls.rs

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,7 @@ pub(crate) fn set_speed(termios: &mut Termios, arbitrary_speed: u32) -> io::Resu
157157

158158
debug_assert_eq!(encoded_speed & !c::CBAUD, 0);
159159

160-
// Use `=` and `-` because `-=` behaves differently.
161-
termios.control_modes =
162-
termios.control_modes - ControlModes::from_bits_retain(c::CBAUD | c::CIBAUD);
160+
termios.control_modes -= ControlModes::from_bits_retain(c::CBAUD | c::CIBAUD);
163161
termios.control_modes |=
164162
ControlModes::from_bits_retain(encoded_speed | (encoded_speed << IBSHIFT));
165163

@@ -177,8 +175,7 @@ pub(crate) fn set_output_speed(termios: &mut Termios, arbitrary_speed: u32) -> i
177175

178176
debug_assert_eq!(encoded_speed & !c::CBAUD, 0);
179177

180-
// Use `=` and `-` because `-=` behaves differently.
181-
termios.control_modes = termios.control_modes - ControlModes::from_bits_retain(c::CBAUD);
178+
termios.control_modes -= ControlModes::from_bits_retain(c::CBAUD);
182179
termios.control_modes |= ControlModes::from_bits_retain(encoded_speed);
183180

184181
termios.output_speed = arbitrary_speed;
@@ -194,8 +191,7 @@ pub(crate) fn set_input_speed(termios: &mut Termios, arbitrary_speed: u32) -> io
194191

195192
debug_assert_eq!(encoded_speed & !c::CBAUD, 0);
196193

197-
// Use `=` and `-` because `-=` behaves differently.
198-
termios.control_modes = termios.control_modes - ControlModes::from_bits_retain(c::CIBAUD);
194+
termios.control_modes -= ControlModes::from_bits_retain(c::CIBAUD);
199195
termios.control_modes |= ControlModes::from_bits_retain(encoded_speed << IBSHIFT);
200196

201197
termios.input_speed = arbitrary_speed;
@@ -208,25 +204,21 @@ pub(crate) fn cfmakeraw(termios: &mut Termios) {
208204
// From the Linux [`cfmakeraw` manual page]:
209205
//
210206
// [`cfmakeraw` manual page]: https://man7.org/linux/man-pages/man3/cfmakeraw.3.html
211-
//
212-
// Use `=` and `-` because `-=` behaves differently.
213-
termios.input_modes = termios.input_modes
214-
- (InputModes::IGNBRK
215-
| InputModes::BRKINT
216-
| InputModes::PARMRK
217-
| InputModes::ISTRIP
218-
| InputModes::INLCR
219-
| InputModes::IGNCR
220-
| InputModes::ICRNL
221-
| InputModes::IXON);
222-
termios.output_modes = termios.output_modes - OutputModes::OPOST;
223-
termios.local_modes = termios.local_modes
224-
- (LocalModes::ECHO
225-
| LocalModes::ECHONL
226-
| LocalModes::ICANON
227-
| LocalModes::ISIG
228-
| LocalModes::IEXTEN);
229-
termios.control_modes = termios.control_modes - (ControlModes::CSIZE | ControlModes::PARENB);
207+
termios.input_modes -= InputModes::IGNBRK
208+
| InputModes::BRKINT
209+
| InputModes::PARMRK
210+
| InputModes::ISTRIP
211+
| InputModes::INLCR
212+
| InputModes::IGNCR
213+
| InputModes::ICRNL
214+
| InputModes::IXON;
215+
termios.output_modes -= OutputModes::OPOST;
216+
termios.local_modes -= LocalModes::ECHO
217+
| LocalModes::ECHONL
218+
| LocalModes::ICANON
219+
| LocalModes::ISIG
220+
| LocalModes::IEXTEN;
221+
termios.control_modes -= ControlModes::CSIZE | ControlModes::PARENB;
230222
termios.control_modes |= ControlModes::CS8;
231223

232224
// Musl and glibc also do these:

0 commit comments

Comments
 (0)