Skip to content

Commit

Permalink
fixed some clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
llogiq committed Aug 25, 2016
1 parent 00db780 commit 04e975d
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 40 deletions.
16 changes: 8 additions & 8 deletions src/highlighting/highlighter.rs
Expand Up @@ -115,7 +115,7 @@ impl<'a, 'b> Iterator for HighlightIterator<'a, 'b> {
(self.text.len(), ScopeStackOp::Noop)
};
// println!("{} - {:?}", self.index, self.pos);
let style = self.state.styles.last().unwrap().clone();
let style = *self.state.styles.last().unwrap();
let text = &self.text[self.pos..end];
match command {
ScopeStackOp::Push(scope) => {
Expand Down Expand Up @@ -147,12 +147,12 @@ impl<'a> Highlighter<'a> {
pub fn new(theme: &'a Theme) -> Highlighter<'a> {
let mut single_selectors = Vec::new();
let mut multi_selectors = Vec::new();
for item in theme.scopes.iter() {
for item in &theme.scopes {
for sel in &item.scope.selectors {
if let Some(scope) = sel.extract_single_scope() {
single_selectors.push((scope, item.style.clone()));
single_selectors.push((scope, item.style));
} else {
multi_selectors.push((sel.clone(), item.style.clone()));
multi_selectors.push((sel.clone(), item.style));
}
}
}
Expand Down Expand Up @@ -223,17 +223,17 @@ impl<'a> Highlighter<'a> {
}
// println!("multi at {:?} score {:?} single score {:?}", path, score, single_score);
if MatchPower(single_score) < score {
return style.clone();
return *style;
}
}
if let Some(&(_, ref style)) = single_res {
return style.clone();
return *style;
}
return StyleModifier {
StyleModifier {
foreground: None,
background: None,
font_style: None,
};
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/highlighting/theme.rs
Expand Up @@ -179,7 +179,7 @@ impl FromStr for FontStyle {
"bold" => FONT_STYLE_BOLD,
"underline" => FONT_STYLE_UNDERLINE,
"italic" => FONT_STYLE_ITALIC,
"normal" => FontStyle::empty(),
"normal" |
"regular" => FontStyle::empty(),
s => return Err(IncorrectFontStyle(s.to_owned())),
})
Expand Down Expand Up @@ -366,7 +366,7 @@ impl ParseSettings for ThemeSettings {
"highlightForeground" => {
settings.highlight_foreground = Color::parse_settings(value).ok()
}
"invisibles" => (), // ignored
"invisibles" | // ignored
_ => (),
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/highlighting/theme_set.rs
Expand Up @@ -19,7 +19,7 @@ impl ThemeSet {
let mut themes = Vec::new();
for entry in WalkDir::new(folder) {
let entry = try!(entry.map_err(LoadingError::WalkDir));
if entry.path().extension().map(|e| e == "tmTheme").unwrap_or(false) {
if entry.path().extension().map_or(false, |e| e == "tmTheme") {
themes.push(entry.path().to_owned());
}
}
Expand Down
24 changes: 11 additions & 13 deletions src/parsing/parser.rs
Expand Up @@ -131,7 +131,7 @@ impl ParseState {
if let Some(maybe_region) =
search_cache.get(&(match_pat as *const MatchPattern)) {
let mut valid_entry = true;
if let &Some(ref region) = maybe_region {
if let Some(ref region) = *maybe_region {
let match_start = region.pos(0).unwrap().0;
if match_start < *start {
valid_entry = false;
Expand Down Expand Up @@ -187,10 +187,8 @@ impl ParseState {
pat_index: pat_index,
});
}
} else {
if refs_regex.is_none() {
search_cache.insert(match_pat, None);
}
} else if refs_regex.is_none() {
search_cache.insert(match_pat, None);
}
}
}
Expand Down Expand Up @@ -224,7 +222,7 @@ impl ParseState {
self.push_meta_ops(true, match_start, &*level_context, &pat.operation, ops);
for s in &pat.scope {
// println!("pushing {:?} at {}", s, match_start);
ops.push((match_start, ScopeStackOp::Push(s.clone())));
ops.push((match_start, ScopeStackOp::Push(*s)));
}
if let Some(ref capture_map) = pat.captures {
// captures could appear in an arbitrary order, have to produce ops in right order
Expand All @@ -240,7 +238,7 @@ impl ParseState {
// println!("capture {:?} at {:?}-{:?}", scopes[0], cap_start, cap_end);
for scope in scopes.iter() {
map.push(((cap_start, -((cap_end - cap_start) as i32)),
ScopeStackOp::Push(scope.clone())));
ScopeStackOp::Push(*scope)));
}
map.push(((cap_end, i32::MIN), ScopeStackOp::Pop(scopes.len())));
}
Expand Down Expand Up @@ -286,9 +284,9 @@ impl ParseState {
ops.push((index, ScopeStackOp::Pop(v.len())));
}
}
match match_op {
&MatchOperation::Push(ref context_refs) |
&MatchOperation::Set(ref context_refs) => {
match *match_op {
MatchOperation::Push(ref context_refs) |
MatchOperation::Set(ref context_refs) => {
for r in context_refs {
let ctx_ptr = r.resolve();
let ctx = ctx_ptr.borrow();
Expand All @@ -298,12 +296,12 @@ impl ParseState {
&ctx.meta_content_scope
};
for scope in v.iter() {
ops.push((index, ScopeStackOp::Push(scope.clone())));
ops.push((index, ScopeStackOp::Push(*scope)));
}
}
}
&MatchOperation::None |
&MatchOperation::Pop => (),
MatchOperation::None |
MatchOperation::Pop => (),
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/parsing/scope.rs
Expand Up @@ -416,7 +416,7 @@ impl FromStr for ScopeStack {

impl fmt::Display for ScopeStack {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
for s in self.scopes.iter() {
for s in &self.scopes {
try!(write!(f, "{} ", s));
}
Ok(())
Expand Down
12 changes: 6 additions & 6 deletions src/parsing/syntax_definition.rs
Expand Up @@ -128,9 +128,9 @@ impl Iterator for MatchIter {
match context.patterns[index] {
Pattern::Match(_) => return Some((context_ref.clone(), index)),
Pattern::Include(ref ctx_ref) => {
let ctx_ptr = match ctx_ref {
&ContextReference::Inline(ref ctx_ptr) => ctx_ptr.clone(),
&ContextReference::Direct(ref ctx_ptr) => {
let ctx_ptr = match *ctx_ref {
ContextReference::Inline(ref ctx_ptr) => ctx_ptr.clone(),
ContextReference::Direct(ref ctx_ptr) => {
ctx_ptr.link.upgrade().unwrap()
}
_ => panic!("Can only iterate patterns after linking: {:?}", ctx_ref),
Expand Down Expand Up @@ -178,9 +178,9 @@ impl Context {
impl ContextReference {
/// find the pointed to context, panics if ref is not linked
pub fn resolve(&self) -> ContextPtr {
match self {
&ContextReference::Inline(ref ptr) => ptr.clone(),
&ContextReference::Direct(ref ptr) => ptr.link.upgrade().unwrap(),
match *self {
ContextReference::Inline(ref ptr) => ptr.clone(),
ContextReference::Direct(ref ptr) => ptr.link.upgrade().unwrap(),
_ => panic!("Can only call resolve on linked references: {:?}", self),
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/parsing/syntax_set.rs
Expand Up @@ -83,7 +83,7 @@ impl SyntaxSet {
self.is_linked = false;
for entry in WalkDir::new(folder) {
let entry = try!(entry.map_err(LoadingError::WalkDir));
if entry.path().extension().map(|e| e == "sublime-syntax").unwrap_or(false) {
if entry.path().extension().map_or(false, |e| e == "sublime-syntax") {
// println!("{}", entry.path().display());
self.syntaxes.push(try!(load_syntax_file(entry.path(), lines_include_newline)));
}
Expand Down Expand Up @@ -217,15 +217,15 @@ impl SyntaxSet {
/// This operation is idempotent, but takes time even on already linked syntax sets.
pub fn link_syntaxes(&mut self) {
// 2 loops necessary to satisfy borrow checker :-(
for syntax in self.syntaxes.iter_mut() {
if let Some(ref proto_ptr) = syntax.contexts.get("prototype") {
for syntax in &mut self.syntaxes {
if let Some(proto_ptr) = syntax.contexts.get("prototype") {
let mut mut_ref = proto_ptr.borrow_mut();
Self::recursively_mark_no_prototype(syntax, mut_ref.deref_mut());
syntax.prototype = Some((*proto_ptr).clone());
}
}
for syntax in &self.syntaxes {
for (_, context_ptr) in &syntax.contexts {
for context_ptr in syntax.contexts.values() {
let mut mut_ref = context_ptr.borrow_mut();
self.link_context(syntax, mut_ref.deref_mut());
}
Expand All @@ -249,7 +249,7 @@ impl SyntaxSet {
};
if let Some(context_refs) = maybe_context_refs {
for context_ref in context_refs.iter() {
if let &ContextReference::Inline(ref context_ptr) = context_ref {
if let ContextReference::Inline(ref context_ptr) = *context_ref {
let mut mut_ref = context_ptr.borrow_mut();
Self::recursively_mark_no_prototype(syntax, mut_ref.deref_mut());
}
Expand Down Expand Up @@ -293,12 +293,12 @@ impl SyntaxSet {
}
ByScope { scope, ref sub_context } => {
let other_syntax = self.find_syntax_by_scope(scope);
let context_name = sub_context.as_ref().map(|x| &**x).unwrap_or("main");
let context_name = sub_context.as_ref().map_or("main", |x| &**x);
other_syntax.and_then(|s| s.contexts.get(context_name))
}
File { ref name, ref sub_context } => {
let other_syntax = self.find_syntax_by_name(name);
let context_name = sub_context.as_ref().map(|x| &**x).unwrap_or("main");
let context_name = sub_context.as_ref().map_or("main", |x| &**x);
other_syntax.and_then(|s| s.contexts.get(context_name))
}
Direct(_) => None,
Expand Down
4 changes: 2 additions & 2 deletions src/parsing/yaml_load.rs
Expand Up @@ -232,7 +232,7 @@ impl SyntaxDefinition {
fn resolve_variables(raw_regex: &str, state: &ParserState) -> String {
state.variable_regex.replace_all(raw_regex, |caps: &Captures| {
let var_regex_raw =
state.variables.get(caps.at(1).unwrap_or("")).map(|x| &**x).unwrap_or("");
state.variables.get(caps.at(1).unwrap_or("")).map_or("", |x| &**x);
Self::resolve_variables(var_regex_raw, state)
})
}
Expand Down Expand Up @@ -315,7 +315,7 @@ impl SyntaxDefinition {
state: &mut ParserState)
-> Result<Vec<ContextReference>, ParseSyntaxError> {
// check for a push of multiple items
if y.as_vec().map(|v| !v.is_empty() && v[0].as_str().is_some()).unwrap_or(false) {
if y.as_vec().map_or(false, |v| !v.is_empty() && v[0].as_str().is_some()) {
// this works because Result implements FromIterator to handle the errors
y.as_vec()
.unwrap()
Expand Down

0 comments on commit 04e975d

Please sign in to comment.