Skip to content

Commit

Permalink
Rollup merge of #102999 - compiler-errors:issue-102985, r=fee1-dead
Browse files Browse the repository at this point in the history
Delay `is_intrinsic` query until after we've determined the callee is a function

Fixes #102985
  • Loading branch information
Dylan-DPC committed Oct 13, 2022
2 parents 48f950c + af3c6f9 commit 0f12b40
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -909,8 +909,6 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
return;
}

let is_intrinsic = tcx.is_intrinsic(callee);

if !tcx.is_const_fn_raw(callee) {
if !tcx.is_const_default_method(callee) {
// To get to here we must have already found a const impl for the
Expand Down Expand Up @@ -970,7 +968,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
// We do not use `const` modifiers for intrinsic "functions", as intrinsics are
// `extern` functions, and these have no way to get marked `const`. So instead we
// use `rustc_const_(un)stable` attributes to mean that the intrinsic is `const`
if self.ccx.is_const_stable_const_fn() || is_intrinsic {
if self.ccx.is_const_stable_const_fn() || tcx.is_intrinsic(callee) {
self.check_op(ops::FnCallUnstable(callee, None));
return;
}
Expand Down
11 changes: 11 additions & 0 deletions src/test/ui/rfc-2632-const-trait-impl/issue-102985.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#![feature(const_trait_impl)]

struct Bug {
inner: [(); match || 1 {
n => n(),
//~^ ERROR the trait bound
//~| ERROR cannot call non-const fn `Bug::inner::{constant#0}::{closure#0}` in constants
}],
}

fn main() {}
26 changes: 26 additions & 0 deletions src/test/ui/rfc-2632-const-trait-impl/issue-102985.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
error[E0277]: the trait bound `[closure@$DIR/issue-102985.rs:4:23: 4:25]: ~const Fn<()>` is not satisfied
--> $DIR/issue-102985.rs:5:14
|
LL | n => n(),
| ^^^ expected an `Fn<()>` closure, found `[closure@$DIR/issue-102985.rs:4:23: 4:25]`
|
= help: the trait `~const Fn<()>` is not implemented for closure `[closure@$DIR/issue-102985.rs:4:23: 4:25]`
note: the trait `Fn<()>` is implemented for `[closure@$DIR/issue-102985.rs:4:23: 4:25]`, but that implementation is not `const`
--> $DIR/issue-102985.rs:5:14
|
LL | n => n(),
| ^^^
= note: wrap the `[closure@$DIR/issue-102985.rs:4:23: 4:25]` in a closure with no arguments: `|| { /* code */ }`

error[E0015]: cannot call non-const fn `Bug::inner::{constant#0}::{closure#0}` in constants
--> $DIR/issue-102985.rs:5:14
|
LL | n => n(),
| ^^^
|
= note: calls in constants are limited to constant functions, tuple structs and tuple variants

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0015, E0277.
For more information about an error, try `rustc --explain E0015`.

0 comments on commit 0f12b40

Please sign in to comment.