-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Fix const-fn check in const_eval #118004
Fix const-fn check in const_eval #118004
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,9 +9,11 @@ use rustc_infer::traits::{ImplSource, Obligation, ObligationCause}; | |
use rustc_middle::mir::visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor}; | ||
use rustc_middle::mir::*; | ||
use rustc_middle::traits::BuiltinImplSource; | ||
use rustc_middle::ty::FnDef; | ||
use rustc_middle::ty::GenericArgs; | ||
use rustc_middle::ty::{self, adjustment::PointerCoercion, Instance, InstanceDef, Ty, TyCtxt}; | ||
use rustc_middle::ty::{TraitRef, TypeVisitableExt}; | ||
use rustc_middle::util::call_kind; | ||
use rustc_mir_dataflow::{self, Analysis}; | ||
use rustc_span::{sym, Span, Symbol}; | ||
use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt as _; | ||
|
@@ -846,6 +848,22 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> { | |
{ | ||
nonconst_call_permission = true; | ||
} | ||
let call_kind = call_kind( | ||
tcx, | ||
self.param_env, | ||
callee, | ||
fn_args, | ||
*fn_span, | ||
call_source.from_hir_call(), | ||
None, | ||
); | ||
if let call_kind::CallKind::FnCall { fn_trait_id: _, self_ty } = | ||
call_kind | ||
&& let FnDef(def_id, ..) = self_ty.kind() | ||
&& tcx.is_const_fn_raw(*def_id) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how do we do that kind of check ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if other parts of the const checking code already check for const stability, so the first step would be creating an auxiliary ui test where upstream has a const-unstable function and downstream tries to call that function without the feature enabled (following the snippet for this ICE). If it already passes, then great. If it doesn't, we can change this from |
||
{ | ||
return; | ||
} | ||
|
||
if !nonconst_call_permission { | ||
let obligation = Obligation::new( | ||
|
@@ -865,7 +883,6 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> { | |
&e, | ||
); | ||
} | ||
|
||
self.check_op(ops::FnCallNonConst { | ||
caller, | ||
callee, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
//check-pass | ||
|
||
#![feature(const_trait_impl)] | ||
#![feature(fn_traits)] | ||
const fn f() -> usize { | ||
5 | ||
} | ||
|
||
const fn main() { | ||
let _ = [0; Fn::call(&f, ())]; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use let-chains here :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
made it more readable now