Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-def/src/expr_store/tests.rs')
-rw-r--r--crates/hir-def/src/expr_store/tests.rs112
1 files changed, 16 insertions, 96 deletions
diff --git a/crates/hir-def/src/expr_store/tests.rs b/crates/hir-def/src/expr_store/tests.rs
index 73eed74471..b84043af68 100644
--- a/crates/hir-def/src/expr_store/tests.rs
+++ b/crates/hir-def/src/expr_store/tests.rs
@@ -1,6 +1,6 @@
mod block;
-use crate::{test_db::TestDB, ModuleDefId};
+use crate::{hir::MatchArm, test_db::TestDB, ModuleDefId};
use expect_test::{expect, Expect};
use la_arena::RawIdx;
use test_fixture::WithFixture;
@@ -459,8 +459,9 @@ async fn foo(a: (), b: i32) -> u32 {
.assert_eq(&printed);
}
-fn test1() {
- let (db, body, owner) = lower(
+#[test]
+fn range_bounds_are_hir_exprs() {
+ let (_, body, _) = lower(
r#"
pub const L: i32 = 6;
mod x {
@@ -468,115 +469,34 @@ mod x {
}
const fn f(x: i32) -> i32 {
match x {
- L..=x::R => x * 100,
-1..=5 => x * 10,
+ L..=x::R => x * 100,
_ => x,
}
}"#,
);
- let pat = body
- .pats
+ let mtch_arms = body
+ .exprs
.iter()
- .find_map(|pat| {
- if let Pat::Range { .. } = pat.1 {
- return Some(pat.1);
+ .find_map(|(_, expr)| {
+ if let Expr::Match { arms, .. } = expr {
+ return Some(arms);
}
None
})
.unwrap();
- match pat {
+ let MatchArm { pat, .. } = mtch_arms[1];
+ match body.pats[pat] {
Pat::Range { start, end } => {
- dbg!(&body.exprs[start.unwrap()]);
- dbg!(&body.exprs[end.unwrap()]);
- }
- _ => {}
- }
-}
-
-#[test]
-fn test2() {
- let (db, body, owner) = lower(
- r#"
-pub const L: i32 = 6;
-mod x {
- pub const R: i32 = 100;
-}
-const fn f(x: i32) -> i32 {
- match x {
- -1..=5 => x * 10,
- ::std::i32::MIN..=x::R => x * 100,
- _ => x,
- }
-}"#,
- );
+ let hir_start = &body.exprs[start.unwrap()];
+ let hir_end = &body.exprs[end.unwrap()];
- for (pat_id, pat) in body.pats.iter() {
- match pat {
- Pat::Range { start, end } => {
- let pretty = body.pretty_print_pat(&db, owner, pat_id, false, Edition::Edition2021);
- eprintln!("RANGE {}", pretty);
-
- if let Some(start) = start {
- eprintln!("START");
- let expr = body.exprs[*start].clone();
- dbg!(expr);
- } else {
- eprintln!("START is None");
- }
-
- if let Some(end) = end {
- eprintln!("END");
- let expr = body.exprs[*end].clone();
- dbg!(expr);
- } else {
- eprintln!("END is None");
- }
- }
- _ => {}
+ assert!(matches!(hir_start, Expr::Path { .. }));
+ assert!(matches!(hir_end, Expr::Path { .. }));
}
- }
-}
-
-#[test]
-fn test3() {
- let (db, body, owner) = lower(
- r#"
-const A: u32 = 0;
-
-fn bar(v: u32) {
- match v {
- 0..=A => {}
_ => {}
}
-}"#,
- );
-
- for (pat_id, pat) in body.pats.iter() {
- match pat {
- Pat::Range { start, end } => {
- let pretty = body.pretty_print_pat(&db, owner, pat_id, false, Edition::Edition2021);
- eprintln!("RANGE {}", pretty);
-
- if let Some(start) = start {
- eprintln!("START");
- let expr = body.exprs[*start].clone();
- dbg!(expr);
- } else {
- eprintln!("START is None");
- }
-
- if let Some(end) = end {
- eprintln!("END");
- let expr = body.exprs[*end].clone();
- dbg!(expr);
- } else {
- eprintln!("END is None");
- }
- }
- _ => {}
- }
- }
}