Skip to content

Commit

Permalink
Bump Rust to 1.84
Browse files Browse the repository at this point in the history
+ fix new warnings/lints
+ update pyo3 to fix some other warnings
  • Loading branch information
dae committed Jan 26, 2025
1 parent a05e41e commit 92b1144
Show file tree
Hide file tree
Showing 20 changed files with 40 additions and 39 deletions.
24 changes: 12 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ prost-build = "0.13"
prost-reflect = "0.14"
prost-types = "0.13"
pulldown-cmark = "0.9.6"
pyo3 = { version = "0.22.5", features = ["extension-module", "abi3", "abi3-py39"] }
pyo3 = { version = "0.23.4", features = ["extension-module", "abi3", "abi3-py39"] }
rand = "0.8.5"
regex = "1.11.0"
reqwest = { version = "0.12.8", default-features = false, features = ["json", "socks", "stream", "multipart"] }
Expand Down
4 changes: 2 additions & 2 deletions pylib/rsbridge/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl Backend {
let in_bytes = input.as_bytes();
py.allow_threads(|| self.backend.run_service_method(service, method, in_bytes))
.map(|out_bytes| {
let out_obj = PyBytes::new_bound(py, &out_bytes);
let out_obj = PyBytes::new(py, &out_bytes);
out_obj.into()
})
.map_err(BackendError::new_err)
Expand All @@ -72,7 +72,7 @@ impl Backend {
.map_err(BackendError::new_err)
});
let out_bytes = out_res?;
let out_obj = PyBytes::new_bound(py, &out_bytes);
let out_obj = PyBytes::new(py, &out_bytes);
Ok(out_obj.into())
}
}
Expand Down
4 changes: 2 additions & 2 deletions rslib/src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ impl Backend {
// currently limited to http1, as nginx doesn't support http2 proxies
let mut web_client = self.web_client.lock().unwrap();

return web_client
web_client
.get_or_insert_with(|| Client::builder().http1_only().build().unwrap())
.clone();
.clone()
}

