Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Squish a Bunch of Clippy Errors and Warnings #5385

Closed
wants to merge 15 commits into from
4 changes: 2 additions & 2 deletions bidi/generate/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn gen_class() -> anyhow::Result<()> {
impl Entry {
fn parse(line: &str) -> anyhow::Result<Option<Self>> {
let line = line.trim();
if line.starts_with("#") || line.is_empty() {
if line.starts_with('#') || line.is_empty() {
return Ok(None);
}
let fields: Vec<&str> = line.split(';').collect();
Expand Down Expand Up @@ -152,7 +152,7 @@ fn gen_brackets() -> anyhow::Result<()> {
impl Entry {
fn parse(line: &str) -> anyhow::Result<Option<Self>> {
let line = line.trim();
if line.starts_with("#") || line.is_empty() {
if line.starts_with('#') || line.is_empty() {
return Ok(None);
}
let fields: Vec<&str> = line.split(';').collect();
Expand Down
2 changes: 1 addition & 1 deletion bidi/src/bidi_brackets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub enum BracketType {
Open,
Close,
}
pub const BIDI_BRACKETS: &'static [(char, char, BracketType)] = &[
pub const BIDI_BRACKETS: &[(char, char, BracketType)] = &[
('\u{28}', '\u{29}', BracketType::Open), // LEFT PARENTHESIS
('\u{29}', '\u{28}', BracketType::Close), // RIGHT PARENTHESIS
('\u{5b}', '\u{5d}', BracketType::Open), // LEFT SQUARE BRACKET
Expand Down
2 changes: 1 addition & 1 deletion bidi/src/bidi_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub enum BidiClass {
WhiteSpace,
}

pub const BIDI_CLASS: &'static [(char, char, BidiClass)] = &[
pub const BIDI_CLASS: &[(char, char, BidiClass)] = &[
('\u{0}', '\u{8}', BidiClass::BoundaryNeutral), // Cc [9] <control-0000>..<control-0008>
('\u{9}', '\u{9}', BidiClass::SegmentSeparator), // Cc <control-0009>
('\u{a}', '\u{a}', BidiClass::ParagraphSeparator), // Cc <control-000A>
Expand Down
42 changes: 18 additions & 24 deletions bidi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub struct BidiRun {
}

impl BidiRun {
pub fn indices<'a>(&'a self) -> impl Iterator<Item = usize> + 'a {
pub fn indices(&self) -> impl Iterator<Item = usize> + '_ {
struct Iter<'a> {
range: Range<usize>,
removed_by_x9: &'a [usize],
Expand Down Expand Up @@ -206,7 +206,7 @@ impl BidiContext {

/// Produces a sequence of `BidiRun` structs that represent runs of
/// text and their direction (and level) across the entire paragraph.
pub fn runs<'a>(&'a self) -> impl Iterator<Item = BidiRun> + 'a {
pub fn runs(&self) -> impl Iterator<Item = BidiRun> + '_ {
RunIter {
pos: 0,
levels: Cow::Borrowed(&self.levels),
Expand Down Expand Up @@ -357,7 +357,7 @@ impl BidiContext {

// Initial visual order
let mut visual = vec![];
for i in 0..levels.len() {
for (i, _) in levels.iter().enumerate() {
if levels[i].removed_by_x9() {
visual.push(DELETED);
} else {
Expand Down Expand Up @@ -843,7 +843,7 @@ impl BidiContext {
// of the substring in this isolating run sequence
// enclosed by those brackets (inclusive
// of the brackets). Resolve that individual pair.
self.resolve_one_pair(pair, &iso_run);
self.resolve_one_pair(pair, iso_run);
}
}
}
Expand Down Expand Up @@ -997,7 +997,6 @@ impl BidiContext {
&self.orig_char_types,
&self.levels,
);
return;
} else {
// No strong type matching the oppositedirection was found either
// before or after these brackets in this text chain. Resolve the
Expand All @@ -1010,7 +1009,6 @@ impl BidiContext {
&self.orig_char_types,
&self.levels,
);
return;
}
} else {
// No strong type was found between the brackets. Leave
Expand Down Expand Up @@ -1262,7 +1260,7 @@ impl BidiContext {
line_range: Range<usize>,
base_level: Level,
orig_char_types: &[BidiClass],
levels: &mut Vec<Level>,
levels: &mut [Level],
) {
for i in line_range.rev() {
if orig_char_types[i] == BidiClass::WhiteSpace
Expand Down Expand Up @@ -1458,12 +1456,8 @@ impl BidiContext {
// Do nothing
} else if overflow_embedding > 0 {
overflow_embedding -= 1;
} else {
if !stack.isolate_status() {
if stack.depth() >= 2 {
stack.pop();
}
}
} else if !stack.isolate_status() && stack.depth() >= 2 {
stack.pop();
}
}
BidiClass::BoundaryNeutral => {}
Expand Down Expand Up @@ -1709,22 +1703,22 @@ impl BidiContext {

impl BidiClass {
pub fn is_iso_init(self) -> bool {
match self {
matches!(
self,
BidiClass::RightToLeftIsolate
| BidiClass::LeftToRightIsolate
| BidiClass::FirstStrongIsolate => true,
_ => false,
}
| BidiClass::LeftToRightIsolate
| BidiClass::FirstStrongIsolate
)
}

pub fn is_iso_control(self) -> bool {
match self {
matches!(
self,
BidiClass::RightToLeftIsolate
| BidiClass::LeftToRightIsolate
| BidiClass::PopDirectionalIsolate
| BidiClass::FirstStrongIsolate => true,
_ => false,
}
| BidiClass::LeftToRightIsolate
| BidiClass::PopDirectionalIsolate
| BidiClass::FirstStrongIsolate
)
}

pub fn is_neutral(self) -> bool {
Expand Down
6 changes: 3 additions & 3 deletions bintree/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ impl<'a, L, N> std::iter::Iterator for ParentIterator<'a, L, N> {
match self.path {
Path::Top => None,
Path::Left { data, up, .. } => {
self.path = &*up;
self.path = up;
Some((PathBranch::IsLeft, data))
}
Path::Right { data, up, .. } => {
self.path = &*up;
self.path = up;
Some((PathBranch::IsRight, data))
}
}
Expand Down Expand Up @@ -211,7 +211,7 @@ impl<L, N> Cursor<L, N> {

/// References the subtree at the current cursor position
pub fn subtree(&self) -> &Tree<L, N> {
&*self.it
&self.it
}

/// Returns true if the current position is a leaf node
Expand Down
31 changes: 17 additions & 14 deletions color-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use csscolorparser::Color;
#[cfg(feature = "use_serde")]
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::fmt::Display;
use std::hash::{Hash, Hasher};
use std::str::FromStr;
use wezterm_dynamic::{FromDynamic, FromDynamicOptions, ToDynamic, Value};
Expand Down Expand Up @@ -407,14 +408,6 @@ impl SrgbaTuple {
)
}

pub fn to_string(self) -> String {
if self.3 == 1.0 {
self.to_rgb_string()
} else {
self.to_rgba_string()
}
}

/// Returns a string of the form `#RRGGBB`
pub fn to_rgb_string(self) -> String {
format!(
Expand Down Expand Up @@ -551,6 +544,16 @@ impl SrgbaTuple {
}
}

impl Display for SrgbaTuple {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if self.3 == 1.0 {
write!(f, "{}", self.to_rgb_string())
} else {
write!(f, "{}", self.to_rgba_string())
}
}
}

/// Convert an RGB color space hue angle to an RYB colorspace hue angle
/// <https://github.com/TNMEM/Material-Design-Color-Picker/blob/1afe330c67d9db4deef7031d601324b538b43b09/rybcolor.js#L33>
fn rgb_hue_to_ryb_hue(hue: f64) -> f64 {
Expand Down Expand Up @@ -631,7 +634,7 @@ fn x_parse_color_component(value: &str) -> Result<f32, ()> {

for c in value.chars() {
num_digits += 1;
component = component << 4;
component <<= 4;

let nybble = match c.to_digit(16) {
Some(v) => v as u16,
Expand Down Expand Up @@ -659,7 +662,7 @@ impl FromStr for SrgbaTuple {
if !s.is_ascii() {
return Err(());
}
if s.len() > 0 && s.as_bytes()[0] == b'#' {
if !s.is_empty() && s.as_bytes()[0] == b'#' {
// Probably `#RGB`

let digits = (s.len() - 1) / 3;
Expand All @@ -679,7 +682,7 @@ impl FromStr for SrgbaTuple {
let mut component = 0u16;

for _ in 0..digits {
component = component << 4;
component <<= 4;

let nybble = match chars.next().unwrap().to_digit(16) {
Some(v) => v as u16,
Expand Down Expand Up @@ -730,7 +733,7 @@ impl FromStr for SrgbaTuple {
Ok(v / 100.)
} else {
let v: f32 = s.parse().map_err(|_| ())?;
if v > 255.0 || v < 0. {
if !(0. ..=255.0).contains(&v) {
Err(())
} else {
Ok(v / 255.)
Expand All @@ -746,8 +749,8 @@ impl FromStr for SrgbaTuple {
} else {
Err(())
}
} else if s.starts_with("hsl:") {
let fields: Vec<_> = s[4..].split_ascii_whitespace().collect();
} else if let Some(stripped) = s.strip_prefix("hsl:") {
let fields: Vec<_> = stripped.split_ascii_whitespace().collect();
if fields.len() == 3 {
// Expected to be degrees in range 0-360, but we allow for negative and wrapping
let h: i32 = fields[0].parse().map_err(|_| ())?;
Expand Down
2 changes: 1 addition & 1 deletion deps/freetype/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ fn freetype() {

fn git_submodule_update() {
let _ = std::process::Command::new("git")
.args(&["submodule", "update", "--init"])
.args(["submodule", "update", "--init"])
.status();
}

Expand Down
2 changes: 1 addition & 1 deletion deps/freetype/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl<T> ::std::default::Default for __BindgenUnionField<T> {
impl<T> ::std::clone::Clone for __BindgenUnionField<T> {
#[inline]
fn clone(&self) -> Self {
Self::new()
*self
}
}
impl<T> ::std::marker::Copy for __BindgenUnionField<T> {}
Expand Down
2 changes: 1 addition & 1 deletion deps/harfbuzz/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fn harfbuzz() {

fn git_submodule_update() {
let _ = std::process::Command::new("git")
.args(&["submodule", "update", "--init"])
.args(["submodule", "update", "--init"])
.status();
}

Expand Down
14 changes: 11 additions & 3 deletions luahelper/src/enumctor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ impl<T> Enum<T> {
}
}

impl<T> Default for Enum<T> {
fn default() -> Self {
Self::new()
}
}

impl<T> UserData for Enum<T>
where
T: FromDynamic,
Expand All @@ -133,14 +139,16 @@ where
methods.add_meta_method(MetaMethod::Index, |lua, _myself, field: String| {
// Step 1: see if this is a unit variant.
// A unit variant will be convertible from string
if let Ok(_) = T::from_dynamic(
if T::from_dynamic(
&DynValue::String(field.to_string()),
FromDynamicOptions {
unknown_fields: UnknownFieldAction::Deny,
deprecated_fields: UnknownFieldAction::Ignore,
},
) {
return Ok(field.into_lua(lua)?);
)
.is_ok()
{
return field.into_lua(lua);
}

// Step 2: see if this is a valid variant, and whether we can
Expand Down
18 changes: 5 additions & 13 deletions luahelper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@ use wezterm_dynamic::{FromDynamic, ToDynamic, Value as DynValue};

pub mod enumctor;

pub fn to_lua<'lua, T: ToDynamic>(
lua: &'lua mlua::Lua,
value: T,
) -> Result<mlua::Value<'lua>, mlua::Error> {
pub fn to_lua<T: ToDynamic>(lua: &mlua::Lua, value: T) -> Result<mlua::Value<'_>, mlua::Error> {
let value = value.to_dynamic();
dynamic_to_lua_value(lua, value)
}

pub fn from_lua<'lua, T: FromDynamic>(value: mlua::Value<'lua>) -> Result<T, mlua::Error> {
pub fn from_lua<T: FromDynamic>(value: mlua::Value<'_>) -> Result<T, mlua::Error> {
let lua_type = value.type_name();
let value = lua_value_to_dynamic(value).map_err(|e| mlua::Error::FromLuaConversionError {
from: lua_type,
Expand Down Expand Up @@ -60,10 +57,7 @@ macro_rules! impl_lua_conversion_dynamic {
};
}

pub fn dynamic_to_lua_value<'lua>(
lua: &'lua mlua::Lua,
value: DynValue,
) -> mlua::Result<mlua::Value> {
pub fn dynamic_to_lua_value(lua: &mlua::Lua, value: DynValue) -> mlua::Result<mlua::Value> {
Ok(match value {
DynValue::Null => LuaValue::Nil,
DynValue::Bool(b) => LuaValue::Boolean(b),
Expand Down Expand Up @@ -284,9 +278,7 @@ impl<'lua> Eq for ValuePrinterHelper<'lua> {}

impl<'lua> PartialOrd for ValuePrinterHelper<'lua> {
fn partial_cmp(&self, rhs: &Self) -> Option<std::cmp::Ordering> {
let lhs = lua_value_to_dynamic(self.value.clone()).unwrap_or(DynValue::Null);
let rhs = lua_value_to_dynamic(rhs.value.clone()).unwrap_or(DynValue::Null);
lhs.partial_cmp(&rhs)
Some(self.cmp(rhs))
}
}

Expand Down Expand Up @@ -343,7 +335,7 @@ impl<'lua> std::fmt::Debug for ValuePrinterHelper<'lua> {
self.visited
.borrow_mut()
.insert(self.value.to_pointer() as usize);
if is_array_style_table(&t) {
if is_array_style_table(t) {
// Treat as list
let mut list = fmt.debug_list();
for value in t.clone().sequence_values() {
Expand Down
Loading
Loading