Update nightly formatter
Rustfmt is now capable of formatting let Some(..) else {} blocks
This commit is contained in:
parent
064b973a2a
commit
ff53625408
@ -1,4 +1,4 @@
|
||||
[toolchain]
|
||||
channel = "nightly-2023-01-24"
|
||||
channel = "nightly-2023-09-02"
|
||||
profile = "minimal"
|
||||
components = ["rustfmt"]
|
||||
|
@ -61,7 +61,10 @@ pub fn get_services(pool: &DescriptorPool) -> (Vec<CollectionService>, Vec<Backe
|
||||
// locate associated collection service
|
||||
let Some(col_service) = col_services
|
||||
.iter()
|
||||
.find(|cs| cs.name == service.name.trim_start_matches("Backend")) else { panic!("missing associated service: {}", service.name) };
|
||||
.find(|cs| cs.name == service.name.trim_start_matches("Backend"))
|
||||
else {
|
||||
panic!("missing associated service: {}", service.name)
|
||||
};
|
||||
|
||||
// add any methods that don't exist in backend trait methods to the delegating
|
||||
// methods
|
||||
|
@ -278,7 +278,9 @@ impl MethodHelpers for Method {
|
||||
}
|
||||
|
||||
fn rust_type(name: &str) -> String {
|
||||
let Some((head, tail)) = name.rsplit_once( '.') else { panic!() };
|
||||
let Some((head, tail)) = name.rsplit_once('.') else {
|
||||
panic!()
|
||||
};
|
||||
format!(
|
||||
"{}::{}",
|
||||
head.to_snake_case()
|
||||
|
@ -142,8 +142,12 @@ impl ExtractedCloze<'_> {
|
||||
|
||||
/// If cloze starts with image-occlusion:, return the text following that.
|
||||
fn image_occlusion(&self) -> Option<&str> {
|
||||
let Some(first_node) = self.nodes.get(0) else { return None };
|
||||
let TextOrCloze::Text(text) = first_node else { return None };
|
||||
let Some(first_node) = self.nodes.get(0) else {
|
||||
return None;
|
||||
};
|
||||
let TextOrCloze::Text(text) = first_node else {
|
||||
return None;
|
||||
};
|
||||
text.strip_prefix("image-occlusion:")
|
||||
}
|
||||
}
|
||||
|
@ -245,7 +245,9 @@ impl Collection {
|
||||
let mut genctx = None;
|
||||
for (_, nid) in group {
|
||||
progress.increment(|p| {
|
||||
let DatabaseCheckProgress::Notes { current, .. } = p else { unreachable!() };
|
||||
let DatabaseCheckProgress::Notes { current, .. } = p else {
|
||||
unreachable!()
|
||||
};
|
||||
current
|
||||
})?;
|
||||
|
||||
|
@ -466,7 +466,9 @@ mod tests {
|
||||
let key_source = DeckSchema11::default();
|
||||
let mut deck = Deck::new_normal();
|
||||
deck.common.other = serde_json::to_vec(&key_source)?;
|
||||
let DeckSchema11::Normal(s11) = DeckSchema11::from(deck) else { panic!() };
|
||||
let DeckSchema11::Normal(s11) = DeckSchema11::from(deck) else {
|
||||
panic!()
|
||||
};
|
||||
|
||||
let empty: &[&String] = &[];
|
||||
assert_eq!(&s11.common.other.keys().collect_vec(), empty);
|
||||
|
@ -57,7 +57,9 @@ pub fn get_image_cloze_data(text: &str) -> String {
|
||||
if !values[1].is_empty() {
|
||||
let mut point_str = String::new();
|
||||
for point_pair in values[1].split(' ') {
|
||||
let Some((x, y)) = point_pair.split_once(',') else { continue };
|
||||
let Some((x, y)) = point_pair.split_once(',') else {
|
||||
continue;
|
||||
};
|
||||
write!(&mut point_str, "{},{} ", x, y).unwrap();
|
||||
}
|
||||
// remove the trailing space
|
||||
|
@ -457,8 +457,8 @@ impl MediaChecker<'_> {
|
||||
});
|
||||
|
||||
let Some(caps) = BASE64_IMG.captures(fname_decoded) else {
|
||||
return Ok(fname_decoded.into());
|
||||
};
|
||||
return Ok(fname_decoded.into());
|
||||
};
|
||||
let (_all, [ext, data]) = caps.extract();
|
||||
let data = data.trim();
|
||||
let data = match BASE64.decode(data.as_bytes()) {
|
||||
|
@ -449,7 +449,9 @@ fn parse_prop(prop_clause: &str) -> ParseResult<SearchNode> {
|
||||
"lapses" => PropertyKind::Lapses(parse_u32(num, prop_clause)?),
|
||||
"pos" => PropertyKind::Position(parse_u32(num, prop_clause)?),
|
||||
other => {
|
||||
let Some(prop) = other.strip_prefix("cdn:") else { unreachable!() };
|
||||
let Some(prop) = other.strip_prefix("cdn:") else {
|
||||
unreachable!()
|
||||
};
|
||||
PropertyKind::CustomDataNumber {
|
||||
key: prop.into(),
|
||||
value: parse_f32(num, prop_clause)?,
|
||||
|
@ -30,8 +30,12 @@ impl GraphsContext {
|
||||
),
|
||||
];
|
||||
'outer: for review in &self.revlog {
|
||||
let Some(interval_bucket) = interval_bucket(review) else { continue; };
|
||||
let Some(button_idx) = button_index(review.button_chosen) else { continue; };
|
||||
let Some(interval_bucket) = interval_bucket(review) else {
|
||||
continue;
|
||||
};
|
||||
let Some(button_idx) = button_index(review.button_chosen) else {
|
||||
continue;
|
||||
};
|
||||
let review_secs = review.id.as_secs();
|
||||
increment_button_counts(&mut all_time, interval_bucket, button_idx);
|
||||
for (stamp, bucket) in &mut conditional_buckets {
|
||||
|
@ -211,13 +211,19 @@ fn add_extract_custom_data_number_function(db: &Connection) -> rusqlite::Result<
|
||||
move |ctx| {
|
||||
assert_eq!(ctx.len(), 2, "called with unexpected number of arguments");
|
||||
|
||||
let Ok(card_data) = ctx.get_raw(0).as_str() else { return Ok(None) };
|
||||
let Ok(card_data) = ctx.get_raw(0).as_str() else {
|
||||
return Ok(None);
|
||||
};
|
||||
if card_data.is_empty() {
|
||||
return Ok(None);
|
||||
}
|
||||
let Ok(key) = ctx.get_raw(1).as_str() else { return Ok(None) };
|
||||
let Ok(key) = ctx.get_raw(1).as_str() else {
|
||||
return Ok(None);
|
||||
};
|
||||
let custom_data = &CardData::from_str(card_data).custom_data;
|
||||
let Ok(value) = serde_json::from_str::<Value>(custom_data) else { return Ok(None) };
|
||||
let Ok(value) = serde_json::from_str::<Value>(custom_data) else {
|
||||
return Ok(None);
|
||||
};
|
||||
let num = value.get(key).and_then(|v| v.as_f64());
|
||||
Ok(num)
|
||||
},
|
||||
@ -233,13 +239,19 @@ fn add_has_custom_data_function(db: &Connection) -> rusqlite::Result<()> {
|
||||
move |ctx| {
|
||||
assert_eq!(ctx.len(), 2, "called with unexpected number of arguments");
|
||||
|
||||
let Ok(card_data) = ctx.get_raw(0).as_str() else { return Ok(None) };
|
||||
let Ok(card_data) = ctx.get_raw(0).as_str() else {
|
||||
return Ok(None);
|
||||
};
|
||||
if card_data.is_empty() {
|
||||
return Ok(Some(false));
|
||||
}
|
||||
let Ok(key) = ctx.get_raw(1).as_str() else { return Ok(Some(false)) };
|
||||
let Ok(key) = ctx.get_raw(1).as_str() else {
|
||||
return Ok(Some(false));
|
||||
};
|
||||
let custom_data = &CardData::from_str(card_data).custom_data;
|
||||
let Ok(value) = serde_json::from_str::<Value>(custom_data) else { return Ok(Some(false)) };
|
||||
let Ok(value) = serde_json::from_str::<Value>(custom_data) else {
|
||||
return Ok(Some(false));
|
||||
};
|
||||
|
||||
Ok(value.get(key).map(|_| true))
|
||||
},
|
||||
|
@ -111,7 +111,10 @@ where
|
||||
}
|
||||
|
||||
fn unwrap_sync_err_kind(err: AnkiError) -> SyncErrorKind {
|
||||
let AnkiError::SyncError { source: SyncError { kind, .. } } = err else {
|
||||
let AnkiError::SyncError {
|
||||
source: SyncError { kind, .. },
|
||||
} = err
|
||||
else {
|
||||
panic!("not sync err: {err:?}");
|
||||
};
|
||||
kind
|
||||
@ -355,7 +358,12 @@ async fn sync_errors_should_prompt_db_check() -> Result<()> {
|
||||
.sync()
|
||||
.await
|
||||
.unwrap_err();
|
||||
let AnkiError::SyncError { source: SyncError { info: _, kind } } = err else { panic!() };
|
||||
let AnkiError::SyncError {
|
||||
source: SyncError { info: _, kind },
|
||||
} = err
|
||||
else {
|
||||
panic!()
|
||||
};
|
||||
assert_eq!(kind, SyncErrorKind::DatabaseCheckRequired);
|
||||
|
||||
// the server should have rolled back
|
||||
@ -368,7 +376,12 @@ async fn sync_errors_should_prompt_db_check() -> Result<()> {
|
||||
.sync()
|
||||
.await
|
||||
.unwrap_err();
|
||||
let AnkiError::SyncError { source: SyncError { info: _, kind } } = err else { panic!() };
|
||||
let AnkiError::SyncError {
|
||||
source: SyncError { info: _, kind },
|
||||
} = err
|
||||
else {
|
||||
panic!()
|
||||
};
|
||||
assert_eq!(kind, SyncErrorKind::DatabaseCheckRequired);
|
||||
|
||||
Ok(())
|
||||
|
@ -26,7 +26,10 @@ impl ServerMediaDatabase {
|
||||
let mut entries = vec![];
|
||||
let mut accumulated_size = 0;
|
||||
for filename in files {
|
||||
let Some(entry) = self.get_nonempty_entry(filename).or_internal_err("fetching entry")? else {
|
||||
let Some(entry) = self
|
||||
.get_nonempty_entry(filename)
|
||||
.or_internal_err("fetching entry")?
|
||||
else {
|
||||
return None.or_conflict(format!("missing/empty file entry: {filename}"));
|
||||
};
|
||||
|
||||
|
@ -647,7 +647,7 @@ pub fn render_card(
|
||||
context.frontside = if context.partial_for_python {
|
||||
Some("")
|
||||
} else {
|
||||
let Some(RenderedNode::Text {text }) = &qnodes.get(0) else {
|
||||
let Some(RenderedNode::Text { text }) = &qnodes.get(0) else {
|
||||
invalid_input!("should not happen: first node not text");
|
||||
};
|
||||
Some(text)
|
||||
|
Loading…
Reference in New Issue
Block a user