未验证 提交 79247651 编写于 作者: M Mark Rousskov 提交者: GitHub

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
...@@ -814,11 +814,6 @@ fn check_pat_tuple_struct(&self, ...@@ -814,11 +814,6 @@ fn check_pat_tuple_struct(&self,
report_unexpected_def(def); report_unexpected_def(def);
return self.tcx.types.err; 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 { let variant = match def {
Def::Err => { Def::Err => {
...@@ -836,6 +831,13 @@ fn check_pat_tuple_struct(&self, ...@@ -836,6 +831,13 @@ fn check_pat_tuple_struct(&self,
} }
_ => bug!("unexpected pattern definition: {:?}", def) _ => 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. // Type check subpatterns.
if subpats.len() == variant.fields.len() || if subpats.len() == variant.fields.len() ||
subpats.len() < variant.fields.len() && ddpos.is_some() { subpats.len() < variant.fields.len() && ddpos.is_some() {
......
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
_ => (),
}
}
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`.
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册