about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAli Bektas <bektasali@protonmail.com>2025-01-08 00:48:25 +0100
committerAli Bektas <bektasali@protonmail.com>2025-02-03 12:14:13 +0100
commit8a18dce223a84e32dff217a0ba641576203600be (patch)
tree4d8684aff6ab382675dddae0fe2519753a428673
parent31a56851449d0e8a65991d2e2a0ae637d5779d9c (diff)
downloadrust-8a18dce223a84e32dff217a0ba641576203600be.tar.gz
rust-8a18dce223a84e32dff217a0ba641576203600be.zip
Add a test to monitor whats going on
-rw-r--r--src/tools/rust-analyzer/crates/hir-def/src/expr_store/lower.rs17
-rw-r--r--src/tools/rust-analyzer/crates/hir-def/src/expr_store/tests.rs43
2 files changed, 54 insertions, 6 deletions
diff --git a/src/tools/rust-analyzer/crates/hir-def/src/expr_store/lower.rs b/src/tools/rust-analyzer/crates/hir-def/src/expr_store/lower.rs
index d2715ac8760..3f3beb21858 100644
--- a/src/tools/rust-analyzer/crates/hir-def/src/expr_store/lower.rs
+++ b/src/tools/rust-analyzer/crates/hir-def/src/expr_store/lower.rs
@@ -44,8 +44,8 @@ use crate::{
             FormatPlaceholder, FormatSign, FormatTrait,
         },
         Array, Binding, BindingAnnotation, BindingId, BindingProblems, CaptureBy, ClosureKind,
-        Expr, ExprId, Item, Label, LabelId, Literal, LiteralOrConst, MatchArm, Movability,
-        OffsetOf, Pat, PatId, RecordFieldPat, RecordLitField, Statement,
+        Expr, ExprId, Item, Label, LabelId, Literal, MatchArm, Movability, OffsetOf, Pat, PatId,
+        RecordFieldPat, RecordLitField, Statement,
     },
     item_scope::BuiltinShadowMode,
     lang_item::LangItem,
@@ -1802,10 +1802,15 @@ impl ExprCollector<'_> {
                                     ptr,
                                 ))
                             }
-                            pat @ (ast::Pat::IdentPat(_) | ast::Pat::PathPat(_)) => {
-                                // let subpat = self.collect_pat(pat.clone(), binding_list);
-                                // Some(Box::new(LiteralOrConst::Const(subpat)))
-                                // TODO
+                            ast::Pat::IdentPat(_) => Some(self.missing_expr()),
+                            ast::Pat::PathPat(p) => {
+                                if let Some(path) = p.path() {
+                                    if let Some(parsed) = self.parse_path(path) {
+                                        return Some(
+                                            self.alloc_expr_from_pat(Expr::Path(parsed), ptr),
+                                        );
+                                    }
+                                }
                                 Some(self.missing_expr())
                             }
                             _ => None,
diff --git a/src/tools/rust-analyzer/crates/hir-def/src/expr_store/tests.rs b/src/tools/rust-analyzer/crates/hir-def/src/expr_store/tests.rs
index 9bf1ddb4793..5ce9a67f9b6 100644
--- a/src/tools/rust-analyzer/crates/hir-def/src/expr_store/tests.rs
+++ b/src/tools/rust-analyzer/crates/hir-def/src/expr_store/tests.rs
@@ -460,3 +460,46 @@ async fn foo(a: (), b: i32) -> u32 {
     expect!["fn foo(�: (), �: i32) -> impl ::core::future::Future::<Output = u32> �"]
         .assert_eq(&printed);
 }
+
+fn abc() {
+    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,
+        L..=x::R => x * 100,
+        _ => x,
+    }
+}"#,
+    );
+
+    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");
+                }
+            }
+            _ => {}
+        }
+    }
+}