Skip to content

Commit ece18fe

Browse files
committed
fix: resolve sub-patterns inside range pattern
1 parent 2898c42 commit ece18fe

File tree

3 files changed

+5
-11
lines changed

3 files changed

+5
-11
lines changed

crates/hir-def/src/body/lower.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,16 +1413,10 @@ impl ExprCollector<'_> {
14131413
ast::Pat::LiteralPat(it) => {
14141414
Some(Box::new(LiteralOrConst::Literal(pat_literal_to_hir(it)?.0)))
14151415
}
1416-
ast::Pat::IdentPat(p) => {
1417-
let name =
1418-
p.name().map(|nr| nr.as_name()).unwrap_or_else(Name::missing);
1419-
Some(Box::new(LiteralOrConst::Const(name.into())))
1416+
pat @ (ast::Pat::IdentPat(_) | ast::Pat::PathPat(_)) => {
1417+
let subpat = self.collect_pat(pat.clone(), binding_list);
1418+
Some(Box::new(LiteralOrConst::Const(subpat)))
14201419
}
1421-
ast::Pat::PathPat(p) => p
1422-
.path()
1423-
.and_then(|path| self.expander.parse_path(self.db, path))
1424-
.map(LiteralOrConst::Const)
1425-
.map(Box::new),
14261420
_ => None,
14271421
})
14281422
};

crates/hir-def/src/body/pretty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ impl Printer<'_> {
635635
fn print_literal_or_const(&mut self, literal_or_const: &LiteralOrConst) {
636636
match literal_or_const {
637637
LiteralOrConst::Literal(l) => self.print_literal(l),
638-
LiteralOrConst::Const(c) => self.print_path(c),
638+
LiteralOrConst::Const(c) => self.print_pat(*c),
639639
}
640640
}
641641

crates/hir-def/src/hir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ pub enum Literal {
101101
/// Used in range patterns.
102102
pub enum LiteralOrConst {
103103
Literal(Literal),
104-
Const(Path),
104+
Const(PatId),
105105
}
106106

107107
impl Literal {

0 commit comments

Comments
 (0)