fix: resolve sub-patterns inside range pattern
This commit is contained in:
parent
2898c4217d
commit
ece18fecfa
@ -1413,16 +1413,10 @@ impl ExprCollector<'_> {
|
|||||||
ast::Pat::LiteralPat(it) => {
|
ast::Pat::LiteralPat(it) => {
|
||||||
Some(Box::new(LiteralOrConst::Literal(pat_literal_to_hir(it)?.0)))
|
Some(Box::new(LiteralOrConst::Literal(pat_literal_to_hir(it)?.0)))
|
||||||
}
|
}
|
||||||
ast::Pat::IdentPat(p) => {
|
pat @ (ast::Pat::IdentPat(_) | ast::Pat::PathPat(_)) => {
|
||||||
let name =
|
let subpat = self.collect_pat(pat.clone(), binding_list);
|
||||||
p.name().map(|nr| nr.as_name()).unwrap_or_else(Name::missing);
|
Some(Box::new(LiteralOrConst::Const(subpat)))
|
||||||
Some(Box::new(LiteralOrConst::Const(name.into())))
|
|
||||||
}
|
}
|
||||||
ast::Pat::PathPat(p) => p
|
|
||||||
.path()
|
|
||||||
.and_then(|path| self.expander.parse_path(self.db, path))
|
|
||||||
.map(LiteralOrConst::Const)
|
|
||||||
.map(Box::new),
|
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
@ -635,7 +635,7 @@ impl Printer<'_> {
|
|||||||
fn print_literal_or_const(&mut self, literal_or_const: &LiteralOrConst) {
|
fn print_literal_or_const(&mut self, literal_or_const: &LiteralOrConst) {
|
||||||
match literal_or_const {
|
match literal_or_const {
|
||||||
LiteralOrConst::Literal(l) => self.print_literal(l),
|
LiteralOrConst::Literal(l) => self.print_literal(l),
|
||||||
LiteralOrConst::Const(c) => self.print_path(c),
|
LiteralOrConst::Const(c) => self.print_pat(*c),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ pub enum Literal {
|
|||||||
/// Used in range patterns.
|
/// Used in range patterns.
|
||||||
pub enum LiteralOrConst {
|
pub enum LiteralOrConst {
|
||||||
Literal(Literal),
|
Literal(Literal),
|
||||||
Const(Path),
|
Const(PatId),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Literal {
|
impl Literal {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user