-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
106 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// check-pass | ||
|
||
#![allow(unused_variables)] | ||
#![feature(generic_arg_infer)] | ||
|
||
struct Zeroes; | ||
impl Into<&'static [usize; 3]> for Zeroes { | ||
fn into(self) -> &'static [usize; 3] { | ||
&[0; 3] | ||
} | ||
} | ||
impl Into<[usize; 3]> for Zeroes { | ||
fn into(self) -> [usize; 3] { | ||
[0; 3] | ||
} | ||
} | ||
fn main() { | ||
let [a, b, c] = Zeroes.into(); | ||
let [d, e, f] = <Zeroes as Into<&'static [usize; 3]>>::into(Zeroes); | ||
let &[g, h, i] = Zeroes.into(); | ||
let [j, k, l]: [usize; _] = Zeroes.into(); | ||
let [m, n, o]: &[usize; _] = Zeroes.into(); | ||
|
||
// check the binding mode of these patterns: | ||
let _: &[usize] = &[a, b, c, g, h, i, j, k, l]; | ||
let _: &[&usize] = &[d, e, f, m, n, o]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Test that we infer the expected type of a pattern to an array of the given length. | ||
|
||
#![allow(unused_variables)] | ||
|
||
use std::array::TryFromSliceError; | ||
use std::convert::TryInto; | ||
|
||
struct Zeroes; | ||
impl Into<[usize; 2]> for Zeroes { | ||
fn into(self) -> [usize; 2] { | ||
[0; 2] | ||
} | ||
} | ||
impl Into<[usize; 3]> for Zeroes { | ||
fn into(self) -> [usize; 3] { | ||
[0; 3] | ||
} | ||
} | ||
impl Into<[usize; 4]> for Zeroes { | ||
fn into(self) -> [usize; 4] { | ||
[0; 4] | ||
} | ||
} | ||
|
||
fn zeroes_into() { | ||
let [a, b, c] = Zeroes.into(); | ||
let [d, e, f]: [_; 3] = Zeroes.into(); | ||
} | ||
|
||
fn array_try_from(x: &[usize]) -> Result<usize, TryFromSliceError> { | ||
let [a, b] = x.try_into()?; | ||
Ok(a + b) | ||
} | ||
|
||
fn default() { | ||
let a: i32; | ||
let b; | ||
[a, b] = Default::default(); | ||
} | ||
|
||
fn test_nested_array() { | ||
let a: [_; 3]; | ||
let b; | ||
//~^ ERROR type annotations needed | ||
[a, b] = Default::default(); | ||
} | ||
|
||
struct Foo<T>([T; 2]); | ||
|
||
impl<T: Default + Copy> Default for Foo<T> { | ||
fn default() -> Self { | ||
Foo([Default::default(); 2]) | ||
} | ||
} | ||
|
||
fn field_array() { | ||
let a: i32; | ||
let b; | ||
Foo([a, b]) = Default::default(); | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
error[E0282]: type annotations needed for `[_; 3]` | ||
--> $DIR/slice-patterns-irrefutable.rs:43:9 | ||
| | ||
LL | let b; | ||
| ^ | ||
| | ||
help: consider giving `b` an explicit type, where the placeholders `_` are specified | ||
| | ||
LL | let b: [_; 3]; | ||
| ++++++++ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0282`. |