Skip to content

Delay is_intrinsic query until after we've determined the callee is a function #102999

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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`.