fix: resolve sub-patterns inside range pattern

This commit is contained in:
roife 2024-03-05 19:29:49 +08:00
parent 2898c4217d
commit ece18fecfa
3 changed files with 5 additions and 11 deletions

View File

@ -1413,16 +1413,10 @@ impl ExprCollector<'_> {
ast::Pat::LiteralPat(it) => {
Some(Box::new(LiteralOrConst::Literal(pat_literal_to_hir(it)?.0)))
}
ast::Pat::IdentPat(p) => {
let name =
p.name().map(|nr| nr.as_name()).unwrap_or_else(Name::missing);
Some(Box::new(LiteralOrConst::Const(name.into())))
pat @ (ast::Pat::IdentPat(_) | ast::Pat::PathPat(_)) => {
let subpat = self.collect_pat(pat.clone(), binding_list);
Some(Box::new(LiteralOrConst::Const(subpat)))
}
ast::Pat::PathPat(p) => p
.path()
.and_then(|path| self.expander.parse_path(self.db, path))
.map(LiteralOrConst::Const)
.map(Box::new),
_ => None,
})
};

View File

@ -635,7 +635,7 @@ impl Printer<'_> {
fn print_literal_or_const(&mut self, literal_or_const: &LiteralOrConst) {
match literal_or_const {
LiteralOrConst::Literal(l) => self.print_literal(l),
LiteralOrConst::Const(c) => self.print_path(c),
LiteralOrConst::Const(c) => self.print_pat(*c),
}
}

View File

@ -101,7 +101,7 @@ pub enum Literal {
/// Used in range patterns.
pub enum LiteralOrConst {
Literal(Literal),
Const(Path),
Const(PatId),
}
impl Literal {