Delay intrinsic call until after we've determined the callee is a function
This commit is contained in:
parent
0938e1680d
commit
af3c6f9a03
@ -909,8 +909,6 @@ fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let is_intrinsic = tcx.is_intrinsic(callee);
|
|
||||||
|
|
||||||
if !tcx.is_const_fn_raw(callee) {
|
if !tcx.is_const_fn_raw(callee) {
|
||||||
if !tcx.is_const_default_method(callee) {
|
if !tcx.is_const_default_method(callee) {
|
||||||
// To get to here we must have already found a const impl for the
|
// To get to here we must have already found a const impl for the
|
||||||
@ -970,7 +968,7 @@ fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location
|
|||||||
// We do not use `const` modifiers for intrinsic "functions", as intrinsics are
|
// 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
|
// `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`
|
// 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));
|
self.check_op(ops::FnCallUnstable(callee, None));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
11
src/test/ui/rfc-2632-const-trait-impl/issue-102985.rs
Normal file
11
src/test/ui/rfc-2632-const-trait-impl/issue-102985.rs
Normal file
@ -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
src/test/ui/rfc-2632-const-trait-impl/issue-102985.stderr
Normal file
26
src/test/ui/rfc-2632-const-trait-impl/issue-102985.stderr
Normal file
@ -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`.
|
Loading…
Reference in New Issue
Block a user