Skip to content

Commit 8f4a39d

Browse files
committed
Warn on clippy::pedantic by default
1 parent 7204f13 commit 8f4a39d

File tree

13 files changed

+210
-32
lines changed

13 files changed

+210
-32
lines changed

Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ tokio = { version = "1.31.0", features = ["rt", "macros"] }
2424
signal-hook = "0.3.17"
2525
pollster = "0.4.0"
2626

27+
[lints.clippy]
28+
pedantic = "warn"
29+
allow_attributes = "warn"
30+
allow_attributes_without_reason = "warn"
31+
should_panic_without_expect = "warn"
32+
str_to_string = "warn"
33+
string_to_string = "warn"
34+
cast_possible_wrap = { level = "allow", priority = 1 }
35+
cast_possible_truncation = { level = "allow", priority = 1 }
36+
2737
[features]
2838
tokio = ["dep:tokio", "futures"]
2939
# Experimental and somewhat incomplete

examples/receive-synchronous.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ async fn open_connection() -> ei::Context {
3434
let x = region.x_offset();
3535
let y = region.y_offset();
3636
let w = region.width() as i32;
37-
let h = region.height() as i32;
37+
let _h = region.height() as i32;
3838
Barrier::new(NonZero::new(n as u32 + 1).unwrap(), (x, y, x + w - 1, y))
3939
})
4040
.collect::<Vec<_>>();
@@ -72,7 +72,7 @@ fn main() {
7272
| DeviceCapability::Scroll
7373
| DeviceCapability::Button,
7474
);
75-
context.flush();
75+
let _ = context.flush();
7676
}
7777
reis::event::EiEvent::DeviceAdded(evt) => {
7878
println!(" seat: {:?}", evt.device.seat().name());

src/ei.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ impl Context {
4949
///
5050
/// let context = Context::new(socket).unwrap();
5151
/// ```
52+
///
53+
/// # Errors
54+
///
55+
/// Will return `Err` if setting the socket to non-blocking mode fails.
5256
pub fn new(socket: UnixStream) -> io::Result<Self> {
5357
Ok(Self(Backend::new(socket, true)?))
5458
}
@@ -63,6 +67,11 @@ impl Context {
6367
///
6468
/// let context = Context::connect_to_env().expect("Shouldn't error").unwrap();
6569
/// ```
70+
///
71+
/// # Errors
72+
///
73+
/// Will return `Err` if the resolved socket path cannot be connected to or if
74+
/// [`Context::new`] fails.
6675
pub fn connect_to_env() -> io::Result<Option<Self>> {
6776
let Some(path) = env::var_os("LIBEI_SOCKET") else {
6877
// XXX return error type
@@ -87,6 +96,10 @@ impl Context {
8796
/// Reads any pending data on the socket into the internal buffer.
8897
///
8998
/// Returns `UnexpectedEof` if end-of-file is reached.
99+
///
100+
/// # Errors
101+
///
102+
/// Will return `Err` if there is an I/O error.
90103
pub fn read(&self) -> io::Result<usize> {
91104
self.0.read()
92105
}
@@ -99,11 +112,16 @@ impl Context {
99112

100113
/// Returns the interface proxy for the `ei_handshake` object.
101114
#[must_use]
115+
#[expect(clippy::missing_panics_doc, reason = "infallible; Backend always creates ei_handshake object at 0")]
102116
pub fn handshake(&self) -> handshake::Handshake {
103117
self.0.object_for_id(0).unwrap().downcast_unchecked()
104118
}
105119

106120
/// Sends buffered messages. Call after you're finished with sending requests.
121+
///
122+
/// # Errors
123+
///
124+
/// An error will be returned if sending the buffered messages fails.
107125
pub fn flush(&self) -> rustix::io::Result<()> {
108126
self.0.flush()
109127
}

src/eiproto.rs.jinja

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
{# ei-scanner jinja template, for `` #}
2-
#![allow(unknown_lints, unused_imports, unused_parens, clippy::useless_conversion, clippy::double_parens, clippy::match_single_binding, clippy::unused_unit, clippy::empty_docs, clippy::doc_lazy_continuation)]
2+
#![allow(
3+
unknown_lints,
4+
unused_imports,
5+
unused_parens,
6+
clippy::useless_conversion,
7+
clippy::double_parens,
8+
clippy::match_single_binding,
9+
clippy::unused_unit,
10+
clippy::empty_docs,
11+
clippy::doc_lazy_continuation,
12+
13+
// Explicitly set to warn
14+
clippy::doc_markdown,
15+
clippy::must_use_candidate,
16+
clippy::semicolon_if_nothing_returned,
17+
clippy::used_underscore_binding,
18+
clippy::match_same_arms,
19+
clippy::str_to_string,
20+
)]
321

422
// GENERATED FILE
523

src/eiproto_ei.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@
77
clippy::match_single_binding,
88
clippy::unused_unit,
99
clippy::empty_docs,
10-
clippy::doc_lazy_continuation
10+
clippy::doc_lazy_continuation,
11+
12+
// Explicitly set to warn
13+
clippy::doc_markdown,
14+
clippy::must_use_candidate,
15+
clippy::semicolon_if_nothing_returned,
16+
clippy::used_underscore_binding,
17+
clippy::match_same_arms,
18+
clippy::str_to_string,
1119
)]
1220

1321
// GENERATED FILE

src/eiproto_eis.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@
77
clippy::match_single_binding,
88
clippy::unused_unit,
99
clippy::empty_docs,
10-
clippy::doc_lazy_continuation
10+
clippy::doc_lazy_continuation,
11+
12+
// Explicitly set to warn
13+
clippy::doc_markdown,
14+
clippy::must_use_candidate,
15+
clippy::semicolon_if_nothing_returned,
16+
clippy::used_underscore_binding,
17+
clippy::match_same_arms,
18+
clippy::str_to_string,
1119
)]
1220

1321
// GENERATED FILE

src/eis.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,23 @@ pub struct Listener {
2929
impl Listener {
3030
// TODO Use a lock here
3131
/// Listens on a specific path.
32+
///
33+
/// # Errors
34+
///
35+
/// Will return `Err` if binding to the given path or setting the socket to
36+
/// non-blocking mode fails.
3237
pub fn bind(path: &Path) -> io::Result<Self> {
3338
Self::bind_inner(PathBuf::from(path), None)
3439
}
3540

3641
// XXX result type?
3742
// Error if XDG_RUNTIME_DIR not set?
3843
/// Listens on a file in `XDG_RUNTIME_DIR`.
44+
///
45+
/// # Errors
46+
///
47+
/// Will return `Err` if a lock file cannot be locked, binding to the generated path
48+
/// fails or setting the socket to non-blocking mode fails.
3949
pub fn bind_auto() -> io::Result<Option<Self>> {
4050
let xdg_dir = if let Some(var) = env::var_os("XDG_RUNTIME_DIR") {
4151
PathBuf::from(var)
@@ -65,6 +75,10 @@ impl Listener {
6575
}
6676

6777
/// Accepts a connection from a client. Returns `Ok(Some(_)` if an incoming connection is ready, and `Ok(None)` if there is no connection ready (would block).
78+
///
79+
/// # Errors
80+
///
81+
/// Will return `Err` if [`Context::new`] fails.
6882
pub fn accept(&self) -> io::Result<Option<Context>> {
6983
match self.listener.accept() {
7084
Ok((socket, _)) => Ok(Some(Context::new(socket)?)),
@@ -116,13 +130,21 @@ impl Context {
116130
///
117131
/// // Pass the `b` file descriptor to implement the RemoteDesktop XDG desktop portal
118132
/// ```
133+
///
134+
/// # Errors
135+
///
136+
/// Will return `Err` if setting the socket to non-blocking mode fails.
119137
pub fn new(socket: UnixStream) -> io::Result<Self> {
120138
Ok(Self(Backend::new(socket, false)?))
121139
}
122140

123141
/// Reads any pending data on the socket into the internal buffer.
124142
///
125143
/// Returns `UnexpectedEof` if end-of-file is reached.
144+
///
145+
/// # Errors
146+
///
147+
/// Will return `Err` if there is an I/O error.
126148
pub fn read(&self) -> io::Result<usize> {
127149
self.0.read()
128150
}
@@ -135,11 +157,16 @@ impl Context {
135157

136158
/// Returns the interface proxy for the `ei_handshake` object.
137159
#[must_use]
160+
#[expect(clippy::missing_panics_doc, reason = "infallible; Backend always creates ei_handshake object at 0")]
138161
pub fn handshake(&self) -> handshake::Handshake {
139162
self.0.object_for_id(0).unwrap().downcast_unchecked()
140163
}
141164

142165
/// Sends buffered messages. Call after you're finished with sending events.
166+
///
167+
/// # Errors
168+
///
169+
/// An error will be returned if sending the buffered messages fails.
143170
pub fn flush(&self) -> rustix::io::Result<()> {
144171
self.0.flush()
145172
}

src/event.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ impl Connection {
7878
}
7979

8080
/// Sends buffered messages. Call after you're finished with sending requests.
81+
///
82+
/// # Errors
83+
///
84+
/// An error will be returned if sending the buffered messages fails.
8185
pub fn flush(&self) -> rustix::io::Result<()> {
8286
self.0.context.flush()
8387
}
@@ -159,6 +163,7 @@ impl EiEventConverter {
159163
/// # Errors
160164
///
161165
/// The errors returned are protocol violations.
166+
#[expect(clippy::too_many_lines, reason = "Handler is allowed to be big")]
162167
pub fn handle_event(&mut self, event: ei::Event) -> Result<(), EventError> {
163168
match event {
164169
ei::Event::Handshake(_handshake, _event) => {
@@ -171,7 +176,7 @@ impl EiEventConverter {
171176
SeatInner {
172177
proto_seat: seat,
173178
name: None,
174-
capability_map: Default::default(),
179+
capability_map: CapabilityMap::default(),
175180
},
176181
);
177182
}
@@ -286,7 +291,7 @@ impl EiEventConverter {
286291
.ok_or(EventError::DeviceSetupEventAfterDone)?;
287292
device
288293
.interfaces
289-
.insert(object.interface().to_string(), object);
294+
.insert(object.interface().to_owned(), object);
290295
}
291296
ei::device::Event::Dimensions { width, height } => {
292297
let device = self
@@ -702,8 +707,8 @@ impl DeviceCapability {
702707

703708
/// Returns the binary logarithm of the capability's bitwise value, useful for indexing
704709
/// lookup tables.
705-
fn index(&self) -> usize {
706-
(*self as u64).trailing_zeros() as usize
710+
fn index(self) -> usize {
711+
(self as u64).trailing_zeros() as usize
707712
}
708713
}
709714

@@ -828,6 +833,10 @@ impl Device {
828833

829834
/// Returns the device's type.
830835
#[must_use]
836+
#[expect(
837+
clippy::missing_panics_doc,
838+
reason = "EiEventConverter makes sure to not return Device if device_type is None"
839+
)]
831840
pub fn device_type(&self) -> ei::device::DeviceType {
832841
self.0.device_type.unwrap()
833842
}
@@ -1306,6 +1315,11 @@ impl Iterator for EiConvertEventIterator {
13061315
}
13071316

13081317
impl ei::Context {
1318+
/// Executes the handshake in blocking mode.
1319+
///
1320+
/// # Errors
1321+
///
1322+
/// Will return `Err` if there is an I/O error or a protocol violation.
13091323
pub fn handshake_blocking(
13101324
&self,
13111325
name: &str,

src/handshake.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ impl<'a> EiHandshaker<'a> {
7373
}
7474
}
7575

76+
/// Handles the given event, possibly returning a filled handshake response.
77+
///
78+
/// # Errors
79+
///
80+
/// The errors returned are protocol violations.
7681
pub fn handle_event(
7782
&mut self,
7883
event: ei::Event,
@@ -120,6 +125,11 @@ pub(crate) fn request_result<T>(result: PendingRequestResult<T>) -> Result<T, Er
120125
}
121126
}
122127

128+
/// Executes the handshake in blocking mode.
129+
///
130+
/// # Errors
131+
///
132+
/// Will return `Err` if there is an I/O error or a protocol violation.
123133
pub fn ei_handshake_blocking(
124134
context: &ei::Context,
125135
name: &str,
@@ -170,6 +180,11 @@ impl EisHandshaker {
170180
}
171181
}
172182

183+
/// Handles the given request, possibly returning a filled handshake response.
184+
///
185+
/// # Errors
186+
///
187+
/// The errors returned are protocol violations.
173188
pub fn handle_request(
174189
&mut self,
175190
request: eis::Request,
@@ -195,7 +210,7 @@ impl EisHandshaker {
195210
if let Some((interface, server_version)) = interfaces().get_key_value(name.as_str())
196211
{
197212
self.negotiated_interfaces
198-
.insert((*interface).to_string(), version.min(*server_version));
213+
.insert((*interface).to_owned(), version.min(*server_version));
199214
}
200215
}
201216
eis::handshake::Request::Finish => {

0 commit comments

Comments
 (0)