Skip to content

Commit

Permalink
Merge #252
Browse files Browse the repository at this point in the history
252: Clippy fixes and changing refs to Copy r=CAD97 a=JamesHinshelwood

Updated clippy allows from `cfg_attr` to proc-macro style.
Fixed #241 + more - Changed a few `impl`s to take `self` instead of `&self`, when they are `Copy` types.

`cargo clippy` should run without any warnings now.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/open-i18n/rust-unic/252)
<!-- Reviewable:end -->


Co-authored-by: JamesHinshelwood <[email protected]>
  • Loading branch information
bors[bot] and JamesHinshelwood committed Jul 24, 2019
2 parents 89f5f55 + eaa2c11 commit b38e713
Show file tree
Hide file tree
Showing 18 changed files with 67 additions and 65 deletions.
2 changes: 1 addition & 1 deletion unic/bidi/src/bidi_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ impl<'text> BidiInfo<'text> {
/// `line` is a range of bytes indices within `levels`.
///
/// <https://www.unicode.org/reports/tr9/#Reordering_Resolved_Levels>
#[cfg_attr(feature = "cargo-clippy", allow(needless_range_loop))]
#[allow(clippy::needless_range_loop)]
pub fn visual_runs(
&self,
para: &ParagraphInfo,
Expand Down
2 changes: 1 addition & 1 deletion unic/bidi/src/implicit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub fn resolve_weak(sequence: &IsolatingRunSequence, processing_classes: &mut [B
let next_class = indices
.clone()
.map(|j| processing_classes[j])
.find(not_removed_by_x9)
.find(|&x| not_removed_by_x9(x))
.unwrap_or(sequence.eos);
processing_classes[i] = match (prev_class, processing_classes[i], next_class) {
(EN, ES, EN) | (EN, CS, EN) => EN,
Expand Down
14 changes: 7 additions & 7 deletions unic/bidi/src/level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,19 @@ impl Level {

/// The level number.
#[inline]
pub fn number(&self) -> u8 {
pub fn number(self) -> u8 {
self.0
}

/// If this level is left-to-right.
#[inline]
pub fn is_ltr(&self) -> bool {
pub fn is_ltr(self) -> bool {
self.0 % 2 == 0
}

/// If this level is right-to-left.
#[inline]
pub fn is_rtl(&self) -> bool {
pub fn is_rtl(self) -> bool {
self.0 % 2 == 1
}

Expand Down Expand Up @@ -168,26 +168,26 @@ impl Level {

/// The next LTR (even) level greater than this, or fail if number is larger than `max_depth`.
#[inline]
pub fn new_explicit_next_ltr(&self) -> Result<Level, Error> {
pub fn new_explicit_next_ltr(self) -> Result<Level, Error> {
Level::new_explicit((self.0 + 2) & !1)
}

/// The next RTL (odd) level greater than this, or fail if number is larger than `max_depth`.
#[inline]
pub fn new_explicit_next_rtl(&self) -> Result<Level, Error> {
pub fn new_explicit_next_rtl(self) -> Result<Level, Error> {
Level::new_explicit((self.0 + 1) | 1)
}

/// The lowest RTL (odd) level greater than or equal to this, or fail if number is larger than
/// `max_depth + 1`.
#[inline]
pub fn new_lowest_ge_rtl(&self) -> Result<Level, Error> {
pub fn new_lowest_ge_rtl(self) -> Result<Level, Error> {
Level::new(self.0 | 1)
}

/// Generate a character type based on a level (as specified in steps X10 and N2).
#[inline]
pub fn bidi_class(&self) -> BidiClass {
pub fn bidi_class(self) -> BidiClass {
if self.is_rtl() {
BidiClass::RightToLeft
} else {
Expand Down
17 changes: 9 additions & 8 deletions unic/bidi/src/prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub struct IsolatingRunSequence {
/// whose matching PDI is the first character of the next level run in the sequence.
///
/// Note: This function does *not* return the sequences in order by their first characters.
#[allow(clippy::len_zero)]
pub fn isolating_run_sequences(
para_level: Level,
original_classes: &[BidiClass],
Expand Down Expand Up @@ -98,7 +99,7 @@ pub fn isolating_run_sequences(
#[cfg(test)]
for run in sequence.clone() {
for idx in run {
if not_removed_by_x9(&original_classes[idx]) {
if not_removed_by_x9(original_classes[idx]) {
assert_eq!(seq_level, levels[idx]);
}
}
Expand All @@ -107,7 +108,7 @@ pub fn isolating_run_sequences(
// Get the level of the last non-removed char before the runs.
let pred_level = match original_classes[..start_of_seq]
.iter()
.rposition(not_removed_by_x9)
.rposition(|&x| not_removed_by_x9(x))
{
Some(idx) => levels[idx],
None => para_level,
Expand All @@ -119,7 +120,7 @@ pub fn isolating_run_sequences(
} else {
match original_classes[end_of_seq..]
.iter()
.position(not_removed_by_x9)
.position(|&x| not_removed_by_x9(x))
{
Some(idx) => levels[end_of_seq + idx],
None => para_level,
Expand Down Expand Up @@ -169,8 +170,8 @@ pub fn removed_by_x9(class: BidiClass) -> bool {
}

// For use as a predicate for `position` / `rposition`
pub fn not_removed_by_x9(class: &BidiClass) -> bool {
!removed_by_x9(*class)
pub fn not_removed_by_x9(class: BidiClass) -> bool {
!removed_by_x9(class)
}

#[cfg(test)]
Expand All @@ -187,7 +188,7 @@ mod tests {
}

// From <https://www.unicode.org/reports/tr9/#BD13>
#[cfg_attr(rustfmt, rustfmt_skip)]
#[rustfmt::skip]
#[test]
fn test_isolating_run_sequences() {

Expand Down Expand Up @@ -232,7 +233,7 @@ mod tests {
}

// From <https://www.unicode.org/reports/tr9/#X10>
#[cfg_attr(rustfmt, rustfmt_skip)]
#[rustfmt::skip]
#[test]
fn test_isolating_run_sequences_sos_and_eos() {

Expand Down Expand Up @@ -363,7 +364,7 @@ mod tests {
L, R, AL, EN, ES, ET, AN, CS, NSM, B, S, WS, ON, LRI, RLI, FSI, PDI,
];
for x in non_x9_classes {
assert_eq!(not_removed_by_x9(&x), true);
assert_eq!(not_removed_by_x9(*x), true);
}
}
}
4 changes: 2 additions & 2 deletions unic/char/property/src/range_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl NumericCharPropertyValue for u8 {}
/// Examples: `Numeric_Value`, `Canonical_Combining_Class`
pub trait NumericCharProperty<NumericValue: NumericCharPropertyValue>: CharProperty {
/// The numeric value for the property value.
fn number(&self) -> NumericValue;
fn number(self) -> NumericValue;
}

// == Custom Types ==
Expand All @@ -100,5 +100,5 @@ pub trait NumericCharProperty<NumericValue: NumericCharPropertyValue>: CharPrope
/// Examples: `Age` property that returns a `UnicodeVersion` value.
pub trait CustomCharProperty<Value>: CharProperty {
/// The actual (inner) value for the property value.
fn actual(&self) -> Value;
fn actual(self) -> Value;
}
1 change: 1 addition & 0 deletions unic/char/range/src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ impl DoubleEndedIterator for CharIter {
}
}

#[allow(clippy::range_plus_one)] // RangeInclusive<u32> does not impl ExactSizeIterator
impl ExactSizeIterator for CharIter {
fn len(&self) -> usize {
if self.is_finished() {
Expand Down
12 changes: 6 additions & 6 deletions unic/char/range/src/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl CharRange {
/// assert!( ! CharRange:: open ('a', 'a').contains('a'));
/// assert!( ! CharRange::closed('z', 'a').contains('g'));
/// ```
pub fn contains(&self, ch: char) -> bool {
pub fn contains(self, ch: char) -> bool {
self.low <= ch && ch <= self.high
}

Expand All @@ -187,7 +187,7 @@ impl CharRange {
///
/// Panics if the range is empty. This fn may be adjusted in the future to not panic
/// in optimized builds. Even if so, an empty range will never compare as `Ordering::Equal`.
pub fn cmp_char(&self, ch: char) -> Ordering {
pub fn cmp_char(self, ch: char) -> Ordering {
// possible optimization: only assert this in debug builds
assert!(!self.is_empty(), "Cannot compare empty range's ordering");
if self.high < ch {
Expand All @@ -200,18 +200,18 @@ impl CharRange {
}

/// How many characters are in this range?
pub fn len(&self) -> usize {
pub fn len(self) -> usize {
self.iter().len()
}

/// Is this range empty?
pub fn is_empty(&self) -> bool {
pub fn is_empty(self) -> bool {
self.low > self.high
}

/// Create an iterator over this range.
pub fn iter(&self) -> CharIter {
(*self).into()
pub fn iter(self) -> CharIter {
self.into()
}
}

Expand Down
2 changes: 1 addition & 1 deletion unic/idna/mapping/src/mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ mod data {
use super::Mapping::*;
use unic_char_property::tables::CharDataTable;

#[cfg_attr(feature = "cargo-clippy", allow(unreadable_literal))]
#[allow(clippy::unreadable_literal)]
pub const MAPPING: CharDataTable<super::Mapping> = include!("../tables/idna_mapping.rsv");
}

Expand Down
2 changes: 1 addition & 1 deletion unic/idna/punycode/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub fn decode_to_string(input: &str) -> Option<String> {
/// Return None on malformed input or overflow.
/// Overflow can only happen on inputs that take more than
/// 63 encoded bytes, the DNS limit on domain name labels.
#[cfg_attr(feature = "cargo-clippy", allow(cast_lossless))]
#[allow(clippy::cast_lossless)]
pub fn decode(input: &str) -> Option<Vec<char>> {
// Handle "basic" (ASCII) code points.
// They are encoded as-is before the last delimiter, if any.
Expand Down
4 changes: 2 additions & 2 deletions unic/idna/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ fn passes_bidi(label: &str, is_bidi_domain: bool) -> bool {
}

// https://www.unicode.org/reports/tr46/#Validity_Criteria
#[cfg_attr(feature = "cargo-clippy", allow(if_same_then_else))]
#[allow(clippy::if_same_then_else)]
fn validate(label: &str, is_bidi_domain: bool, flags: Flags, errors: &mut Vec<Error>) {
let first_char = label.chars().next();

Expand Down Expand Up @@ -296,7 +296,7 @@ pub struct Flags {
}

/// Error types recorded during UTS #46 processing.
#[cfg_attr(feature = "cargo-clippy", allow(enum_variant_names))]
#[allow(clippy::enum_variant_names)]
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
enum Error {
PunycodeError,
Expand Down
4 changes: 2 additions & 2 deletions unic/segment/src/grapheme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ enum PairResult {
fn check_pair(before: GCB, after: GCB) -> PairResult {
use self::PairResult::*;

#[cfg_attr(feature = "cargo-clippy", allow(match_same_arms))]
#[allow(clippy::match_same_arms)]
match (before, after) {
// Do not break between a CR and LF. Otherwise, break before and after controls.
(GCB::CR, GCB::LF) => NotBreak, // GB3
Expand Down Expand Up @@ -533,7 +533,7 @@ impl GraphemeCursor {
// TODO(clippy): Fix clippy warning or leave it as allowed if really needed.
// `warning: methods called `is_*` usually take self by reference or no self; consider choosing
// a less ambiguous name`
#[cfg_attr(feature = "cargo-clippy", allow(wrong_self_convention))]
#[allow(clippy::wrong_self_convention)]
/// Determine whether the current cursor location is a grapheme cluster boundary.
/// Only a part of the string need be supplied. If `chunk_start` is nonzero or
/// the length of `chunk` is not equal to `len` on creation, then this method
Expand Down
4 changes: 2 additions & 2 deletions unic/segment/src/word.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ impl<'a> Iterator for WordBounds<'a> {
}

#[inline]
#[cfg_attr(feature = "cargo-clippy", allow(match_same_arms))]
#[allow(clippy::match_same_arms, clippy::cyclomatic_complexity)]
fn next(&mut self) -> Option<&'a str> {
use self::FormatExtendType::*;
use self::WordBoundsState::*;
Expand Down Expand Up @@ -401,7 +401,7 @@ impl<'a> Iterator for WordBounds<'a> {

impl<'a> DoubleEndedIterator for WordBounds<'a> {
#[inline]
#[cfg_attr(feature = "cargo-clippy", allow(cyclomatic_complexity))]
#[allow(clippy::cyclomatic_complexity)]
fn next_back(&mut self) -> Option<&'a str> {
use self::FormatExtendType::*;
use self::WordBoundsState::*;
Expand Down
4 changes: 2 additions & 2 deletions unic/ucd/age/src/age.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl PartialCharProperty for Age {

impl CustomCharProperty<UnicodeVersion> for Age {
/// Get numeric value for character property value
fn actual(&self) -> UnicodeVersion {
fn actual(self) -> UnicodeVersion {
Self::actual(self)
}
}
Expand All @@ -78,7 +78,7 @@ impl Age {
}

/// Return the `UnicodeVersion` value of the age.
pub fn actual(&self) -> UnicodeVersion {
pub fn actual(self) -> UnicodeVersion {
self.0
}
}
Expand Down
12 changes: 6 additions & 6 deletions unic/ucd/bidi/src/bidi_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ impl BidiClass {

/// If the `BidiClass` has strong or explicit Left-to-Right direction.
#[inline]
pub fn category(&self) -> BidiClassCategory {
match *self {
pub fn category(self) -> BidiClassCategory {
match self {
BidiClass::LeftToRight | BidiClass::RightToLeft | BidiClass::ArabicLetter => {
BidiClassCategory::Strong
}
Expand Down Expand Up @@ -269,8 +269,8 @@ impl BidiClass {

/// If the `BidiClass` has strong or explicit Left-to-Right direction.
#[inline]
pub fn is_ltr(&self) -> bool {
match *self {
pub fn is_ltr(self) -> bool {
match self {
BidiClass::LeftToRight
| BidiClass::LeftToRightEmbedding
| BidiClass::LeftToRightOverride
Expand All @@ -281,8 +281,8 @@ impl BidiClass {

/// If the `BidiClass` has strong or explicit Right-To-Left direction.
#[inline]
pub fn is_rtl(&self) -> bool {
match *self {
pub fn is_rtl(self) -> bool {
match self {
BidiClass::RightToLeft
| BidiClass::ArabicLetter
| BidiClass::RightToLeftEmbedding
Expand Down
Loading

0 comments on commit b38e713

Please sign in to comment.