Skip to content

Commit 5baf2a1

Browse files
authored
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
2 parents d95cbec + 1f42be6 commit 5baf2a1

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

Diff for: compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,11 @@ impl<'tcx> ConstToPat<'tcx> {
325325
// `PartialEq::eq` on it.
326326
return Err(FallbackToConstRef);
327327
}
328+
ty::FnDef(..) => {
329+
self.saw_const_match_error.set(true);
330+
tcx.sess.emit_err(InvalidPattern { span, non_sm_ty: ty });
331+
PatKind::Wild
332+
}
328333
ty::Adt(adt_def, _) if !self.type_marked_structural(ty) => {
329334
debug!("adt_def {:?} has !type_marked_structural for cv.ty: {:?}", adt_def, ty,);
330335
self.saw_const_match_error.set(true);
@@ -440,7 +445,7 @@ impl<'tcx> ConstToPat<'tcx> {
440445
}
441446
}
442447
},
443-
ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::FnDef(..) => PatKind::Constant {
448+
ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) => PatKind::Constant {
444449
value: mir::ConstantKind::Ty(ty::Const::new_value(tcx, cv, ty)),
445450
},
446451
ty::FnPtr(..) | ty::RawPtr(..) => unreachable!(),

Diff for: tests/ui/inline-const/pat-match-fndef.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![feature(inline_const_pat)]
2+
//~^ WARN the feature `inline_const_pat` is incomplete
3+
4+
fn uwu() {}
5+
6+
fn main() {
7+
let x = [];
8+
match x[123] {
9+
const { uwu } => {}
10+
//~^ ERROR `fn() {uwu}` cannot be used in patterns
11+
_ => {}
12+
}
13+
}

Diff for: tests/ui/inline-const/pat-match-fndef.stderr

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
warning: the feature `inline_const_pat` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/pat-match-fndef.rs:1:12
3+
|
4+
LL | #![feature(inline_const_pat)]
5+
| ^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #76001 <https://github.com/rust-lang/rust/issues/76001> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
error: `fn() {uwu}` cannot be used in patterns
11+
--> $DIR/pat-match-fndef.rs:9:9
12+
|
13+
LL | const { uwu } => {}
14+
| ^^^^^^^^^^^^^
15+
16+
error: aborting due to previous error; 1 warning emitted
17+

0 commit comments

Comments
 (0)