Skip to content

Commit ddfc168

Browse files
authored
Auto merge of #56 - mbrubeck:edition-2018, r=Manishearth
Update to 2018 edition and fix warnings This increases the minimum supported Rust version from 1.17 to 1.31 (released in December 2018). I hope this will have little impact on users, since this version of Rust is almost 2.5 years old, and because our main downstream crates (`url` and `postgres-protocol`) already require 1.31 or later. Many of the changes below are fixing new rustc/clippy warnings added in recent toolchains. r? @Manishearth
2 parents 6f815ba + d01aa65 commit ddfc168

11 files changed

+37
-74
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ rust:
77
- nightly
88
- beta
99
- stable
10-
- 1.17.0
10+
- 1.31.0
1111

1212
matrix:
1313
fast_finish: true

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
[package]
22
name = "unicode-bidi"
3-
version = "0.3.4"
3+
version = "0.3.5"
44
authors = ["The Servo Project Developers"]
55
license = "MIT / Apache-2.0"
66
description = "Implementation of the Unicode Bidirectional Algorithm"
77
repository = "https://github.com/servo/unicode-bidi"
88
documentation = "https://docs.rs/unicode-bidi/"
99
keywords = ["rtl", "unicode", "text", "layout", "bidi"]
1010
readme="README.md"
11+
edition = "2018"
1112

1213
# No data is shipped; benches, examples and tests also depend on data.
1314
exclude = [

examples/flame_udhr.rs

+3-14
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,14 @@
1010

1111
//! Profiling example
1212
13-
#![allow(unused_imports)]
14-
1513
#![cfg_attr(feature="flame_it", feature(plugin, custom_attribute))]
1614
#![cfg_attr(feature="flame_it", plugin(flamer))]
1715

18-
19-
#[cfg(feature = "flame_it")]
20-
extern crate flame;
21-
22-
extern crate unicode_bidi;
23-
24-
25-
use std::fs::File;
26-
27-
use unicode_bidi::BidiInfo;
28-
29-
3016
#[cfg(feature = "flame_it")]
3117
fn main() {
18+
use std::fs::File;
19+
use unicode_bidi::BidiInfo;
20+
3221
const BIDI_TEXT: &str = include_str!("../data/udhr/bidi/udhr_pes_1.txt");
3322

3423
flame::start("main(): BidiInfo::new()");

src/char_data/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use std::cmp::Ordering::{Equal, Less, Greater};
1717
use std::char;
1818

1919
use self::tables::bidi_class_table;
20-
use BidiClass::*;
20+
use crate::BidiClass::*;
2121

2222
/// Find the `BidiClass` of a single char.
2323
pub fn bidi_class(c: char) -> BidiClass {

src/deprecated.rs

-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99

1010
//! This module holds deprecated assets only.
1111
12-
// Doesn't worth updating API here
13-
#![cfg_attr(feature="cargo-clippy", allow(needless_pass_by_value))]
14-
1512
use super::*;
1613

1714
/// Find the level runs within a line and return them in visual order.

src/explicit.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
//!
1212
//! <http://www.unicode.org/reports/tr9/#Explicit_Levels_and_Directions>
1313
14-
use super::char_data::{BidiClass, is_rtl};
15-
use super::level::Level;
14+
use matches::matches;
1615

17-
use BidiClass::*;
16+
use super::char_data::{BidiClass::{self, *}, is_rtl};
17+
use super::level::Level;
1818

1919
/// Compute explicit embedding levels for one paragraph of text (X1-X8).
2020
///

src/implicit.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@
1010
//! 3.3.4 - 3.3.6. Resolve implicit levels and types.
1111
1212
use std::cmp::max;
13+
use matches::matches;
1314

14-
use super::char_data::BidiClass;
15+
use super::char_data::BidiClass::{self, *};
1516
use super::prepare::{IsolatingRunSequence, LevelRun, not_removed_by_x9, removed_by_x9};
1617
use super::level::Level;
1718

18-
use BidiClass::*;
19-
2019
/// 3.3.4 Resolving Weak Types
2120
///
2221
/// <http://www.unicode.org/reports/tr9/#Resolving_Weak_Types>

src/level.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use super::char_data::BidiClass;
2828
///
2929
/// <http://www.unicode.org/reports/tr9/#BD2>
3030
#[derive(Copy, Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
31-
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
31+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
3232
pub struct Level(u8);
3333

3434
pub const LTR_LEVEL: Level = Level(0);

src/lib.rs

+20-38
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,6 @@
6060
#![cfg_attr(feature="flame_it", feature(plugin, custom_attribute))]
6161
#![cfg_attr(feature="flame_it", plugin(flamer))]
6262

63-
64-
#[macro_use]
65-
extern crate matches;
66-
67-
#[cfg(feature = "serde")]
68-
#[macro_use]
69-
extern crate serde;
70-
71-
#[cfg(all(feature = "serde", test))]
72-
extern crate serde_test;
73-
74-
#[cfg(feature = "flame_it")]
75-
extern crate flame;
76-
77-
7863
pub mod deprecated;
7964
pub mod format_chars;
8065
pub mod level;
@@ -84,18 +69,17 @@ mod explicit;
8469
mod implicit;
8570
mod prepare;
8671

87-
pub use char_data::{BidiClass, bidi_class, UNICODE_VERSION};
88-
pub use level::{Level, LTR_LEVEL, RTL_LEVEL};
89-
pub use prepare::LevelRun;
72+
pub use crate::char_data::{BidiClass, bidi_class, UNICODE_VERSION};
73+
pub use crate::level::{Level, LTR_LEVEL, RTL_LEVEL};
74+
pub use crate::prepare::LevelRun;
9075

9176
use std::borrow::Cow;
9277
use std::cmp::{max, min};
9378
use std::iter::repeat;
9479
use std::ops::Range;
9580

96-
use BidiClass::*;
97-
use format_chars as chars;
98-
81+
use crate::BidiClass::*;
82+
use crate::format_chars as chars;
9983

10084
/// Bidi information about a single paragraph
10185
#[derive(Debug, PartialEq)]
@@ -136,7 +120,7 @@ impl<'text> InitialInfo<'text> {
136120
/// character is found before the matching PDI. If no strong character is found, the class will
137121
/// remain FSI, and it's up to later stages to treat these as LRI when needed.
138122
#[cfg_attr(feature = "flame_it", flame)]
139-
pub fn new(text: &str, default_para_level: Option<Level>) -> InitialInfo {
123+
pub fn new(text: &str, default_para_level: Option<Level>) -> InitialInfo<'_> {
140124
let mut original_classes = Vec::with_capacity(text.len());
141125

142126
// The stack contains the starting byte index for each nested isolate we're inside.
@@ -262,7 +246,7 @@ impl<'text> BidiInfo<'text> {
262246
///
263247
/// TODO: Support auto-RTL base direction
264248
#[cfg_attr(feature = "flame_it", flame)]
265-
pub fn new(text: &str, default_para_level: Option<Level>) -> BidiInfo {
249+
pub fn new(text: &str, default_para_level: Option<Level>) -> BidiInfo<'_> {
266250
let InitialInfo {
267251
original_classes,
268252
paragraphs,
@@ -311,7 +295,7 @@ impl<'text> BidiInfo<'text> {
311295
/// per *byte*.
312296
#[cfg_attr(feature = "flame_it", flame)]
313297
pub fn reordered_levels(&self, para: &ParagraphInfo, line: Range<usize>) -> Vec<Level> {
314-
let (levels, _) = self.visual_runs(para, line.clone());
298+
let (levels, _) = self.visual_runs(para, line);
315299
levels
316300
}
317301

@@ -335,7 +319,7 @@ impl<'text> BidiInfo<'text> {
335319

336320
// If all isolating run sequences are LTR, no reordering is needed
337321
if runs.iter().all(|run| levels[run.start].is_ltr()) {
338-
return self.text[line.clone()].into();
322+
return self.text[line].into();
339323
}
340324

341325
let mut result = String::with_capacity(line.len());
@@ -395,18 +379,16 @@ impl<'text> BidiInfo<'text> {
395379
}
396380
}
397381
if let (Some(from), Some(to)) = (reset_from, reset_to) {
398-
#[cfg_attr(feature = "cargo-clippy", allow(needless_range_loop))]
399-
for j in from..to {
400-
line_levels[j] = para.level;
382+
for level in &mut line_levels[from..to] {
383+
*level = para.level;
401384
}
402385
reset_from = None;
403386
reset_to = None;
404387
}
405388
}
406389
if let Some(from) = reset_from {
407-
#[cfg_attr(feature = "cargo-clippy", allow(needless_range_loop))]
408-
for j in from..line_str.len() {
409-
line_levels[j] = para.level;
390+
for level in &mut line_levels[from..] {
391+
*level = para.level;
410392
}
411393
}
412394

@@ -676,7 +658,7 @@ mod tests {
676658
}
677659
);
678660

679-
/// BidiTest:69635 (AL ET EN)
661+
// BidiTest:69635 (AL ET EN)
680662
let bidi_info = BidiInfo::new("\u{060B}\u{20CF}\u{06F9}", None);
681663
assert_eq!(bidi_info.original_classes, vec![AL, AL, ET, ET, ET, EN, EN]);
682664
}
@@ -705,7 +687,7 @@ mod tests {
705687
assert_eq!(BidiInfo::new("אבּג\n123", None).has_rtl(), true);
706688
}
707689

708-
fn reorder_paras(text: &str) -> Vec<Cow<str>> {
690+
fn reorder_paras(text: &str) -> Vec<Cow<'_, str>> {
709691
let bidi_info = BidiInfo::new(text, None);
710692
bidi_info
711693
.paragraphs
@@ -716,22 +698,22 @@ mod tests {
716698

717699
#[test]
718700
fn test_reorder_line() {
719-
/// Bidi_Class: L L L B L L L B L L L
701+
// Bidi_Class: L L L B L L L B L L L
720702
assert_eq!(
721703
reorder_paras("abc\ndef\nghi"),
722704
vec!["abc\n", "def\n", "ghi"]
723705
);
724706

725-
/// Bidi_Class: L L EN B L L EN B L L EN
707+
// Bidi_Class: L L EN B L L EN B L L EN
726708
assert_eq!(
727709
reorder_paras("ab1\nde2\ngh3"),
728710
vec!["ab1\n", "de2\n", "gh3"]
729711
);
730712

731-
/// Bidi_Class: L L L B AL AL AL
713+
// Bidi_Class: L L L B AL AL AL
732714
assert_eq!(reorder_paras("abc\nابج"), vec!["abc\n", "جبا"]);
733715

734-
/// Bidi_Class: AL AL AL B L L L
716+
// Bidi_Class: AL AL AL B L L L
735717
assert_eq!(reorder_paras("ابج\nabc"), vec!["\nجبا", "abc"]);
736718

737719
assert_eq!(reorder_paras("1.-2"), vec!["1.-2"]);
@@ -814,7 +796,7 @@ mod tests {
814796
#[test]
815797
fn test_reordered_levels() {
816798

817-
/// BidiTest:946 (LRI PDI)
799+
// BidiTest:946 (LRI PDI)
818800
let text = "\u{2067}\u{2069}";
819801
assert_eq!(
820802
reordered_levels_for_paras(text),

src/prepare.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@
1313
1414
use std::cmp::max;
1515
use std::ops::Range;
16+
use matches::matches;
1617

17-
use super::char_data::BidiClass;
18+
use super::BidiClass::{self, *};
1819
use super::level::Level;
1920

20-
use BidiClass::*;
21-
2221
/// A maximal substring of characters with the same embedding level.
2322
///
2423
/// Represented as a range of byte indices.
@@ -186,7 +185,7 @@ mod tests {
186185
}
187186

188187
// From <http://www.unicode.org/reports/tr9/#BD13>
189-
#[cfg_attr(rustfmt, rustfmt_skip)]
188+
#[rustfmt::skip]
190189
#[test]
191190
fn test_isolating_run_sequences() {
192191

@@ -231,7 +230,7 @@ mod tests {
231230
}
232231

233232
// From <http://www.unicode.org/reports/tr9/#X10>
234-
#[cfg_attr(rustfmt, rustfmt_skip)]
233+
#[rustfmt::skip]
235234
#[test]
236235
fn test_isolating_run_sequences_sos_and_eos() {
237236

tests/conformance_tests.rs

-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77
// option. This file may not be copied, modified, or distributed
88
// except according to those terms.
99

10-
#![cfg(test)]
11-
12-
extern crate unicode_bidi;
13-
1410
use unicode_bidi::{bidi_class, BidiInfo, format_chars, level, Level};
1511

1612
#[derive(Debug)]

0 commit comments

Comments
 (0)