Skip to content

Manual clippy fixes#1111

Merged
lionel- merged 34 commits intomainfrom
task/clippy-manual
Mar 16, 2026
Merged

Manual clippy fixes#1111
lionel- merged 34 commits intomainfrom
task/clippy-manual

Conversation

@lionel-
Copy link
Contributor

@lionel- lionel- commented Mar 12, 2026

Branched from #1108
Progress towards #1104

Main lints fixed:

  • Too many arguments
  • Unnecessary try_ conversions (can just use non-failing conversions)
  • Large enum variants. Sometimes fixed by boxing, sometimes by disabling the lint.
  • Use &str instead of &String, &Path instead of &PathBuf, &[] instead of &Vec
  • Clippy doesn't like uppercase variants like EOF, so they've become e.g. EndOfFile
  • Removed common prefixes/suffixes from enum variants. I added an opt out for the LSP notification enum so we can keep the Did prefix, e.g. KernelNotification::DidOpenVirtualDocument.
  • into_ methods must take self. Renamed those that didn't, e.g. Dap::make_variables() which is not really an "into" method strictly speaking.
  • Simplified unnecessary uses of match
  • Use .is_some() or is_err() methods when applicable
  • Use ? instead of explicit return when applicable
  • Build regex in lazy globals

}

/// Handler implementations provided by the language runtime.
pub struct Handlers {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These new structs fix the "too many arguments" lint.

}

/// Send an outgoing comm message through IOPub.
#[allow(clippy::result_large_err)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably one I would perma-allow in Cargo.toml

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like individual crates can re-opt into lints disabled at workspace level if needed, so that approach sounds good to me

Comment on lines 18 to 19
#[allow(clippy::large_enum_variant)]
pub mod data_explorer_comm;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As of late last year, clippy has gained expect() rather than allow() which I think is quite nice.
https://users.rust-lang.org/t/dont-allow-expect-and-be-reasonable/136078

allow() says "if there is a problem, ignore it"

expect() says "there is a problem, ignore it, but also let me know if it isnt there anymore", which allows you to remove the expect() if it goes away at some point in the future

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh that's nice!

Copy link
Contributor Author

@lionel- lionel- Mar 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switching to expect() already allowed finding some dangling opt-outs for deref lints, following the SEXP repr PR!

Comment on lines +63 to +99
iopub_tx: Sender<IOPubMessage>,
iopub_rx: Receiver<IOPubMessage>,
comm_event_rx: Receiver<CommEvent>,
// Receiver channel for the stdin socket; when input is needed, the
// language runtime can request it by sending an StdInRequest::Input to
// this channel. The frontend will prompt the user for input and
// the reply will be delivered via `stdin_reply_tx`.
// https://jupyter-client.readthedocs.io/en/stable/messaging.html#messages-on-the-stdin-router-dealer-channel.
// Note that we've extended the StdIn socket to support synchronous requests
// from a comm, see `StdInRequest::Comm`.
stdin_request_rx: Receiver<StdInRequest>,
// Transmission channel for StdIn replies
stdin_reply_tx: Sender<crate::Result<InputReply>>,
channels: ConnectionChannels,
) -> Result<(), Error> {
let Handlers {
shell_handler,
control_handler,
server_handlers,
} = handlers;
let ConnectionChannels {
iopub_tx,
iopub_rx,
comm_event_rx,
stdin_request_rx,
stdin_reply_tx,
} = channels;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me, packing and immediately unpacking is more noise, and I'd just ignore clippy here.

Copy link
Contributor Author

@lionel- lionel- Mar 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know, if feels a bit more tidy to me.

Although the unpacking is unnecessary, I'll remove it

R_INIT.set(()).expect("`R_INIT` can only be set once");
}

#[allow(clippy::too_many_arguments)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would personally perma ignore, I can decide if it is too many arguments or not 😛

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't feel strongly either way so I'll perma-ignore.

I do like packed arguments in the kernel connection entry points as it makes call sites easier to read and understand. But I can see cases where that doesn't make sense.

