From 8701ebbba73d468f7c7bc3fe128ee97fda8ff13a Mon Sep 17 00:00:00 2001 From: Nathan Vegdahl Date: Thu, 29 Jan 2015 21:03:56 -0800 Subject: [PATCH] Tweaked code to avoid warnings from latest rustc compiler. --- src/buffer/line.rs | 12 ++++++------ src/buffer/mod.rs | 20 ++++++++++---------- src/buffer/node.rs | 4 ++-- src/editor/mod.rs | 2 +- src/main.rs | 10 +++++++--- src/term_ui/mod.rs | 16 ++++++++-------- 6 files changed, 34 insertions(+), 30 deletions(-) diff --git a/src/buffer/line.rs b/src/buffer/line.rs index 200b17c..14e38a8 100644 --- a/src/buffer/line.rs +++ b/src/buffer/line.rs @@ -117,7 +117,7 @@ impl Line { let mut le_size: usize = 0; let text_size = tl.text.len(); if tl.text.len() >= 3 { - match unsafe{mem::transmute::<&[u8], &str>(tl.text.slice_from(text_size-3))} { + match unsafe{mem::transmute::<&[u8], &str>(&tl.text[(text_size-3)..])} { // LS "\u{2028}" => { tl.ending = LineEnding::LS; @@ -135,7 +135,7 @@ impl Line { } if le_size == 0 && tl.text.len() >= 2 { - match unsafe{mem::transmute::<&[u8], &str>(tl.text.slice_from(text_size-2))} { + match unsafe{mem::transmute::<&[u8], &str>(&tl.text[(text_size-2)..])} { // CRLF "\u{000D}\u{000A}" => { tl.ending = LineEnding::CRLF; @@ -147,7 +147,7 @@ impl Line { } if le_size == 0 && tl.text.len() >= 1 { - match unsafe{mem::transmute::<&[u8], &str>(tl.text.slice_from(text_size-1))} { + match unsafe{mem::transmute::<&[u8], &str>(&tl.text[(text_size-1)..])} { // LF "\u{000A}" => { tl.ending = LineEnding::LF; @@ -230,7 +230,7 @@ impl Line { /// Returns an immutable string slice into the text block's memory pub fn as_str<'a>(&'a self) -> &'a str { unsafe { - mem::transmute(self.text.as_slice()) + mem::transmute(&self.text[]) } } @@ -336,7 +336,7 @@ impl Line { let byte_pos = grapheme_pos_to_byte_pos(self.as_str(), pos); // Copy the elements after the split index to the second line - other.text.push_all(self.text.slice_from(byte_pos)); + other.text.push_all(&self.text[byte_pos..]); // Truncate the first line self.text.truncate(byte_pos); @@ -362,7 +362,7 @@ impl Line { /// Returns an iterator over the graphemes of the line pub fn grapheme_iter_at_index<'a>(&'a self, index: usize) -> LineGraphemeIter<'a> { - let temp: &str = unsafe{mem::transmute(self.text.as_slice())}; + let temp: &str = unsafe{mem::transmute(&self.text[])}; let mut iter = LineGraphemeIter { graphemes: temp.graphemes(true), diff --git a/src/buffer/mod.rs b/src/buffer/mod.rs index be31b68..2ccbb10 100644 --- a/src/buffer/mod.rs +++ b/src/buffer/mod.rs @@ -168,7 +168,7 @@ impl Buffer { // manipulates the node tree. let s = self.string_from_range(pos_a, pos_b); self._remove_text(pos_a, pos_b); - self._insert_text(s.as_slice(), pos_to); + self._insert_text(&s[], pos_to); } } @@ -219,19 +219,19 @@ impl Buffer { if let Some(op) = self.undo_stack.prev() { match op { InsertText(ref s, p) => { - let size = grapheme_count(s.as_slice()); + let size = grapheme_count(&s[]); self._remove_text(p, p+size); return Some(p); }, RemoveTextBefore(ref s, p) => { - let size = grapheme_count(s.as_slice()); - self._insert_text(s.as_slice(), p); + let size = grapheme_count(&s[]); + self._insert_text(&s[], p); return Some(p+size); }, RemoveTextAfter(ref s, p) => { - self._insert_text(s.as_slice(), p); + self._insert_text(&s[], p); return Some(p); }, @@ -257,13 +257,13 @@ impl Buffer { if let Some(op) = self.undo_stack.next() { match op { InsertText(ref s, p) => { - let size = grapheme_count(s.as_slice()); - self._insert_text(s.as_slice(), p); + let size = grapheme_count(&s[]); + self._insert_text(&s[], p); return Some(p+size); }, RemoveTextBefore(ref s, p) | RemoveTextAfter(ref s, p) => { - let size = grapheme_count(s.as_slice()); + let size = grapheme_count(&s[]); self._remove_text(p, p+size); return Some(p); }, @@ -1498,7 +1498,7 @@ mod tests { let s = buf.string_from_range(1, 12); - assert!(s.as_slice() == "i\nthere\npeo"); + assert!(&s[] == "i\nthere\npeo"); } @@ -1509,7 +1509,7 @@ mod tests { let s = buf.string_from_range(0, 29); - assert!(s.as_slice() == "Hi\nthere\npeople\nof\nthe\nworld!"); + assert!(&s[] == "Hi\nthere\npeople\nof\nthe\nworld!"); } diff --git a/src/buffer/node.rs b/src/buffer/node.rs index afcbf99..0449eec 100644 --- a/src/buffer/node.rs +++ b/src/buffer/node.rs @@ -357,7 +357,7 @@ impl BufferNode { for grapheme in text.grapheme_indices(true) { if is_line_ending(grapheme.1) { if g1 < g2 { - self.insert_text_recursive(f, text.slice(b1, b2), pos + g1); + self.insert_text_recursive(f, &text[b1..b2], pos + g1); } g1 = g2; @@ -376,7 +376,7 @@ impl BufferNode { } if g1 < g2 { - self.insert_text_recursive(f, text.slice(b1, b2), pos + g1); + self.insert_text_recursive(f, &text[b1..b2], pos + g1); } } diff --git a/src/editor/mod.rs b/src/editor/mod.rs index 92c0759..032aef9 100644 --- a/src/editor/mod.rs +++ b/src/editor/mod.rs @@ -159,7 +159,7 @@ impl Editor { if space_blocks > (tab_blocks * 2) { let mut width = 0; let mut width_count = 0; - for i in range(0, 9) { + for i in 0us..9 { if space_histogram[i] > width_count { width = i; width_count = space_histogram[i]; diff --git a/src/main.rs b/src/main.rs index a960c24..d90a133 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,8 @@ -#![allow(unstable)] +#![feature(core)] +#![feature(io)] +#![feature(collections)] +#![feature(path)] +#![feature(std_misc)] extern crate rustbox; extern crate docopt; @@ -56,7 +60,7 @@ fn main() { if args.flag_gui { // // Load file, if specified // let editor = if let Option::Some(s) = args.arg_file { - // Editor::new_from_file(GUILineFormatter::new(4), &Path::new(s.as_slice())) + // Editor::new_from_file(GUILineFormatter::new(4), &Path::new(&s[])) // } // else { // Editor::new(GUILineFormatter::new(4)) @@ -71,7 +75,7 @@ fn main() { else { // Load file, if specified let editor = if let Option::Some(s) = args.arg_file { - Editor::new_from_file(ConsoleLineFormatter::new(4), &Path::new(s.as_slice())) + Editor::new_from_file(ConsoleLineFormatter::new(4), &Path::new(&s[])) } else { Editor::new(ConsoleLineFormatter::new(4)) diff --git a/src/term_ui/mod.rs b/src/term_ui/mod.rs index 0fdd161..3fce677 100644 --- a/src/term_ui/mod.rs +++ b/src/term_ui/mod.rs @@ -170,7 +170,7 @@ impl TermUI { // Character 0 => { if let Option::Some(c) = char::from_u32(character) { - self.editor.insert_text_at_cursor(c.to_string().as_slice()); + self.editor.insert_text_at_cursor(&c.to_string()[]); } }, @@ -214,11 +214,11 @@ impl TermUI { // Draw the editor to screen self.rb.clear(); self.draw_editor(&self.editor, (0, 0), (self.height-1, self.width-1)); - for i in range(0, self.width) { + for i in 0..self.width { self.rb.print(i, 0, rustbox::RB_NORMAL, foreground, background, " "); } self.rb.print(1, 0, rustbox::RB_NORMAL, foreground, background, prefix); - self.rb.print(prefix.len() + 1, 0, rustbox::RB_NORMAL, foreground, background, line.as_slice()); + self.rb.print(prefix.len() + 1, 0, rustbox::RB_NORMAL, foreground, background, &line[]); self.rb.present(); @@ -300,7 +300,7 @@ impl TermUI { let background = Color::Cyan; // Fill in top row with info line color - for i in range(c1.1, c2.1 + 1) { + for i in c1.1..(c2.1 + 1) { self.rb.print(i, c1.0, rustbox::RB_NORMAL, foreground, background, " "); } @@ -308,7 +308,7 @@ impl TermUI { let filename = editor.file_path.display(); let dirty_char = if editor.dirty {"*"} else {""}; let name = format!("{}{}", filename, dirty_char); - self.rb.print(c1.1 + 1, c1.0, rustbox::RB_NORMAL, foreground, background, name.as_slice()); + self.rb.print(c1.1 + 1, c1.0, rustbox::RB_NORMAL, foreground, background, &name[]); // Percentage position in document // TODO: use view instead of cursor for calculation if there is more @@ -320,7 +320,7 @@ impl TermUI { 100 }; let pstring = format!("{}%", percentage); - self.rb.print(c2.1 - pstring.len(), c1.0, rustbox::RB_NORMAL, foreground, background, pstring.as_slice()); + self.rb.print(c2.1 - pstring.len(), c1.0, rustbox::RB_NORMAL, foreground, background, &pstring[]); // Text encoding info and tab style let nl = match editor.buffer.line_ending_type { @@ -336,7 +336,7 @@ impl TermUI { }; let soft_tabs_str = if editor.soft_tabs {"spaces"} else {"tabs"}; let info_line = format!("UTF8:{} {}:{}", nl, soft_tabs_str, editor.soft_tab_width as usize); - self.rb.print(c2.1 - 30, c1.0, rustbox::RB_NORMAL, foreground, background, info_line.as_slice()); + self.rb.print(c2.1 - 30, c1.0, rustbox::RB_NORMAL, foreground, background, &info_line[]); // Draw main text editing area self.draw_editor_text(editor, (c1.0 + 1, c1.1), c2); @@ -387,7 +387,7 @@ impl TermUI { } } else if g == "\t" { - for i in range(0, width) { + for i in 0..width { let tpx = px as usize + i; if tpx <= c2.1 { self.rb.print(tpx as usize, py as usize, rustbox::RB_NORMAL, Color::White, Color::Black, " ");