Skip to content

First pass at fixing clippy::use_self

Marijn Suijten requested to merge MarijnS95/gstreamer-rs:dry into master

Attempting to make the code slightly more readable by using Self instead of repeating the type name (of the surrounding impl block) over and over again.

This PR includes quite a few things:

  • Autogenerate GstVideo.VideoColorRange, I don't see anything manual that's different;
  • Fixes use_self warnings in base, audio, video and gl;
  • Replace T::type_data with Self::type_data in for T blocks, mainly to silence a bunch of warnings while fixing the rest. Not sure if we want this;
  • Update gir to shorten the names in auto to Self too: https://github.com/gtk-rs/gir/pull/1121;
  • Temporary commit to allow use_self on the auto module. This made it easier to go over manual warnings, but we might as well leave it if we're serious about combating use_self. It is a major hassle to fix every offender in gir, like turning function arguments and return types into Self. (It needs to be disabled or fixed in sys crates as well, where self-referential pointers are used in structs).

In the end this effort is futile if we can't enable clippy::use_self in the CI... And we really can't unless someone performs a massive pass on the rest of the code. For the gstreamer crate alone:

  • nightly: warning: 413 warnings emitted
  • stable: warning: 477 warnings emitted

Unfortunately stable has some false-positives when lifetime and templated Self-types are involved, but nightly misses out on the valid suggestions there too (ie. it told me to replace Result<xxx> with Self, but not the Ok(xxx) further down in the code). It's inconsistent and you have to run both + doublecheck every suggestion.

Edited by Marijn Suijten

Merge request reports