Skip to content

Commit

Permalink
Implement pretty-printing of .. and update tests.
Browse files Browse the repository at this point in the history
Update tests to change all `&expr[]` to `&expr[..]` to make sure pretty printing
passes.
  • Loading branch information
Ulrik Sverdrup committed Feb 5, 2015
1 parent 7523914 commit 7d527fa
Show file tree
Hide file tree
Showing 13 changed files with 23 additions and 28 deletions.
4 changes: 1 addition & 3 deletions src/libsyntax/print/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1813,9 +1813,7 @@ impl<'a> State<'a> {
if let &Some(ref e) = start {
try!(self.print_expr(&**e));
}
if start.is_some() || end.is_some() {
try!(word(&mut self.s, ".."));
}
try!(word(&mut self.s, ".."));
if let &Some(ref e) = end {
try!(self.print_expr(&**e));
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/bench/shootout-fasta-redux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ impl<'a, W: Writer> RandomFasta<'a, W> {

fn nextc(&mut self) -> u8 {
let r = self.rng(1.0);
for a in &self.lookup[] {
for a in &self.lookup[..] {
if a.p >= r {
return a.c;
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/packed-struct-generic-transmute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ fn main() {
let foo = Foo { bar: [1u8, 2, 3, 4, 5], baz: 10i32 };
unsafe {
let oof: Oof<[u8; 5], i32> = mem::transmute(foo);
println!("{:?} {:?}", &oof.rab[], oof.zab);
println!("{:?} {:?}", &oof.rab[..], oof.zab);
}
}
2 changes: 1 addition & 1 deletion src/test/run-pass/auto-encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn test_rbml<'a, 'b, A:
let mut rbml_w = EBwriter::Encoder::new(&mut wr);
a1.encode(&mut rbml_w);

let d: serialize::rbml::Doc<'a> = EBDoc::new(&wr[]);
let d: serialize::rbml::Doc<'a> = EBDoc::new(&wr);
let mut decoder: EBReader::Decoder<'a> = EBreader::Decoder::new(d);
let a2: A = Decodable::decode(&mut decoder);
assert!(*a1 == a2);
Expand Down
8 changes: 4 additions & 4 deletions src/test/run-pass/coerce-overloaded-autoderef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,19 @@ fn use_slice(_: &[u8]) {}
fn use_slice_mut(_: &mut [u8]) {}

fn use_vec(mut v: Vec<u8>) {
use_slice_mut(&mut v[]); // what you have to write today
use_slice_mut(&mut v); // what you'd be able to write
use_slice_mut(&mut v[..]); // what you have to write today
use_slice_mut(&mut v); // what you'd be able to write
use_slice_mut(&mut &mut &mut v);

use_slice(&v[]); // what you have to write today
use_slice(&v[..]); // what you have to write today
use_slice(&v); // what you'd be able to write
use_slice(&&&&&&v);
use_slice(&mut &&&&&v);
use_slice(&&&mut &&&v);
}

fn use_vec_ref(v: &Vec<u8>) {
use_slice(&v[]); // what you have to write today
use_slice(&v[..]); // what you have to write today
use_slice(v); // what you'd be able to write
use_slice(&&&&&&v);
use_slice(&mut &&&&&v);
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/deriving-encodable-decodable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ fn roundtrip<'a, T: Rand + Eq + Encodable<Encoder<'a>> +
let mut w = Vec::new();
let mut e = Encoder::new(&mut w);
obj.encode(&mut e);
let doc = rbml::Doc::new(&w[]);
let doc = rbml::Doc::new(&w);
let mut dec = Decoder::new(doc);
let obj2 = Decodable::decode(&mut dec);
assert!(obj == obj2);
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/foreach-external-iterators-break.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
pub fn main() {
let x = [1; 100];
let mut y = 0;
for i in &x[] {
for i in &x[..] {
if y > 10 {
break;
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/run-pass/foreach-external-iterators-nested.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ pub fn main() {
let y = [2; 100];
let mut p = 0;
let mut q = 0;
for i in &x[] {
for j in &y[] {
for i in &x[..] {
for j in &y[..] {
p += *j;
}
q += *i + p;
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/foreach-external-iterators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
pub fn main() {
let x = [1; 100];
let mut y = 0;
for i in &x[] {
for i in &x[..] {
y += *i
}
assert!(y == 100);
Expand Down
8 changes: 4 additions & 4 deletions src/test/run-pass/issue-8898.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ pub fn main() {
let x = [(), ()];
let slice = &x[..1];

assert_repr_eq(&abc[], "[1, 2, 3]".to_string());
assert_repr_eq(&tf[], "[true, false]".to_string());
assert_repr_eq(&x[], "[(), ()]".to_string());
assert_repr_eq(&abc[..], "[1, 2, 3]".to_string());
assert_repr_eq(&tf[..], "[true, false]".to_string());
assert_repr_eq(&x[..], "[(), ()]".to_string());
assert_repr_eq(slice, "[()]".to_string());
assert_repr_eq(&x[], "[(), ()]".to_string());
assert_repr_eq(&x[..], "[(), ()]".to_string());
}
6 changes: 3 additions & 3 deletions src/test/run-pass/repeated-vector-syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ pub fn main() {
let y = [ 0; 1 ];

print!("[");
for xi in &x[] {
print!("{:?}, ", &xi[]);
for xi in &x[..] {
print!("{:?}, ", &xi[..]);
}
println!("]");
println!("{:?}", &y[]);
println!("{:?}", &y[..]);
}
5 changes: 1 addition & 4 deletions src/test/run-pass/slice-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
fn main() {
let x: &[int] = &[1, 2, 3, 4, 5];
let cmp: &[int] = &[1, 2, 3, 4, 5];
assert!(&x[] == cmp);
assert!(&x[..] == cmp);
let cmp: &[int] = &[3, 4, 5];
assert!(&x[2..] == cmp);
Expand All @@ -24,7 +23,7 @@ fn main() {

let x: Vec<int> = vec![1, 2, 3, 4, 5];
let cmp: &[int] = &[1, 2, 3, 4, 5];
assert!(&x[] == cmp);
assert!(&x[..] == cmp);
let cmp: &[int] = &[3, 4, 5];
assert!(&x[2..] == cmp);
let cmp: &[int] = &[1, 2, 3];
Expand All @@ -35,7 +34,6 @@ fn main() {
let x: &mut [int] = &mut [1, 2, 3, 4, 5];
{
let cmp: &mut [int] = &mut [1, 2, 3, 4, 5];
assert!(&mut x[] == cmp);
assert!(&mut x[..] == cmp);
}
{
Expand All @@ -54,7 +52,6 @@ fn main() {
let mut x: Vec<int> = vec![1, 2, 3, 4, 5];
{
let cmp: &mut [int] = &mut [1, 2, 3, 4, 5];
assert!(&mut x[] == cmp);
assert!(&mut x[..] == cmp);
}
{
Expand Down
4 changes: 2 additions & 2 deletions src/test/run-pass/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ impl IndexMut<RangeFull> for Foo {

fn main() {
let mut x = Foo;
&x[];
&x[..];
&x[Foo..];
&x[..Foo];
&x[Foo..Foo];
&mut x[];
&mut x[..];
&mut x[Foo..];
&mut x[..Foo];
&mut x[Foo..Foo];
Expand Down

0 comments on commit 7d527fa

Please sign in to comment.