The body of an if, else, for, while or do is a single statement without braces

tx0/c:unbraced-bodyallwarningstyle/conventionsdepth faststyle

What it finds

if (err) log(err); return err; on two lines: without braces, a statement added under the body runs whatever the condition, though the indentation says otherwise. else if is left alone, and so are bodies on the line of their statement, as in if (!p) return;, which a statement added below cannot be mistaken for. Only bodies that run over more than one line count, where the missing braces are easiest to overlook.

From the rule's source, unbraced_body.rs.

Example from the rule's tests
int clamp(int x){  if (x < 0)    x =tx0 reports: this body has no braces      0;  if (x > 9)    x = 9;  for (int i = 0; i < 3; i++) {    x++;  }  return x;}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the all tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/c:unbraced-body" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/c:unbraced-body] reason="..."

tx0 explain tx0/c:unbraced-body shows the same in the terminal. Found a false positive? Report it.