Skip to content

Commit 735469a

Browse files
committed
Replace unwraps in ast/
Replace if x.is_some() { x.as_ref().unwrap() } with if let Some(x) = x { x }
1 parent 9833c03 commit 735469a

4 files changed

Lines changed: 26 additions & 39 deletions

File tree

src/ast/ddl.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2113,8 +2113,7 @@ impl fmt::Display for ColumnOption {
21132113
GeneratedAs::ExpStored => "",
21142114
};
21152115
write!(f, "GENERATED {when} AS IDENTITY")?;
2116-
if sequence_options.is_some() {
2117-
let so = sequence_options.as_ref().unwrap();
2116+
if let Some(so) = sequence_options {
21182117
if !so.is_empty() {
21192118
write!(f, " (")?;
21202119
}

src/ast/helpers/stmt_data_loading.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,14 @@ pub struct StageLoadSelectItem {
8686

8787
impl fmt::Display for StageParamsObject {
8888
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
89-
let url = &self.url.as_ref();
90-
let storage_integration = &self.storage_integration.as_ref();
91-
let endpoint = &self.endpoint.as_ref();
92-
93-
if url.is_some() {
94-
write!(f, " URL='{}'", url.unwrap())?;
89+
if let Some(ref url) = self.url {
90+
write!(f, " URL='{url}'")?;
9591
}
96-
if storage_integration.is_some() {
97-
write!(f, " STORAGE_INTEGRATION={}", storage_integration.unwrap())?;
92+
if let Some(ref storage_integration) = self.storage_integration {
93+
write!(f, " STORAGE_INTEGRATION={storage_integration}")?;
9894
}
99-
if endpoint.is_some() {
100-
write!(f, " ENDPOINT='{}'", endpoint.unwrap())?;
95+
if let Some(ref endpoint) = self.endpoint {
96+
write!(f, " ENDPOINT='{endpoint}'")?;
10197
}
10298
if !self.credentials.options.is_empty() {
10399
write!(f, " CREDENTIALS=({})", self.credentials)?;

src/ast/mod.rs

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1853,16 +1853,10 @@ impl fmt::Display for Expr {
18531853
negated,
18541854
} => {
18551855
let not_ = if *negated { "NOT " } else { "" };
1856-
if form.is_none() {
1857-
write!(f, "{expr} IS {not_}NORMALIZED")
1856+
if let Some(form) = form {
1857+
write!(f, "{} IS {}{} NORMALIZED", expr, not_, form)
18581858
} else {
1859-
write!(
1860-
f,
1861-
"{} IS {}{} NORMALIZED",
1862-
expr,
1863-
not_,
1864-
form.as_ref().unwrap()
1865-
)
1859+
write!(f, "{expr} IS {not_}NORMALIZED")
18661860
}
18671861
}
18681862
Expr::SimilarTo {
@@ -5741,8 +5735,8 @@ impl fmt::Display for Statement {
57415735
write!(f, " SESSION")?;
57425736
}
57435737
write!(f, " STATUS")?;
5744-
if filter.is_some() {
5745-
write!(f, " {}", filter.as_ref().unwrap())?;
5738+
if let Some(filter) = filter {
5739+
write!(f, " {}", filter)?;
57465740
}
57475741
Ok(())
57485742
}
@@ -5759,8 +5753,8 @@ impl fmt::Display for Statement {
57595753
write!(f, " SESSION")?;
57605754
}
57615755
write!(f, " VARIABLES")?;
5762-
if filter.is_some() {
5763-
write!(f, " {}", filter.as_ref().unwrap())?;
5756+
if let Some(filter) = filter {
5757+
write!(f, " {}", filter)?;
57645758
}
57655759
Ok(())
57665760
}
@@ -6172,8 +6166,8 @@ impl fmt::Display for Statement {
61726166
if !copy_options.options.is_empty() {
61736167
write!(f, " COPY_OPTIONS=({copy_options})")?;
61746168
}
6175-
if comment.is_some() {
6176-
write!(f, " COMMENT='{}'", comment.as_ref().unwrap())?;
6169+
if let Some(comment) = comment {
6170+
write!(f, " COMMENT='{}'", comment)?;
61776171
}
61786172
Ok(())
61796173
}
@@ -6260,12 +6254,11 @@ impl fmt::Display for Statement {
62606254
}
62616255
Statement::Pragma { name, value, is_eq } => {
62626256
write!(f, "PRAGMA {name}")?;
6263-
if value.is_some() {
6264-
let val = value.as_ref().unwrap();
6257+
if let Some(value) = value {
62656258
if *is_eq {
6266-
write!(f, " = {val}")?;
6259+
write!(f, " = {value}")?;
62676260
} else {
6268-
write!(f, "({val})")?;
6261+
write!(f, "({value})")?;
62696262
}
62706263
}
62716264
Ok(())

src/ast/query.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -307,15 +307,14 @@ pub struct Table {
307307

308308
impl fmt::Display for Table {
309309
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
310-
if let Some(ref schema_name) = self.schema_name {
311-
write!(
312-
f,
313-
"TABLE {}.{}",
314-
schema_name,
315-
self.table_name.as_ref().unwrap(),
316-
)?;
310+
if let Some(ref table_name) = self.table_name {
311+
if let Some(ref schema_name) = self.schema_name {
312+
write!(f, "TABLE {}.{}", schema_name, table_name,)?;
313+
} else {
314+
write!(f, "TABLE {}", table_name)?;
315+
}
317316
} else {
318-
write!(f, "TABLE {}", self.table_name.as_ref().unwrap(),)?;
317+
write!(f, "TABLE")?;
319318
}
320319
Ok(())
321320
}

0 commit comments

Comments
 (0)