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

CI: add a clippy job #30

Merged
merged 28 commits into from
Nov 19, 2020
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
7b84b17
CI: add a clippy job
bilelmoussaoui Nov 8, 2020
196e23d
atk: fix clippy warnings
bilelmoussaoui Nov 15, 2020
66aacbd
cairo: fix clippy warnings
bilelmoussaoui Nov 15, 2020
09bb1ec
gio: fix clippy warnings
bilelmoussaoui Nov 15, 2020
a433200
gdk: fix clippy warnings
bilelmoussaoui Nov 15, 2020
4fb194b
pango: fix clippy warnings
bilelmoussaoui Nov 15, 2020
f21f30c
pangocairo: fix clippy warnings
bilelmoussaoui Nov 15, 2020
9287dbb
graphene: fix clippy warnings
bilelmoussaoui Nov 15, 2020
31bb7d4
gdk-pixbuf: fix clippy warnings
bilelmoussaoui Nov 15, 2020
030c2ed
glib: fix clippy warnings
bilelmoussaoui Nov 15, 2020
a68488e
bump min rustc to 1.42.0
bilelmoussaoui Nov 15, 2020
1087c04
gdkx11: fix clippy warnings
bilelmoussaoui Nov 15, 2020
7ec265f
examples: fix clippy warnings
bilelmoussaoui Nov 15, 2020
bd53b40
gtk: fix clippy warnings
bilelmoussaoui Nov 15, 2020
f0f5647
misc: cleanup clippy linters
bilelmoussaoui Nov 15, 2020
b2a0354
misc: set missing unsafe doc per crate
bilelmoussaoui Nov 15, 2020
1991275
clippy: run with --all-features
bilelmoussaoui Nov 15, 2020
1e46c89
ci: Run clippy with --all-targets
sdroege Nov 17, 2020
5b7b30e
examples/clipboard_simple: Slightly clean up
sdroege Nov 17, 2020
5f24445
Fix a few other clippy warnings
sdroege Nov 17, 2020
3227fbf
CI: run clippy on rust-nightly
bilelmoussaoui Nov 17, 2020
07ec278
glib: allow unused doc comments
bilelmoussaoui Nov 17, 2020
451e6d3
glib: return a BoolError for VariantTy
bilelmoussaoui Nov 17, 2020
fe8c818
glib: make ObjectImpl return a Value
bilelmoussaoui Nov 17, 2020
4e47323
More clippy fixes
bilelmoussaoui Nov 17, 2020
8d1c331
gdk: Remove unnecessary lifetime annotations in ChangeData functions …
sdroege Nov 19, 2020
ee8edd3
glib: Improve error string in VariantTy::new()
sdroege Nov 19, 2020
ec7dbdc
CI: split clippy jobs
bilelmoussaoui Nov 19, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,26 @@ jobs:
command: fmt
args: --all -- --check

clippy:
sdroege marked this conversation as resolved.
Show resolved Hide resolved
name: clippy
runs-on: ubuntu-latest
container:
image: ubuntu:20.10
steps:
- run: apt-get update -y
- run: apt-get install -y libgtk-3-dev libglib2.0-dev libgraphene-1.0-dev git xvfb curl libcairo-gobject2 libcairo2-dev
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
sdroege marked this conversation as resolved.
Show resolved Hide resolved
override: true
- run: rustup component add clippy
- uses: actions-rs/cargo@v1
with:
command: clippy
args: --all-features --all-targets -- -D warnings

checker:
name: gtk-rs checker
runs-on: ubuntu-latest
Expand Down
11 changes: 0 additions & 11 deletions atk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@
//! This library contains safe Rust bindings for [ATK](https://developer.gnome.org/atk/). It's
//! a part of [Gtk-rs](https://gtk-rs.org/).