fn db_command(&self, input: &[u8]) -> Result<Vec<u8>> {
Expand Down
1 change: 1 addition & 0 deletions rslib/src/backend/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ impl crate::services::BackendSyncService for Backend {

impl Backend {
/// Return a handle for regular (non-media) syncing.
#[allow(clippy::type_complexity)]
fn sync_abort_handle(
&self,
) -> Result<(
Expand Down
12 changes: 6 additions & 6 deletions rslib/src/card_rendering/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,17 @@ impl<'a> Directive<'a> {
}

/// Consume 0 or more of anything in " \t\r\n" after `parser`.
fn trailing_whitespace0<'parser, 's, P, O>(parser: P) -> impl FnMut(&'s str) -> IResult<O>
fn trailing_whitespace0<'parser, 's, P, O>(parser: P) -> impl FnMut(&'s str) -> IResult<'s, O>
where
P: FnMut(&'s str) -> IResult<O> + 'parser,
P: FnMut(&'s str) -> IResult<'s, O> + 'parser,
{
terminated(parser, multispace0)
}

/// Parse until char in `arr` is found. Always succeeds.
fn is_not0<'parser, 'arr: 'parser, 's: 'parser>(
arr: &'arr str,
) -> impl FnMut(&'s str) -> IResult<&'s str> + 'parser {
) -> impl FnMut(&'s str) -> IResult<'s, &'s str> + 'parser {
alt((is_not(arr), success("")))
}

Expand All @@ -120,7 +120,7 @@ fn tag_node(s: &str) -> IResult<Node> {
/// Return a parser to match an opening `name` tag and return its options.
fn opening_parser<'name, 's: 'name>(
name: &'name str,
) -> impl FnMut(&'s str) -> IResult<Vec<(&str, &str)>> + 'name {
) -> impl FnMut(&'s str) -> IResult<'s, Vec<(&'s str, &'s str)>> + 'name {
/// List of whitespace-separated `key=val` tuples, where `val` may be
/// empty.
fn options(s: &str) -> IResult<Vec<(&str, &str)>> {
Expand Down Expand Up @@ -148,15 +148,15 @@ fn tag_node(s: &str) -> IResult<Node> {
/// Return a parser to match a closing `name` tag.
fn closing_parser<'parser, 'name: 'parser, 's: 'parser>(
name: &'name str,
) -> impl FnMut(&'s str) -> IResult<()> + 'parser {
) -> impl FnMut(&'s str) -> IResult<'s, ()> + 'parser {
value((), tuple((tag("[/anki:"), tag(name), tag("]"))))
}

/// Return a parser to match and return anything until a closing `name` tag
/// is found.
fn content_parser<'parser, 'name: 'parser, 's: 'parser>(
name: &'name str,
) -> impl FnMut(&'s str) -> IResult<&str> + 'parser {
) -> impl FnMut(&'s str) -> IResult<'s, &'s str> + 'parser {
recognize(many0(pair(not(closing_parser(name)), anychar)))
}

Expand Down
2 changes: 1 addition & 1 deletion rslib/src/card_rendering/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::prelude::*;
use crate::text::decode_entities;
use crate::text::strip_html_for_tts;

impl<'a> CardNodes<'a> {
impl CardNodes<'_> {
pub(super) fn write_without_av_tags(&self) -> String {
AvStripper::new().write(self)
}
Expand Down
4 changes: 2 additions & 2 deletions rslib/src/import_export/package/media.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ impl SafeMediaEntry {
get_checksum: &mut impl FnMut(&str) -> Result<Option<Sha1Hash>>,
) -> Result<bool> {
get_checksum(&self.name)
.map(|opt| opt.map_or(false, |sha1| sha1 == self.sha1.expect("sha1 not set")))
.map(|opt| opt.is_some_and(|sha1| sha1 == self.sha1.expect("sha1 not set")))
}

pub(super) fn has_size_equal_to(&self, other_path: &Path) -> bool {
fs::metadata(other_path).map_or(false, |metadata| metadata.len() == self.size as u64)
fs::metadata(other_path).is_ok_and(|metadata| metadata.len() == self.size as u64)
}

/// Copy the archived file to the target folder, setting its hash if
Expand Down
2 changes: 1 addition & 1 deletion rslib/src/import_export/text/csv/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ fn remove_tags_line_from_reader(reader: &mut (impl Read + Seek)) -> Result<()> {
let mut first_line = String::new();
buf_reader.read_line(&mut first_line)?;
let offset = if strip_utf8_bom(&first_line).starts_with("tags:") {
first_line.as_bytes().len()
first_line.len()
} else {
0
};
Expand Down
2 changes: 1 addition & 1 deletion rslib/src/import_export/text/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ impl NoteContext<'_> {
fn is_guid_dupe(&self) -> bool {
self.dupes
.first()
.map_or(false, |d| d.note.guid == self.note.guid)
.is_some_and(|d| d.note.guid == self.note.guid)
}

fn has_first_field(&self) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion rslib/src/notetype/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fn references_media_field(format: &str) -> bool {
fn captures_contain_field_replacement(caps: Captures) -> bool {
caps.iter()
.skip(1)
.any(|opt| opt.map_or(false, match_contains_field_replacement))
.any(|opt| opt.is_some_and(match_contains_field_replacement))
}

fn match_contains_field_replacement(m: Match) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion rslib/src/notetype/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ fn missing_cloze_filter(
fn has_cloze(template: &Option<ParsedTemplate>) -> bool {
template
.as_ref()
.map_or(false, |t| !t.all_referenced_cloze_field_names().is_empty())
.is_some_and(|t| !t.all_referenced_cloze_field_names().is_empty())
}

impl From<Notetype> for NotetypeProto {
Expand Down
2 changes: 1 addition & 1 deletion rslib/src/scheduler/states/fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static FUZZ_RANGES: [FuzzRange; 3] = [
},
];

impl<'a> StateContext<'a> {
impl StateContext<'_> {
/// Apply fuzz, respecting the passed bounds.
pub(crate) fn with_review_fuzz(&self, interval: f32, minimum: u32, maximum: u32) -> u32 {
self.load_balancer
Expand Down
2 changes: 1 addition & 1 deletion rslib/src/scheduler/states/load_balancer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pub struct LoadBalancerContext<'a> {
fuzz_seed: Option<u64>,
}

impl<'a> LoadBalancerContext<'a> {
impl LoadBalancerContext<'_> {
pub fn find_interval(&self, interval: f32, minimum: u32, maximum: u32) -> Option<u32> {
self.load_balancer.find_interval(
interval,
Expand Down
2 changes: 1 addition & 1 deletion rslib/src/scheduler/states/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ pub(crate) struct StateContext<'a> {
pub preview_delays: PreviewDelays,
}

impl<'a> StateContext<'a> {
impl StateContext<'_> {
/// Return the minimum and maximum review intervals.
/// - `maximum` is `self.maximum_review_interval`, but at least 1.
/// - `minimum` is as passed, but at least 1, and at most `maximum`.
Expand Down
2 changes: 1 addition & 1 deletion rslib/src/scheduler/states/steps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fn to_secs(v: f32) -> u32 {
(v * 60.0) as u32
}

impl<'a> LearningSteps<'a> {
impl LearningSteps<'_> {
/// Takes `steps` as minutes.
pub(crate) fn new(steps: &[f32]) -> LearningSteps<'_> {
LearningSteps { steps }
Expand Down
2 changes: 1 addition & 1 deletion rslib/src/storage/card/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ fn validate_custom_data(json_str: &str) -> Result<()> {
let object: HashMap<&str, Value> =
serde_json::from_str(json_str).or_invalid("custom data not an object")?;
require!(
object.keys().all(|k| k.as_bytes().len() <= 8),
object.keys().all(|k| k.len() <= 8),
"custom data keys must be <= 8 bytes"
);
require!(
Expand Down
4 changes: 2 additions & 2 deletions rslib/src/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ fn render_into(
Ok(())
}

impl<'a> RenderContext<'a> {
impl RenderContext<'_> {
fn evaluate_conditional(&self, key: &str, negated: bool) -> TemplateResult<bool> {
if self.nonempty_fields.contains(key) {
Ok(true ^ negated)
Expand Down Expand Up @@ -904,7 +904,7 @@ fn find_field_references<'a>(

fn is_cloze_conditional(key: &str) -> bool {
key.strip_prefix('c')
.map_or(false, |s| s.parse::<u32>().is_ok())
.is_some_and(|s| s.parse::<u32>().is_ok())
}

// Tests
Expand Down
2 changes: 1 addition & 1 deletion rslib/src/typeanswer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ fn isolate_leading_mark(text: &str) -> Cow<str> {
if text
.chars()
.next()
.map_or(false, |c| GeneralCategory::of(c).is_mark())
.is_some_and(|c| GeneralCategory::of(c).is_mark())
{
Cow::Owned(format!("\u{a0}{text}"))
} else {
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
# older versions may fail to compile; newer versions may fail the clippy tests
channel = "1.82.0"
channel = "1.84.0"

0 comments on commit 92b1144

Please sign in to comment.