Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Caleb Cartwright <calebcartwright@users.noreply.github.com>
  • Loading branch information
ArjenL and calebcartwright authored Aug 29, 2021
1 parent 7ffd59f commit 553fa0a
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ license_template_path = ""
format_strings = false
format_macro_matchers = false
format_macro_bodies = true
hex_literal_case = "Ignore"
hex_literal_case = "Preserve"
empty_item_single_line = true
struct_lit_single_line = true
fn_single_line = false
Expand Down
10 changes: 5 additions & 5 deletions src/config/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ pub enum ImportGranularity {
#[config_type]
pub enum HexLiteralCase {
/// Leave the literal as-is
Ignore,
/// Uppercase the literal
ToUpper,
/// Lowercase the literal
ToLower,
Preserve,
/// Ensure all literals use uppercase lettering
Upper,
/// Ensure all literals use lowercase lettering
Lower,
}

#[config_type]
Expand Down
6 changes: 3 additions & 3 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1217,9 +1217,9 @@ fn rewrite_int_lit(context: &RewriteContext<'_>, lit: &ast::Lit) -> Option<Strin

if symbol.starts_with("0x") {
let hex_lit = match context.config.hex_literal_case() {
HexLiteralCase::Ignore => None,
HexLiteralCase::ToUpper => Some(symbol[2..].to_ascii_uppercase()),
HexLiteralCase::ToLower => Some(symbol[2..].to_ascii_lowercase()),
HexLiteralCase::Preserve => None,
HexLiteralCase::Upper => Some(symbol[2..].to_ascii_uppercase()),
HexLiteralCase::Lower => Some(symbol[2..].to_ascii_lowercase()),
};
if let Some(hex_lit) = hex_lit {
return Some(format!(
Expand Down
2 changes: 1 addition & 1 deletion tests/source/hex_literal_lower.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// rustfmt-hex_literal_case: ToLower
// rustfmt-hex_literal_case: Lower
fn main() {
let h1 = 0xCAFE_5EA7;
let h2 = 0xCAFE_F00Du32;
Expand Down
4 changes: 2 additions & 2 deletions tests/source/hex_literal_upper.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// rustfmt-hex_literal_case: ToUpper
// rustfmt-hex_literal_case: Upper
fn main() {
let h1 = 0xCAFE_5EA7;
let h1 = 0xCaFE_5ea7;
let h2 = 0xCAFE_F00Du32;
}
2 changes: 1 addition & 1 deletion tests/target/hex_literal_ignore.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// rustfmt-hex_literal_case: Ignore
// rustfmt-hex_literal_case: Preserve
fn main() {
let h1 = 0xcAfE_5Ea7;
let h2 = 0xCaFe_F00du32;
Expand Down
2 changes: 1 addition & 1 deletion tests/target/hex_literal_lower.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// rustfmt-hex_literal_case: ToLower
// rustfmt-hex_literal_case: Lower
fn main() {
let h1 = 0xcafe_5ea7;
let h2 = 0xcafe_f00du32;
Expand Down
2 changes: 1 addition & 1 deletion tests/target/hex_literal_upper.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// rustfmt-hex_literal_case: ToUpper
// rustfmt-hex_literal_case: Upper
fn main() {
let h1 = 0xCAFE_5EA7;
let h2 = 0xCAFE_F00Du32;
Expand Down

0 comments on commit 553fa0a

Please sign in to comment.