Pretty-print PatKind::Missing
as _
.
Printing "no pattern" as `_` isn't ideal, but better than crashing, and HIR pretty-printing already has plenty of imperfections. The added `f2` and `f6` examples are ones that triggered the crash. Note that some of the added examples are printed badly, e.g. `fn(, ...)`. The next commit will fix those. Fixes #139633.
This commit is contained in:
parent
092a284ba0
commit
f8edc831ca
3 changed files with 56 additions and 3 deletions
|
@ -1871,10 +1871,11 @@ impl<'a> State<'a> {
|
||||||
fn print_pat(&mut self, pat: &hir::Pat<'_>) {
|
fn print_pat(&mut self, pat: &hir::Pat<'_>) {
|
||||||
self.maybe_print_comment(pat.span.lo());
|
self.maybe_print_comment(pat.span.lo());
|
||||||
self.ann.pre(self, AnnNode::Pat(pat));
|
self.ann.pre(self, AnnNode::Pat(pat));
|
||||||
// Pat isn't normalized, but the beauty of it
|
// Pat isn't normalized, but the beauty of it is that it doesn't matter.
|
||||||
// is that it doesn't matter
|
|
||||||
match pat.kind {
|
match pat.kind {
|
||||||
PatKind::Missing => unreachable!(),
|
// Printing `_` isn't ideal for a missing pattern, but it's easy and good enough.
|
||||||
|
// E.g. `fn(u32)` gets printed as `fn(_: u32)`.
|
||||||
|
PatKind::Missing => self.word("_"),
|
||||||
PatKind::Wild => self.word("_"),
|
PatKind::Wild => self.word("_"),
|
||||||
PatKind::Never => self.word("!"),
|
PatKind::Never => self.word("!"),
|
||||||
PatKind::Binding(BindingMode(by_ref, mutbl), _, ident, sub) => {
|
PatKind::Binding(BindingMode(by_ref, mutbl), _, ident, sub) => {
|
||||||
|
|
|
@ -13,3 +13,39 @@ extern "C" {
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "C" fn bar(_: i32, mut va2: ...) -> usize { va2.arg::<usize>() }
|
unsafe extern "C" fn bar(_: i32, mut va2: ...) -> usize { va2.arg::<usize>() }
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
fn g1(_: extern "C" fn(_: u8, va: ...)) { }
|
||||||
|
fn g2(_: extern "C" fn(_: u8, ...)) { }
|
||||||
|
fn g3(_: extern "C" fn(u8, va: ...)) { }
|
||||||
|
fn g4(_: extern "C" fn(u8, ...)) { }
|
||||||
|
|
||||||
|
fn g5(_: extern "C" fn(, va: ...)) { }
|
||||||
|
fn g6(_: extern "C" fn(, ...)) { }
|
||||||
|
|
||||||
|
{
|
||||||
|
let _ =
|
||||||
|
{
|
||||||
|
unsafe extern "C" fn f1(_: u8, va: ...) { }
|
||||||
|
};
|
||||||
|
};
|
||||||
|
{
|
||||||
|
let _ =
|
||||||
|
{
|
||||||
|
unsafe extern "C" fn f2(_: u8, _: ...) { }
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
{
|
||||||
|
let _ =
|
||||||
|
{
|
||||||
|
unsafe extern "C" fn f5(, va: ...) { }
|
||||||
|
};
|
||||||
|
};
|
||||||
|
{
|
||||||
|
let _ =
|
||||||
|
{
|
||||||
|
unsafe extern "C" fn f6(, _: ...) { }
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
@ -11,3 +11,19 @@ extern "C" {
|
||||||
pub unsafe extern "C" fn bar(_: i32, mut va2: ...) -> usize {
|
pub unsafe extern "C" fn bar(_: i32, mut va2: ...) -> usize {
|
||||||
va2.arg::<usize>()
|
va2.arg::<usize>()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
fn g1(_: extern "C" fn(_: u8, va: ...)) {}
|
||||||
|
fn g2(_: extern "C" fn(_: u8, ...)) {}
|
||||||
|
fn g3(_: extern "C" fn(u8, va: ...)) {}
|
||||||
|
fn g4(_: extern "C" fn(u8, ...)) {}
|
||||||
|
|
||||||
|
fn g5(_: extern "C" fn(va: ...)) {}
|
||||||
|
fn g6(_: extern "C" fn(...)) {}
|
||||||
|
|
||||||
|
_ = { unsafe extern "C" fn f1(_: u8, va: ...) {} };
|
||||||
|
_ = { unsafe extern "C" fn f2(_: u8, ...) {} };
|
||||||
|
|
||||||
|
_ = { unsafe extern "C" fn f5(va: ...) {} };
|
||||||
|
_ = { unsafe extern "C" fn f6(...) {} };
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue