diff --git a/Cargo.toml b/Cargo.toml index 81bbdebeb39..80a0e86e6d3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -382,10 +382,12 @@ use_self = "warn" useless_let_if_seq = "warn" # pedantic lints to enforce gradually +bool_to_int_with_if = "warn" checked_conversions = "warn" cloned_instead_of_copied = "warn" collapsible_else_if = "warn" comparison_chain = "warn" +doc_link_with_quotes = "warn" duration_suboptimal_units = "warn" explicit_deref_methods = "warn" explicit_into_iter_loop = "warn" @@ -397,8 +399,11 @@ from_iter_instead_of_collect = "warn" inconsistent_struct_constructor = "warn" index_refutable_slice = "warn" inefficient_to_string = "warn" +ip_constant = "warn" iter_filter_is_ok = "warn" iter_filter_is_some = "warn" +large_futures = "warn" +manual_instant_elapsed = "warn" manual_is_variant_and = "warn" map_unwrap_or = "warn" match_bool = "warn" @@ -406,10 +411,17 @@ must_use_candidate = "warn" mut_mut = "warn" needless_bitwise_bool = "warn" needless_for_each = "warn" +non_std_lazy_statics = "warn" option_as_ref_cloned = "warn" ptr_offset_by_literal = "warn" +range_minus_one = "warn" +range_plus_one = "warn" redundant_else = "warn" return_self_not_must_use = "warn" +single_char_pattern = "warn" +unchecked_time_subtraction = "warn" uninlined_format_args = "warn" +unnecessary_box_returns = "warn" +unnecessary_join = "warn" unnecessary_wraps = "warn" unnested_or_patterns = "warn" diff --git a/crates/codegen/src/compile.rs b/crates/codegen/src/compile.rs index c3b86ce46bc..9fde1fc0841 100644 --- a/crates/codegen/src/compile.rs +++ b/crates/codegen/src/compile.rs @@ -4411,10 +4411,10 @@ impl Compiler { .chain(parameters.kwonlyargs.iter().map(|x| &x.parameter)) .chain(parameters.kwarg.as_deref()); - let num_annotations: u32 = + let num_annotations = u32::try_from(parameters_iter.filter(|p| p.annotation.is_some()).count()) .expect("too many annotations") - + if returns.is_some() { 1 } else { 0 }; + + u32::from(returns.is_some()); // Compile annotations inside the annotation scope let parameters_iter = parameters @@ -6925,7 +6925,7 @@ impl Compiler { let has_default = num_cases > 1 && is_trailing_wildcard_default(&cases.last().unwrap().pattern); - let case_count = num_cases - if has_default { 1 } else { 0 }; + let case_count = num_cases - usize::from(has_default); for (i, m) in cases.iter().enumerate().take(case_count) { // Only copy the subject if not on the last case if i != case_count - 1 { diff --git a/crates/host_env/src/ctypes.rs b/crates/host_env/src/ctypes.rs index ae64b06cfe0..9bfd41c2818 100644 --- a/crates/host_env/src/ctypes.rs +++ b/crates/host_env/src/ctypes.rs @@ -1096,7 +1096,7 @@ pub fn simple_storage_value_to_bytes_endian( result } "?" => match value { - SimpleStorageValue::Bool(value) => vec![if value { 1 } else { 0 }], + SimpleStorageValue::Bool(value) => vec![u8::from(value)], _ => vec![0], }, "v" => match value { @@ -1435,11 +1435,7 @@ pub fn ffi_value_from_type_code(type_code: &str, buffer: &[u8]) -> FfiValue { .map_or(0.0, f64::from_ne_bytes), ), "z" | "Z" | "P" | "O" => FfiValue::Pointer(read_pointer_from_buffer(buffer)), - "?" => FfiValue::U8(if buffer.first().is_some_and(|&b| b != 0) { - 1 - } else { - 0 - }), + "?" => FfiValue::U8(u8::from(buffer.first().is_some_and(|&b| b != 0))), "u" => FfiValue::U32(buffer.first_chunk().copied().map_or(0, u32::from_ne_bytes)), _ => FfiValue::Pointer(0), } diff --git a/crates/host_env/src/overlapped.rs b/crates/host_env/src/overlapped.rs index d84897d620d..be5e75f585f 100644 --- a/crates/host_env/src/overlapped.rs +++ b/crates/host_env/src/overlapped.rs @@ -892,7 +892,7 @@ unsafe extern "system" fn post_to_queue_callback( unsafe { let _ = windows_sys::Win32::System::IO::PostQueuedCompletionStatus( data.completion_port, - if timer_or_wait_fired { 1 } else { 0 }, + u32::from(timer_or_wait_fired), 0, data.overlapped, ); diff --git a/crates/stdlib/src/ssl.rs b/crates/stdlib/src/ssl.rs index d4a01c9b131..35cb1794045 100644 --- a/crates/stdlib/src/ssl.rs +++ b/crates/stdlib/src/ssl.rs @@ -3496,7 +3496,7 @@ mod _ssl { // When server_hostname=None, use an IP address to suppress SNI // no hostname = no SNI extension ServerName::IpAddress( - core::net::IpAddr::V4(core::net::Ipv4Addr::new(127, 0, 0, 1)).into(), + core::net::IpAddr::V4(core::net::Ipv4Addr::LOCALHOST).into(), ) }; diff --git a/crates/vm/src/builtins/range.rs b/crates/vm/src/builtins/range.rs index ef141cdd69d..415d34fdb05 100644 --- a/crates/vm/src/builtins/range.rs +++ b/crates/vm/src/builtins/range.rs @@ -406,12 +406,7 @@ impl Py { #[pymethod] fn count(&self, item: PyObjectRef, vm: &VirtualMachine) -> PyResult { if let Ok(int) = item.clone().downcast::() { - let count = if self.index_of(int.as_bigint()).is_some() { - 1 - } else { - 0 - }; - Ok(count) + Ok(usize::from(self.index_of(int.as_bigint()).is_some())) } else { // Dealing with classes who might compare equal with ints in their // __eq__, slow search. diff --git a/crates/vm/src/stdlib/_ast.rs b/crates/vm/src/stdlib/_ast.rs index 57da9b3c3a8..38e0d546f44 100644 --- a/crates/vm/src/stdlib/_ast.rs +++ b/crates/vm/src/stdlib/_ast.rs @@ -512,14 +512,17 @@ pub(crate) fn parse_func_type( fn type_ignores_from_source(vm: &VirtualMachine, source: &str) -> Vec { let mut ignores = Vec::new(); for (idx, line) in source.lines().enumerate() { - let Some(pos) = line.find("#") else { + let Some(pos) = line.find('#') else { continue; }; + let comment = &line[pos + 1..]; let comment = comment.trim_start(); + let Some(rest) = comment.strip_prefix("type: ignore") else { continue; }; + let tag = rest.trim_start(); let tag = if tag.is_empty() { "" } else { tag }; let node = NodeAst diff --git a/crates/vm/src/stdlib/_ctypes/base.rs b/crates/vm/src/stdlib/_ctypes/base.rs index a339e362786..62856c4cef8 100644 --- a/crates/vm/src/stdlib/_ctypes/base.rs +++ b/crates/vm/src/stdlib/_ctypes/base.rs @@ -1111,11 +1111,7 @@ impl PyCData { fn _b_needsfree_(&self) -> i32 { // Borrowed (from_address) or has base object → 0 (don't free) // Owned and no base → 1 (need to free) - if self.is_borrowed() || self.base.read().is_some() { - 0 - } else { - 1 - } + i32::from(!(self.is_borrowed() || self.base.read().is_some())) } // CDataType_methods - shared across all ctypes types diff --git a/crates/vm/src/warn.rs b/crates/vm/src/warn.rs index 081a9621ba1..6500e8de0f6 100644 --- a/crates/vm/src/warn.rs +++ b/crates/vm/src/warn.rs @@ -138,7 +138,7 @@ fn get_warnings_attr( module.get_attr(attr_name, vm).ok() } -/// Get the warnings filters list from sys.modules['warnings'].filters, +/// Get the warnings filters list from `sys.modules['warnings'].filters`, /// falling back to vm.state.warnings.filters. fn get_warnings_filters(vm: &VirtualMachine) -> PyListRef { if let Some(filters_obj) = get_warnings_attr(vm, identifier!(&vm.ctx, filters), false) @@ -149,7 +149,7 @@ fn get_warnings_filters(vm: &VirtualMachine) -> PyListRef { vm.state.warnings.filters.clone() } -/// Get the default action from sys.modules['warnings']._defaultaction, +/// Get the default action from `sys.modules['warnings']._defaultaction`, /// falling back to vm.state.warnings.default_action. fn get_default_action(vm: &VirtualMachine) -> PyResult { if let Some(action) = get_warnings_attr(vm, identifier!(&vm.ctx, defaultaction), false) { @@ -164,7 +164,7 @@ fn get_default_action(vm: &VirtualMachine) -> PyResult { Ok(vm.state.warnings.default_action.clone().into()) } -/// Get the once registry from sys.modules['warnings']._onceregistry, +/// Get the once registry from `sys.modules['warnings']._onceregistry`, /// falling back to vm.state.warnings.once_registry. fn get_once_registry(vm: &VirtualMachine) -> PyResult { if let Some(registry) = get_warnings_attr(vm, identifier!(&vm.ctx, onceregistry), false) {