#![cfg_attr(feature = "cargo-clippy", allow(let_unit_value))]
#![cfg_attr(feature = "cargo-clippy", allow(new_without_default))]
#![cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
#![cfg_attr(feature = "cargo-clippy", allow(trivially_copy_pass_by_ref))]
#![cfg_attr(feature = "cargo-clippy", allow(derive_hash_xor_eq))]
#![cfg_attr(feature = "dox", feature(doc_cfg))]
#![allow(deprecated)]

extern crate libc;
#[macro_use]
Expand All @@ -30,11 +24,6 @@ extern crate glib;
#[macro_use]
mod rt;

#[cfg_attr(feature = "cargo-clippy", allow(too_many_arguments))]
#[cfg_attr(feature = "cargo-clippy", allow(match_same_arms))]
#[cfg_attr(feature = "cargo-clippy", allow(let_and_return))]
#[cfg_attr(feature = "cargo-clippy", allow(many_single_char_names))]
#[cfg_attr(feature = "cargo-clippy", allow(wrong_self_convention))]
#[allow(unused_imports)]
mod auto;

Expand Down
1 change: 1 addition & 0 deletions atk/src/text_rectangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ impl TextRectangle {

#[doc(hidden)]
#[inline]
#[allow(clippy::wrong_self_convention)]
pub fn to_glib_none_mut(&mut self) -> (*mut atk_sys::AtkTextRectangle, i32) {
(self as *mut TextRectangle as usize as *mut _, 0)
}
Expand Down
2 changes: 1 addition & 1 deletion cairo/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ impl Context {
ffi::cairo_show_text_glyphs(
self.0.as_ptr(),
text.as_ptr(),
-1 as c_int, //NULL terminated
-1_i32, //NULL terminated
glyphs.as_ptr(),
glyphs.len() as c_int,
clusters.as_ptr(),
Expand Down
5 changes: 3 additions & 2 deletions cairo/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::fmt::{self, Debug};
use std::i32;
use std::u32;

use error::Error;
use ffi;

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

impl Format {
pub fn stride_for_width(self, width: u32) -> Result<i32, ()> {
pub fn stride_for_width(self, width: u32) -> Result<i32, Error> {
assert!(width <= i32::MAX as u32);
let width = width as i32;

let stride = unsafe { ffi::cairo_format_stride_for_width(self.into(), width) };
if stride == -1 {
Err(())
Err(Error::InvalidFormat)
} else {
Ok(stride)
}
Expand Down
4 changes: 3 additions & 1 deletion cairo/src/font/font_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ impl FontOptions {
let v = CString::new(*v).unwrap();
ffi::cairo_font_options_set_variations(self.to_raw_none(), v.as_ptr())
}
None => ffi::cairo_font_options_set_variations(self.to_raw_none(), 0 as *const _),
None => {
ffi::cairo_font_options_set_variations(self.to_raw_none(), std::ptr::null())
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions cairo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
//! * **win32-surface** - Microsoft Windows surface support

#![cfg_attr(feature = "dox", feature(doc_cfg))]
#![allow(clippy::missing_safety_doc)]

pub extern crate cairo_sys as ffi;
extern crate libc;
Expand Down
15 changes: 7 additions & 8 deletions cairo/src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ mod tests {
Context::new(&surface)
}

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

let expected_iter = expected.iter();
Expand All @@ -151,9 +151,8 @@ mod tests {
let expected_iter = expected.iter();
let actual_iter = actual.iter();

let mut iter = expected_iter.zip(actual_iter);

while let Some((e, a)) = iter.next() {
let iter = expected_iter.zip(actual_iter);
for (e, a) in iter {
assert_eq!(e, *a);
}
}
Expand All @@ -175,7 +174,7 @@ mod tests {

let path = cr.copy_path();

assert_path_equals_segments(&path, &vec![PathSegment::MoveTo((1.0, 2.0))]);
assert_path_equals_segments(&path, &[PathSegment::MoveTo((1.0, 2.0))]);
}

#[test]
Expand All @@ -190,7 +189,7 @@ mod tests {

assert_path_equals_segments(
&path,
&vec![
&[
PathSegment::MoveTo((1.0, 2.0)),
PathSegment::LineTo((3.0, 4.0)),
PathSegment::MoveTo((5.0, 6.0)),
Expand All @@ -212,7 +211,7 @@ mod tests {
// from the extra moveto.
assert_path_equals_segments(
&path,
&vec![
&[
PathSegment::MoveTo((1.0, 2.0)),
PathSegment::ClosePath,
PathSegment::MoveTo((1.0, 2.0)),
Expand All @@ -232,7 +231,7 @@ mod tests {

assert_path_equals_segments(
&path,
&vec![
&[
PathSegment::MoveTo((1.0, 2.0)),
PathSegment::CurveTo((3.0, 4.0), (5.0, 6.0), (7.0, 8.0)),
PathSegment::ClosePath,
Expand Down
2 changes: 1 addition & 1 deletion cairo/src/svg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ mod test {

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

self.0 += buf.len();
Ok(buf.len())
Expand Down
3 changes: 2 additions & 1 deletion cairo/sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
// Licensed under the MIT license, see the LICENSE file or <https://opensource.org/licenses/MIT>

#![allow(non_camel_case_types)]
#![cfg_attr(feature = "cargo-clippy", allow(unreadable_literal, write_literal))]
#![allow(clippy::unreadable_literal)]
#![allow(clippy::write_literal)]

extern crate libc;

Expand Down
1 change: 1 addition & 0 deletions examples/src/bin/basic_subclass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ glib_wrapper! {
}

impl SimpleApplication {
#[allow(clippy::new_without_default)]
pub fn new() -> Self {
glib::Object::new(
Self::static_type(),
Expand Down
36 changes: 18 additions & 18 deletions examples/src/bin/clipboard_simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ fn build_ui(application: &gtk::Application) {
// Save out UI in thread-local storage so we can use it in callbacks later
GLOBAL.with(move |global| {
*global.borrow_mut() = Some(Ui {
button_a1: button_a1,
button_a2: button_a2,
button_b1: button_b1,
button_b2: button_b2,
button_a1,
button_a2,
button_b1,
button_b2,
})
});

Expand All @@ -82,24 +82,24 @@ fn build_ui(application: &gtk::Application) {
GLOBAL.with(|global| {
if let Some(ref ui) = *global.borrow() {
if ui.button_a1.get_active() {
s.push_str("1");
s.push('1');
} else {
s.push_str("0");
s.push('0');
}
if ui.button_a2.get_active() {
s.push_str("1");
s.push('1');
} else {
s.push_str("0");
s.push('0');
}
if ui.button_b1.get_active() {
s.push_str("1");
s.push('1');
} else {
s.push_str("0");
s.push('0');
}
if ui.button_b2.get_active() {
s.push_str("1");
s.push('1');
} else {
s.push_str("0");
s.push('0');
}
}
});
Expand All @@ -109,15 +109,15 @@ fn build_ui(application: &gtk::Application) {
paste_button.connect_clicked(|_| {
let clipboard = gtk::Clipboard::get(&gdk::SELECTION_CLIPBOARD);
clipboard.request_text(|_, t| {
if t.is_some() {
let t = t.unwrap();
if let Some(t) = t {
let t = t.chars().collect::<Vec<_>>();
if t.len() >= 4 {
GLOBAL.with(|global| {
if let Some(ref ui) = *global.borrow() {
ui.button_a1.set_active(t.chars().nth(0).unwrap() == '1');
ui.button_a2.set_active(t.chars().nth(1).unwrap() == '1');
ui.button_b1.set_active(t.chars().nth(2).unwrap() == '1');
ui.button_b2.set_active(t.chars().nth(3).unwrap() == '1');
ui.button_a1.set_active(t[0] == '1');
ui.button_a2.set_active(t[1] == '1');
ui.button_b1.set_active(t[2] == '1');
ui.button_b2.set_active(t[3] == '1');
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion examples/src/bin/gio_futures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn read_and_print_file(
) -> impl Future<Output = Result<(), String>> + std::marker::Unpin {
file.read_async_future(glib::PRIORITY_DEFAULT)
.map_err(|err| format!("Failed to open file: {}", err))
.and_then(|strm| read_and_print_chunks(strm))
.and_then(read_and_print_chunks)
}

// Read the input stream in chunks of 64 bytes, always into the same buffer
Expand Down
2 changes: 1 addition & 1 deletion examples/src/bin/iconview_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fn create_list_store_model() -> gtk::ListStore {
}
}

return icon_view_model;
icon_view_model
}

fn build_ui(application: &gtk::Application) {
Expand Down
10 changes: 8 additions & 2 deletions examples/src/bin/list_store.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use gio::prelude::*;
use glib::clone;
use gtk::prelude::*;

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

window.show_all();

let model = model.clone();
glib::timeout_add_local(Duration::from_millis(80), move || spinner_timeout(&model));
glib::timeout_add_local(
Duration::from_millis(80),
clone!(@weak model => @default-return glib::Continue(false), move || {
spinner_timeout(&model);
glib::Continue(false)
}),
);
}

struct Data {
Expand Down
6 changes: 3 additions & 3 deletions examples/src/bin/listbox_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,12 @@ mod row_data {
}
}

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

match *prop {
subclass::Property("name", ..) => Ok(self.name.borrow().to_value()),
subclass::Property("count", ..) => Ok(self.count.borrow().to_value()),
subclass::Property("name", ..) => self.name.borrow().to_value(),
subclass::Property("count", ..) => self.count.borrow().to_value(),
_ => unimplemented!(),
}
}
Expand Down
1 change: 0 additions & 1 deletion examples/src/bin/notebook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ impl Notebook {
let tab = gtk::Box::new(Orientation::Horizontal, 0);

button.set_relief(ReliefStyle::None);
button.set_focus_on_click(false);
button.add(&close_image);

tab.pack_start(&label, false, false, 0);
Expand Down
14 changes: 7 additions & 7 deletions examples/src/bin/progress_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ impl Application {
let _ = tx.send(None);
});

let active = active.clone();
let widgets = widgets.clone();
rx.attach(None, move |value| match value {
rx.attach(None, clone!(@weak active, @weak widgets => @default-return glib::Continue(false), move |value| match value {
Some(value) => {
widgets
.main_view
Expand All @@ -85,14 +83,13 @@ impl Application {
.view_stack
.set_visible_child(&widgets.complete_view.container);

let widgets = widgets.clone();
glib::timeout_add_local(Duration::from_millis(1500), move || {
glib::timeout_add_local(Duration::from_millis(1500), clone!(@weak widgets => @default-return glib::Continue(false), move || {
widgets.main_view.progress.set_fraction(0.0);
widgets
.view_stack
.set_visible_child(&widgets.main_view.container);
glib::Continue(false)
});
}));
}

glib::Continue(true)
Expand All @@ -101,7 +98,7 @@ impl Application {
active.set(false);
glib::Continue(false)
}
});
}));
}),
);
}
Expand Down Expand Up @@ -156,6 +153,7 @@ pub struct Header {
}

impl Header {
#[allow(clippy::new_without_default)]
pub fn new() -> Self {
let container = gtk::HeaderBar::new();
container.set_title(Some("Progress Tracker"));
Expand All @@ -170,6 +168,7 @@ pub struct CompleteView {
}

impl CompleteView {
#[allow(clippy::new_without_default)]
pub fn new() -> Self {
let label = gtk::Label::new(None);
label.set_markup("Task complete");
Expand All @@ -194,6 +193,7 @@ pub struct MainView {
}

impl MainView {
#[allow(clippy::new_without_default)]
pub fn new() -> Self {
let progress = gtk::ProgressBar::new();
progress.set_text(Some("Progress Bar"));
Expand Down
Loading