Skip to content
This repository was archived by the owner on Mar 4, 2024. It is now read-only.

Commit ca08014

Browse files
authored
Merge pull request #30 from gtk-rs/bilelmoussaoui/ci-clippy
CI: add a clippy job
2 parents 1126eff + ec7dbdc commit ca08014

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+244
-274
lines changed

.github/workflows/CI.yml

+68
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,74 @@ jobs:
223223
command: fmt
224224
args: --all -- --check
225225

226+
clippy:
227+
name: clippy
228+
runs-on: ubuntu-latest
229+
container:
230+
image: ubuntu:20.10
231+
steps:
232+
- run: apt-get update -y
233+
- run: apt-get install -y libgtk-3-dev libglib2.0-dev libgraphene-1.0-dev git xvfb curl libcairo-gobject2 libcairo2-dev
234+
- uses: actions/checkout@v2
235+
- uses: actions-rs/toolchain@v1
236+
with:
237+
profile: minimal
238+
toolchain: stable
239+
override: true
240+
- run: rustup component add clippy
241+
242+
- working-directory: atk
243+
name: atk
244+
run: cargo clippy --features "v2_34" --all-targets -- -D warnings
245+
246+
- working-directory: cairo
247+
name: cairo
248+
run: cargo clippy --features "png,pdf,svg,ps,use_glib,v1_16,freetype,script,xcb,xlib,win32-surface" --all-targets -- -D warnings
249+
250+
- working-directory: examples
251+
name: examples
252+
run: cargo clippy --all-features --all-targets -- -D warnings
253+
254+
- working-directory: gdk
255+
name: gdk
256+
run: cargo clippy --features "v3_24" --all-targets -- -D warnings
257+
258+
- working-directory: gdk-pixbuf
259+
name: gdk-pixbuf
260+
run: cargo clippy --features "v2_40" --all-targets -- -D warnings
261+
262+
- working-directory: gdkx11
263+
name: gdkx11
264+
run: cargo clippy --features "v3_24" --all-targets -- -D warnings
265+
266+
- working-directory: gio
267+
name: gio
268+
run: cargo clippy --features "v2_66" --all-targets -- -D warnings
269+
270+
- working-directory: glib
271+
name: glib
272+
run: cargo clippy --features "v2_66" --all-targets -- -D warnings
273+
274+
- working-directory: glib-macros
275+
name: glib-macros
276+
run: cargo clippy --all-targets -- -D warnings
277+
278+
- working-directory: graphene
279+
name: graphene
280+
run: cargo clippy --features "v1_10" --all-targets -- -D warnings
281+
282+
- working-directory: gtk
283+
name: gtk
284+
run: cargo clippy --features "v3_24_9" --all-targets -- -D warnings
285+
286+
- working-directory: pango
287+
name: pango
288+
run: cargo clippy --features "v1_46" --all-targets -- -D warnings
289+
290+
- working-directory: pangocairo
291+
name: pangocairo
292+
run: cargo clippy --all-targets -- -D warnings
293+
226294
checker:
227295
name: gtk-rs checker
228296
runs-on: ubuntu-latest

atk/src/lib.rs

-11
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,7 @@
77
//! This library contains safe Rust bindings for [ATK](https://developer.gnome.org/atk/). It's
88
//! a part of [Gtk-rs](https://gtk-rs.org/).
99
10-
#![cfg_attr(feature = "cargo-clippy", allow(let_unit_value))]
11-
#![cfg_attr(feature = "cargo-clippy", allow(new_without_default))]
12-
#![cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
13-
#![cfg_attr(feature = "cargo-clippy", allow(trivially_copy_pass_by_ref))]
14-
#![cfg_attr(feature = "cargo-clippy", allow(derive_hash_xor_eq))]
1510
#![cfg_attr(feature = "dox", feature(doc_cfg))]
16-
#![allow(deprecated)]
1711

