From 0fc667730d7619f5cfa8c45d88e16dff691740a5 Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Fri, 1 Apr 2022 18:50:42 +0200 Subject: [PATCH] join: fix workaround for IntErrorKind In Rust versions before 1.55, there was no enum for parse errors. With the bump of the MSRV to 1.56 we can simplify this. --- src/uu/join/src/join.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/uu/join/src/join.rs b/src/uu/join/src/join.rs index 1d306415b..ef19fe328 100644 --- a/src/uu/join/src/join.rs +++ b/src/uu/join/src/join.rs @@ -18,6 +18,7 @@ use std::error::Error; use std::fmt::Display; use std::fs::File; use std::io::{stdin, stdout, BufRead, BufReader, BufWriter, Split, Stdin, Write}; +use std::num::IntErrorKind; #[cfg(unix)] use std::os::unix::ffi::OsStrExt; use uucore::display::Quotable; @@ -965,13 +966,9 @@ fn get_field_number(keys: Option, key: Option) -> UResult { /// Parse the specified field string as a natural number and return /// the zero-based field number. fn parse_field_number(value: &str) -> UResult { - // TODO: use ParseIntError.kind() once MSRV >= 1.55 - // For now, store an overflow Err from parsing a value 10x 64 bit usize::MAX - // Adapted from https://github.com/rust-lang/rust/issues/22639 - let overflow = "184467440737095516150".parse::().err().unwrap(); match value.parse::() { Ok(result) if result > 0 => Ok(result - 1), - Err(ref e) if *e == overflow => Ok(usize::MAX), + Err(e) if e.kind() == &IntErrorKind::PosOverflow => Ok(usize::MAX), _ => Err(USimpleError::new( 1, format!("invalid field number: {}", value.quote()),