diff options
| author | Michael Sproul <micsproul@gmail.com> | 2015-05-24 14:29:12 +1000 |
|---|---|---|
| committer | Michael Sproul <micsproul@gmail.com> | 2015-06-03 16:15:15 +1000 |
| commit | 25d0ef347affe79557cdfbaa4e66144c7f476fc0 (patch) | |
| tree | ca28f418e1f9a3f64dd0d96da6a28105c36992de /src/test | |
| parent | 448ce12bc1c20e19fb5c798f1583d8e69969b5f1 (diff) | |
| download | rust-25d0ef347affe79557cdfbaa4e66144c7f476fc0.tar.gz rust-25d0ef347affe79557cdfbaa4e66144c7f476fc0.zip | |
Improve diagnostic messages for range patterns.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/compile-fail/match-ill-type1.rs | 16 | ||||
| -rw-r--r-- | src/test/compile-fail/match-range-fail.rs | 28 | ||||
| -rw-r--r-- | src/test/run-pass/match-range-infer.rs | 26 |
3 files changed, 45 insertions, 25 deletions
diff --git a/src/test/compile-fail/match-ill-type1.rs b/src/test/compile-fail/match-ill-type1.rs deleted file mode 100644 index c60ef2ed287..00000000000 --- a/src/test/compile-fail/match-ill-type1.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -fn main() { - match 1 { - 1...2_usize => 1, //~ ERROR mismatched types in range - _ => 2, - }; -} diff --git a/src/test/compile-fail/match-range-fail.rs b/src/test/compile-fail/match-range-fail.rs index c3292adfa34..234b74f76d1 100644 --- a/src/test/compile-fail/match-range-fail.rs +++ b/src/test/compile-fail/match-range-fail.rs @@ -8,22 +8,32 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -//error-pattern: lower range bound -//error-pattern: only char and numeric types -//error-pattern: mismatched types - fn main() { match 5 { - 6 ... 1 => { } - _ => { } + 6 ... 1 => { } + _ => { } + }; + //~^^^ ERROR lower range bound must be less than or equal to upper + + match "wow" { + "bar" ... "foo" => { } }; + //~^^ ERROR only char and numeric types are allowed in range + //~| start type: &'static str + //~| end type: &'static str match "wow" { - "bar" ... "foo" => { } + 10 ... "what" => () }; + //~^^ ERROR only char and numeric types are allowed in range + //~| start type: _ + //~| end type: &'static str match 5 { - 'c' ... 100 => { } - _ => { } + 'c' ... 100 => { } + _ => { } }; + //~^^^ ERROR mismatched types in range + //~| expected char + //~| found integral variable } diff --git a/src/test/run-pass/match-range-infer.rs b/src/test/run-pass/match-range-infer.rs new file mode 100644 index 00000000000..74f513ef081 --- /dev/null +++ b/src/test/run-pass/match-range-infer.rs @@ -0,0 +1,26 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test that type inference for range patterns works correctly (is bi-directional). + +pub fn main() { + match 1 { + 1 ... 3 => {} + _ => panic!("should match range") + } + match 1 { + 1 ... 3u16 => {} + _ => panic!("should match range with inferred start type") + } + match 1 { + 1u16 ... 3 => {} + _ => panic!("should match range with inferred end type") + } +} |
