const_evaluatable_unchecked
to const eval
This commit is contained in:
parent
660ca48041
commit
116d35d401
12 changed files with 51 additions and 42 deletions
|
@ -9,14 +9,12 @@
|
|||
//! `thir_abstract_const` which can then be checked for structural equality with other
|
||||
//! generic constants mentioned in the `caller_bounds` of the current environment.
|
||||
use rustc_errors::ErrorGuaranteed;
|
||||
use rustc_hir::def::DefKind;
|
||||
use rustc_infer::infer::InferCtxt;
|
||||
use rustc_middle::mir::interpret::ErrorHandled;
|
||||
use rustc_middle::ty::abstract_const::{
|
||||
walk_abstract_const, AbstractConst, FailureKind, Node, NotConstEvaluatable,
|
||||
};
|
||||
use rustc_middle::ty::{self, TyCtxt, TypeVisitable};
|
||||
use rustc_session::lint;
|
||||
use rustc_span::Span;
|
||||
|
||||
use std::iter;
|
||||
|
@ -262,25 +260,7 @@ pub fn is_const_evaluatable<'tcx>(
|
|||
Err(NotConstEvaluatable::Error(reported))
|
||||
}
|
||||
Err(ErrorHandled::Reported(e)) => Err(NotConstEvaluatable::Error(e)),
|
||||
Ok(_) => {
|
||||
if uv.substs.has_non_region_param() {
|
||||
assert!(matches!(infcx.tcx.def_kind(uv.def.did), DefKind::AnonConst));
|
||||
let mir_body = infcx.tcx.mir_for_ctfe_opt_const_arg(uv.def);
|
||||
|
||||
if mir_body.is_polymorphic {
|
||||
let Some(local_def_id) = uv.def.did.as_local() else { return Ok(()) };
|
||||
tcx.struct_span_lint_hir(
|
||||
lint::builtin::CONST_EVALUATABLE_UNCHECKED,
|
||||
tcx.hir().local_def_id_to_hir_id(local_def_id),
|
||||
span,
|
||||
"cannot use constants which depend on generic parameters in types",
|
||||
|err| err
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
},
|
||||
Ok(_) => Ok(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue