Skip to content

Commit

Permalink
Fix all clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
rj00a committed Jun 9, 2024
1 parent 0d23682 commit 9f9d284
Show file tree
Hide file tree
Showing 160 changed files with 888 additions and 882 deletions.
17 changes: 8 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,10 @@ valence_world_border = { path = "crates/valence_world_border", version = "0.2.0-
zip = "0.6.3"

[workspace.lints.rust]
# missing_debug_implementations = "warn" # TODO: enable me.
# missing_debug_implementations = "warn" # TODO: enable me.`
# missing_docs = "warn"
nonstandard_style = "warn"
rust_2018_idioms = "warn"
elided_lifetimes_in_paths = "allow" # TODO: Remove me?
trivial_numeric_casts = "warn"
nonstandard_style = { level = "warn", priority = -1 }
# rust_2018_idioms = { level = "warn", priority = -1 }
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(unstable_doc)'] }
unreachable_pub = "warn"
unused_import_braces = "warn"
Expand Down Expand Up @@ -246,7 +244,7 @@ flat_map_option = "warn"
format_push_string = "warn"
from_iter_instead_of_collect = "warn"
get_unwrap = "warn"
if_then_some_else_none = "warn"
# if_then_some_else_none = "warn" # TODO: Too many false positives.
ignored_unit_patterns = "warn"
impl_trait_in_params = "warn"
implicit_clone = "warn"
Expand All @@ -258,7 +256,7 @@ invalid_upcast_comparisons = "warn"
iter_filter_is_ok = "warn"
iter_filter_is_some = "warn"
iter_not_returning_iterator = "warn"
iter_over_hash_type = "warn"
# iter_over_hash_type = "warn" # TODO: enable me.
iter_without_into_iter = "warn"
large_stack_arrays = "warn"
large_types_passed_by_value = "warn"
Expand All @@ -276,7 +274,7 @@ mismatching_type_param_order = "warn"
missing_fields_in_debug = "warn"
mixed_read_write_in_expression = "warn"
mod_module_files = "warn"
multiple_inherent_impl = "warn"
# multiple_inherent_impl = "warn" TODO: enable me.
mut_mut = "warn"
mutex_atomic = "warn"
needless_bitwise_bool = "warn"
Expand All @@ -300,9 +298,10 @@ string_lit_chars_any = "warn"
string_to_string = "warn"
struct_field_names = "warn"
tests_outside_test_module = "warn"
todo = "warn"
# todo = "warn"
trivially_copy_pass_by_ref = "warn"
try_err = "warn"
type_complexity = "allow"
# undocumented_unsafe_blocks = "warn"
uninlined_format_args = "warn"
unnecessary_join = "warn"
Expand Down
2 changes: 1 addition & 1 deletion benches/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use criterion::Criterion;
use valence::block::{BlockKind, BlockState, PropName, PropValue};
use valence::ItemKind;

pub fn block(c: &mut Criterion) {
pub(crate) fn block(c: &mut Criterion) {
let mut group = c.benchmark_group("block");

let states = BlockKind::ALL.map(BlockKind::to_state);
Expand Down
4 changes: 2 additions & 2 deletions benches/decode_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use std::hint::black_box;
use criterion::Criterion;
use valence::protocol::{Decode, Encode};

pub fn decode_array(c: &mut Criterion) {
pub(crate) fn decode_array(c: &mut Criterion) {
let mut group = c.benchmark_group("decode_array");

let floats = [123.0, 456.0, 789.0];
let mut buf = [0u8; 24];
let mut buf = [0_u8; 24];

floats.encode(buf.as_mut_slice()).unwrap();

Expand Down
2 changes: 1 addition & 1 deletion benches/idle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use valence::prelude::*;

/// Benches the performance of a single server tick while nothing much is
/// happening.
pub fn idle_update(c: &mut Criterion) {
pub(crate) fn idle_update(c: &mut Criterion) {
let mut app = App::new();

app.add_plugins(DefaultPlugins);
Expand Down
6 changes: 3 additions & 3 deletions benches/many_players.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use valence::testing::create_mock_client;
use valence::{ident, ChunkPos, DefaultPlugins, Hand, Server, ServerSettings};
use valence_server::CompressionThreshold;

pub fn many_players(c: &mut Criterion) {
pub(crate) fn many_players(c: &mut Criterion) {
run_many_players(c, "many_players", 3000, 16, 16);
run_many_players(c, "many_players_spread_out", 3000, 8, 200);
}
Expand Down Expand Up @@ -71,8 +71,8 @@ fn run_many_players(
bundle.view_distance.set(view_dist);

let mut rng = rand::thread_rng();
let x = rng.gen_range(-world_size as f64 * 16.0..=world_size as f64 * 16.0);
let z = rng.gen_range(-world_size as f64 * 16.0..=world_size as f64 * 16.0);
let x = rng.gen_range(-f64::from(world_size) * 16.0..=f64::from(world_size) * 16.0);
let z = rng.gen_range(-f64::from(world_size) * 16.0..=f64::from(world_size) * 16.0);

bundle.player.position.set(DVec3::new(x, 64.0, z));

Expand Down
2 changes: 1 addition & 1 deletion benches/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use valence::text::IntoText;
use valence_server::protocol::Velocity;
use valence_server::CompressionThreshold;

pub fn packet(c: &mut Criterion) {
pub(crate) fn packet(c: &mut Criterion) {
let mut group = c.benchmark_group("packet");

let mut encoder = PacketEncoder::new();
Expand Down
2 changes: 1 addition & 1 deletion benches/var_int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use criterion::Criterion;
use rand::Rng;
use valence::protocol::{Decode, Encode, VarInt};

pub fn var_int(c: &mut Criterion) {
pub(crate) fn var_int(c: &mut Criterion) {
let mut group = c.benchmark_group("varint");

let mut rng = rand::thread_rng();
Expand Down
2 changes: 1 addition & 1 deletion benches/var_long.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use criterion::Criterion;
use rand::Rng;
use valence::protocol::{Decode, Encode, VarLong};

pub fn var_long(c: &mut Criterion) {
pub(crate) fn var_long(c: &mut Criterion) {
let mut group = c.benchmark_group("varlong");

let mut rng = rand::thread_rng();
Expand Down
26 changes: 13 additions & 13 deletions crates/java_string/src/cesu8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ impl JavaStr {
/// assert_eq!(JavaStr::from_str("Hello World!"), result);
///
/// let result = JavaStr::from_modified_utf8(&[
/// 0x61, 0x62, 0x63, 0xC0, 0x80, 0xE2, 0x84, 0x9D, 0xED, 0xA0, 0xBD, 0xED, 0xB2, 0xA3, 0xED,
/// 0xA0, 0x80,
/// 0x61, 0x62, 0x63, 0xc0, 0x80, 0xe2, 0x84, 0x9d, 0xed, 0xa0, 0xbd, 0xed, 0xb2, 0xa3, 0xed,
/// 0xa0, 0x80,
/// ])
/// .unwrap();
/// assert!(matches!(result, Cow::Owned(_)));
/// let mut expected = JavaString::from("abc\0ℝ💣");
/// expected.push_java(JavaCodePoint::from_u32(0xD800).unwrap());
/// expected.push_java(JavaCodePoint::from_u32(0xd800).unwrap());
/// assert_eq!(expected, result);
///
/// let result = JavaStr::from_modified_utf8(&[0xED]);
/// let result = JavaStr::from_modified_utf8(&[0xed]);
/// assert!(result.is_err());
/// ```
#[inline]
Expand All @@ -46,11 +46,11 @@ impl JavaStr {
/// assert_eq!(result, &b"Hello World!"[..]);
///
/// let mut str = JavaString::from("abc\0ℝ💣");
/// str.push_java(JavaCodePoint::from_u32(0xD800).unwrap());
/// str.push_java(JavaCodePoint::from_u32(0xd800).unwrap());
/// let result = str.to_modified_utf8();
/// let expected = [
/// 0x61, 0x62, 0x63, 0xC0, 0x80, 0xE2, 0x84, 0x9D, 0xED, 0xA0, 0xBD, 0xED, 0xB2, 0xA3, 0xED,
/// 0xA0, 0x80,
/// 0x61, 0x62, 0x63, 0xc0, 0x80, 0xe2, 0x84, 0x9d, 0xed, 0xa0, 0xbd, 0xed, 0xb2, 0xa3, 0xed,
/// 0xa0, 0x80,
/// ];
/// assert!(matches!(result, Cow::Owned(_)));
/// assert_eq!(result, &expected[..]);
Expand All @@ -73,7 +73,7 @@ impl JavaStr {
while i < bytes.len() {
let b = bytes[i];
if b == 0 {
encoded.extend([0xC0, 0x80]);
encoded.extend([0xc0, 0x80]);
i += 1;
} else if b < 128 {
// Pass ASCII through quickly.
Expand All @@ -100,7 +100,7 @@ impl JavaStr {
// SAFETY: s contains a single char of width 4
s.chars().next().unwrap_unchecked().as_u32() - 0x10000
};
let s = [((c >> 10) as u16) | 0xD800, ((c & 0x3FF) as u16) | 0xDC00];
let s = [((c >> 10) as u16) | 0xd800, ((c & 0x3ff) as u16) | 0xdc00];
encoded.extend(enc_surrogate(s[0]));
encoded.extend(enc_surrogate(s[1]));
}
Expand Down Expand Up @@ -168,7 +168,7 @@ impl JavaString {
} else if first < 128 {
// Pass ASCII through directly.
decoded.push(first);
} else if first == 0xC0 {
} else if first == 0xc0 {
// modified UTF-8 encoding of null character
match next!() {
0x80 => decoded.push(0),
Expand Down Expand Up @@ -242,16 +242,16 @@ impl JavaString {

#[inline]
fn dec_surrogate(second: u8, third: u8) -> u32 {
0xD000 | u32::from(second & CONT_MASK) << 6 | u32::from(third & CONT_MASK)
0xd000 | u32::from(second & CONT_MASK) << 6 | u32::from(third & CONT_MASK)
}

#[inline]
fn dec_surrogates(second: u8, third: u8, fifth: u8, sixth: u8) -> [u8; 4] {
// Convert to a 32-bit code point.
let s1 = dec_surrogate(second, third);
let s2 = dec_surrogate(fifth, sixth);
let c = 0x10000 + (((s1 - 0xD800) << 10) | (s2 - 0xDC00));
assert!((0x010000..=0x10FFFF).contains(&c));
let c = 0x10000 + (((s1 - 0xd800) << 10) | (s2 - 0xdc00));
assert!((0x010000..=0x10ffff).contains(&c));

// Convert to UTF-8.
// 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
Expand Down
50 changes: 25 additions & 25 deletions crates/java_string/src/char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl JavaCodePoint {
#[inline]
#[must_use]
pub const fn from_u32(i: u32) -> Option<JavaCodePoint> {
if i <= 0x10FFFF {
if i <= 0x10ffff {
unsafe { Some(Self::from_u32_unchecked(i)) }
} else {
None
Expand Down Expand Up @@ -94,7 +94,7 @@ impl JavaCodePoint {
/// ```
/// # use java_string::JavaCodePoint;
/// assert_eq!(65, JavaCodePoint::from_char('A').as_u32());
/// assert_eq!(0xD800, JavaCodePoint::from_u32(0xD800).unwrap().as_u32());
/// assert_eq!(0xd800, JavaCodePoint::from_u32(0xd800).unwrap().as_u32());
/// ```
#[inline]
#[must_use]
Expand All @@ -103,7 +103,7 @@ impl JavaCodePoint {
// SAFETY: JavaCodePoint has the same repr as a u32
let result = std::mem::transmute(self);

if result > 0x10FFFF {
if result > 0x10ffff {
// SAFETY: JavaCodePoint can never have a value > 0x10FFFF.
// This statement may allow the optimizer to remove branches in the calling code
// associated with out of bounds chars.
Expand All @@ -119,7 +119,7 @@ impl JavaCodePoint {
/// ```
/// # use java_string::JavaCodePoint;
/// assert_eq!(Some('a'), JavaCodePoint::from_char('a').as_char());
/// assert_eq!(None, JavaCodePoint::from_u32(0xD800).unwrap().as_char());
/// assert_eq!(None, JavaCodePoint::from_u32(0xd800).unwrap().as_char());
/// ```
#[inline]
#[must_use]
Expand Down Expand Up @@ -148,7 +148,7 @@ impl JavaCodePoint {
/// );
/// assert_eq!(
/// 1,
/// JavaCodePoint::from_u32(0xD800)
/// JavaCodePoint::from_u32(0xd800)
/// .unwrap()
/// .encode_utf16(&mut [0; 2])
/// .len()
Expand Down Expand Up @@ -182,7 +182,7 @@ impl JavaCodePoint {
/// );
/// assert_eq!(
/// 3,
/// JavaCodePoint::from_u32(0xD800)
/// JavaCodePoint::from_u32(0xd800)
/// .unwrap()
/// .encode_semi_utf8(&mut [0; 4])
/// .len()
Expand All @@ -202,19 +202,19 @@ impl JavaCodePoint {
*a = code as u8;
}
(2, [a, b, ..]) => {
*a = (code >> 6 & 0x1F) as u8 | TAG_TWO_B;
*b = (code & 0x3F) as u8 | TAG_CONT;
*a = (code >> 6 & 0x1f) as u8 | TAG_TWO_B;
*b = (code & 0x3f) as u8 | TAG_CONT;
}
(3, [a, b, c, ..]) => {
*a = (code >> 12 & 0x0F) as u8 | TAG_THREE_B;
*b = (code >> 6 & 0x3F) as u8 | TAG_CONT;
*c = (code & 0x3F) as u8 | TAG_CONT;
*a = (code >> 12 & 0x0f) as u8 | TAG_THREE_B;
*b = (code >> 6 & 0x3f) as u8 | TAG_CONT;
*c = (code & 0x3f) as u8 | TAG_CONT;
}
(4, [a, b, c, d, ..]) => {
*a = (code >> 18 & 0x07) as u8 | TAG_FOUR_B;
*b = (code >> 12 & 0x3F) as u8 | TAG_CONT;
*c = (code >> 6 & 0x3F) as u8 | TAG_CONT;
*d = (code & 0x3F) as u8 | TAG_CONT;
*b = (code >> 12 & 0x3f) as u8 | TAG_CONT;
*c = (code >> 6 & 0x3f) as u8 | TAG_CONT;
*d = (code & 0x3f) as u8 | TAG_CONT;
}
_ => panic!(
"encode_utf8: need {} bytes to encode U+{:X}, but the buffer has {}",
Expand Down Expand Up @@ -250,7 +250,7 @@ impl JavaCodePoint {
/// );
/// assert_eq!(
/// "\\u{d800}",
/// JavaCodePoint::from_u32(0xD800)
/// JavaCodePoint::from_u32(0xd800)
/// .unwrap()
/// .escape_debug()
/// .to_string()
Expand Down Expand Up @@ -317,7 +317,7 @@ impl JavaCodePoint {
/// );
/// assert_eq!(
/// "\\u{d800}",
/// JavaCodePoint::from_u32(0xD800)
/// JavaCodePoint::from_u32(0xd800)
/// .unwrap()
/// .escape_default()
/// .to_string()
Expand All @@ -342,7 +342,7 @@ impl JavaCodePoint {
SINGLE_QUOTE => CharEscapeIter::new([b'\\', b'\'']),
DOUBLE_QUOTE => CharEscapeIter::new([b'\\', b'"']),
BACKSLASH => CharEscapeIter::new([b'\\', b'\\']),
0x20..=0x7E => CharEscapeIter::new([self.as_u32() as u8]),
0x20..=0x7e => CharEscapeIter::new([self.as_u32() as u8]),
_ => self.escape_unicode(),
}
}
Expand All @@ -358,7 +358,7 @@ impl JavaCodePoint {
/// );
/// assert_eq!(
/// "\\u{d800}",
/// JavaCodePoint::from_u32(0xD800)
/// JavaCodePoint::from_u32(0xd800)
/// .unwrap()
/// .escape_unicode()
/// .to_string()
Expand Down Expand Up @@ -410,7 +410,7 @@ impl JavaCodePoint {
#[inline]
#[must_use]
pub fn is_ascii(self) -> bool {
self.as_u32() <= 0x7F
self.as_u32() <= 0x7f
}

/// See [`char::is_ascii_alphabetic`].
Expand All @@ -431,7 +431,7 @@ impl JavaCodePoint {
#[inline]
#[must_use]
pub const fn is_ascii_control(self) -> bool {
matches!(self.as_u32(), 0..=0x1F | 0x7F)
matches!(self.as_u32(), 0..=0x1f | 0x7f)
}

/// See [`char::is_ascii_digit`].
Expand All @@ -447,7 +447,7 @@ impl JavaCodePoint {
#[inline]
#[must_use]
pub const fn is_ascii_graphic(self) -> bool {
matches!(self.as_u32(), 0x21..=0x7E)
matches!(self.as_u32(), 0x21..=0x7e)
}

/// See [`char::is_ascii_hexdigit`].
Expand Down Expand Up @@ -485,7 +485,7 @@ impl JavaCodePoint {
pub const fn is_ascii_punctuation(self) -> bool {
matches!(
self.as_u32(),
(0x21..=0x2F) | (0x3A..=0x40) | (0x5B..=0x60) | (0x7B..=0x7E)
(0x21..=0x2f) | (0x3a..=0x40) | (0x5b..=0x60) | (0x7b..=0x7e)
)
}

Expand All @@ -505,7 +505,7 @@ impl JavaCodePoint {
const SPACE: u32 = ' ' as u32;
const HORIZONTAL_TAB: u32 = '\t' as u32;
const LINE_FEED: u32 = '\n' as u32;
const FORM_FEED: u32 = 0xC;
const FORM_FEED: u32 = 0xc;
const CARRIAGE_RETURN: u32 = '\r' as u32;
matches!(
self.as_u32(),
Expand Down Expand Up @@ -566,7 +566,7 @@ impl JavaCodePoint {
/// let len = JavaCodePoint::from_char('💣').len_utf16();
/// assert_eq!(len, 2);
///
/// assert_eq!(1, JavaCodePoint::from_u32(0xD800).unwrap().len_utf16());
/// assert_eq!(1, JavaCodePoint::from_u32(0xd800).unwrap().len_utf16());
/// ```
#[inline]
#[must_use]
Expand Down Expand Up @@ -595,7 +595,7 @@ impl JavaCodePoint {
/// let len = JavaCodePoint::from_char('💣').len_utf8();
/// assert_eq!(len, 4);
///
/// let len = JavaCodePoint::from_u32(0xD800).unwrap().len_utf8();
/// let len = JavaCodePoint::from_u32(0xd800).unwrap().len_utf8();
/// assert_eq!(len, 3);
/// ```
#[inline]
Expand Down
Loading

0 comments on commit 9f9d284

Please sign in to comment.