Skip to content

Commit 2b41803

Browse files
committed
fix ICE
1 parent 15d7704 commit 2b41803

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

src/librustc_typeck/check/_match.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
802802

803803
// Resolve the path and check the definition for errors.
804804
let (def, opt_ty, segments) = self.resolve_ty_and_def_ufcs(qpath, pat.id, pat.span);
805+
805806
if def == Def::Err {
806807
self.set_tainted_by_errors();
807808
on_error();
@@ -814,11 +815,6 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
814815
report_unexpected_def(def);
815816
return self.tcx.types.err;
816817
}
817-
// Replace constructor type with constructed type for tuple struct patterns.
818-
let pat_ty = pat_ty.fn_sig(tcx).output();
819-
let pat_ty = pat_ty.no_bound_vars().expect("expected fn type");
820-
821-
self.demand_eqtype(pat.span, expected, pat_ty);
822818

823819
let variant = match def {
824820
Def::Err => {
@@ -836,6 +832,13 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
836832
}
837833
_ => bug!("unexpected pattern definition: {:?}", def)
838834
};
835+
836+
// Replace constructor type with constructed type for tuple struct patterns.
837+
let pat_ty = pat_ty.fn_sig(tcx).output();
838+
let pat_ty = pat_ty.no_bound_vars().expect("expected fn type");
839+
840+
self.demand_eqtype(pat.span, expected, pat_ty);
841+
839842
// Type check subpatterns.
840843
if subpats.len() == variant.fields.len() ||
841844
subpats.len() < variant.fields.len() && ddpos.is_some() {

src/test/ui/match/match-fn-call.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use std::path::Path;
2+
3+
fn main() {
4+
let path = Path::new("foo");
5+
match path {
6+
Path::new("foo") => println!("foo"),
7+
Path::new("bar") => println!("bar"),
8+
_ => (),
9+
}
10+
}
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0164]: expected tuple struct/variant, found method `<Path>::new`
2+
--> $DIR/match-fn-call.rs:6:9
3+
|
4+
LL | Path::new("foo") => println!("foo"),
5+
| ^^^^^^^^^^^^^^^^ not a tuple variant or struct
6+
7+
error[E0164]: expected tuple struct/variant, found method `<Path>::new`
8+
--> $DIR/match-fn-call.rs:7:9
9+
|
10+
LL | Path::new("bar") => println!("bar"),
11+
| ^^^^^^^^^^^^^^^^ not a tuple variant or struct
12+
13+
error: aborting due to 2 previous errors
14+
15+
For more information about this error, try `rustc --explain E0164`.

0 commit comments

Comments
 (0)