1812
extern crate libc;
1913
#[macro_use]
@@ -30,11 +24,6 @@ extern crate glib;
3024
#[macro_use]
3125
mod rt;
3226

33-
#[cfg_attr(feature = "cargo-clippy", allow(too_many_arguments))]
34-
#[cfg_attr(feature = "cargo-clippy", allow(match_same_arms))]
35-
#[cfg_attr(feature = "cargo-clippy", allow(let_and_return))]
36-
#[cfg_attr(feature = "cargo-clippy", allow(many_single_char_names))]
37-
#[cfg_attr(feature = "cargo-clippy", allow(wrong_self_convention))]
3827
#[allow(unused_imports)]
3928
mod auto;
4029

atk/src/text_rectangle.rs

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ impl TextRectangle {
2626

2727
#[doc(hidden)]
2828
#[inline]
29+
#[allow(clippy::wrong_self_convention)]
2930
pub fn to_glib_none_mut(&mut self) -> (*mut atk_sys::AtkTextRectangle, i32) {
3031
(self as *mut TextRectangle as usize as *mut _, 0)
3132
}

cairo/src/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ impl Context {
603603
ffi::cairo_show_text_glyphs(
604604
self.0.as_ptr(),
605605
text.as_ptr(),
606-
-1 as c_int, //NULL terminated
606+
-1_i32, //NULL terminated
607607
glyphs.as_ptr(),
608608
glyphs.len() as c_int,
609609
clusters.as_ptr(),

cairo/src/enums.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::fmt::{self, Debug};
66
use std::i32;
77
use std::u32;
88

9+
use error::Error;
910
use ffi;
1011

1112
#[cfg(feature = "use_glib")]
@@ -1409,13 +1410,13 @@ impl fmt::Display for Format {
14091410
gvalue_impl!(Format, ffi::gobject::cairo_gobject_format_get_type);
14101411

14111412
impl Format {
1412-
pub fn stride_for_width(self, width: u32) -> Result<i32, ()> {
1413+
pub fn stride_for_width(self, width: u32) -> Result<i32, Error> {
14131414
assert!(width <= i32::MAX as u32);
14141415
let width = width as i32;
14151416

14161417
let stride = unsafe { ffi::cairo_format_stride_for_width(self.into(), width) };
14171418
if stride == -1 {
1418-
Err(())
1419+
Err(Error::InvalidFormat)
14191420
} else {
14201421
Ok(stride)
14211422
}

cairo/src/font/font_options.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@ impl FontOptions {
121121
let v = CString::new(*v).unwrap();
122122
ffi::cairo_font_options_set_variations(self.to_raw_none(), v.as_ptr())
123123
}
124-
None => ffi::cairo_font_options_set_variations(self.to_raw_none(), 0 as *const _),
124+
None => {
125+
ffi::cairo_font_options_set_variations(self.to_raw_none(), std::ptr::null())
126+
}
125127
}
126128
}
127129
}

cairo/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
//! * **win32-surface** - Microsoft Windows surface support
4242
4343
#![cfg_attr(feature = "dox", feature(doc_cfg))]
44+
#![allow(clippy::missing_safety_doc)]
4445

4546
pub extern crate cairo_sys as ffi;
4647
extern crate libc;

cairo/src/paths.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ mod tests {
138138
Context::new(&surface)
139139
}
140140

141-
fn assert_path_equals_segments(expected: &Path, actual: &Vec<PathSegment>) {
141+
fn assert_path_equals_segments(expected: &Path, actual: &[PathSegment]) {
142142
// First ensure the lengths are equal
143143

144144
let expected_iter = expected.iter();
@@ -151,9 +151,8 @@ mod tests {
151151
let expected_iter = expected.iter();
152152
let actual_iter = actual.iter();
153153

154-
let mut iter = expected_iter.zip(actual_iter);
155-
156-
while let Some((e, a)) = iter.next() {
154+
let iter = expected_iter.zip(actual_iter);
155+
for (e, a) in iter {
157156
assert_eq!(e, *a);
158157
}
159158
}
@@ -175,7 +174,7 @@ mod tests {
175174

176175
let path = cr.copy_path();
177176

178-
assert_path_equals_segments(&path, &vec![PathSegment::MoveTo((1.0, 2.0))]);
177+
assert_path_equals_segments(&path, &[PathSegment::MoveTo((1.0, 2.0))]);
179178
}
180179

181180
#[test]
@@ -190,7 +189,7 @@ mod tests {
190189

191190
assert_path_equals_segments(
192191
&path,
193-
&vec![
192+
&[
194193
PathSegment::MoveTo((1.0, 2.0)),
195194
PathSegment::LineTo((3.0, 4.0)),
196195
PathSegment::MoveTo((5.0, 6.0)),
@@ -212,7 +211,7 @@ mod tests {
212211
// from the extra moveto.
213212
assert_path_equals_segments(
214213
&path,
215-
&vec![
214+
&[
216215
PathSegment::MoveTo((1.0, 2.0)),
217216
PathSegment::ClosePath,
218217
PathSegment::MoveTo((1.0, 2.0)),
@@ -232,7 +231,7 @@ mod tests {
232231

233232
assert_path_equals_segments(
234233
&path,
235-
&vec![
234+
&[
236235
PathSegment::MoveTo((1.0, 2.0)),
237236
PathSegment::CurveTo((3.0, 4.0), (5.0, 6.0), (7.0, 8.0)),
238237
PathSegment::ClosePath,

cairo/src/svg.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ mod test {
211211

212212
impl io::Write for CustomWriter {
213213
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
214-
self.1.write(buf)?;
214+
self.1.write_all(buf)?;
215215

216216
self.0 += buf.len();
217217
Ok(buf.len())

cairo/sys/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
// Licensed under the MIT license, see the LICENSE file or <https://opensource.org/licenses/MIT>
44

55
#![allow(non_camel_case_types)]
6-
#![cfg_attr(feature = "cargo-clippy", allow(unreadable_literal, write_literal))]
6+
#![allow(clippy::unreadable_literal)]
7+
#![allow(clippy::write_literal)]
78

89
extern crate libc;
910

examples/src/bin/basic_subclass.rs

+1
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ glib_wrapper! {
194194
}
195195

196196
impl SimpleApplication {
197+
#[allow(clippy::new_without_default)]
197198
pub fn new() -> Self {
198199
glib::Object::new(
199200
Self::static_type(),

examples/src/bin/clipboard_simple.rs

+18-18
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ fn build_ui(application: &gtk::Application) {
6969
// Save out UI in thread-local storage so we can use it in callbacks later
7070
GLOBAL.with(move |global| {
7171
*global.borrow_mut() = Some(Ui {
72-
button_a1: button_a1,
73-
button_a2: button_a2,
74-
button_b1: button_b1,
75-
button_b2: button_b2,
72+
button_a1,
73+
button_a2,
74+
button_b1,
75+
button_b2,
7676
})
7777
});
7878

@@ -82,24 +82,24 @@ fn build_ui(application: &gtk::Application) {
8282
GLOBAL.with(|global| {
8383
if let Some(ref ui) = *global.borrow() {
8484
if ui.button_a1.get_active() {
85-
s.push_str("1");
85+
s.push('1');
8686
} else {
87-
s.push_str("0");
87+
s.push('0');
8888
}
8989
if ui.button_a2.get_active() {
90-
s.push_str("1");
90+
s.push('1');
9191
} else {
92-
s.push_str("0");
92+
s.push('0');
9393
}
9494
if ui.button_b1.get_active() {
95-
s.push_str("1");
95+
s.push('1');
9696
} else {
97-
s.push_str("0");
97+
s.push('0');
9898
}
9999
if ui.button_b2.get_active() {
100-
s.push_str("1");
100+
s.push('1');
101101
} else {
102-
s.push_str("0");
102+
s.push('0');
103103
}
104104
}
105105
});
@@ -109,15 +109,15 @@ fn build_ui(application: &gtk::Application) {
109109
paste_button.connect_clicked(|_| {
110110
let clipboard = gtk::Clipboard::get(&gdk::SELECTION_CLIPBOARD);
111111
clipboard.request_text(|_, t| {
112-
if t.is_some() {
113-
let t = t.unwrap();
112+
if let Some(t) = t {
113+
let t = t.chars().collect::<Vec<_>>();
114114
if t.len() >= 4 {
115115
GLOBAL.with(|global| {
116116
if let Some(ref ui) = *global.borrow() {
117-
ui.button_a1.set_active(t.chars().nth(0).unwrap() == '1');
118-
ui.button_a2.set_active(t.chars().nth(1).unwrap() == '1');
119-
ui.button_b1.set_active(t.chars().nth(2).unwrap() == '1');
120-
ui.button_b2.set_active(t.chars().nth(3).unwrap() == '1');
117+
ui.button_a1.set_active(t[0] == '1');
118+
ui.button_a2.set_active(t[1] == '1');
119+
ui.button_b1.set_active(t[2] == '1');
120+
ui.button_b2.set_active(t[3] == '1');
121121
}
122122
});
123123
}

examples/src/bin/gio_futures.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fn read_and_print_file(
1414
) -> impl Future<Output = Result<(), String>> + std::marker::Unpin {
1515
file.read_async_future(glib::PRIORITY_DEFAULT)
1616
.map_err(|err| format!("Failed to open file: {}", err))
17-
.and_then(|strm| read_and_print_chunks(strm))
17+
.and_then(read_and_print_chunks)
1818
}
1919

2020
// Read the input stream in chunks of 64 bytes, always into the same buffer

examples/src/bin/iconview_example.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ fn create_list_store_model() -> gtk::ListStore {
6767
}
6868
}
6969

70-
return icon_view_model;
70+
icon_view_model
7171
}
7272

7373
fn build_ui(application: &gtk::Application) {

examples/src/bin/list_store.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use gio::prelude::*;
2+
use glib::clone;
23
use gtk::prelude::*;
34

45
use std::env::args;
@@ -51,8 +52,13 @@ fn build_ui(application: &gtk::Application) {
5152

5253
window.show_all();
5354

54-
let model = model.clone();
55-
glib::timeout_add_local(Duration::from_millis(80), move || spinner_timeout(&model));
55+
glib::timeout_add_local(
56+
Duration::from_millis(80),
57+
clone!(@weak model => @default-return glib::Continue(false), move || {
58+
spinner_timeout(&model);
59+
glib::Continue(false)
60+
}),
61+
);
5662
}
5763

5864
struct Data {

examples/src/bin/listbox_model.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -300,12 +300,12 @@ mod row_data {
300300
}
301301
}
302302

303-
fn get_property(&self, _obj: &Self::Type, id: usize) -> Result<glib::Value, ()> {
303+
fn get_property(&self, _obj: &Self::Type, id: usize) -> glib::Value {
304304
let prop = &PROPERTIES[id];
305305

306306
match *prop {
307-
subclass::Property("name", ..) => Ok(self.name.borrow().to_value()),
308-
subclass::Property("count", ..) => Ok(self.count.borrow().to_value()),
307+
subclass::Property("name", ..) => self.name.borrow().to_value(),
308+
subclass::Property("count", ..) => self.count.borrow().to_value(),
309309
_ => unimplemented!(),
310310
}
311311
}

examples/src/bin/notebook.rs

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ impl Notebook {
2525
let tab = gtk::Box::new(Orientation::Horizontal, 0);
2626

2727
button.set_relief(ReliefStyle::None);
28-
button.set_focus_on_click(false);
2928
button.add(&close_image);
3029

3130
tab.pack_start(&label, false, false, 0);

0 commit comments

Comments
 (0)