Comment on lines -396 to +397
NULL,
NA,
NaN,
Null,
Na,
Nan,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Booo I like mimicking the R values!

Comment on lines +65 to +73
// /// Move this cursor to the node that is at or closest to (but not after)
// /// the requested point.
// ///
// /// Returns `false` if the cursor is after the `point`.
// ///
// /// TODO: It would be nice to use this, but there is a bug in tree sitter
// /// that makes it impossible right now:
// /// https://github.com/tree-sitter/tree-sitter/issues/2767
// /// For now, use `node.find_closest_node_for_point()`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you meant to remove a / not add more

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope I actually commented out the docstring

Comment on lines +24 to +25
// Point is a small Copy type, so it's fine to pass by value
#[allow(clippy::wrong_self_convention)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is a little weird for is_ methods though

Comment on lines -287 to +290
NodeType::UnaryOperator(op) => match op {
UnaryOperatorType::Tilde => recurse_formula(node, context, diagnostics),
_ => recurse_default(node, context, diagnostics),
NodeType::UnaryOperator(UnaryOperatorType::Tilde) => {
recurse_formula(node, context, diagnostics)
},
NodeType::UnaryOperator(_) => recurse_default(node, context, diagnostics),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im not really sure if i like that

sizeof_node: usize,
sizeof_vector: usize,
seen: &mut HashSet<SEXP>,
depth: u32,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this have been used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In lobstr it's only used in debugging print statements that are commented out.

Comment on lines +33 to +49
@@ -45,7 +46,7 @@ macro_rules! generate {
$(#[doc=$doc])*
$(#[cfg($cfg)])*
pub fn $name() -> bool {
unsafe { matches!([<$name _opt>], Some(_)) }
unsafe { (*std::ptr::addr_of!([<$name _opt>])).is_some() }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is clippy upset about here? This seems fine to me.

Is it possible to leave this and functions.rs as is for now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current versions are accessing static mut references, which the Rust community has been trying to phase out (rust-lang/rust#53639). The new ones are creating raw pointers instead, to be accessed by unsafe code.

Since you wrote these macros I've reverted, but I'd have kept the new versions I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually the switch to is_some() creates a reference that is linted by rustc, not just clippy. I'd keep the new versions.

@lionel- lionel- force-pushed the task/clippy-unsafe branch from 491100b to 7de2cc8 Compare March 16, 2026 10:49
Base automatically changed from task/clippy-unsafe to main March 16, 2026 11:09
lionel- added 12 commits March 16, 2026 12:15
As of late last year, clippy has gained expect() rather than allow()
which I think is quite nice.
https://users.rust-lang.org/t/dont-allow-expect-and-be-reasonable/136078

allow() says "if there is a problem, ignore it"

expect() says "there is a problem, ignore it, but also let me know if it
isnt there anymore", which allows you to remove the expect() if it goes
away at some point in the future
Fixes:

warning: creating a shared reference to mutable static
--> crates/libr/src/functions.rs:46:25
|
46 |                           [<$name _opt>].is_some()
|                           ^^^^^^^^^^^^^^ shared reference to mutable static
|
::: crates/libr/src/r.rs:21:1
|
21 | / functions::generate! {
22 | |     pub fn R_NewEnv(enclos: SEXP, hash: std::ffi::c_int, size:
std::ffi::c_int) -> SEXP;
23 | |
24 | |     pub fn R_ParentEnv(x: SEXP) -> SEXP;
...   |
444 | | }
| |_- in this macro invocation
@lionel- lionel- force-pushed the task/clippy-manual branch from 6b7a977 to 529fc05 Compare March 16, 2026 12:28
@lionel- lionel- merged commit ba23fce into main Mar 16, 2026
12 checks passed
@lionel- lionel- deleted the task/clippy-manual branch March 16, 2026 12:52
@github-actions github-actions bot locked and limited conversation to collaborators Mar 16, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants