diff options
| author | Matthias Einwag <matthias.einwag@live.com> | 2019-02-12 22:46:14 -0800 |
|---|---|---|
| committer | Matthias Einwag <matthias.einwag@live.com> | 2019-02-12 22:46:14 -0800 |
| commit | 871338c3aed87cb84f02ebd7fd9b447966d5b05d (patch) | |
| tree | a2e1315d7d17d0b9f3463686ed2fbf36f3238ec4 /src/libsyntax/util | |
| parent | 1ef34a5a39641846e824b6450a705d6031002beb (diff) | |
| parent | 0f949c2fcc696d0260a99196d5e5400c59a26a54 (diff) | |
| download | rust-871338c3aed87cb84f02ebd7fd9b447966d5b05d.tar.gz rust-871338c3aed87cb84f02ebd7fd9b447966d5b05d.zip | |
Merging master
Diffstat (limited to 'src/libsyntax/util')
| -rw-r--r-- | src/libsyntax/util/lev_distance.rs | 8 | ||||
| -rw-r--r-- | src/libsyntax/util/map_in_place.rs (renamed from src/libsyntax/util/move_map.rs) | 29 | ||||
| -rw-r--r-- | src/libsyntax/util/node_count.rs | 6 | ||||
| -rw-r--r-- | src/libsyntax/util/parser.rs | 24 | ||||
| -rw-r--r-- | src/libsyntax/util/parser_testing.rs | 24 |
5 files changed, 41 insertions, 50 deletions
diff --git a/src/libsyntax/util/lev_distance.rs b/src/libsyntax/util/lev_distance.rs index d6d2251b5bc..2f150d22159 100644 --- a/src/libsyntax/util/lev_distance.rs +++ b/src/libsyntax/util/lev_distance.rs @@ -1,7 +1,7 @@ use std::cmp; -use symbol::Symbol; +use crate::symbol::Symbol; -/// Find the Levenshtein distance between two strings +/// Finds the Levenshtein distance between two strings pub fn lev_distance(a: &str, b: &str) -> usize { // cases which don't require further computation if a.is_empty() { @@ -32,7 +32,7 @@ pub fn lev_distance(a: &str, b: &str) -> usize { dcol[t_last + 1] } -/// Find the best match for a given word in the given iterator +/// Finds the best match for a given word in the given iterator /// /// As a loose rule to avoid the obviously incorrect suggestions, it takes /// an optional limit for the maximum allowable edit distance, which defaults @@ -101,7 +101,7 @@ fn test_lev_distance() { #[test] fn test_find_best_match_for_name() { - use with_globals; + use crate::with_globals; with_globals(|| { let input = vec![Symbol::intern("aaab"), Symbol::intern("aaabc")]; assert_eq!( diff --git a/src/libsyntax/util/move_map.rs b/src/libsyntax/util/map_in_place.rs index a0f9d39ce89..5724b540a0d 100644 --- a/src/libsyntax/util/move_map.rs +++ b/src/libsyntax/util/map_in_place.rs @@ -1,18 +1,18 @@ use std::ptr; use smallvec::{Array, SmallVec}; -pub trait MoveMap<T>: Sized { - fn move_map<F>(self, mut f: F) -> Self where F: FnMut(T) -> T { - self.move_flat_map(|e| Some(f(e))) +pub trait MapInPlace<T>: Sized { + fn map_in_place<F>(&mut self, mut f: F) where F: FnMut(T) -> T { + self.flat_map_in_place(|e| Some(f(e))) } - fn move_flat_map<F, I>(self, f: F) -> Self + fn flat_map_in_place<F, I>(&mut self, f: F) where F: FnMut(T) -> I, I: IntoIterator<Item=T>; } -impl<T> MoveMap<T> for Vec<T> { - fn move_flat_map<F, I>(mut self, mut f: F) -> Self +impl<T> MapInPlace<T> for Vec<T> { + fn flat_map_in_place<F, I>(&mut self, mut f: F) where F: FnMut(T) -> I, I: IntoIterator<Item=T> { @@ -53,22 +53,11 @@ impl<T> MoveMap<T> for Vec<T> { // write_i tracks the number of actually written new items. self.set_len(write_i); } - - self - } -} - -impl<T> MoveMap<T> for ::ptr::P<[T]> { - fn move_flat_map<F, I>(self, f: F) -> Self - where F: FnMut(T) -> I, - I: IntoIterator<Item=T> - { - ::ptr::P::from_vec(self.into_vec().move_flat_map(f)) } } -impl<T, A: Array<Item = T>> MoveMap<T> for SmallVec<A> { - fn move_flat_map<F, I>(mut self, mut f: F) -> Self +impl<T, A: Array<Item = T>> MapInPlace<T> for SmallVec<A> { + fn flat_map_in_place<F, I>(&mut self, mut f: F) where F: FnMut(T) -> I, I: IntoIterator<Item=T> { @@ -109,7 +98,5 @@ impl<T, A: Array<Item = T>> MoveMap<T> for SmallVec<A> { // write_i tracks the number of actually written new items. self.set_len(write_i); } - - self } } diff --git a/src/libsyntax/util/node_count.rs b/src/libsyntax/util/node_count.rs index 7dd213ae38b..521edac8f5f 100644 --- a/src/libsyntax/util/node_count.rs +++ b/src/libsyntax/util/node_count.rs @@ -1,7 +1,7 @@ // Simply gives a rought count of the number of nodes in an AST. -use visit::*; -use ast::*; +use crate::visit::*; +use crate::ast::*; use syntax_pos::Span; pub struct NodeCounter { @@ -69,7 +69,7 @@ impl<'ast> Visitor<'ast> for NodeCounter { self.count += 1; walk_generics(self, g) } - fn visit_fn(&mut self, fk: FnKind, fd: &FnDecl, s: Span, _: NodeId) { + fn visit_fn(&mut self, fk: FnKind<'_>, fd: &FnDecl, s: Span, _: NodeId) { self.count += 1; walk_fn(self, fk, fd, s) } diff --git a/src/libsyntax/util/parser.rs b/src/libsyntax/util/parser.rs index 89d4e53b8d1..5f15ede7b0b 100644 --- a/src/libsyntax/util/parser.rs +++ b/src/libsyntax/util/parser.rs @@ -1,6 +1,6 @@ -use parse::token::{Token, BinOpToken}; -use symbol::keywords; -use ast::{self, BinOpKind}; +use crate::parse::token::{Token, BinOpToken}; +use crate::symbol::keywords; +use crate::ast::{self, BinOpKind}; /// Associative operator with precedence. /// @@ -70,9 +70,9 @@ pub enum Fixity { } impl AssocOp { - /// Create a new AssocOP from a token + /// Creates a new AssocOP from a token pub fn from_token(t: &Token) -> Option<AssocOp> { - use self::AssocOp::*; + use AssocOp::*; match *t { Token::BinOpEq(k) => Some(AssignOp(k)), Token::LArrow => Some(ObsoleteInPlace), @@ -105,9 +105,9 @@ impl AssocOp { } } - /// Create a new AssocOp from ast::BinOpKind. + /// Creates a new AssocOp from ast::BinOpKind. pub fn from_ast_binop(op: BinOpKind) -> Self { - use self::AssocOp::*; + use AssocOp::*; match op { BinOpKind::Lt => Less, BinOpKind::Gt => Greater, @@ -132,7 +132,7 @@ impl AssocOp { /// Gets the precedence of this operator pub fn precedence(&self) -> usize { - use self::AssocOp::*; + use AssocOp::*; match *self { As | Colon => 14, Multiply | Divide | Modulus => 13, @@ -152,7 +152,7 @@ impl AssocOp { /// Gets the fixity of this operator pub fn fixity(&self) -> Fixity { - use self::AssocOp::*; + use AssocOp::*; // NOTE: it is a bug to have an operators that has same precedence but different fixities! match *self { ObsoleteInPlace | Assign | AssignOp(_) => Fixity::Right, @@ -164,7 +164,7 @@ impl AssocOp { } pub fn is_comparison(&self) -> bool { - use self::AssocOp::*; + use AssocOp::*; match *self { Less | Greater | LessEqual | GreaterEqual | Equal | NotEqual => true, ObsoleteInPlace | Assign | AssignOp(_) | As | Multiply | Divide | Modulus | Add | @@ -174,7 +174,7 @@ impl AssocOp { } pub fn is_assign_like(&self) -> bool { - use self::AssocOp::*; + use AssocOp::*; match *self { Assign | AssignOp(_) | ObsoleteInPlace => true, Less | Greater | LessEqual | GreaterEqual | Equal | NotEqual | As | Multiply | Divide | @@ -184,7 +184,7 @@ impl AssocOp { } pub fn to_ast_binop(&self) -> Option<BinOpKind> { - use self::AssocOp::*; + use AssocOp::*; match *self { Less => Some(BinOpKind::Lt), Greater => Some(BinOpKind::Gt), diff --git a/src/libsyntax/util/parser_testing.rs b/src/libsyntax/util/parser_testing.rs index d0b3cd865ce..733c4f83e37 100644 --- a/src/libsyntax/util/parser_testing.rs +++ b/src/libsyntax/util/parser_testing.rs @@ -1,18 +1,22 @@ -use ast::{self, Ident}; -use source_map::FilePathMapping; -use parse::{ParseSess, PResult, source_file_to_stream}; -use parse::{lexer, new_parser_from_source_str}; -use parse::parser::Parser; -use ptr::P; -use tokenstream::TokenStream; +use crate::ast::{self, Ident}; +use crate::source_map::FilePathMapping; +use crate::parse::{ParseSess, PResult, source_file_to_stream}; +use crate::parse::{lexer, new_parser_from_source_str}; +use crate::parse::parser::Parser; +use crate::ptr::P; +use crate::tokenstream::TokenStream; + use std::iter::Peekable; use std::path::PathBuf; /// Map a string to tts, using a made-up filename: pub fn string_to_stream(source_str: String) -> TokenStream { let ps = ParseSess::new(FilePathMapping::empty()); - source_file_to_stream(&ps, ps.source_map() - .new_source_file(PathBuf::from("bogofile").into(), source_str), None) + source_file_to_stream( + &ps, + ps.source_map().new_source_file(PathBuf::from("bogofile").into(), + source_str, + ), None).0 } /// Map string to parser (via tts) @@ -62,7 +66,7 @@ pub fn string_to_pat(source_str: String) -> P<ast::Pat> { }) } -/// Convert a vector of strings to a vector of Ident's +/// Converts a vector of strings to a vector of Ident's pub fn strs_to_idents(ids: Vec<&str> ) -> Vec<Ident> { ids.iter().map(|u| Ident::from_str(*u)).collect() } |
