Implement .. syntax for RangeFull as expression
Allows the expression `..` (without either endpoint) in general, can be used in slicing syntax `&expr[..]` where we previously wrote `&expr[]`. The old syntax &expr[] is not yet removed or warned for.
This commit is contained in:
parent
3b2ed14906
commit
75239142a8
6 changed files with 28 additions and 23 deletions
|
|
@ -8,12 +8,15 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// Test slicing expr[..] is an error and gives a helpful error message.
|
||||
// Test slicing &expr[] is deprecated and gives a helpful error message.
|
||||
//
|
||||
// ignore-test
|
||||
|
||||
struct Foo;
|
||||
|
||||
fn main() {
|
||||
let x = Foo;
|
||||
&x[..]; //~ ERROR incorrect slicing expression: `[..]`
|
||||
//~^ NOTE use `&expr[]` to construct a slice of the whole of expr
|
||||
&x[]; //~ WARNING deprecated slicing syntax: `[]`
|
||||
//~^ NOTE use `&expr[..]` to construct a slice of the whole of expr
|
||||
//~^^ ERROR cannot index a value of type `Foo`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ struct Foo;
|
|||
|
||||
fn main() {
|
||||
let x = Foo;
|
||||
&x[]; //~ ERROR cannot index a value of type `Foo`
|
||||
&x[..]; //~ ERROR cannot index a value of type `Foo`
|
||||
&x[Foo..]; //~ ERROR cannot index a value of type `Foo`
|
||||
&x[..Foo]; //~ ERROR cannot index a value of type `Foo`
|
||||
&x[Foo..Foo]; //~ ERROR cannot index a value of type `Foo`
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ fn foo() -> int { 42 }
|
|||
|
||||
// Test that range syntax works in return statements
|
||||
fn return_range_to() -> ::std::ops::RangeTo<i32> { return ..1; }
|
||||
fn return_full_range() -> ::std::ops::RangeFull { return ..; }
|
||||
|
||||
pub fn main() {
|
||||
let mut count = 0;
|
||||
|
|
|
|||
|
|
@ -55,5 +55,8 @@ fn main() {
|
|||
|
||||
let x = [1]..[2];
|
||||
assert!(x == (([1])..([2])));
|
||||
|
||||
let y = ..;
|
||||
assert!(y == (..));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ 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);
|
||||
let cmp: &[int] = &[1, 2, 3];
|
||||
|
|
@ -35,6 +36,7 @@ fn main() {
|
|||
{
|
||||
let cmp: &mut [int] = &mut [1, 2, 3, 4, 5];
|
||||
assert!(&mut x[] == cmp);
|
||||
assert!(&mut x[..] == cmp);
|
||||
}
|
||||
{
|
||||
let cmp: &mut [int] = &mut [3, 4, 5];
|
||||
|
|
@ -53,6 +55,7 @@ fn main() {
|
|||
{
|
||||
let cmp: &mut [int] = &mut [1, 2, 3, 4, 5];
|
||||
assert!(&mut x[] == cmp);
|
||||
assert!(&mut x[..] == cmp);
|
||||
}
|
||||
{
|
||||
let cmp: &mut [int] = &mut [3, 4, 5];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue