Disallow &a..=b and box a..=b in pattern.

They are disallowed because they have different precedence than
expressions. I assume parenthesis in pattern will be soon stabilized and
thus write that as suggestion directly.
This commit is contained in:
kennytm 2018-03-03 06:05:54 +08:00
parent a4d80336c9
commit 6399d16cfd
No known key found for this signature in database
GPG key ID: FEF6C8051D0E013C
5 changed files with 131 additions and 2 deletions

View file

@ -1810,15 +1810,35 @@ impl<'a> State<'a> {
self.pclose()?;
}
PatKind::Box(ref inner) => {
let is_range_inner = match inner.node {
PatKind::Range(..) => true,
_ => false,
};
self.s.word("box ")?;
if is_range_inner {
self.popen()?;
}
self.print_pat(&inner)?;
if is_range_inner {
self.pclose()?;
}
}
PatKind::Ref(ref inner, mutbl) => {
let is_range_inner = match inner.node {
PatKind::Range(..) => true,
_ => false,
};
self.s.word("&")?;
if mutbl == hir::MutMutable {
self.s.word("mut ")?;
}
if is_range_inner {
self.popen()?;
}
self.print_pat(&inner)?;
if is_range_inner {
self.pclose()?;
}
}
PatKind::Lit(ref e) => self.print_expr(&e)?,
PatKind::Range(ref begin, ref end, ref end_kind) => {