-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Fix nightly clippy warnings #5803
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughThis update modernizes string formatting throughout the codebase by adopting Rust's inline variable interpolation syntax (Rust 1.58+), replacing older positional formatting and explicit argument passing. Additionally, minor refactoring was performed to simplify assignment and control flow in a few locations, with no changes to logic, error handling, or public interfaces. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Application
participant Logger
User->>Application: Trigger action (e.g., command, REPL, error)
Application->>Logger: Log message with inline variable formatting
Logger-->>Application: Handles formatted output
Application-->>User: Continue execution or return result
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (21)
✅ Files skipped from review due to trivial changes (2)
🚧 Files skipped from review as they are similar to previous changes (19)
⏰ Context from checks skipped due to timeout of 90000ms (11)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (9)
src/shell.rs (1)
155-155
: Consider whether logging raw REPL input is desirable
debug!("You entered {line:?}");
will emit every line the user types – including potentially sensitive data – to the log at debug level.
If the interactive shell can ever run in production or be embedded in another process that collects logs, this could leak secrets.-debug!("You entered {line:?}"); +// Debug-level logging can expose user input verbatim; enable only when really useful. +debug!(target: "repl", "You entered {line:?}");Alternatively gate the statement behind a feature flag or redact long inputs.
vm/src/frame.rs (1)
1670-1670
: Debug message looks good, just watch allocation cost
debug!("Exception raised: {exception:?} …")
allocates the fullDebug
representation of the exception even when thedebug
level is disabled, becauselog
still formats the message inside the macro.
If the exception objects can be large or contain heavy.repr()
implementations, you might prefer:if log::log_enabled!(log::Level::Debug) { debug!("Exception raised: {exception:?} with cause: {cause:?}"); }Purely optional; current code is acceptable for most cases.
vm/src/stdlib/ctypes/base.rs (1)
254-254
: Nit: minor wording tweakThe message now reads “Array length must be >= 0, not {n}”.
Consider adding a space after the comma for consistency with other errors:-return Err(vm.new_value_error(format!("Array length must be >= 0, not {n}"))); +return Err(vm.new_value_error(format!("array length must be >= 0, not {n}")));Also lower-case the first word to follow CPython style. Optional.
vm/src/vm/compile.rs (1)
52-52
: OK, but think about back-pressure instead ofprocess::exit
Logging improved; however, the block still terminates the whole VM on an IO error.
For library users this is surprising. Returning anErr
upward would give callers control.Out of scope for this PR, just flagging.
vm/src/stdlib/ctypes/function.rs (1)
80-86
: Consider usingCString
to guard against interior NULs
format!("{function}\0")
is concise, but it silently accepts function names that might already contain'\0'
, producing an over-long C string.
Wrapping the name inCString::new()
would validate this upfront and avoid undefined behaviour when the symbol is looked up.+use std::ffi::CString; ... - let terminated = format!("{function}\0"); - let pointer: Symbol<'_, FP> = unsafe { - library - .get(terminated.as_bytes()) + let terminated = CString::new(function) + .map_err(|_| vm.new_value_error("Function name contains NUL byte".to_owned()))?; + let pointer: Symbol<'_, FP> = unsafe { + library + .get(terminated.as_c_str().to_bytes_with_nul()) .map_err(|err| err.to_string()) .map_err(|err| vm.new_attribute_error(err))? };Would you like a follow-up patch covering the additional
use std::ffi::CString;
import and the error mapping?vm/src/builtins/object.rs (1)
55-62
: Minor wording polish for the new error message
"class {name} without an implementation for abstract method …"
reads a little awkwardly.
Consider adding a verb for clarity:-return Err(vm.new_type_error(format!( - "class {name} without an implementation for abstract method '{methods}'" -))); +return Err(vm.new_type_error(format!( + "class {name} has no implementation for abstract method '{methods}'" +)));Same tweak applies to the plural branch below.
stdlib/src/csv.rs (1)
350-351
: Redundantto_string()
allocation
format!
already returns aString
; the extra.to_string()
just clones the
buffer.-return Err(vm.new_type_error( - format!("field_size_limit() takes at most 1 argument ({arg_len} given)") - .to_string(), -)); +return Err(vm.new_type_error(format!( + "field_size_limit() takes at most 1 argument ({arg_len} given)" +)));This shaves an allocation and removes a clippy
inherent_to_string
warning.vm/src/exceptions.rs (1)
208-210
: Minor allocation nit: avoid an extraString
filename_suffix = format!(" ({filename})");
allocates a newString
.
Becausefilename_suffix
is only appended once, a cheaper option is:-filename_suffix = format!(" ({filename})"); +filename_suffix.push_str(" ("); +filename_suffix.push_str(filename.as_str()); +filename_suffix.push(')');Not critical, just a micro-optimisation.
vm/src/builtins/complex.rs (1)
65-72
: Consider printing the type’s Python-level name
{ret_class}
ends up usingDisplay
forPy<PyType>
, which produces something like<class 'complex'>
.
If you want the message to mirror CPython more closely and avoid the pointer-like wrapper you could use:-format!( - "__complex__ returned non-complex (type {ret_class}). \ +format!( + "__complex__ returned non-complex (type {}). \ The ability to return an instance of a strict subclass of complex \ is deprecated, and may be removed in a future version of Python.", - ret_class.name(), // <-- uses the type’s __name__ -) + ret_class.name(), +)Purely cosmetic; existing code compiles and behaves correctly.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (21)
src/lib.rs
(1 hunks)src/shell.rs
(1 hunks)stdlib/src/binascii.rs
(1 hunks)stdlib/src/csv.rs
(2 hunks)vm/src/buffer.rs
(2 hunks)vm/src/builtins/complex.rs
(1 hunks)vm/src/builtins/object.rs
(1 hunks)vm/src/builtins/property.rs
(1 hunks)vm/src/builtins/super.rs
(1 hunks)vm/src/codecs.rs
(2 hunks)vm/src/eval.rs
(1 hunks)vm/src/exceptions.rs
(3 hunks)vm/src/frame.rs
(1 hunks)vm/src/protocol/number.rs
(4 hunks)vm/src/stdlib/ctypes/base.rs
(1 hunks)vm/src/stdlib/ctypes/function.rs
(1 hunks)vm/src/stdlib/ctypes/structure.rs
(1 hunks)vm/src/stdlib/io.rs
(1 hunks)vm/src/stdlib/posix.rs
(2 hunks)vm/src/stdlib/sys.rs
(2 hunks)vm/src/vm/compile.rs
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (11)
- GitHub Check: Run tests under miri
- GitHub Check: Run snippets and cpython tests (ubuntu-latest)
- GitHub Check: Run snippets and cpython tests on wasm-wasi
- GitHub Check: Run snippets and cpython tests (macos-latest)
- GitHub Check: Run rust tests (ubuntu-latest)
- GitHub Check: Run snippets and cpython tests (windows-latest)
- GitHub Check: Check Rust code with rustfmt and clippy
- GitHub Check: Check the WASM package and demo
- GitHub Check: Run rust tests (windows-latest)
- GitHub Check: Ensure compilation on various targets
- GitHub Check: Run rust tests (macos-latest)
🔇 Additional comments (17)
vm/src/eval.rs (1)
6-6
: LGTM – modernised formatting onlyInline interpolation compiles fine and is cheaper to read. No further issues spotted.
vm/src/stdlib/ctypes/structure.rs (1)
56-57
: Modernised formatting looks goodInline named-parameter formatting is clearer and resolves the recent
clippy::uninlined_format_args
lint.
No further issues spotted.vm/src/builtins/super.rs (1)
128-130
: Nice simplification – avoidsstd::mem::swap
Replacing the swap with direct assignment via the write guard is clearer and equally safe; lock scope remains minimal because the heavy construction happens beforehand.
stdlib/src/binascii.rs (1)
758-760
: Updated error string – no concernsThe inline placeholder removes the unnecessary positional argument, matching the clippy fix across the PR.
vm/src/stdlib/posix.rs (2)
1992-1992
: Modernize formatting with inline variable interpolation
Replacingformat!("{:?}", variant)
withformat!("{variant:?}")
here is correct and consistent with the PR’s style updates.
2188-2188
: Modernize formatting with inline variable interpolation
This change mirrors the one above forsysconf_names
and correctly uses named interpolation forvariant
.vm/src/builtins/property.rs (1)
135-136
: Use inline formatting for error message
Switching to"{func_args_len}"
interpolation is stylistic only and aligns with the project’s formatting conventions.vm/src/buffer.rs (2)
367-367
: Use inline variable formatting in debug log
Updating todebug!("code: {code:?}")
follows the new inline formatting style and has no impact on functionality.
410-410
: Use inline variable formatting in debug log
Consistent with other debug statements, this change improves clarity without altering behavior.vm/src/stdlib/io.rs (1)
1163-1181
: Clearer vector restoration via direct assignment – looks goodReplacing the previous buffer-swap logic with a single
*v = read_buf.take();
cleanly moves the data back into the caller-suppliedVec<u8>
without extra allocations or indirection.
Behavior, ownership semantics, and safety remain intact. Nice simplification.vm/src/stdlib/sys.rs (1)
320-323
: Modernised formatting looks goodThe change to inline interpolation (
{e}
,{threshold:?}
) keeps behaviour intact and silences the new clippy lint.
No functional, performance or style issues spotted here.Also applies to: 726-727
vm/src/codecs.rs (2)
420-423
: Redundantreturn
successfully removed – stylistic winReplacing
return Some(Self::Utf32Be)
/return None
style with bare expression keeps the arm consistent with the others and is more idiomatic Rust. No functional impact noticed.
1108-1120
: Uniform early-exit style inreplace_errors
The last branch now ends with
Err(bad_err_type(err, vm))
instead of an explicitreturn
. This mirrors the earlier branches, trims one level of indentation, and leaves behaviour unchanged. 👍vm/src/exceptions.rs (2)
212-218
: Inline-interpolation upgrade looks goodSwitching to
writeln!(output, " {l_text}")?;
matches the new Rust 1.58-style formatting adopted in the rest of the PR. Functionality unchanged.
1613-1620
: Consistent formatting inPySyntaxError::__str__
Modern interpolation (
{msg}
,{lineno}
) improves readability with no behavioural change. Verified that the underlying variables are alreadyPyStrRef
orString
, soDisplay
is implemented.src/lib.rs (2)
200-200
: Modernize debug log for command with inline variable interpolation
Clippy warnings are resolved and behavior is unchanged.
205-205
: Modernize debug log for module with inline variable interpolation
Consistent with the new Rust 1.58+ formatting style and no change in functionality.
@coolreader18 redoxer-action is broken |
Summary by CodeRabbit