Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-ty/src/tests/patterns.rs')
| -rw-r--r-- | crates/hir-ty/src/tests/patterns.rs | 72 |
1 files changed, 55 insertions, 17 deletions
diff --git a/crates/hir-ty/src/tests/patterns.rs b/crates/hir-ty/src/tests/patterns.rs index 607daada42..c312b16759 100644 --- a/crates/hir-ty/src/tests/patterns.rs +++ b/crates/hir-ty/src/tests/patterns.rs @@ -6,7 +6,7 @@ use super::{check, check_infer, check_infer_with_mismatches, check_no_mismatches fn infer_pattern() { check_infer( r#" - //- minicore: iterator + //- minicore: iterator, add, builtin_impls fn test(x: &i32) { let y = x; let &z = x; @@ -189,26 +189,45 @@ fn infer_literal_pattern() { fn infer_range_pattern() { check_infer_with_mismatches( r#" - fn test(x: &i32) { - if let 1..76 = 2u32 {} - if let 1..=76 = 2u32 {} - } +//- minicore: range +fn test(x..y: &core::ops::Range<u32>) { + if let 1..76 = 2u32 {} + if let 1..=76 = 2u32 {} +} "#, expect![[r#" - 8..9 'x': &'? i32 - 17..75 '{ ...2 {} }': () - 23..45 'if let...u32 {}': () - 26..42 'let 1....= 2u32': bool - 30..35 '1..76': u32 - 38..42 '2u32': u32 - 43..45 '{}': () - 50..73 'if let...u32 {}': () - 53..70 'let 1....= 2u32': bool - 57..63 '1..=76': u32 - 66..70 '2u32': u32 - 71..73 '{}': () + 8..9 'x': Range<u32> + 8..12 'x..y': Range<u32> + 11..12 'y': Range<u32> + 38..96 '{ ...2 {} }': () + 44..66 'if let...u32 {}': () + 47..63 'let 1....= 2u32': bool + 51..52 '1': u32 + 51..56 '1..76': u32 + 54..56 '76': u32 + 59..63 '2u32': u32 + 64..66 '{}': () + 71..94 'if let...u32 {}': () + 74..91 'let 1....= 2u32': bool + 78..79 '1': u32 + 78..84 '1..=76': u32 + 82..84 '76': u32 + 87..91 '2u32': u32 + 92..94 '{}': () "#]], ); + check_no_mismatches( + r#" +//- minicore: range +fn main() { + let byte: u8 = 0u8; + let b = match byte { + b'0'..=b'9' => true, + _ => false, + }; +} + "#, + ); } #[test] @@ -1259,3 +1278,22 @@ fn main() { "#, ); } + +#[test] +fn destructuring_assign_ref() { + check_no_mismatches( + r#" +struct Foo; + +fn foo() -> (&'static Foo, u32) { + (&Foo, 0) +} + +fn bar() { + let ext: &Foo; + let v; + (ext, v) = foo(); +} + "#, + ); +} |