From cc40f41ee5baefa0dc1845dd9d794abe90511161 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 8 May 2019 10:23:55 -0700 Subject: [PATCH] Instead of ICEing on incorrect pattern, use delay_span_bug --- src/librustc/middle/mem_categorization.rs | 12 ++++++++++-- src/test/ui/fn-in-pat.rs | 16 ++++++++++++++++ src/test/ui/fn-in-pat.stderr | 9 +++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 src/test/ui/fn-in-pat.rs create mode 100644 src/test/ui/fn-in-pat.stderr diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index f6caf357b393d..7edd5c5a9de1b 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -1300,8 +1300,16 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> { } } def => { - span_bug!(pat.span, "tuple struct pattern didn't resolve \ - to variant or struct {:?}", def); + debug!( + "tuple struct pattern didn't resolve to variant or struct {:?} at {:?}", + def, + pat.span, + ); + self.tcx.sess.delay_span_bug(pat.span, &format!( + "tuple struct pattern didn't resolve to variant or struct {:?}", + def, + )); + return Err(()); } }; diff --git a/src/test/ui/fn-in-pat.rs b/src/test/ui/fn-in-pat.rs new file mode 100644 index 0000000000000..ed76b2c5db025 --- /dev/null +++ b/src/test/ui/fn-in-pat.rs @@ -0,0 +1,16 @@ +struct A {} + +impl A { + fn new() {} +} + +fn hof(_: F) where F: FnMut(()) {} + +fn ice() { + hof(|c| match c { + A::new() => (), //~ ERROR expected tuple struct/variant, found method + _ => () + }) +} + +fn main() {} diff --git a/src/test/ui/fn-in-pat.stderr b/src/test/ui/fn-in-pat.stderr new file mode 100644 index 0000000000000..eee97fe9587c2 --- /dev/null +++ b/src/test/ui/fn-in-pat.stderr @@ -0,0 +1,9 @@ +error[E0164]: expected tuple struct/variant, found method `::new` + --> $DIR/fn-in-pat.rs:11:9 + | +LL | A::new() => (), + | ^^^^^^^^ not a tuple variant or struct + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0164`.