Skip to content

Commit 6cc4904

Browse files
committed
a perhaps unidiomatic way of using 'let else' to emphasise controlflow
1 parent 483334f commit 6cc4904

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

src/visudo/mod.rs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -278,21 +278,7 @@ fn edit_sudoers_file(
278278
)
279279
})?;
280280

281-
if errors.is_empty() {
282-
if visudo_is_allowed(sudoers, &host_name) == Some(false) {
283-
writeln!(stderr, "It looks like these changes may lock you out of editing the sudoers file again.\n")?;
284-
match ask_response(
285-
b"What now? (p)roceed anyway / e(x)it without saving / (e)dit again: ",
286-
b"xep",
287-
)? {
288-
b'x' => return Ok(()),
289-
b'p' => {}
290-
_ => continue,
291-
}
292-
}
293-
294-
break;
295-
} else {
281+
let true = errors.is_empty() else {
296282
writeln!(stderr, "The provided sudoers file format is not recognized or contains syntax errors. Please review:\n")?;
297283

298284
for crate::sudoers::Error {
@@ -311,7 +297,24 @@ fn edit_sudoers_file(
311297
b'x' => return Ok(()),
312298
_ => continue,
313299
}
300+
};
301+
302+
if visudo_is_allowed(sudoers, &host_name) == Some(false) {
303+
writeln!(
304+
stderr,
305+
"It looks like these changes may lock you out of editing the sudoers file again.\n"
306+
)?;
307+
match ask_response(
308+
b"What now? (p)roceed anyway / e(x)it without saving / (e)dit again: ",
309+
b"xep",
310+
)? {
311+
b'x' => return Ok(()),
312+
b'p' => {}
313+
_ => continue,
314+
}
314315
}
316+
317+
break;
315318
}
316319

317320
let tmp_contents = std::fs::read(tmp_path)?;

0 commit comments

Comments
 (0)