Cleanup more issues noted by 'clippy'

Mostly stuff that was introduced by commit 3600b33f1c.
This commit is contained in:
Heikki Linnakangas
2021-04-22 09:20:05 +03:00
parent 9b71ae7dce
commit a4fd1e1a80
10 changed files with 39 additions and 43 deletions

View File

@@ -189,11 +189,11 @@ impl PostgresNode {
);
let port: u16 = CONF_PORT_RE
.captures(config.as_str())
.ok_or(anyhow::Error::msg(err_msg.clone() + " 1"))?
.ok_or_else(|| anyhow::Error::msg(err_msg.clone() + " 1"))?
.iter()
.last()
.ok_or(anyhow::Error::msg(err_msg.clone() + " 2"))?
.ok_or(anyhow::Error::msg(err_msg.clone() + " 3"))?
.ok_or_else(|| anyhow::Error::msg(err_msg.clone() + " 2"))?
.ok_or_else(|| anyhow::Error::msg(err_msg.clone() + " 3"))?
.as_str()
.parse()
.with_context(|| err_msg)?;

View File

@@ -174,7 +174,7 @@ fn parse_rel_file_path(path: &str) -> Result<(), FilePathError> {
Ok(())
} else if let Some(dbpath) = path.strip_prefix("base/") {
let mut s = dbpath.split("/");
let mut s = dbpath.split('/');
let dbnode_str = s
.next()
.ok_or_else(|| FilePathError::new("invalid relation data file name"))?;

View File

@@ -169,9 +169,9 @@ fn start_pageserver(conf: &PageServerConf) -> Result<()> {
.unwrap();
threads.push(page_server_thread);
if tui_thread.is_some() {
if let Some(tui_thread) = tui_thread {
// The TUI thread exits when the user asks to Quit.
tui_thread.unwrap().join().unwrap();
tui_thread.join().unwrap();
} else {
// In non-interactive mode, wait forever.
for t in threads {

View File

@@ -487,7 +487,7 @@ impl PageCache {
let oldentry = shared.pagecache.insert(key, Arc::new(entry));
self.num_entries.fetch_add(1, Ordering::Relaxed);
if !oldentry.is_none() {
if oldentry.is_some() {
error!(
"overwriting WAL record with LSN {:X}/{:X} in page cache",
lsn >> 32,

View File

@@ -203,7 +203,7 @@ impl FeParseMessage {
// now, just ignore the statement name, assuming that the client never
// uses more than one prepared statement at a time.
/*
if pstmt_name.len() != 0 {
if !pstmt_name.is_empty() {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
"named prepared statements not implemented in Parse",
@@ -235,7 +235,7 @@ impl FeDescribeMessage {
// FIXME: see FeParseMessage::parse
/*
if pstmt_name.len() != 0 {
if !pstmt_name.is_empty() {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
"named prepared statements not implemented in Describe",
@@ -266,7 +266,7 @@ impl FeExecuteMessage {
let portal_name = read_null_terminated(&mut buf)?;
let maxrows = buf.get_i32();
if portal_name.len() != 0 {
if !portal_name.is_empty() {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
"named portals not implemented",
@@ -293,7 +293,7 @@ impl FeBindMessage {
let portal_name = read_null_terminated(&mut buf)?;
let _pstmt_name = read_null_terminated(&mut buf)?;
if portal_name.len() != 0 {
if !portal_name.is_empty() {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
"named portals not implemented",
@@ -302,7 +302,7 @@ impl FeBindMessage {
// FIXME: see FeParseMessage::parse
/*
if pstmt_name.len() != 0 {
if !pstmt_name.is_empty() {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
"named prepared statements not implemented",
@@ -941,10 +941,10 @@ impl Connection {
let f_tar2 = async {
let joinres = f_tar.await;
if joinres.is_err() {
if let Err(joinreserr) = joinres {
return Err(io::Error::new(
io::ErrorKind::InvalidData,
joinres.unwrap_err(),
joinreserr,
));
}
joinres.unwrap()

View File

@@ -186,10 +186,9 @@ fn restore_relfile(
// Does it look like a relation file?
let p = parse_relfilename(path.file_name().unwrap().to_str().unwrap());
if p.is_err() {
let e = p.unwrap_err();
if let Err(e) = p {
warn!("unrecognized file in snapshot: {:?} ({})", path, e);
return Err(e)?;
return Err(e.into());
}
let (relnode, forknum, segno) = p.unwrap();
@@ -266,7 +265,7 @@ fn restore_wal(
// It could be as .partial
if !PathBuf::from(&path).exists() {
path = path + ".partial";
path += ".partial";
}
// Slurp the WAL file

View File

@@ -388,7 +388,7 @@ fn build_begin_redo_for_block_msg(tag: BufferTag) -> Bytes {
let len = 4 + 5 * 4;
let mut buf = BytesMut::with_capacity(1 + len);
buf.put_u8('B' as u8);
buf.put_u8(b'B');
buf.put_u32(len as u32);
buf.put_u32(tag.spcnode);
buf.put_u32(tag.dbnode);
@@ -407,7 +407,7 @@ fn build_push_page_msg(tag: BufferTag, base_img: Bytes) -> Bytes {
let len = 4 + 5 * 4 + base_img.len();
let mut buf = BytesMut::with_capacity(1 + len);
buf.put_u8('P' as u8);
buf.put_u8(b'P');
buf.put_u32(len as u32);
buf.put_u32(tag.spcnode);
buf.put_u32(tag.dbnode);
@@ -425,7 +425,7 @@ fn build_apply_record_msg(endlsn: u64, rec: Bytes) -> Bytes {
let len = 4 + 8 + rec.len();
let mut buf = BytesMut::with_capacity(1 + len);
buf.put_u8('A' as u8);
buf.put_u8(b'A');
buf.put_u32(len as u32);
buf.put_u64(endlsn);
buf.put(rec);
@@ -439,7 +439,7 @@ fn build_get_page_msg(tag: BufferTag) -> Bytes {
let len = 4 + 5 * 4;
let mut buf = BytesMut::with_capacity(1 + len);
buf.put_u8('G' as u8);
buf.put_u8(b'G');
buf.put_u32(len as u32);
buf.put_u32(tag.spcnode);
buf.put_u32(tag.dbnode);

View File

@@ -91,9 +91,9 @@ impl FeStartupMessage {
options = true;
} else if options {
for opt in p.split(' ') {
if opt.starts_with("ztimelineid=") {
if let Some(ztimelineid_str) = opt.strip_prefix("ztimelineid=") {
// FIXME: rethrow parsing error, don't unwrap
timelineid = Some(ZTimelineId::from_str(&opt[12..]).unwrap());
timelineid = Some(ZTimelineId::from_str(ztimelineid_str).unwrap());
break;
}
}

View File

@@ -554,7 +554,7 @@ impl Connection {
async fn run(&mut self) -> Result<()> {
self.inbuf.resize(4, 0u8);
self.stream.read_exact(&mut self.inbuf[0..4]).await?;
let startup_pkg_len = BigEndian::read_u32(&mut self.inbuf[0..4]);
let startup_pkg_len = BigEndian::read_u32(&self.inbuf[0..4]);
if startup_pkg_len == 0 {
self.receive_wal().await?; // internal protocol between wal_proposer and wal_acceptor
} else {
@@ -997,12 +997,12 @@ impl Connection {
// Try to fetch replica's feedback
match self.stream.try_read_buf(&mut self.inbuf) {
Ok(0) => break,
Ok(_) => match self.parse_message()? {
Some(FeMessage::CopyData(m)) => self
.timeline()
.add_hs_feedback(HotStandbyFeedback::parse(&m.body)),
_ => {}
},
Ok(_) => {
if let Some(FeMessage::CopyData(m)) = self.parse_message()? {
self.timeline()
.add_hs_feedback(HotStandbyFeedback::parse(&m.body))
}
}
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => {}
Err(e) => {
return Err(e);
@@ -1102,7 +1102,7 @@ impl Connection {
let mut bytes_written: usize = 0;
let mut partial;
let mut start_pos = startpos;
const ZERO_BLOCK: &'static [u8] = &[0u8; XLOG_BLCKSZ];
const ZERO_BLOCK: &[u8] = &[0u8; XLOG_BLCKSZ];
/* Extract WAL location for this block */
let mut xlogoff = XLogSegmentOffset(start_pos, wal_seg_size) as usize;

View File

@@ -186,7 +186,7 @@ fn handle_pg(pg_match: &ArgMatches, env: &local_env::LocalEnv) -> Result<()> {
let node = cplane
.nodes
.get(name)
.ok_or(anyhow!("postgres {} is not found", name))?;
.ok_or_else(|| anyhow!("postgres {} is not found", name))?;
node.start()?;
}
("stop", Some(sub_m)) => {
@@ -194,7 +194,7 @@ fn handle_pg(pg_match: &ArgMatches, env: &local_env::LocalEnv) -> Result<()> {
let node = cplane
.nodes
.get(name)
.ok_or(anyhow!("postgres {} is not found", name))?;
.ok_or_else(|| anyhow!("postgres {} is not found", name))?;
node.stop()?;
}
@@ -277,19 +277,19 @@ fn list_branches() -> Result<()> {
//
//
fn parse_point_in_time(s: &str) -> Result<local_env::PointInTime> {
let mut strings = s.split("@");
let mut strings = s.split('@');
let name = strings.next().unwrap();
let lsn: Option<u64>;
if let Some(lsnstr) = strings.next() {
let mut s = lsnstr.split("/");
let mut s = lsnstr.split('/');
let lsn_hi: u64 = s
.next()
.ok_or(anyhow!("invalid LSN in point-in-time specification"))?
.ok_or_else(|| anyhow!("invalid LSN in point-in-time specification"))?
.parse()?;
let lsn_lo: u64 = s
.next()
.ok_or(anyhow!("invalid LSN in point-in-time specification"))?
.ok_or_else(|| anyhow!("invalid LSN in point-in-time specification"))?
.parse()?;
lsn = Some(lsn_hi << 32 | lsn_lo);
} else {
@@ -312,11 +312,8 @@ fn parse_point_in_time(s: &str) -> Result<local_env::PointInTime> {
let pointstr = fs::read_to_string(branchpath)?;
let mut result = parse_point_in_time(&pointstr)?;
if lsn.is_some() {
result.lsn = lsn.unwrap();
} else {
result.lsn = 0;
}
result.lsn = lsn.unwrap_or(0);
return Ok(result);
}