From 18041a2e1d60b2196f1ee31c8b42c0bc1b9f9468 Mon Sep 17 00:00:00 2001 From: Lam <15622383059@163.com> Date: Fri, 6 Sep 2019 11:11:41 +1000 Subject: [PATCH] '...' range patterns are deprecated, fix it Compile the previous program results in serveral following warnings: > warning: `...` range patterns are deprecated > --> src/n0008_string_to_integer_atoi.rs:77:24 > | > 77 | '0'...'9' => { > | ^^^ help: use `..=` for an inclusive range > | > = note: `#[warn(ellipsis_inclusive_range_patterns)]` on by default See this link (https://github.com/rust-lang/book/pull/2072) for more details --- src/n0008_string_to_integer_atoi.rs | 4 ++-- src/n0224_basic_calculator.rs | 2 +- src/n0227_basic_calculator_ii.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/n0008_string_to_integer_atoi.rs b/src/n0008_string_to_integer_atoi.rs index cabb68bb..5eef8f01 100644 --- a/src/n0008_string_to_integer_atoi.rs +++ b/src/n0008_string_to_integer_atoi.rs @@ -74,7 +74,7 @@ impl Solution { if !num_matched { match ch { ' ' => {}, - '0'...'9' => { + '0'..='9' => { num_matched = true; result = result * 10 + ch.to_digit(10).unwrap() as i64; }, @@ -84,7 +84,7 @@ impl Solution { } } else { match ch { - '0'...'9' => { + '0'..='9' => { result = result * 10 + ch.to_digit(10).unwrap() as i64; if result > i32_max { break } }, diff --git a/src/n0224_basic_calculator.rs b/src/n0224_basic_calculator.rs index e448a0ab..bbdb5077 100644 --- a/src/n0224_basic_calculator.rs +++ b/src/n0224_basic_calculator.rs @@ -52,7 +52,7 @@ impl Solution { let mut in_num = false; for ch in s.chars() { match ch { - '0'...'9' => { + '0'..='9' => { in_num = true; num = 10 * num + (ch as u8 - '0' as u8) as i64; } diff --git a/src/n0227_basic_calculator_ii.rs b/src/n0227_basic_calculator_ii.rs index 06fb2e5b..0b91565d 100644 --- a/src/n0227_basic_calculator_ii.rs +++ b/src/n0227_basic_calculator_ii.rs @@ -47,7 +47,7 @@ impl Solution { let mut multiple = true; for ch in s.chars() { match ch { - '0'...'9' => { curr = 10 * curr + (ch as u8 - '0' as u8) as i64; }, + '0'..='9' => { curr = 10 * curr + (ch as u8 - '0' as u8) as i64; }, '+' | '-' => { if has_prev { if multiple {