Add did-you-mean suggestions for bitwise ops (#7252)

Continues work from #7251 to include the bitwise operations.
Covers the C style conventions as well as the typo `bits-*` instead of
`bit-*`
This commit is contained in:
Stefan Holderbach 2022-12-01 11:34:41 +01:00 committed by GitHub
parent cbc7b94b02
commit a9e6b1ec6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4514,7 +4514,7 @@ pub fn parse_operator(
b"pow" => "pow",
_ => unreachable!(),
},
"Use '**' for exponentiation",
"Use '**' for exponentiation or 'bit-xor' for bitwise XOR.",
span,
)),
);
@ -4553,6 +4553,60 @@ pub fn parse_operator(
)),
);
}
b"&" => {
return (
garbage(span),
Some(ParseError::UnknownOperator(
"&",
"Did you mean 'bit-and'?",
span,
)),
);
}
b"<<" => {
return (
garbage(span),
Some(ParseError::UnknownOperator(
"<<",
"Did you mean 'bit-shl'?",
span,
)),
);
}
b">>" => {
return (
garbage(span),
Some(ParseError::UnknownOperator(
">>",
"Did you mean 'bit-shr'?",
span,
)),
);
}
bits @ (b"bits-and" | b"bits-xor" | b"bits-or" | b"bits-shl" | b"bits-shr") => {
return (
garbage(span),
Some(ParseError::UnknownOperator(
match bits {
b"bits-and" => "bits-and",
b"bits-xor" => "bits-xor",
b"bits-or" => "bits-or",
b"bits-shl" => "bits-shl",
b"bits-shr" => "bits-shr",
_ => unreachable!(),
},
match bits {
b"bits-and" => "Did you mean 'bit-and'?",
b"bits-xor" => "Did you mean 'bit-xor'?",
b"bits-or" => "Did you mean 'bit-or'?",
b"bits-shl" => "Did you mean 'bit-shl'?",
b"bits-shr" => "Did you mean 'bit-shr'?",
_ => unreachable!(),
},
span,
)),
);
}
_ => {
return (
garbage(span),