From 2b418035fbf4088236cd31ece58b870425b1e0ea Mon Sep 17 00:00:00 2001 From: F001 Date: Wed, 7 Nov 2018 12:26:05 +0800 Subject: [PATCH] fix ICE --- src/librustc_typeck/check/_match.rs | 13 ++++++++----- src/test/ui/match/match-fn-call.rs | 10 ++++++++++ src/test/ui/match/match-fn-call.stderr | 15 +++++++++++++++ 3 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 src/test/ui/match/match-fn-call.rs create mode 100644 src/test/ui/match/match-fn-call.stderr diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs index 40f2072079a5a..d464bf594b417 100644 --- a/src/librustc_typeck/check/_match.rs +++ b/src/librustc_typeck/check/_match.rs @@ -802,6 +802,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects"); // Resolve the path and check the definition for errors. let (def, opt_ty, segments) = self.resolve_ty_and_def_ufcs(qpath, pat.id, pat.span); + if def == Def::Err { self.set_tainted_by_errors(); on_error(); @@ -814,11 +815,6 @@ https://doc.rust-lang.org/reference/types.html#trait-objects"); report_unexpected_def(def); return self.tcx.types.err; } - // Replace constructor type with constructed type for tuple struct patterns. - let pat_ty = pat_ty.fn_sig(tcx).output(); - let pat_ty = pat_ty.no_bound_vars().expect("expected fn type"); - - self.demand_eqtype(pat.span, expected, pat_ty); let variant = match def { Def::Err => { @@ -836,6 +832,13 @@ https://doc.rust-lang.org/reference/types.html#trait-objects"); } _ => bug!("unexpected pattern definition: {:?}", def) }; + + // Replace constructor type with constructed type for tuple struct patterns. + let pat_ty = pat_ty.fn_sig(tcx).output(); + let pat_ty = pat_ty.no_bound_vars().expect("expected fn type"); + + self.demand_eqtype(pat.span, expected, pat_ty); + // Type check subpatterns. if subpats.len() == variant.fields.len() || subpats.len() < variant.fields.len() && ddpos.is_some() { diff --git a/src/test/ui/match/match-fn-call.rs b/src/test/ui/match/match-fn-call.rs new file mode 100644 index 0000000000000..5a6c2043cfb80 --- /dev/null +++ b/src/test/ui/match/match-fn-call.rs @@ -0,0 +1,10 @@ +use std::path::Path; + +fn main() { + let path = Path::new("foo"); + match path { + Path::new("foo") => println!("foo"), + Path::new("bar") => println!("bar"), + _ => (), + } +} diff --git a/src/test/ui/match/match-fn-call.stderr b/src/test/ui/match/match-fn-call.stderr new file mode 100644 index 0000000000000..0b7ca111e384e --- /dev/null +++ b/src/test/ui/match/match-fn-call.stderr @@ -0,0 +1,15 @@ +error[E0164]: expected tuple struct/variant, found method `::new` + --> $DIR/match-fn-call.rs:6:9 + | +LL | Path::new("foo") => println!("foo"), + | ^^^^^^^^^^^^^^^^ not a tuple variant or struct + +error[E0164]: expected tuple struct/variant, found method `::new` + --> $DIR/match-fn-call.rs:7:9 + | +LL | Path::new("bar") => println!("bar"), + | ^^^^^^^^^^^^^^^^ not a tuple variant or struct + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0164`.