diff options
| author | Mark Rousskov <mark.simulacrum@gmail.com> | 2018-11-08 18:15:03 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-11-08 18:15:03 -0700 |
| commit | 792476516f3faeafb873b63e00acebab70ab001d (patch) | |
| tree | 9652ff6cc00f04357f80967321a7d2141b851a97 /src | |
| parent | 96ee13a56d856f6d0d58da796389c0b49f438bc8 (diff) | |
| parent | f63c2f80e51a1942a28c660adad0d3bad74574e2 (diff) | |
| download | rust-792476516f3faeafb873b63e00acebab70ab001d.tar.gz rust-792476516f3faeafb873b63e00acebab70ab001d.zip | |
Rollup merge of #55742 - F001:fix-55718, r=petrochenkov
Avoid panic when matching function call
Fix #55718
This bug is introduced by #53751. The original code checked `Def::AssociatedConst(..) | Def::Method(..)` before `pat_ty.no_bound_vars().expect("expected fn type")`. But somehow I exchanged the sequence carelessly. Sorry about that.
r? @petrochenkov
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_typeck/check/_match.rs | 12 | ||||
| -rw-r--r-- | src/test/ui/match/match-fn-call.rs | 12 | ||||
| -rw-r--r-- | src/test/ui/match/match-fn-call.stderr | 15 |
3 files changed, 34 insertions, 5 deletions
diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs index 40f2072079a..4a300fe0921 100644 --- a/src/librustc_typeck/check/_match.rs +++ b/src/librustc_typeck/check/_match.rs @@ -814,11 +814,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 +831,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 00000000000..d9c50e75c49 --- /dev/null +++ b/src/test/ui/match/match-fn-call.rs @@ -0,0 +1,12 @@ +use std::path::Path; + +fn main() { + let path = Path::new("foo"); + match path { + Path::new("foo") => println!("foo"), + //~^ ERROR expected tuple struct/variant + Path::new("bar") => println!("bar"), + //~^ ERROR expected tuple struct/variant + _ => (), + } +} 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 00000000000..4e24621706b --- /dev/null +++ b/src/test/ui/match/match-fn-call.stderr @@ -0,0 +1,15 @@ +error[E0164]: expected tuple struct/variant, found method `<Path>::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 `<Path>::new` + --> $DIR/match-fn-call.rs:8: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`. |
