Skip to content

Commit 0f12b40

Browse files
authored
Rollup merge of #102999 - compiler-errors:issue-102985, r=fee1-dead
Delay `is_intrinsic` query until after we've determined the callee is a function Fixes #102985
2 parents 48f950c + af3c6f9 commit 0f12b40

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

Diff for: compiler/rustc_const_eval/src/transform/check_consts/check.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -909,8 +909,6 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
909909
return;
910910
}
911911

912-
let is_intrinsic = tcx.is_intrinsic(callee);
913-
914912
if !tcx.is_const_fn_raw(callee) {
915913
if !tcx.is_const_default_method(callee) {
916914
// To get to here we must have already found a const impl for the
@@ -970,7 +968,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
970968
// We do not use `const` modifiers for intrinsic "functions", as intrinsics are
971969
// `extern` functions, and these have no way to get marked `const`. So instead we
972970
// use `rustc_const_(un)stable` attributes to mean that the intrinsic is `const`
973-
if self.ccx.is_const_stable_const_fn() || is_intrinsic {
971+
if self.ccx.is_const_stable_const_fn() || tcx.is_intrinsic(callee) {
974972
self.check_op(ops::FnCallUnstable(callee, None));
975973
return;
976974
}
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![feature(const_trait_impl)]
2+
3+
struct Bug {
4+
inner: [(); match || 1 {
5+
n => n(),
6+
//~^ ERROR the trait bound
7+
//~| ERROR cannot call non-const fn `Bug::inner::{constant#0}::{closure#0}` in constants
8+
}],
9+
}
10+
11+
fn main() {}
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error[E0277]: the trait bound `[closure@$DIR/issue-102985.rs:4:23: 4:25]: ~const Fn<()>` is not satisfied
2+
--> $DIR/issue-102985.rs:5:14
3+
|
4+
LL | n => n(),
5+
| ^^^ expected an `Fn<()>` closure, found `[closure@$DIR/issue-102985.rs:4:23: 4:25]`
6+
|
7+
= help: the trait `~const Fn<()>` is not implemented for closure `[closure@$DIR/issue-102985.rs:4:23: 4:25]`
8+
note: the trait `Fn<()>` is implemented for `[closure@$DIR/issue-102985.rs:4:23: 4:25]`, but that implementation is not `const`
9+
--> $DIR/issue-102985.rs:5:14
10+
|
11+
LL | n => n(),
12+
| ^^^
13+
= note: wrap the `[closure@$DIR/issue-102985.rs:4:23: 4:25]` in a closure with no arguments: `|| { /* code */ }`
14+
15+
error[E0015]: cannot call non-const fn `Bug::inner::{constant#0}::{closure#0}` in constants
16+
--> $DIR/issue-102985.rs:5:14
17+
|
18+
LL | n => n(),
19+
| ^^^
20+
|
21+
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
22+
23+
error: aborting due to 2 previous errors
24+
25+
Some errors have detailed explanations: E0015, E0277.
26+
For more information about an error, try `rustc --explain E0015`.

0 commit comments

Comments
 (0)