Skip to content

Commit 37e0345

Browse files
F001nikomatsakis
authored andcommitted
fix ICE
1 parent 4b3a1d9 commit 37e0345

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

Diff for: src/librustc_typeck/check/_match.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -814,11 +814,6 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
814814
report_unexpected_def(def);
815815
return self.tcx.types.err;
816816
}
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_late_bound_regions().expect("expected fn type");
820-
821-
self.demand_eqtype(pat.span, expected, pat_ty);
822817

823818
let variant = match def {
824819
Def::Err => {
@@ -836,6 +831,13 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
836831
}
837832
_ => bug!("unexpected pattern definition: {:?}", def)
838833
};
834+
835+
// Replace constructor type with constructed type for tuple struct patterns.
836+
let pat_ty = pat_ty.fn_sig(tcx).output();
837+
let pat_ty = pat_ty.no_late_bound_regions().expect("expected fn type");
838+
839+
self.demand_eqtype(pat.span, expected, pat_ty);
840+
839841
// Type check subpatterns.
840842
if subpats.len() == variant.fields.len() ||
841843
subpats.len() < variant.fields.len() && ddpos.is_some() {

Diff for: src/test/ui/match/match-fn-call.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
//~^ ERROR expected tuple struct/variant
8+
Path::new("bar") => println!("bar"),
9+
//~^ ERROR expected tuple struct/variant
10+
_ => (),
11+
}
12+
}

Diff for: src/test/ui/match/match-fn-call.stderr

+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:8: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)