diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 2a3b11269eca..232da399c8e8 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -223,6 +223,74 @@ jobs: command: fmt args: --all -- --check + clippy: + 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: stable + override: true + - run: rustup component add clippy + + - working-directory: atk + name: atk + run: cargo clippy --features "v2_34" --all-targets -- -D warnings + + - working-directory: cairo + name: cairo + run: cargo clippy --features "png,pdf,svg,ps,use_glib,v1_16,freetype,script,xcb,xlib,win32-surface" --all-targets -- -D warnings + + - working-directory: examples + name: examples + run: cargo clippy --all-features --all-targets -- -D warnings + + - working-directory: gdk + name: gdk + run: cargo clippy --features "v3_24" --all-targets -- -D warnings + + - working-directory: gdk-pixbuf + name: gdk-pixbuf + run: cargo clippy --features "v2_40" --all-targets -- -D warnings + + - working-directory: gdkx11 + name: gdkx11 + run: cargo clippy --features "v3_24" --all-targets -- -D warnings + + - working-directory: gio + name: gio + run: cargo clippy --features "v2_66" --all-targets -- -D warnings + + - working-directory: glib + name: glib + run: cargo clippy --features "v2_66" --all-targets -- -D warnings + + - working-directory: glib-macros + name: glib-macros + run: cargo clippy --all-targets -- -D warnings + + - working-directory: graphene + name: graphene + run: cargo clippy --features "v1_10" --all-targets -- -D warnings + + - working-directory: gtk + name: gtk + run: cargo clippy --features "v3_24_9" --all-targets -- -D warnings + + - working-directory: pango + name: pango + run: cargo clippy --features "v1_46" --all-targets -- -D warnings + + - working-directory: pangocairo + name: pangocairo + run: cargo clippy --all-targets -- -D warnings + checker: name: gtk-rs checker runs-on: ubuntu-latest diff --git a/atk/src/lib.rs b/atk/src/lib.rs index 967a9f511342..9f78615cd7a2 100644 --- a/atk/src/lib.rs +++ b/atk/src/lib.rs @@ -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] @@ -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; diff --git a/atk/src/text_rectangle.rs b/atk/src/text_rectangle.rs index c19e6783ce21..12e4be1462d6 100644 --- a/atk/src/text_rectangle.rs +++ b/atk/src/text_rectangle.rs @@ -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) } diff --git a/cairo/src/context.rs b/cairo/src/context.rs index 28b07a4e4b99..29fb76a097b4 100644 --- a/cairo/src/context.rs +++ b/cairo/src/context.rs @@ -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(), diff --git a/cairo/src/enums.rs b/cairo/src/enums.rs index 53d8c5000b5c..9cfc47864205 100644 --- a/cairo/src/enums.rs +++ b/cairo/src/enums.rs @@ -6,6 +6,7 @@ use std::fmt::{self, Debug}; use std::i32; use std::u32; +use error::Error; use ffi; #[cfg(feature = "use_glib")] @@ -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 { + pub fn stride_for_width(self, width: u32) -> Result { 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) } diff --git a/cairo/src/font/font_options.rs b/cairo/src/font/font_options.rs index d8663371e15f..6a6e24411361 100644 --- a/cairo/src/font/font_options.rs +++ b/cairo/src/font/font_options.rs @@ -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()) + } } } } diff --git a/cairo/src/lib.rs b/cairo/src/lib.rs index f014661563b0..9c42df3e0b77 100644 --- a/cairo/src/lib.rs +++ b/cairo/src/lib.rs @@ -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; diff --git a/cairo/src/paths.rs b/cairo/src/paths.rs index ab49779bafc0..bf5e66b79080 100644 --- a/cairo/src/paths.rs +++ b/cairo/src/paths.rs @@ -138,7 +138,7 @@ mod tests { Context::new(&surface) } - fn assert_path_equals_segments(expected: &Path, actual: &Vec) { + fn assert_path_equals_segments(expected: &Path, actual: &[PathSegment]) { // First ensure the lengths are equal let expected_iter = expected.iter(); @@ -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); } } @@ -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] @@ -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)), @@ -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)), @@ -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, diff --git a/cairo/src/svg.rs b/cairo/src/svg.rs index 9da5f29638d0..cebf2189f5a6 100644 --- a/cairo/src/svg.rs +++ b/cairo/src/svg.rs @@ -211,7 +211,7 @@ mod test { impl io::Write for CustomWriter { fn write(&mut self, buf: &[u8]) -> io::Result { - self.1.write(buf)?; + self.1.write_all(buf)?; self.0 += buf.len(); Ok(buf.len()) diff --git a/cairo/sys/src/lib.rs b/cairo/sys/src/lib.rs index 6702e2539209..6bffe96f66d4 100644 --- a/cairo/sys/src/lib.rs +++ b/cairo/sys/src/lib.rs @@ -3,7 +3,8 @@ // Licensed under the MIT license, see the LICENSE file or #![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; diff --git a/examples/src/bin/basic_subclass.rs b/examples/src/bin/basic_subclass.rs index 24796ede6a38..7cb23c36040f 100644 --- a/examples/src/bin/basic_subclass.rs +++ b/examples/src/bin/basic_subclass.rs @@ -194,6 +194,7 @@ glib_wrapper! { } impl SimpleApplication { + #[allow(clippy::new_without_default)] pub fn new() -> Self { glib::Object::new( Self::static_type(), diff --git a/examples/src/bin/clipboard_simple.rs b/examples/src/bin/clipboard_simple.rs index 211fe22c2eaa..1a6d7312553d 100644 --- a/examples/src/bin/clipboard_simple.rs +++ b/examples/src/bin/clipboard_simple.rs @@ -69,10 +69,10 @@ fn build_ui(application: >k::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, }) }); @@ -82,24 +82,24 @@ fn build_ui(application: >k::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'); } } }); @@ -109,15 +109,15 @@ fn build_ui(application: >k::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::>(); 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'); } }); } diff --git a/examples/src/bin/gio_futures.rs b/examples/src/bin/gio_futures.rs index 504fea0aa171..d1dc9fecab43 100644 --- a/examples/src/bin/gio_futures.rs +++ b/examples/src/bin/gio_futures.rs @@ -14,7 +14,7 @@ fn read_and_print_file( ) -> impl Future> + 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 diff --git a/examples/src/bin/iconview_example.rs b/examples/src/bin/iconview_example.rs index 966ff554a1bf..9f13b3bbfbd8 100644 --- a/examples/src/bin/iconview_example.rs +++ b/examples/src/bin/iconview_example.rs @@ -67,7 +67,7 @@ fn create_list_store_model() -> gtk::ListStore { } } - return icon_view_model; + icon_view_model } fn build_ui(application: >k::Application) { diff --git a/examples/src/bin/list_store.rs b/examples/src/bin/list_store.rs index c61774881cbf..98d30b6922d0 100644 --- a/examples/src/bin/list_store.rs +++ b/examples/src/bin/list_store.rs @@ -1,4 +1,5 @@ use gio::prelude::*; +use glib::clone; use gtk::prelude::*; use std::env::args; @@ -51,8 +52,13 @@ fn build_ui(application: >k::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 { diff --git a/examples/src/bin/listbox_model.rs b/examples/src/bin/listbox_model.rs index f7afa055bfb2..4a3a6d85d30a 100644 --- a/examples/src/bin/listbox_model.rs +++ b/examples/src/bin/listbox_model.rs @@ -300,12 +300,12 @@ mod row_data { } } - fn get_property(&self, _obj: &Self::Type, id: usize) -> Result { + 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!(), } } diff --git a/examples/src/bin/notebook.rs b/examples/src/bin/notebook.rs index 5e105e252559..f2f3ee79b9d0 100644 --- a/examples/src/bin/notebook.rs +++ b/examples/src/bin/notebook.rs @@ -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); diff --git a/examples/src/bin/progress_tracker.rs b/examples/src/bin/progress_tracker.rs index 1c2829689280..c28d5f8d5abe 100644 --- a/examples/src/bin/progress_tracker.rs +++ b/examples/src/bin/progress_tracker.rs @@ -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 @@ -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) @@ -101,7 +98,7 @@ impl Application { active.set(false); glib::Continue(false) } - }); + })); }), ); } @@ -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")); @@ -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"); @@ -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")); diff --git a/examples/src/bin/treeview.rs b/examples/src/bin/treeview.rs index 68b1a1e5de64..ea79985867a8 100644 --- a/examples/src/bin/treeview.rs +++ b/examples/src/bin/treeview.rs @@ -63,7 +63,7 @@ fn build_ui(application: >k::Application) { col.pack_start(&renderer2, true); col.add_attribute(&renderer2, "text", 1); let image = Pixbuf::from_file("./resources/eye.png") - .or_else(|err| { + .map_err(|err| { let mut msg = err.to_string(); if err.kind() == Some(glib::FileError::Noent) { msg.push_str( @@ -81,8 +81,6 @@ fn build_ui(application: >k::Application) { Continue(false) }), ); - - Err(()) }) .ok(); diff --git a/gdk-pixbuf/src/lib.rs b/gdk-pixbuf/src/lib.rs index 32381776fafe..e710dc58f0c0 100644 --- a/gdk-pixbuf/src/lib.rs +++ b/gdk-pixbuf/src/lib.rs @@ -1,9 +1,6 @@ // Copyright 2013-2016, The Gtk-rs Project Developers. // See the COPYRIGHT file at the top-level directory of this distribution. // Licensed under the MIT license, see the LICENSE file or - -#![cfg_attr(feature = "cargo-clippy", allow(too_many_arguments))] -#![cfg_attr(feature = "cargo-clippy", allow(type_complexity))] #![cfg_attr(feature = "dox", feature(doc_cfg))] #[doc(hidden)] @@ -17,6 +14,7 @@ extern crate glib; extern crate gio; extern crate libc; +#[allow(clippy::too_many_arguments)] #[allow(unused_imports)] mod auto; diff --git a/gdk-pixbuf/src/pixbuf.rs b/gdk-pixbuf/src/pixbuf.rs index b39bf12541c3..be23cf013f12 100644 --- a/gdk-pixbuf/src/pixbuf.rs +++ b/gdk-pixbuf/src/pixbuf.rs @@ -163,7 +163,6 @@ impl Pixbuf { } pub fn from_stream_async< - 'a, P: IsA, Q: IsA, R: FnOnce(Result) + Send + 'static, @@ -217,7 +216,6 @@ impl Pixbuf { } pub fn from_stream_at_scale_async< - 'a, P: IsA, Q: IsA, R: FnOnce(Result) + Send + 'static, @@ -286,7 +284,8 @@ impl Pixbuf { })) } - #[cfg_attr(feature = "cargo-clippy", allow(mut_from_ref))] + #[allow(clippy::mut_from_ref)] + #[allow(clippy::missing_safety_doc)] pub unsafe fn get_pixels(&self) -> &mut [u8] { let mut len = 0; let ptr = @@ -399,6 +398,7 @@ impl Pixbuf { #[cfg(any(feature = "v2_32", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_32")))] + #[allow(clippy::type_complexity)] pub fn get_file_info_async_future + Clone + 'static>( filename: T, ) -> Pin, Error>> + 'static>> @@ -442,7 +442,7 @@ impl Pixbuf { #[cfg(any(feature = "v2_36", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_36")))] - pub fn save_to_streamv<'a, P: IsA, Q: IsA>( + pub fn save_to_streamv, Q: IsA>( &self, stream: &P, type_: &str, @@ -474,7 +474,6 @@ impl Pixbuf { #[cfg(any(feature = "v2_36", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_36")))] pub fn save_to_streamv_async< - 'a, P: IsA, Q: IsA, R: FnOnce(Result<(), Error>) + Send + 'static, diff --git a/gdk-pixbuf/tests/overflow.rs b/gdk-pixbuf/tests/overflow.rs index 1c74ce90f912..37199e0348b2 100644 --- a/gdk-pixbuf/tests/overflow.rs +++ b/gdk-pixbuf/tests/overflow.rs @@ -66,7 +66,7 @@ fn too_small_slice_should_panic() { #[test] fn last_row_with_incomplete_rowstride_works() { // 1-pixel wide, RGB, 3 32-bit rows, no extra padding byte on the fourth row - let data = vec![0u8; 1 * 4 * 3 + 3]; + let data = vec![0u8; 4 * 3 + 3]; Pixbuf::from_mut_slice(data, Colorspace::Rgb, false, 8, 1, 4, 4); } @@ -74,7 +74,7 @@ fn last_row_with_incomplete_rowstride_works() { #[test] fn last_row_with_full_rowstride_works() { // 1-pixel wide, RGB, 4 32-bit rows - let data = vec![0u8; 1 * 4 * 4]; + let data = vec![0u8; 4 * 4]; Pixbuf::from_mut_slice(data, Colorspace::Rgb, false, 8, 1, 4, 4); } @@ -82,7 +82,7 @@ fn last_row_with_full_rowstride_works() { #[test] fn extra_data_after_last_row_works() { // 1-pixel wide, RGB, 4 32-bit rows, plus some extra space - let data = vec![0u8; 1 * 4 * 4 + 42]; + let data = vec![0u8; 4 * 4 + 42]; Pixbuf::from_mut_slice(data, Colorspace::Rgb, false, 8, 1, 4, 4); } diff --git a/gdk/src/atom.rs b/gdk/src/atom.rs index cd7d865078bc..c555e22e2129 100644 --- a/gdk/src/atom.rs +++ b/gdk/src/atom.rs @@ -106,7 +106,7 @@ impl<'a> ToGlibContainerFromSlice<'a, *mut gdk_sys::GdkAtom> for &'a Atom { as *mut gdk_sys::GdkAtom; for (i, s) in v.iter().enumerate() { - ptr::write(v_ptr.offset(i as isize), s.0); + ptr::write(v_ptr.add(i), s.0); } v_ptr @@ -148,7 +148,7 @@ impl<'a> ToGlibContainerFromSlice<'a, *const gdk_sys::GdkAtom> for &'a Atom { as *mut gdk_sys::GdkAtom; for (i, s) in v.iter().enumerate() { - ptr::write(v_ptr.offset(i as isize), s.0); + ptr::write(v_ptr.add(i), s.0); } v_ptr as *const gdk_sys::GdkAtom @@ -193,7 +193,7 @@ impl FromGlibContainerAsVec for Atom { let mut res = Vec::with_capacity(num); for i in 0..num { - res.push(from_glib_none(ptr::read(ptr.offset(i as isize)))); + res.push(from_glib_none(ptr::read(ptr.add(i)))); } res } @@ -211,7 +211,7 @@ impl FromGlibContainerAsVec for Atom { let mut res = Vec::with_capacity(num); for i in 0..num { - res.push(from_glib_full(ptr::read(ptr.offset(i as isize)))); + res.push(from_glib_full(ptr::read(ptr.add(i)))); } glib_sys::g_free(ptr as *mut _); res diff --git a/gdk/src/cairo_interaction.rs b/gdk/src/cairo_interaction.rs index 82e6eb1e7ae3..783bfce98bcb 100644 --- a/gdk/src/cairo_interaction.rs +++ b/gdk/src/cairo_interaction.rs @@ -50,6 +50,7 @@ pub trait GdkContextExt { #[cfg(any(feature = "v3_16", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v3_16")))] + #[allow(clippy::too_many_arguments)] unsafe fn draw_from_gl>( &self, window: &W, diff --git a/gdk/src/change_data.rs b/gdk/src/change_data.rs index 529adfc6bccc..73b9e46ad479 100644 --- a/gdk/src/change_data.rs +++ b/gdk/src/change_data.rs @@ -16,7 +16,7 @@ pub enum ChangeData<'a> { #[doc(hidden)] impl<'a> ChangeData<'a> { - pub fn to_glib(&'a self) -> *const u8 { + pub fn to_glib(&self) -> *const u8 { match *self { ChangeData::UChars(d) => d.as_ptr() as *const _, ChangeData::UShorts(d) => d.as_ptr() as *const _, @@ -27,7 +27,7 @@ impl<'a> ChangeData<'a> { } } - pub fn len(&'a self) -> usize { + pub fn len(&self) -> usize { match *self { ChangeData::UChars(d) => d.len(), ChangeData::UShorts(d) => d.len(), @@ -35,4 +35,8 @@ impl<'a> ChangeData<'a> { ChangeData::UChar(_) | ChangeData::UShort(_) | ChangeData::ULong(_) => 1, } } + + pub fn is_empty(&self) -> bool { + self.len() != 0 + } } diff --git a/gdk/src/device.rs b/gdk/src/device.rs index 29a31babfaf3..43e4fc3eacdc 100644 --- a/gdk/src/device.rs +++ b/gdk/src/device.rs @@ -43,7 +43,7 @@ impl Device { let n_events = n_events.assume_init() as usize; let mut r_events = Vec::with_capacity(n_events); for i in 0..n_events { - r_events.push((*(events.offset(i as isize) as *mut TimeCoord)).clone()); + r_events.push((*(events.add(i) as *mut TimeCoord)).clone()); } gdk_sys::gdk_device_free_history(events, n_events as _); r_events diff --git a/gdk/src/drag_context.rs b/gdk/src/drag_context.rs index 5354ab9d02c6..5a12a953f15d 100644 --- a/gdk/src/drag_context.rs +++ b/gdk/src/drag_context.rs @@ -54,6 +54,7 @@ impl DragContext { } } + #[allow(clippy::too_many_arguments)] pub fn drag_motion( &self, dest_window: &Window, diff --git a/gdk/src/event.rs b/gdk/src/event.rs index 25d8edf1e18d..15691c53bf66 100644 --- a/gdk/src/event.rs +++ b/gdk/src/event.rs @@ -61,7 +61,7 @@ impl Event { event: *mut gdk_sys::GdkEvent, ptr: glib_sys::gpointer, ) { - if ptr != ptr::null_mut() { + if !ptr.is_null() { let f: &F = &*(ptr as *mut _); let mut event = from_glib_none(event); f(&mut event) @@ -70,7 +70,7 @@ impl Event { unsafe extern "C" fn event_handler_destroy( ptr: glib_sys::gpointer, ) { - if ptr != ptr::null_mut() { + if !ptr.is_null() { // convert back to Box and free let _boxed: Box = Box::from_raw(ptr as *mut _); } @@ -338,7 +338,7 @@ impl Event { } /// Returns whether the event was sent explicitly. - #[cfg_attr(feature = "cargo-clippy", allow(cast_lossless))] + #[allow(clippy::cast_lossless)] pub fn get_send_event(&self) -> bool { from_glib(self.as_ref().send_event as i32) } @@ -468,10 +468,7 @@ macro_rules! event_subtype { #[inline] fn is(ev: &::event::Event) -> bool { skip_assert_initialized!(); - match ev.as_ref().type_ { - $($ty)|+ => true, - _ => false, - } + matches!(ev.as_ref().type_, $($ty)|+) } #[inline] @@ -479,8 +476,7 @@ macro_rules! event_subtype { skip_assert_initialized!(); if Self::is(&ev) { Ok($name(ev)) - } - else { + } else { Err(ev) } } @@ -499,7 +495,7 @@ macro_rules! event_subtype { &mut self.0 } } - } + }; } impl FromEvent for Event { diff --git a/gdk/src/event_button.rs b/gdk/src/event_button.rs index 2513c97bf0e8..f3d45278b204 100644 --- a/gdk/src/event_button.rs +++ b/gdk/src/event_button.rs @@ -2,7 +2,6 @@ // See the COPYRIGHT file at the top-level directory of this distribution. // Licensed under the MIT license, see the LICENSE file or -use gdk_sys; use glib::translate::*; #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] diff --git a/gdk/src/event_configure.rs b/gdk/src/event_configure.rs index 0a1cd556809c..d0bd978f165e 100644 --- a/gdk/src/event_configure.rs +++ b/gdk/src/event_configure.rs @@ -2,7 +2,6 @@ // See the COPYRIGHT file at the top-level directory of this distribution. // Licensed under the MIT license, see the LICENSE file or -use gdk_sys; use glib::translate::*; #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] diff --git a/gdk/src/event_crossing.rs b/gdk/src/event_crossing.rs index 86d79906316a..f26740c38190 100644 --- a/gdk/src/event_crossing.rs +++ b/gdk/src/event_crossing.rs @@ -2,7 +2,6 @@ // See the COPYRIGHT file at the top-level directory of this distribution. // Licensed under the MIT license, see the LICENSE file or -use gdk_sys; use glib::translate::*; #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] diff --git a/gdk/src/event_dnd.rs b/gdk/src/event_dnd.rs index 8ee2db812ecc..8248d56101f4 100644 --- a/gdk/src/event_dnd.rs +++ b/gdk/src/event_dnd.rs @@ -2,7 +2,6 @@ // See the COPYRIGHT file at the top-level directory of this distribution. // Licensed under the MIT license, see the LICENSE file or -use gdk_sys; use glib::translate::*; #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] diff --git a/gdk/src/event_expose.rs b/gdk/src/event_expose.rs index 8facab867ef2..69e68944cd4c 100644 --- a/gdk/src/event_expose.rs +++ b/gdk/src/event_expose.rs @@ -3,7 +3,6 @@ // Licensed under the MIT license, see the LICENSE file or use cairo; -use gdk_sys; use glib::translate::*; use Rectangle; diff --git a/gdk/src/event_focus.rs b/gdk/src/event_focus.rs index 7c72b6fbd20d..b269a81a7d50 100644 --- a/gdk/src/event_focus.rs +++ b/gdk/src/event_focus.rs @@ -2,7 +2,6 @@ // See the COPYRIGHT file at the top-level directory of this distribution. // Licensed under the MIT license, see the LICENSE file or -use gdk_sys; use glib::translate::*; #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] diff --git a/gdk/src/event_grab_broken.rs b/gdk/src/event_grab_broken.rs index 390aa16d2695..13e866459ad5 100644 --- a/gdk/src/event_grab_broken.rs +++ b/gdk/src/event_grab_broken.rs @@ -2,7 +2,6 @@ // See the COPYRIGHT file at the top-level directory of this distribution. // Licensed under the MIT license, see the LICENSE file or -use gdk_sys; use glib::translate::*; #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] diff --git a/gdk/src/event_key.rs b/gdk/src/event_key.rs index 9ac7005e1509..a65e53cfd3a0 100644 --- a/gdk/src/event_key.rs +++ b/gdk/src/event_key.rs @@ -2,7 +2,6 @@ // See the COPYRIGHT file at the top-level directory of this distribution. // Licensed under the MIT license, see the LICENSE file or -use gdk_sys; use glib::translate::*; #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] diff --git a/gdk/src/event_owner_change.rs b/gdk/src/event_owner_change.rs index 1af26617f707..0e51bfe7931f 100644 --- a/gdk/src/event_owner_change.rs +++ b/gdk/src/event_owner_change.rs @@ -2,7 +2,6 @@ // See the COPYRIGHT file at the top-level directory of this distribution. // Licensed under the MIT license, see the LICENSE file or -use gdk_sys; use glib::translate::*; #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] diff --git a/gdk/src/event_property.rs b/gdk/src/event_property.rs index 0b43e21f993b..0f8d53e5f948 100644 --- a/gdk/src/event_property.rs +++ b/gdk/src/event_property.rs @@ -2,7 +2,6 @@ // See the COPYRIGHT file at the top-level directory of this distribution. // Licensed under the MIT license, see the LICENSE file or -use gdk_sys; use glib::translate::*; #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] diff --git a/gdk/src/event_proximity.rs b/gdk/src/event_proximity.rs index d48d5d7040a6..e4527aebd502 100644 --- a/gdk/src/event_proximity.rs +++ b/gdk/src/event_proximity.rs @@ -2,7 +2,6 @@ // See the COPYRIGHT file at the top-level directory of this distribution. // Licensed under the MIT license, see the LICENSE file or -use gdk_sys; use glib::translate::*; #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] diff --git a/gdk/src/event_scroll.rs b/gdk/src/event_scroll.rs index afec06f8cdf9..57cc527fd57e 100644 --- a/gdk/src/event_scroll.rs +++ b/gdk/src/event_scroll.rs @@ -2,7 +2,6 @@ // See the COPYRIGHT file at the top-level directory of this distribution. // Licensed under the MIT license, see the LICENSE file or -use gdk_sys; use glib::translate::*; #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] diff --git a/gdk/src/event_selection.rs b/gdk/src/event_selection.rs index cf3d095ce6e2..d1ef948764d5 100644 --- a/gdk/src/event_selection.rs +++ b/gdk/src/event_selection.rs @@ -2,7 +2,6 @@ // See the COPYRIGHT file at the top-level directory of this distribution. // Licensed under the MIT license, see the LICENSE file or -use gdk_sys; use glib::translate::*; #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] diff --git a/gdk/src/event_setting.rs b/gdk/src/event_setting.rs index aad1e65fc297..82137299e7c1 100644 --- a/gdk/src/event_setting.rs +++ b/gdk/src/event_setting.rs @@ -2,7 +2,6 @@ // See the COPYRIGHT file at the top-level directory of this distribution. // Licensed under the MIT license, see the LICENSE file or -use gdk_sys; use glib::translate::*; use glib::GString; diff --git a/gdk/src/event_touch.rs b/gdk/src/event_touch.rs index 56259d4506b6..70a7ad121bc1 100644 --- a/gdk/src/event_touch.rs +++ b/gdk/src/event_touch.rs @@ -2,7 +2,6 @@ // See the COPYRIGHT file at the top-level directory of this distribution. // Licensed under the MIT license, see the LICENSE file or -use gdk_sys; use glib::translate::*; #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] diff --git a/gdk/src/event_visibility.rs b/gdk/src/event_visibility.rs index 760b4777c3d0..dea353d1c486 100644 --- a/gdk/src/event_visibility.rs +++ b/gdk/src/event_visibility.rs @@ -2,7 +2,6 @@ // See the COPYRIGHT file at the top-level directory of this distribution. // Licensed under the MIT license, see the LICENSE file or -use gdk_sys; use glib::translate::*; #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] diff --git a/gdk/src/event_window_state.rs b/gdk/src/event_window_state.rs index 0f71c86dede1..1d5eee05c4da 100644 --- a/gdk/src/event_window_state.rs +++ b/gdk/src/event_window_state.rs @@ -2,7 +2,6 @@ // See the COPYRIGHT file at the top-level directory of this distribution. // Licensed under the MIT license, see the LICENSE file or -use gdk_sys; use glib::translate::*; #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] diff --git a/gdk/src/functions.rs b/gdk/src/functions.rs index df85a6891351..1202e1eef251 100644 --- a/gdk/src/functions.rs +++ b/gdk/src/functions.rs @@ -59,7 +59,7 @@ pub fn setting_get(name: &str) -> Option { name.to_glib_none().0, value.to_glib_none_mut().0, )); - if done == true { + if done { Some(value) } else { None diff --git a/gdk/src/lib.rs b/gdk/src/lib.rs index 65176214289f..d5f88ef57b76 100644 --- a/gdk/src/lib.rs +++ b/gdk/src/lib.rs @@ -1,11 +1,9 @@ // Copyright 2013-2018, The Gtk-rs Project Developers. // See the COPYRIGHT file at the top-level directory of this distribution. // Licensed under the MIT license, see the LICENSE file or - -#![allow(deprecated)] -#![cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))] -#![cfg_attr(feature = "cargo-clippy", allow(trivially_copy_pass_by_ref))] #![cfg_attr(feature = "dox", feature(doc_cfg))] +#![allow(clippy::missing_safety_doc)] +#![allow(deprecated)] extern crate gdk_pixbuf; #[doc(hidden)] @@ -29,8 +27,9 @@ mod rt; #[macro_use] mod event; -#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))] -#[cfg_attr(feature = "cargo-clippy", allow(unreadable_literal))] +#[allow(clippy::type_complexity)] +#[allow(clippy::unreadable_literal)] +#[allow(unused_doc_comments)] #[allow(unused_imports)] mod auto; diff --git a/gdk/src/screen.rs b/gdk/src/screen.rs index fb3265c2f4df..e3eeea179b73 100644 --- a/gdk/src/screen.rs +++ b/gdk/src/screen.rs @@ -26,7 +26,7 @@ impl Screen { value.to_glib_none_mut().0, )); - if done == true { + if done { Some(value) } else { None diff --git a/gdk/src/time_coord.rs b/gdk/src/time_coord.rs index 9b46f5de5bb9..cc75ed5ad65a 100644 --- a/gdk/src/time_coord.rs +++ b/gdk/src/time_coord.rs @@ -100,7 +100,7 @@ impl FromGlibContainerAsVec f let mut res = Vec::with_capacity(num); for i in 0..num { - res.push((*(ptr.offset(i as isize) as *mut TimeCoord)).clone()); + res.push((*(ptr.add(i) as *mut TimeCoord)).clone()); } res } @@ -121,7 +121,7 @@ impl FromGlibContainerAsVec f let mut res = Vec::with_capacity(num); for i in 0..num { - res.push((*(ptr.offset(i as isize) as *mut TimeCoord)).clone()); + res.push((*(ptr.add(i) as *mut TimeCoord)).clone()); } glib_sys::g_free(ptr as *mut _); res diff --git a/gdk/src/window.rs b/gdk/src/window.rs index 4997bd9b9b1b..d4c5f3f64381 100644 --- a/gdk/src/window.rs +++ b/gdk/src/window.rs @@ -79,7 +79,7 @@ impl WindowAttr { } } -#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))] +#[allow(clippy::type_complexity)] impl<'a> ToGlibPtr<'a, *mut gdk_sys::GdkWindowAttr> for WindowAttr { type Storage = ( Box, @@ -146,7 +146,7 @@ impl Window { pub trait WindowExtManual: 'static { unsafe fn set_user_data(&self, user_data: &mut T); - #[cfg_attr(feature = "cargo-clippy", allow(mut_from_ref))] + #[allow(clippy::mut_from_ref)] unsafe fn get_user_data(&self) -> &mut T; fn get_default_root_window() -> Window; diff --git a/gdkx11/build.rs b/gdkx11/build.rs index f9e53f435795..58290d785795 100644 --- a/gdkx11/build.rs +++ b/gdkx11/build.rs @@ -5,8 +5,8 @@ fn main() { #[cfg(any(feature = "embed-lgpl-docs", feature = "purge-lgpl-docs"))] fn manage_docs() { extern crate lgpl_docs; - const PATH: &'static str = "src"; - const IGNORES: &'static [&'static str] = &["lib.rs"]; + const PATH: &str = "src"; + const IGNORES: &[&str] = &["lib.rs"]; lgpl_docs::purge(PATH, IGNORES); if cfg!(feature = "embed-lgpl-docs") { lgpl_docs::embed(lgpl_docs::Library::SourceView, PATH, IGNORES); diff --git a/gdkx11/src/lib.rs b/gdkx11/src/lib.rs index c21cc974bd6c..46ae5ab57229 100644 --- a/gdkx11/src/lib.rs +++ b/gdkx11/src/lib.rs @@ -1,10 +1,9 @@ // Copyright 2013-2020, The Gtk-rs Project Developers. // See the COPYRIGHT file at the top-level directory of this distribution. // Licensed under the MIT license, see the LICENSE file or - -#![allow(deprecated)] -#![cfg_attr(feature = "cargo-clippy", allow(type_complexity))] #![cfg_attr(feature = "dox", feature(doc_cfg))] +#![allow(deprecated)] +#![allow(clippy::type_complexity)] #[macro_use] extern crate glib; @@ -27,6 +26,8 @@ pub(crate) use x11::xlib; #[macro_use] mod rt; +#[allow(clippy::let_and_return)] +#[allow(unused_doc_comments)] #[allow(unused_imports)] mod auto; diff --git a/gio/src/inet_address.rs b/gio/src/inet_address.rs index 5bf0d9090a47..690444910c99 100644 --- a/gio/src/inet_address.rs +++ b/gio/src/inet_address.rs @@ -42,12 +42,12 @@ impl InetAddress { } pub trait InetAddressExtManual { - fn to_bytes<'a>(&'a self) -> Option>; + fn to_bytes(&self) -> Option>; } impl> InetAddressExtManual for O { /// Returns `None` in case the address has a native size different than 4 and 16. - fn to_bytes<'a>(&'a self) -> Option> { + fn to_bytes(&self) -> Option> { let size = self.get_native_size(); unsafe { let bytes = gio_sys::g_inet_address_to_bytes(self.as_ref().to_glib_none().0); diff --git a/gio/src/lib.rs b/gio/src/lib.rs index afb2d6c7aa84..3d581253d477 100644 --- a/gio/src/lib.rs +++ b/gio/src/lib.rs @@ -1,12 +1,11 @@ // Copyright 2013-2018, The Gtk-rs Project Developers. // See the COPYRIGHT file at the top-level directory of this distribution. // Licensed under the MIT license, see the LICENSE file or - -#![allow(deprecated)] -#![allow(clippy::let_and_return)] -#![allow(clippy::too_many_arguments)] -#![allow(clippy::type_complexity)] #![cfg_attr(feature = "dox", feature(doc_cfg))] +#![allow(clippy::type_complexity)] +#![allow(clippy::too_many_arguments)] +#![allow(clippy::missing_safety_doc)] +#![allow(deprecated)] #[macro_use] extern crate bitflags; @@ -101,6 +100,9 @@ pub mod prelude; #[allow(clippy::cast_ptr_alignment)] #[allow(clippy::wrong_self_convention)] +#[allow(clippy::new_ret_no_self)] +#[allow(clippy::let_and_return)] +#[allow(unused_doc_comments)] #[allow(unused_imports)] mod auto; diff --git a/gio/src/read_input_stream.rs b/gio/src/read_input_stream.rs index 126c90402bcb..e0245f18f1f7 100644 --- a/gio/src/read_input_stream.rs +++ b/gio/src/read_input_stream.rs @@ -98,10 +98,7 @@ mod imp { fn can_seek(&self, _seekable: &Self::Type) -> bool { let read = self.read.borrow(); - match *read { - Some(Reader::ReadSeek(_)) => true, - _ => false, - } + matches!(*read, Some(Reader::ReadSeek(_))) } fn seek( diff --git a/gio/src/test_util.rs b/gio/src/test_util.rs index c751ab62c06c..577d02bcca0c 100644 --- a/gio/src/test_util.rs +++ b/gio/src/test_util.rs @@ -23,6 +23,5 @@ pub fn run_async, MainLoop) + Send + 'sta l.run(); c.pop_thread_default(); - let ret = rx.recv().unwrap(); - ret + rx.recv().unwrap() } diff --git a/gio/src/unix_input_stream.rs b/gio/src/unix_input_stream.rs index 33f276dd73e1..36556c2f1033 100644 --- a/gio/src/unix_input_stream.rs +++ b/gio/src/unix_input_stream.rs @@ -14,6 +14,7 @@ use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; use socket::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; impl UnixInputStream { + #[allow(clippy::missing_safety_doc)] pub unsafe fn new(fd: T) -> UnixInputStream { let fd = fd.into_raw_fd(); let close_fd = true.to_glib(); @@ -29,6 +30,7 @@ impl AsRawFd for UnixInputStream { pub trait UnixInputStreamExtManual: Sized { fn get_fd(&self) -> T; + #[allow(clippy::missing_safety_doc)] unsafe fn set_close_fd(&self, close_fd: bool); } diff --git a/gio/src/unix_socket_address.rs b/gio/src/unix_socket_address.rs index 2e70cb5f7272..e84a7291dbb4 100644 --- a/gio/src/unix_socket_address.rs +++ b/gio/src/unix_socket_address.rs @@ -6,8 +6,10 @@ use gio_sys; use glib::object::{Cast, IsA}; use glib::translate::*; use libc; +#[cfg(not(feature = "dox"))] use std::ffi::OsStr; #[cfg(unix)] +#[cfg(not(feature = "dox"))] use std::os::unix::ffi::OsStrExt; use std::path; use std::ptr; diff --git a/gio/src/write_output_stream.rs b/gio/src/write_output_stream.rs index 4b162c83da1f..4f204dbcd5dc 100644 --- a/gio/src/write_output_stream.rs +++ b/gio/src/write_output_stream.rs @@ -125,10 +125,7 @@ mod imp { fn can_seek(&self, _seekable: &Self::Type) -> bool { let write = self.write.borrow(); - match *write { - Some(Writer::WriteSeek(_)) => true, - _ => false, - } + matches!(*write, Some(Writer::WriteSeek(_))) } fn seek( diff --git a/glib/src/boxed.rs b/glib/src/boxed.rs index b9450888da10..ace66b31abaf 100644 --- a/glib/src/boxed.rs +++ b/glib/src/boxed.rs @@ -145,7 +145,6 @@ macro_rules! glib_boxed_wrapper { #[doc(hidden)] impl $crate::translate::FromGlibPtrNone<*mut $ffi_name> for $name { #[inline] - #[allow(clippy::missing_safety_doc)] unsafe fn from_glib_none(ptr: *mut $ffi_name) -> Self { $name($crate::translate::from_glib_none(ptr)) } @@ -154,7 +153,6 @@ macro_rules! glib_boxed_wrapper { #[doc(hidden)] impl $crate::translate::FromGlibPtrNone<*const $ffi_name> for $name { #[inline] - #[allow(clippy::missing_safety_doc)] unsafe fn from_glib_none(ptr: *const $ffi_name) -> Self { $name($crate::translate::from_glib_none(ptr)) } @@ -163,7 +161,6 @@ macro_rules! glib_boxed_wrapper { #[doc(hidden)] impl $crate::translate::FromGlibPtrFull<*mut $ffi_name> for $name { #[inline] - #[allow(clippy::missing_safety_doc)] unsafe fn from_glib_full(ptr: *mut $ffi_name) -> Self { $name($crate::translate::from_glib_full(ptr)) } @@ -172,7 +169,6 @@ macro_rules! glib_boxed_wrapper { #[doc(hidden)] impl $crate::translate::FromGlibPtrFull<*const $ffi_name> for $name { #[inline] - #[allow(clippy::missing_safety_doc)] unsafe fn from_glib_full(ptr: *const $ffi_name) -> Self { $name($crate::translate::from_glib_full(ptr)) } @@ -181,7 +177,6 @@ macro_rules! glib_boxed_wrapper { #[doc(hidden)] impl $crate::translate::FromGlibPtrBorrow<*mut $ffi_name> for $name { #[inline] - #[allow(clippy::missing_safety_doc)] unsafe fn from_glib_borrow(ptr: *mut $ffi_name) -> $crate::translate::Borrowed { $crate::translate::Borrowed::new( $name( @@ -194,7 +189,6 @@ macro_rules! glib_boxed_wrapper { #[doc(hidden)] impl $crate::translate::FromGlibPtrBorrow<*const $ffi_name> for $name { #[inline] - #[allow(clippy::missing_safety_doc)] unsafe fn from_glib_borrow(ptr: *const $ffi_name) -> $crate::translate::Borrowed { $crate::translate::from_glib_borrow::<_, $name>(ptr as *mut $ffi_name) } @@ -202,7 +196,6 @@ macro_rules! glib_boxed_wrapper { #[doc(hidden)] impl $crate::translate::FromGlibContainerAsVec<*mut $ffi_name, *mut *mut $ffi_name> for $name { - #[allow(clippy::missing_safety_doc)] unsafe fn from_glib_none_num_as_vec(ptr: *mut *mut $ffi_name, num: usize) -> Vec { if num == 0 || ptr.is_null() { return Vec::new(); @@ -215,14 +208,12 @@ macro_rules! glib_boxed_wrapper { res } - #[allow(clippy::missing_safety_doc)] unsafe fn from_glib_container_num_as_vec(ptr: *mut *mut $ffi_name, num: usize) -> Vec { let res = $crate::translate::FromGlibContainerAsVec::from_glib_none_num_as_vec(ptr, num); $crate::glib_sys::g_free(ptr as *mut _); res } - #[allow(clippy::missing_safety_doc)] unsafe fn from_glib_full_num_as_vec(ptr: *mut *mut $ffi_name, num: usize) -> Vec { if num == 0 || ptr.is_null() { return Vec::new(); @@ -239,17 +230,14 @@ macro_rules! glib_boxed_wrapper { #[doc(hidden)] impl $crate::translate::FromGlibPtrArrayContainerAsVec<*mut $ffi_name, *mut *mut $ffi_name> for $name { - #[allow(clippy::missing_safety_doc)] unsafe fn from_glib_none_as_vec(ptr: *mut *mut $ffi_name) -> Vec { $crate::translate::FromGlibContainerAsVec::from_glib_none_num_as_vec(ptr, $crate::translate::c_ptr_array_len(ptr)) } - #[allow(clippy::missing_safety_doc)] unsafe fn from_glib_container_as_vec(ptr: *mut *mut $ffi_name) -> Vec { $crate::translate::FromGlibContainerAsVec::from_glib_container_num_as_vec(ptr, $crate::translate::c_ptr_array_len(ptr)) } - #[allow(clippy::missing_safety_doc)] unsafe fn from_glib_full_as_vec(ptr: *mut *mut $ffi_name) -> Vec { $crate::translate::FromGlibContainerAsVec::from_glib_full_num_as_vec(ptr, $crate::translate::c_ptr_array_len(ptr)) } @@ -266,7 +254,6 @@ macro_rules! glib_boxed_wrapper { #[doc(hidden)] impl<'a> $crate::value::FromValueOptional<'a> for $name { - #[allow(clippy::missing_safety_doc)] unsafe fn from_value_optional(value: &$crate::Value) -> Option { $crate::translate::from_glib_full($crate::gobject_sys::g_value_dup_boxed($crate::translate::ToGlibPtr::to_glib_none(value).0) as *mut $ffi_name) } @@ -274,7 +261,6 @@ macro_rules! glib_boxed_wrapper { #[doc(hidden)] impl $crate::value::SetValue for $name { - #[allow(clippy::missing_safety_doc)] unsafe fn set_value(value: &mut $crate::Value, this: &Self) { $crate::gobject_sys::g_value_set_boxed($crate::translate::ToGlibPtrMut::to_glib_none_mut(value).0, $crate::translate::ToGlibPtr::<*const $ffi_name>::to_glib_none(this).0 as $crate::glib_sys::gpointer) } @@ -282,7 +268,6 @@ macro_rules! glib_boxed_wrapper { #[doc(hidden)] impl $crate::value::SetValueOptional for $name { - #[allow(clippy::missing_safety_doc)] unsafe fn set_value_optional(value: &mut $crate::Value, this: Option<&Self>) { $crate::gobject_sys::g_value_set_boxed($crate::translate::ToGlibPtrMut::to_glib_none_mut(value).0, $crate::translate::ToGlibPtr::<*const $ffi_name>::to_glib_none(&this).0 as $crate::glib_sys::gpointer) } @@ -365,7 +350,6 @@ impl fmt::Debug for AnyBox { } // The safety docs really belong in the glib_wrapper!() macro for Boxed -#[allow(clippy::missing_safety_doc)] /// Memory management functions for a boxed type. pub trait BoxedMemoryManager: 'static { /// Makes a copy. diff --git a/glib/src/byte_array.rs b/glib/src/byte_array.rs index f783151c5428..36c87b53a02e 100644 --- a/glib/src/byte_array.rs +++ b/glib/src/byte_array.rs @@ -97,7 +97,6 @@ impl ByteArray { } } - #[allow(clippy::missing_safety_doc)] pub unsafe fn set_size(&self, size: usize) { glib_sys::g_byte_array_set_size(self.to_glib_none().0, size as u32); } diff --git a/glib/src/char.rs b/glib/src/char.rs index b55694d14e04..c62c6a833b8f 100644 --- a/glib/src/char.rs +++ b/glib/src/char.rs @@ -139,12 +139,10 @@ mod tests { #[test] fn converts_single_byte_chars() { - assert_eq!(Char::new(0 as char), Some(Char(0 as c_char))); - assert_eq!(Char::new(255 as char), Some(Char(-1 as i8 as c_char))); - assert_eq!(Char::new('ñ'), Some(Char(241 as u8 as c_char))); - assert_eq!(UChar::new(0 as char), Some(UChar(0 as c_uchar))); - assert_eq!(UChar::new(255 as char), Some(UChar(255 as c_uchar))); - assert_eq!(UChar::new('ñ'), Some(UChar(241 as c_uchar))); + assert_eq!(Char::new(0 as char), Some(Char(0_i8))); + assert_eq!(UChar::new(0 as char), Some(UChar(0_u8))); + assert_eq!(UChar::new(255 as char), Some(UChar(255_u8))); + assert_eq!(UChar::new('ñ'), Some(UChar(241_u8))); } #[test] @@ -155,23 +153,23 @@ mod tests { #[test] fn into_i8() { - assert_eq!(Char::new('A').unwrap().to_glib(), 65 as c_char); + assert_eq!(Char::new('A').unwrap().to_glib(), 65_i8); } #[test] fn into_u8() { - assert_eq!(UChar::new('A').unwrap().to_glib(), 65 as c_uchar); + assert_eq!(UChar::new('A').unwrap().to_glib(), 65_u8); } #[test] fn into_char() { - assert_eq!(char::from(Char(65 as c_char)), 'A'); - assert_eq!('ñ', UChar(241 as c_uchar).into()); + assert_eq!(char::from(Char(65_i8)), 'A'); + assert_eq!('ñ', UChar(241_u8).into()); } #[test] fn convert_from_glib() { - assert_eq!(Char(65 as c_char), from_glib(65 as c_char)); - assert_eq!(UChar(241 as c_uchar), from_glib(241 as u8 as c_uchar)); + assert_eq!(Char(65_i8), from_glib(65_i8)); + assert_eq!(UChar(241_u8), from_glib(241_u8)); } } diff --git a/glib/src/closure.rs b/glib/src/closure.rs index 3d9b05a9e402..b00e6107c5a0 100644 --- a/glib/src/closure.rs +++ b/glib/src/closure.rs @@ -41,7 +41,6 @@ impl Closure { unsafe { Closure::new_unsafe(move |values| (callback.get_ref())(values)) } } - #[allow(clippy::missing_safety_doc)] pub unsafe fn new_unsafe Option>(callback: F) -> Self { unsafe extern "C" fn marshal( _closure: *mut gobject_sys::GClosure, diff --git a/glib/src/lib.rs b/glib/src/lib.rs index 9239a5b4616b..469f2bb91d4c 100644 --- a/glib/src/lib.rs +++ b/glib/src/lib.rs @@ -77,6 +77,7 @@ #![allow(clippy::doc_markdown)] #![allow(clippy::unreadable_literal)] #![cfg_attr(feature = "dox", feature(doc_cfg))] +#![allow(clippy::missing_safety_doc)] #[doc(hidden)] #[macro_use] @@ -143,6 +144,7 @@ pub use auto::*; #[allow(clippy::let_unit_value)] #[allow(clippy::too_many_arguments)] #[allow(clippy::type_complexity)] +#[allow(unused_doc_comments)] #[allow(non_upper_case_globals)] #[allow(unused_imports)] mod auto; diff --git a/glib/src/object.rs b/glib/src/object.rs index 1ac2358d8ff6..8472b95c5063 100644 --- a/glib/src/object.rs +++ b/glib/src/object.rs @@ -652,7 +652,6 @@ macro_rules! glib_object_wrapper { #[doc(hidden)] impl $crate::object::UnsafeFrom<$crate::object::ObjectRef> for $name { - #[allow(clippy::missing_safety_doc)] unsafe fn unsafe_from(t: $crate::object::ObjectRef) -> Self { $name(t) } @@ -793,7 +792,6 @@ macro_rules! glib_object_wrapper { impl $crate::translate::FromGlibPtrNone<*mut $ffi_name> for $name { #[inline] #[allow(clippy::cast_ptr_alignment)] - #[allow(clippy::missing_safety_doc)] unsafe fn from_glib_none(ptr: *mut $ffi_name) -> Self { debug_assert!($crate::types::instance_of::(ptr as *const _)); $name($crate::translate::from_glib_none(ptr as *mut _)) @@ -804,7 +802,6 @@ macro_rules! glib_object_wrapper { impl $crate::translate::FromGlibPtrNone<*const $ffi_name> for $name { #[inline] #[allow(clippy::cast_ptr_alignment)] - #[allow(clippy::missing_safety_doc)] unsafe fn from_glib_none(ptr: *const $ffi_name) -> Self { debug_assert!($crate::types::instance_of::(ptr as *const _)); $name($crate::translate::from_glib_none(ptr as *mut _)) @@ -815,7 +812,6 @@ macro_rules! glib_object_wrapper { impl $crate::translate::FromGlibPtrFull<*mut $ffi_name> for $name { #[inline] #[allow(clippy::cast_ptr_alignment)] - #[allow(clippy::missing_safety_doc)] unsafe fn from_glib_full(ptr: *mut $ffi_name) -> Self { debug_assert!($crate::types::instance_of::(ptr as *const _)); $name($crate::translate::from_glib_full(ptr as *mut _)) @@ -826,7 +822,6 @@ macro_rules! glib_object_wrapper { impl $crate::translate::FromGlibPtrBorrow<*mut $ffi_name> for $name { #[inline] #[allow(clippy::cast_ptr_alignment)] - #[allow(clippy::missing_safety_doc)] unsafe fn from_glib_borrow(ptr: *mut $ffi_name) -> $crate::translate::Borrowed { debug_assert!($crate::types::instance_of::(ptr as *const _)); $crate::translate::Borrowed::new( @@ -841,7 +836,6 @@ macro_rules! glib_object_wrapper { impl $crate::translate::FromGlibPtrBorrow<*const $ffi_name> for $name { #[inline] #[allow(clippy::cast_ptr_alignment)] - #[allow(clippy::missing_safety_doc)] unsafe fn from_glib_borrow(ptr: *const $ffi_name) -> $crate::translate::Borrowed { $crate::translate::from_glib_borrow::<_, $name>(ptr as *mut $ffi_name) } @@ -849,7 +843,6 @@ macro_rules! glib_object_wrapper { #[doc(hidden)] impl $crate::translate::FromGlibContainerAsVec<*mut $ffi_name, *mut *mut $ffi_name> for $name { - #[allow(clippy::missing_safety_doc)] unsafe fn from_glib_none_num_as_vec(ptr: *mut *mut $ffi_name, num: usize) -> Vec { if num == 0 || ptr.is_null() { return Vec::new(); @@ -862,14 +855,12 @@ macro_rules! glib_object_wrapper { res } - #[allow(clippy::missing_safety_doc)] unsafe fn from_glib_container_num_as_vec(ptr: *mut *mut $ffi_name, num: usize) -> Vec { let res = $crate::translate::FromGlibContainerAsVec::from_glib_none_num_as_vec(ptr, num); $crate::glib_sys::g_free(ptr as *mut _); res } - #[allow(clippy::missing_safety_doc)] unsafe fn from_glib_full_num_as_vec(ptr: *mut *mut $ffi_name, num: usize) -> Vec { if num == 0 || ptr.is_null() { return Vec::new(); @@ -886,17 +877,14 @@ macro_rules! glib_object_wrapper { #[doc(hidden)] impl $crate::translate::FromGlibPtrArrayContainerAsVec<*mut $ffi_name, *mut *mut $ffi_name> for $name { - #[allow(clippy::missing_safety_doc)] unsafe fn from_glib_none_as_vec(ptr: *mut *mut $ffi_name) -> Vec { $crate::translate::FromGlibContainerAsVec::from_glib_none_num_as_vec(ptr, $crate::translate::c_ptr_array_len(ptr)) } - #[allow(clippy::missing_safety_doc)] unsafe fn from_glib_container_as_vec(ptr: *mut *mut $ffi_name) -> Vec { $crate::translate::FromGlibContainerAsVec::from_glib_container_num_as_vec(ptr, $crate::translate::c_ptr_array_len(ptr)) } - #[allow(clippy::missing_safety_doc)] unsafe fn from_glib_full_as_vec(ptr: *mut *mut $ffi_name) -> Vec { $crate::translate::FromGlibContainerAsVec::from_glib_full_num_as_vec(ptr, $crate::translate::c_ptr_array_len(ptr)) } @@ -904,18 +892,15 @@ macro_rules! glib_object_wrapper { #[doc(hidden)] impl $crate::translate::FromGlibContainerAsVec<*mut $ffi_name, *const *mut $ffi_name> for $name { - #[allow(clippy::missing_safety_doc)] unsafe fn from_glib_none_num_as_vec(ptr: *const *mut $ffi_name, num: usize) -> Vec { $crate::translate::FromGlibContainerAsVec::from_glib_none_num_as_vec(ptr as *mut *mut _, num) } - #[allow(clippy::missing_safety_doc)] unsafe fn from_glib_container_num_as_vec(_: *const *mut $ffi_name, _: usize) -> Vec { // Can't free a *const unimplemented!() } - #[allow(clippy::missing_safety_doc)] unsafe fn from_glib_full_num_as_vec(_: *const *mut $ffi_name, _: usize) -> Vec { // Can't free a *const unimplemented!() @@ -924,18 +909,15 @@ macro_rules! glib_object_wrapper { #[doc(hidden)] impl $crate::translate::FromGlibPtrArrayContainerAsVec<*mut $ffi_name, *const *mut $ffi_name> for $name { - #[allow(clippy::missing_safety_doc)] unsafe fn from_glib_none_as_vec(ptr: *const *mut $ffi_name) -> Vec { $crate::translate::FromGlibPtrArrayContainerAsVec::from_glib_none_as_vec(ptr as *mut *mut _) } - #[allow(clippy::missing_safety_doc)] unsafe fn from_glib_container_as_vec(_: *const *mut $ffi_name) -> Vec { // Can't free a *const unimplemented!() } - #[allow(clippy::missing_safety_doc)] unsafe fn from_glib_full_as_vec(_: *const *mut $ffi_name) -> Vec { // Can't free a *const unimplemented!() @@ -965,7 +947,6 @@ macro_rules! glib_object_wrapper { #[doc(hidden)] impl<'a> $crate::value::FromValueOptional<'a> for $name { - #[allow(clippy::missing_safety_doc)] unsafe fn from_value_optional(value: &$crate::Value) -> Option { let obj = $crate::gobject_sys::g_value_get_object($crate::translate::ToGlibPtr::to_glib_none(value).0); @@ -984,7 +965,6 @@ macro_rules! glib_object_wrapper { #[doc(hidden)] impl $crate::value::SetValue for $name { #[allow(clippy::cast_ptr_alignment)] - #[allow(clippy::missing_safety_doc)] unsafe fn set_value(value: &mut $crate::Value, this: &Self) { $crate::gobject_sys::g_value_set_object($crate::translate::ToGlibPtrMut::to_glib_none_mut(value).0, $crate::translate::ToGlibPtr::<*mut $ffi_name>::to_glib_none(this).0 as *mut $crate::gobject_sys::GObject) } @@ -993,7 +973,6 @@ macro_rules! glib_object_wrapper { #[doc(hidden)] impl $crate::value::SetValueOptional for $name { #[allow(clippy::cast_ptr_alignment)] - #[allow(clippy::missing_safety_doc)] unsafe fn set_value_optional(value: &mut $crate::Value, this: Option<&Self>) { $crate::gobject_sys::g_value_set_object($crate::translate::ToGlibPtrMut::to_glib_none_mut(value).0, $crate::translate::ToGlibPtr::<*mut $ffi_name>::to_glib_none(&this).0 as *mut $crate::gobject_sys::GObject) } @@ -1276,7 +1255,6 @@ pub trait ObjectExt: ObjectType { where N: Into<&'a str>, F: Fn(&[Value]) -> Option + 'static; - #[allow(clippy::missing_safety_doc)] unsafe fn connect_unsafe<'a, N, F>( &self, signal_name: N, @@ -1308,7 +1286,6 @@ pub trait ObjectExt: ObjectType { name: Option<&str>, f: F, ) -> SignalHandlerId; - #[allow(clippy::missing_safety_doc)] unsafe fn connect_notify_unsafe( &self, name: Option<&str>, diff --git a/glib/src/param_spec.rs b/glib/src/param_spec.rs index 4949b6c8cf22..c83938da7097 100644 --- a/glib/src/param_spec.rs +++ b/glib/src/param_spec.rs @@ -33,7 +33,6 @@ impl StaticType for ParamSpec { #[doc(hidden)] impl<'a> value::FromValueOptional<'a> for ParamSpec { - #[allow(clippy::missing_safety_doc)] unsafe fn from_value_optional(value: &Value) -> Option { from_glib_full(gobject_sys::g_value_dup_param(value.to_glib_none().0)) } @@ -41,7 +40,6 @@ impl<'a> value::FromValueOptional<'a> for ParamSpec { #[doc(hidden)] impl value::SetValue for ParamSpec { - #[allow(clippy::missing_safety_doc)] unsafe fn set_value(value: &mut Value, this: &Self) { gobject_sys::g_value_set_param(value.to_glib_none_mut().0, this.to_glib_none().0) } @@ -49,7 +47,6 @@ impl value::SetValue for ParamSpec { #[doc(hidden)] impl value::SetValueOptional for ParamSpec { - #[allow(clippy::missing_safety_doc)] unsafe fn set_value_optional(value: &mut Value, this: Option<&Self>) { gobject_sys::g_value_set_param(value.to_glib_none_mut().0, this.to_glib_none().0) } @@ -642,7 +639,6 @@ macro_rules! define_param_spec { #[doc(hidden)] impl<'a> value::FromValueOptional<'a> for $rust_type { - #[allow(clippy::missing_safety_doc)] unsafe fn from_value_optional(value: &Value) -> Option { from_glib_full(gobject_sys::g_value_dup_param(value.to_glib_none().0) as *mut $ffi_type) } @@ -650,7 +646,6 @@ macro_rules! define_param_spec { #[doc(hidden)] impl value::SetValue for $rust_type { - #[allow(clippy::missing_safety_doc)] unsafe fn set_value(value: &mut Value, this: &Self) { gobject_sys::g_value_set_param(value.to_glib_none_mut().0, this.to_glib_none().0 as *mut gobject_sys::GParamSpec) } @@ -658,7 +653,6 @@ macro_rules! define_param_spec { #[doc(hidden)] impl value::SetValueOptional for $rust_type { - #[allow(clippy::missing_safety_doc)] unsafe fn set_value_optional(value: &mut Value, this: Option<&Self>) { gobject_sys::g_value_set_param(value.to_glib_none_mut().0, this.to_glib_none().0 as *mut gobject_sys::GParamSpec) } diff --git a/glib/src/shared.rs b/glib/src/shared.rs index 4275ea6dd73d..990c2c8c8409 100644 --- a/glib/src/shared.rs +++ b/glib/src/shared.rs @@ -29,7 +29,6 @@ macro_rules! glib_shared_wrapper { #[doc(hidden)] impl<'a> $crate::value::FromValueOptional<'a> for $name { - #[allow(clippy::missing_safety_doc)] unsafe fn from_value_optional(value: &$crate::Value) -> Option { $crate::translate::from_glib_full($crate::gobject_sys::g_value_dup_boxed($crate::translate::ToGlibPtr::to_glib_none(value).0) as *mut $ffi_name) } @@ -37,7 +36,6 @@ macro_rules! glib_shared_wrapper { #[doc(hidden)] impl $crate::value::SetValue for $name { - #[allow(clippy::missing_safety_doc)] unsafe fn set_value(value: &mut $crate::Value, this: &Self) { $crate::gobject_sys::g_value_set_boxed($crate::translate::ToGlibPtrMut::to_glib_none_mut(value).0, $crate::translate::ToGlibPtr::<*mut $ffi_name>::to_glib_none(this).0 as $crate::glib_sys::gpointer) } @@ -45,7 +43,6 @@ macro_rules! glib_shared_wrapper { #[doc(hidden)] impl $crate::value::SetValueOptional for $name { - #[allow(clippy::missing_safety_doc)] unsafe fn set_value_optional(value: &mut $crate::Value, this: Option<&Self>) { $crate::gobject_sys::g_value_set_boxed($crate::translate::ToGlibPtrMut::to_glib_none_mut(value).0, $crate::translate::ToGlibPtr::<*mut $ffi_name>::to_glib_none(&this).0 as $crate::glib_sys::gpointer) } diff --git a/glib/src/signal.rs b/glib/src/signal.rs index e7ff2e7cbc44..72d03222ac03 100644 --- a/glib/src/signal.rs +++ b/glib/src/signal.rs @@ -49,7 +49,6 @@ impl ToGlib for Inhibit { } } -#[allow(clippy::missing_safety_doc)] pub unsafe fn connect_raw( receiver: *mut gobject_sys::GObject, signal_name: *const c_char, diff --git a/glib/src/string.rs b/glib/src/string.rs index c5f89c45b770..e477c6311546 100644 --- a/glib/src/string.rs +++ b/glib/src/string.rs @@ -232,7 +232,6 @@ mod tests { let a1 = ::String::new("a"); let a2 = ::String::new("a"); let b = ::String::new("b"); - assert_eq!(a1, a1); assert_eq!(a1, a2); assert_ne!(a1, b); assert_ne!(a2, b); diff --git a/glib/src/subclass/mod.rs b/glib/src/subclass/mod.rs index 161bc6e8fa5f..d859d5e2e205 100644 --- a/glib/src/subclass/mod.rs +++ b/glib/src/subclass/mod.rs @@ -172,13 +172,13 @@ //! //! // Called whenever a property is retrieved from this instance. The id //! // is the same as the index of the property in the PROPERTIES array. -//! fn get_property(&self, _obj: &Self::Type, id: usize) -> Result { +//! 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("animal", ..) => Ok(self.animal.get().to_value()), -//! subclass::Property("flags", ..) => Ok(self.flags.get().to_value()), +//! subclass::Property("name", ..) => self.name.borrow().to_value(), +//! subclass::Property("animal", ..) => self.animal.get().to_value(), +//! subclass::Property("flags", ..) => self.flags.get().to_value(), //! _ => unimplemented!(), //! } //! } diff --git a/glib/src/subclass/object.rs b/glib/src/subclass/object.rs index 92ab85cedbba..f1ad48db0133 100644 --- a/glib/src/subclass/object.rs +++ b/glib/src/subclass/object.rs @@ -31,7 +31,7 @@ pub trait ObjectImpl: ObjectSubclass + ObjectImplExt { /// /// This is called whenever the property value of the specific subclass with the /// given index should be returned. - fn get_property(&self, _obj: &Self::Type, _id: usize) -> Result { + fn get_property(&self, _obj: &Self::Type, _id: usize) -> Value { unimplemented!() } @@ -54,25 +54,22 @@ unsafe extern "C" fn get_property( let instance = &*(obj as *mut T::Instance); let imp = instance.get_impl(); - match imp.get_property( + let v = imp.get_property( &from_glib_borrow::<_, Object>(obj).unsafe_cast_ref(), (id - 1) as usize, - ) { - Ok(v) => { - // We first unset the value we get passed in, in case it contained - // any previous data. Then we directly overwrite it with our new - // value, and pass ownership of the contained data to the C GValue - // by forgetting it on the Rust side. - // - // Without this, by using the GValue API, we would have to create - // a copy of the value when setting it on the destination just to - // immediately free the original value afterwards. - gobject_sys::g_value_unset(value); - let v = mem::ManuallyDrop::new(v); - ptr::write(value, ptr::read(v.to_glib_none().0)); - } - Err(()) => eprintln!("Failed to get property"), - } + ); + + // We first unset the value we get passed in, in case it contained + // any previous data. Then we directly overwrite it with our new + // value, and pass ownership of the contained data to the C GValue + // by forgetting it on the Rust side. + // + // Without this, by using the GValue API, we would have to create + // a copy of the value when setting it on the destination just to + // immediately free the original value afterwards. + gobject_sys::g_value_unset(value); + let v = mem::ManuallyDrop::new(v); + ptr::write(value, ptr::read(v.to_glib_none().0)); } unsafe extern "C" fn set_property( @@ -455,13 +452,13 @@ mod test { } } - fn get_property(&self, _obj: &Self::Type, id: usize) -> Result { + fn get_property(&self, _obj: &Self::Type, id: usize) -> Value { let prop = &PROPERTIES[id]; match *prop { - Property("name", ..) => Ok(self.name.borrow().to_value()), - Property("construct-name", ..) => Ok(self.construct_name.borrow().to_value()), - Property("constructed", ..) => Ok(self.constructed.borrow().to_value()), + Property("name", ..) => self.name.borrow().to_value(), + Property("construct-name", ..) => self.construct_name.borrow().to_value(), + Property("constructed", ..) => self.constructed.borrow().to_value(), _ => unimplemented!(), } } diff --git a/glib/src/translate.rs b/glib/src/translate.rs index d98532e4e8d3..20ecb317a619 100644 --- a/glib/src/translate.rs +++ b/glib/src/translate.rs @@ -205,13 +205,11 @@ pub fn const_override(ptr: *mut T) -> *const T { /// A trait for creating an uninitialized value. Handy for receiving outparams. pub trait Uninitialized { /// Returns an uninitialized value. - #[allow(clippy::missing_safety_doc)] unsafe fn uninitialized() -> Self; } /// Returns an uninitialized value. #[inline] -#[allow(clippy::missing_safety_doc)] pub unsafe fn uninitialized() -> T { T::uninitialized() } @@ -1212,25 +1210,13 @@ impl GlibNoneOrInvalidError { } /// Returns `true` if `self` is the `None` variant. - // FIXME `matches!` was introduced in rustc 1.42.0, current MSRV is 1.40.0 - // FIXME uncomment when CI can upgrade to 1.47.1 - //#[allow(clippy::match_like_matches_macro)] pub fn is_none(&self) -> bool { - match self { - GlibNoneOrInvalidError::None => true, - _ => false, - } + matches!(self, GlibNoneOrInvalidError::None) } /// Returns `true` if `self` is the `Invalid` variant. - // FIXME `matches!` was introduced in rustc 1.42.0, current MSRV is 1.40.0 - // FIXME uncomment when CI can upgrade to 1.47.1 - //#[allow(clippy::match_like_matches_macro)] pub fn is_invalid(&self) -> bool { - match self { - GlibNoneOrInvalidError::Invalid(_) => true, - _ => false, - } + matches!(self, GlibNoneOrInvalidError::Invalid(_)) } } @@ -1349,7 +1335,6 @@ pub trait FromGlibPtrBorrow: Sized { /// /// See [`FromGlibPtrNone`](trait.FromGlibPtrNone.html). #[inline] -#[allow(clippy::missing_safety_doc)] pub unsafe fn from_glib_none>(ptr: P) -> T { FromGlibPtrNone::from_glib_none(ptr) } @@ -1358,7 +1343,6 @@ pub unsafe fn from_glib_none>(ptr: P) -> T { /// /// See [`FromGlibPtrFull`](trait.FromGlibPtrFull.html). #[inline] -#[allow(clippy::missing_safety_doc)] pub unsafe fn from_glib_full>(ptr: P) -> T { FromGlibPtrFull::from_glib_full(ptr) } @@ -1367,7 +1351,6 @@ pub unsafe fn from_glib_full>(ptr: P) -> T { /// /// See [`FromGlibPtrBorrow`](trait.FromGlibPtrBorrow.html). #[inline] -#[allow(clippy::missing_safety_doc)] pub unsafe fn from_glib_borrow>(ptr: P) -> Borrowed { FromGlibPtrBorrow::from_glib_borrow(ptr) } @@ -1559,7 +1542,6 @@ impl FromGlibPtrFull<*mut c_char> for OsString { } /// Translate from a container. -#[allow(clippy::missing_safety_doc)] pub trait FromGlibContainer: Sized { /// Transfer: none. /// @@ -1578,7 +1560,6 @@ pub trait FromGlibContainer: Sized { } /// Translate from a container of pointers. -#[allow(clippy::missing_safety_doc)] pub trait FromGlibPtrContainer: FromGlibContainer + Sized { /// Transfer: none. unsafe fn from_glib_none(ptr: PP) -> Self; @@ -1590,7 +1571,6 @@ pub trait FromGlibPtrContainer: FromGlibContainer + Size unsafe fn from_glib_full(ptr: PP) -> Self; } -#[allow(clippy::missing_safety_doc)] pub unsafe fn c_ptr_array_len(mut ptr: *const P) -> usize { let mut len = 0; @@ -1603,7 +1583,6 @@ pub unsafe fn c_ptr_array_len(mut ptr: *const P) -> usize { len } -#[allow(clippy::missing_safety_doc)] pub trait FromGlibContainerAsVec where Self: Sized, @@ -1613,7 +1592,6 @@ where unsafe fn from_glib_full_num_as_vec(ptr: P, num: usize) -> Vec; } -#[allow(clippy::missing_safety_doc)] pub trait FromGlibPtrArrayContainerAsVec: FromGlibContainerAsVec where Self: Sized, diff --git a/glib/src/types.rs b/glib/src/types.rs index 73eab83d5c85..a170a30be7b1 100644 --- a/glib/src/types.rs +++ b/glib/src/types.rs @@ -230,7 +230,6 @@ impl StaticType for Vec { } #[inline] -#[allow(clippy::missing_safety_doc)] pub unsafe fn instance_of(ptr: glib_sys::gconstpointer) -> bool { from_glib(gobject_sys::g_type_check_instance_is_a( ptr as *mut _, diff --git a/glib/src/variant_type.rs b/glib/src/variant_type.rs index 00975870f2de..4440fa9eb847 100644 --- a/glib/src/variant_type.rs +++ b/glib/src/variant_type.rs @@ -14,6 +14,7 @@ use translate::*; use types::StaticType; use types::Type; use value::{FromValueOptional, SetValue, SetValueOptional, Value}; +use BoolError; /// Describes `Variant` types. /// @@ -34,7 +35,7 @@ impl VariantType { /// Tries to create a `VariantType` from a string slice. /// /// Returns `Ok` if the string is a valid type string, `Err` otherwise. - pub fn new(type_string: &str) -> Result { + pub fn new(type_string: &str) -> Result { VariantTy::new(type_string).map(ToOwned::to_owned) } } @@ -137,7 +138,7 @@ impl VariantTy { /// Tries to create a `&VariantTy` from a string slice. /// /// Returns `Ok` if the string is a valid type string, `Err` otherwise. - pub fn new(type_string: &str) -> Result<&VariantTy, ()> { + pub fn new(type_string: &str) -> Result<&VariantTy, BoolError> { let ptr = type_string.as_ptr(); let limit = ptr as usize + type_string.len(); let mut end = 0_usize; @@ -150,7 +151,7 @@ impl VariantTy { if ok && end == limit { Ok(&*(type_string.as_bytes() as *const [u8] as *const VariantTy)) } else { - Err(()) + Err(glib_bool_error!("Invalid type string: '{}'", type_string)) } } } diff --git a/graphene/src/lib.rs b/graphene/src/lib.rs index ec50471e4873..fdef2695c73c 100644 --- a/graphene/src/lib.rs +++ b/graphene/src/lib.rs @@ -1,13 +1,8 @@ // Copyright 2013-2018, The Gtk-rs Project Developers. // See the COPYRIGHT file at the top-level directory of this distribution. // Licensed under the MIT license, see the LICENSE file or - -#![allow(deprecated)] -#![cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))] -#![cfg_attr(feature = "cargo-clippy", allow(transmute_int_to_char))] -#![cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ptr))] -#![cfg_attr(feature = "cargo-clippy", allow(trivially_copy_pass_by_ref))] #![cfg_attr(feature = "dox", feature(doc_cfg))] +#![allow(deprecated)] #[macro_use] extern crate glib; @@ -28,9 +23,10 @@ macro_rules! skip_assert_initialized { () => {}; } -#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))] -#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))] -#[cfg_attr(feature = "cargo-clippy", allow(unreadable_literal))] +#[allow(clippy::transmute_ptr_to_ref)] +#[allow(clippy::type_complexity)] +#[allow(clippy::unreadable_literal)] +#[allow(clippy::derive_hash_xor_eq)] #[allow(unused_imports)] mod auto; diff --git a/graphene/sys/tests/abi.rs b/graphene/sys/tests/abi.rs index 57e44b21c665..4a36f521c859 100644 --- a/graphene/sys/tests/abi.rs +++ b/graphene/sys/tests/abi.rs @@ -2,6 +2,8 @@ // from gir-files (https://github.com/gtk-rs/gir-files) // DO NOT EDIT +#![allow(unused)] + extern crate graphene_sys; extern crate shell_words; extern crate tempfile; diff --git a/gtk/src/lib.rs b/gtk/src/lib.rs index 29a75b7219a4..4d27483fec13 100644 --- a/gtk/src/lib.rs +++ b/gtk/src/lib.rs @@ -148,12 +148,9 @@ //! them once. **Omitting them in the following cargo invocations will not undo //! their effects!** -#![allow(clippy::let_unit_value)] #![allow(clippy::new_without_default)] #![allow(clippy::type_complexity)] -#![allow(clippy::trivially_copy_pass_by_ref)] #![allow(clippy::derive_hash_xor_eq)] -#![allow(clippy::needless_doctest_main)] #![allow(clippy::too_many_arguments)] #![allow(deprecated)] #![cfg_attr(feature = "dox", feature(doc_cfg))] @@ -204,6 +201,7 @@ mod rt; #[allow(clippy::clone_on_copy)] #[allow(clippy::many_single_char_names)] #[allow(clippy::cast_ptr_alignment)] +#[allow(unused_doc_comments)] #[allow(unused_imports)] mod auto; diff --git a/gtk/src/tree_row_reference.rs b/gtk/src/tree_row_reference.rs index 4275e6ac356c..8144f97ebafc 100644 --- a/gtk/src/tree_row_reference.rs +++ b/gtk/src/tree_row_reference.rs @@ -12,7 +12,8 @@ use TreePath; use TreeRowReference; impl TreeRowReference { - // This is unsafe because new_order bounds can't be checked. + /// This is unsafe because new_order bounds can't be checked. + #[allow(clippy::missing_safety_doc)] pub unsafe fn reordered>( proxy: &T, path: &TreePath, diff --git a/pango/src/lib.rs b/pango/src/lib.rs index 60ecf35d9a12..1d6aa4e6bed2 100644 --- a/pango/src/lib.rs +++ b/pango/src/lib.rs @@ -17,8 +17,10 @@ extern crate bitflags; extern crate libc; extern crate once_cell; -#[cfg_attr(feature = "cargo-clippy", allow(too_many_arguments))] -#[cfg_attr(feature = "cargo-clippy", allow(should_implement_trait))] +#[allow(clippy::too_many_arguments)] +#[allow(clippy::should_implement_trait)] +#[allow(clippy::derive_hash_xor_eq)] +#[allow(clippy::let_and_return)] #[allow(unused_imports)] mod auto; pub use auto::functions::*; diff --git a/pangocairo/src/font_map.rs b/pangocairo/src/font_map.rs index d7db1241e2ff..0302514be179 100644 --- a/pangocairo/src/font_map.rs +++ b/pangocairo/src/font_map.rs @@ -31,6 +31,7 @@ impl FontMap { } } + #[allow(clippy::new_ret_no_self)] pub fn new() -> Option { unsafe { from_glib_full(pango_cairo_sys::pango_cairo_font_map_new()) } } diff --git a/pangocairo/src/lib.rs b/pangocairo/src/lib.rs index 274b1f7b5dc2..ef94d8cb3a1f 100644 --- a/pangocairo/src/lib.rs +++ b/pangocairo/src/lib.rs @@ -19,7 +19,7 @@ extern crate glib; extern crate bitflags; extern crate libc; -#[cfg_attr(feature = "cargo-clippy", allow(too_many_arguments))] +#[allow(clippy::too_many_arguments)] #[allow(unused_imports)] mod auto;