未验证 提交 5baf2a11 编写于 作者: M Matthias Krüger 提交者: GitHub

Rollup merge of #114668 - compiler-errors:match-fn-def, r=petrochenkov

Deny `FnDef` in patterns

We can only see these via `const { .. }` patterns, which are unstable.

cc #76001 (tracking issue for inline const pats)

Fixes #114658
Fixes #114659
......@@ -325,6 +325,11 @@ fn recur(
// `PartialEq::eq` on it.
return Err(FallbackToConstRef);
}
ty::FnDef(..) => {
self.saw_const_match_error.set(true);
tcx.sess.emit_err(InvalidPattern { span, non_sm_ty: ty });
PatKind::Wild
}
ty::Adt(adt_def, _) if !self.type_marked_structural(ty) => {
debug!("adt_def {:?} has !type_marked_structural for cv.ty: {:?}", adt_def, ty,);
self.saw_const_match_error.set(true);
......@@ -440,7 +445,7 @@ fn recur(
}
}
},
ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::FnDef(..) => PatKind::Constant {
ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) => PatKind::Constant {
value: mir::ConstantKind::Ty(ty::Const::new_value(tcx, cv, ty)),
},
ty::FnPtr(..) | ty::RawPtr(..) => unreachable!(),
......
#![feature(inline_const_pat)]
//~^ WARN the feature `inline_const_pat` is incomplete
fn uwu() {}
fn main() {
let x = [];
match x[123] {
const { uwu } => {}
//~^ ERROR `fn() {uwu}` cannot be used in patterns
_ => {}
}
}
warning: the feature `inline_const_pat` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/pat-match-fndef.rs:1:12
|
LL | #![feature(inline_const_pat)]
| ^^^^^^^^^^^^^^^^
|
= note: see issue #76001 <https://github.com/rust-lang/rust/issues/76001> for more information
= note: `#[warn(incomplete_features)]` on by default
error: `fn() {uwu}` cannot be used in patterns
--> $DIR/pat-match-fndef.rs:9:9
|
LL | const { uwu } => {}
| ^^^^^^^^^^^^^
error: aborting due to previous error; 1 warning emitted
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册