Auto merge of #137848 - matthiaskrgr:rollup-vxtrkis, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #136503 (Tweak output of const panic diagnostic) - #137390 (tests: fix up new test for nocapture -> capture(none) change) - #137617 (Introduce `feature(generic_const_parameter_types)`) - #137719 (Add missing case explanation for doc inlined re-export of doc hidden item) - #137763 (Use `mk_ty_from_kind` a bit less, clean up lifetime handling in borrowck) - #137769 (Do not yeet `unsafe<>` from type when formatting unsafe binder) - #137776 (Some `rustc_transmute` cleanups) - #137800 (Remove `ParamEnv::without_caller_bounds`) r? `@ghost` `@rustbot` modify labels: rollup
This commit is contained in:
commit
8c392966a0
206 changed files with 2299 additions and 2305 deletions
|
|
@ -4501,8 +4501,6 @@ dependencies = [
|
|||
"rustc_abi",
|
||||
"rustc_data_structures",
|
||||
"rustc_hir",
|
||||
"rustc_infer",
|
||||
"rustc_macros",
|
||||
"rustc_middle",
|
||||
"rustc_span",
|
||||
"tracing",
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ use rustc_mir_dataflow::move_paths::MoveData;
|
|||
use rustc_mir_dataflow::points::DenseLocationMap;
|
||||
use rustc_span::def_id::CRATE_DEF_ID;
|
||||
use rustc_span::source_map::Spanned;
|
||||
use rustc_span::{DUMMY_SP, Span, sym};
|
||||
use rustc_span::{Span, sym};
|
||||
use rustc_trait_selection::traits::query::type_op::custom::scrape_region_constraints;
|
||||
use rustc_trait_selection::traits::query::type_op::{TypeOp, TypeOpOutput};
|
||||
use tracing::{debug, instrument, trace};
|
||||
|
|
@ -51,7 +51,6 @@ use crate::polonius::legacy::{PoloniusFacts, PoloniusLocationTable};
|
|||
use crate::polonius::{PoloniusContext, PoloniusLivenessContext};
|
||||
use crate::region_infer::TypeTest;
|
||||
use crate::region_infer::values::{LivenessValues, PlaceholderIndex, PlaceholderIndices};
|
||||
use crate::renumber::RegionCtxt;
|
||||
use crate::session_diagnostics::{MoveUnsized, SimdIntrinsicArgConst};
|
||||
use crate::type_check::free_region_relations::{CreateResult, UniversalRegionRelations};
|
||||
use crate::universal_regions::{DefiningTy, UniversalRegions};
|
||||
|
|
@ -2121,35 +2120,31 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
//
|
||||
// Note that other checks (such as denying `dyn Send` -> `dyn
|
||||
// Debug`) are in `rustc_hir_typeck`.
|
||||
if let ty::Dynamic(src_tty, ..) = src_tail.kind()
|
||||
&& let ty::Dynamic(dst_tty, ..) = dst_tail.kind()
|
||||
if let ty::Dynamic(src_tty, _src_lt, _) = *src_tail.kind()
|
||||
&& let ty::Dynamic(dst_tty, dst_lt, _) = *dst_tail.kind()
|
||||
&& src_tty.principal().is_some()
|
||||
&& dst_tty.principal().is_some()
|
||||
{
|
||||
// Remove auto traits.
|
||||
// Auto trait checks are handled in `rustc_hir_typeck` as FCW.
|
||||
let src_obj = tcx.mk_ty_from_kind(ty::Dynamic(
|
||||
let src_obj = Ty::new_dynamic(
|
||||
tcx,
|
||||
tcx.mk_poly_existential_predicates(
|
||||
&src_tty.without_auto_traits().collect::<Vec<_>>(),
|
||||
),
|
||||
tcx.lifetimes.re_static,
|
||||
// FIXME: Once we disallow casting `*const dyn Trait + 'short`
|
||||
// to `*const dyn Trait + 'long`, then this can just be `src_lt`.
|
||||
dst_lt,
|
||||
ty::Dyn,
|
||||
));
|
||||
let dst_obj = tcx.mk_ty_from_kind(ty::Dynamic(
|
||||
);
|
||||
let dst_obj = Ty::new_dynamic(
|
||||
tcx,
|
||||
tcx.mk_poly_existential_predicates(
|
||||
&dst_tty.without_auto_traits().collect::<Vec<_>>(),
|
||||
),
|
||||
tcx.lifetimes.re_static,
|
||||
dst_lt,
|
||||
ty::Dyn,
|
||||
));
|
||||
|
||||
// Replace trait object lifetimes with fresh vars, to allow
|
||||
// casts like
|
||||
// `*mut dyn FnOnce() + 'a` -> `*mut dyn FnOnce() + 'static`
|
||||
let src_obj =
|
||||
freshen_single_trait_object_lifetime(self.infcx, src_obj);
|
||||
let dst_obj =
|
||||
freshen_single_trait_object_lifetime(self.infcx, dst_obj);
|
||||
);
|
||||
|
||||
debug!(?src_tty, ?dst_tty, ?src_obj, ?dst_obj);
|
||||
|
||||
|
|
@ -2707,16 +2702,3 @@ impl<'tcx> TypeOp<'tcx> for InstantiateOpaqueType<'tcx> {
|
|||
Ok(output)
|
||||
}
|
||||
}
|
||||
|
||||
fn freshen_single_trait_object_lifetime<'tcx>(
|
||||
infcx: &BorrowckInferCtxt<'tcx>,
|
||||
ty: Ty<'tcx>,
|
||||
) -> Ty<'tcx> {
|
||||
let &ty::Dynamic(tty, _, dyn_kind @ ty::Dyn) = ty.kind() else { bug!("expected trait object") };
|
||||
|
||||
let fresh = infcx
|
||||
.next_region_var(rustc_infer::infer::RegionVariableOrigin::MiscVariable(DUMMY_SP), || {
|
||||
RegionCtxt::Unknown
|
||||
});
|
||||
infcx.tcx.mk_ty_from_kind(ty::Dynamic(tty, fresh, dyn_kind))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -109,6 +109,8 @@ const_eval_frame_note_inner = inside {$where_ ->
|
|||
*[other] {""}
|
||||
}
|
||||
|
||||
const_eval_frame_note_last = the failure occurred here
|
||||
|
||||
const_eval_in_bounds_test = out-of-bounds pointer use
|
||||
const_eval_incompatible_calling_conventions =
|
||||
calling a function with calling convention {$callee_conv} using calling convention {$caller_conv}
|
||||
|
|
@ -300,8 +302,7 @@ const_eval_overflow_arith =
|
|||
const_eval_overflow_shift =
|
||||
overflowing shift by {$shift_amount} in `{$intrinsic}`
|
||||
|
||||
const_eval_panic =
|
||||
the evaluated program panicked at '{$msg}', {$file}:{$line}:{$col}
|
||||
const_eval_panic = evaluation panicked: {$msg}
|
||||
|
||||
const_eval_panic_non_str = argument to `panic!()` in a const context must have type `&str`
|
||||
|
||||
|
|
|
|||
|
|
@ -48,11 +48,8 @@ impl MachineStopType for ConstEvalErrKind {
|
|||
| ModifiedGlobal
|
||||
| WriteThroughImmutablePointer => {}
|
||||
AssertFailure(kind) => kind.add_args(adder),
|
||||
Panic { msg, line, col, file } => {
|
||||
Panic { msg, .. } => {
|
||||
adder("msg".into(), msg.into_diag_arg(&mut None));
|
||||
adder("file".into(), file.into_diag_arg(&mut None));
|
||||
adder("line".into(), line.into_diag_arg(&mut None));
|
||||
adder("col".into(), col.into_diag_arg(&mut None));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -72,7 +69,7 @@ pub fn get_span_and_frames<'tcx>(
|
|||
let mut stacktrace = Frame::generate_stacktrace_from_stack(stack);
|
||||
// Filter out `requires_caller_location` frames.
|
||||
stacktrace.retain(|frame| !frame.instance.def.requires_caller_location(*tcx));
|
||||
let span = stacktrace.first().map(|f| f.span).unwrap_or(tcx.span);
|
||||
let span = stacktrace.last().map(|f| f.span).unwrap_or(tcx.span);
|
||||
|
||||
let mut frames = Vec::new();
|
||||
|
||||
|
|
@ -115,6 +112,20 @@ pub fn get_span_and_frames<'tcx>(
|
|||
}
|
||||
}
|
||||
|
||||
// In `rustc`, we present const-eval errors from the outer-most place first to the inner-most.
|
||||
// So we reverse the frames here. The first frame will be the same as the span from the current
|
||||
// `TyCtxtAt<'_>`, so we remove it as it would be redundant.
|
||||
frames.reverse();
|
||||
if frames.len() > 0 {
|
||||
frames.remove(0);
|
||||
}
|
||||
if let Some(last) = frames.last_mut()
|
||||
// If the span is not going to be printed, we don't want the span label for `is_last`.
|
||||
&& tcx.sess.source_map().span_to_snippet(last.span.source_callsite()).is_ok()
|
||||
{
|
||||
last.has_label = true;
|
||||
}
|
||||
|
||||
(span, frames)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use rustc_abi::WrappingRange;
|
|||
use rustc_errors::codes::*;
|
||||
use rustc_errors::{
|
||||
Diag, DiagArgValue, DiagCtxtHandle, DiagMessage, Diagnostic, EmissionGuarantee, Level,
|
||||
MultiSpan, SubdiagMessageOp, Subdiagnostic,
|
||||
};
|
||||
use rustc_hir::ConstContext;
|
||||
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
|
||||
|
|
@ -17,6 +18,7 @@ use rustc_middle::mir::interpret::{
|
|||
use rustc_middle::ty::{self, Mutability, Ty};
|
||||
use rustc_span::{Span, Symbol};
|
||||
|
||||
use crate::fluent_generated as fluent;
|
||||
use crate::interpret::InternKind;
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
|
|
@ -278,14 +280,31 @@ pub(crate) struct NonConstImplNote {
|
|||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(Subdiagnostic, Clone)]
|
||||
#[note(const_eval_frame_note)]
|
||||
#[derive(Clone)]
|
||||
pub struct FrameNote {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
pub times: i32,
|
||||
pub where_: &'static str,
|
||||
pub instance: String,
|
||||
pub has_label: bool,
|
||||
}
|
||||
|
||||
impl Subdiagnostic for FrameNote {
|
||||
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
|
||||
self,
|
||||
diag: &mut Diag<'_, G>,
|
||||
f: &F,
|
||||
) {
|
||||
diag.arg("times", self.times);
|
||||
diag.arg("where_", self.where_);
|
||||
diag.arg("instance", self.instance);
|
||||
let mut span: MultiSpan = self.span.into();
|
||||
if self.has_label && !self.span.is_dummy() {
|
||||
span.push_span_label(self.span, fluent::const_eval_frame_note_last);
|
||||
}
|
||||
let msg = f(diag, fluent::const_eval_frame_note.into());
|
||||
diag.span_note(span, msg);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
|
|
|
|||
|
|
@ -231,13 +231,19 @@ impl<'tcx> FrameInfo<'tcx> {
|
|||
pub fn as_note(&self, tcx: TyCtxt<'tcx>) -> errors::FrameNote {
|
||||
let span = self.span;
|
||||
if tcx.def_key(self.instance.def_id()).disambiguated_data.data == DefPathData::Closure {
|
||||
errors::FrameNote { where_: "closure", span, instance: String::new(), times: 0 }
|
||||
errors::FrameNote {
|
||||
where_: "closure",
|
||||
span,
|
||||
instance: String::new(),
|
||||
times: 0,
|
||||
has_label: false,
|
||||
}
|
||||
} else {
|
||||
let instance = format!("{}", self.instance);
|
||||
// Note: this triggers a `must_produce_diag` state, which means that if we ever get
|
||||
// here we must emit a diagnostic. We should never display a `FrameInfo` unless we
|
||||
// actually want to emit a warning or error to the user.
|
||||
errors::FrameNote { where_: "instance", span, instance, times: 0 }
|
||||
errors::FrameNote { where_: "instance", span, instance, times: 0, has_label: false }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -508,6 +508,8 @@ declare_features! (
|
|||
(incomplete, generic_const_exprs, "1.56.0", Some(76560)),
|
||||
/// Allows generic parameters and where-clauses on free & associated const items.
|
||||
(incomplete, generic_const_items, "1.73.0", Some(113521)),
|
||||
/// Allows the type of const generics to depend on generic parameters
|
||||
(incomplete, generic_const_parameter_types, "CURRENT_RUSTC_VERSION", Some(137626)),
|
||||
/// Allows any generic constants being used as pattern type range ends
|
||||
(incomplete, generic_pattern_types, "1.86.0", Some(136574)),
|
||||
/// Allows registering static items globally, possibly across crates, to iterate over at runtime.
|
||||
|
|
|
|||
|
|
@ -966,7 +966,7 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) -> Result<(),
|
|||
let ty = tcx.type_of(param.def_id).instantiate_identity();
|
||||
|
||||
if tcx.features().unsized_const_params() {
|
||||
enter_wf_checking_ctxt(tcx, hir_ty.span, param.def_id, |wfcx| {
|
||||
enter_wf_checking_ctxt(tcx, hir_ty.span, tcx.local_parent(param.def_id), |wfcx| {
|
||||
wfcx.register_bound(
|
||||
ObligationCause::new(
|
||||
hir_ty.span,
|
||||
|
|
@ -980,7 +980,7 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) -> Result<(),
|
|||
Ok(())
|
||||
})
|
||||
} else if tcx.features().adt_const_params() {
|
||||
enter_wf_checking_ctxt(tcx, hir_ty.span, param.def_id, |wfcx| {
|
||||
enter_wf_checking_ctxt(tcx, hir_ty.span, tcx.local_parent(param.def_id), |wfcx| {
|
||||
wfcx.register_bound(
|
||||
ObligationCause::new(
|
||||
hir_ty.span,
|
||||
|
|
|
|||
|
|
@ -1822,6 +1822,9 @@ fn const_param_default<'tcx>(
|
|||
),
|
||||
};
|
||||
let icx = ItemCtxt::new(tcx, def_id);
|
||||
let ct = icx.lowerer().lower_const_arg(default_ct, FeedConstTy::Param(def_id.to_def_id()));
|
||||
let identity_args = ty::GenericArgs::identity_for_item(tcx, def_id);
|
||||
let ct = icx
|
||||
.lowerer()
|
||||
.lower_const_arg(default_ct, FeedConstTy::Param(def_id.to_def_id(), identity_args));
|
||||
ty::EarlyBinder::bind(ct)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -223,10 +223,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
|
|||
}
|
||||
hir::GenericParamKind::Const { .. } => {
|
||||
let param_def_id = param.def_id.to_def_id();
|
||||
let ct_ty = tcx
|
||||
.type_of(param_def_id)
|
||||
.no_bound_vars()
|
||||
.expect("const parameters cannot be generic");
|
||||
let ct_ty = tcx.type_of(param_def_id).instantiate_identity();
|
||||
let ct = icx.lowerer().lower_const_param(param_def_id, param.hir_id);
|
||||
predicates
|
||||
.insert((ty::ClauseKind::ConstArgHasType(ct, ct_ty).upcast(tcx), param.span));
|
||||
|
|
|
|||
|
|
@ -273,7 +273,7 @@ pub fn lower_generic_args<'tcx: 'a, 'a>(
|
|||
|
||||
// We lower to an infer even when the feature gate is not enabled
|
||||
// as it is useful for diagnostics to be able to see a `ConstKind::Infer`
|
||||
args.push(ctx.provided_kind(param, arg));
|
||||
args.push(ctx.provided_kind(&args, param, arg));
|
||||
args_iter.next();
|
||||
params.next();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -232,12 +232,15 @@ impl AssocItemQSelf {
|
|||
/// Use this enum with `<dyn HirTyLowerer>::lower_const_arg` to instruct it with the
|
||||
/// desired behavior.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum FeedConstTy {
|
||||
pub enum FeedConstTy<'a, 'tcx> {
|
||||
/// Feed the type.
|
||||
///
|
||||
/// The `DefId` belongs to the const param that we are supplying
|
||||
/// this (anon) const arg to.
|
||||
Param(DefId),
|
||||
///
|
||||
/// The list of generic args is used to instantiate the parameters
|
||||
/// used by the type of the const param specified by `DefId`.
|
||||
Param(DefId, &'a [ty::GenericArg<'tcx>]),
|
||||
/// Don't feed the type.
|
||||
No,
|
||||
}
|
||||
|
|
@ -298,6 +301,7 @@ pub trait GenericArgsLowerer<'a, 'tcx> {
|
|||
|
||||
fn provided_kind(
|
||||
&mut self,
|
||||
preceding_args: &[ty::GenericArg<'tcx>],
|
||||
param: &ty::GenericParamDef,
|
||||
arg: &GenericArg<'tcx>,
|
||||
) -> ty::GenericArg<'tcx>;
|
||||
|
|
@ -481,6 +485,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||
|
||||
fn provided_kind(
|
||||
&mut self,
|
||||
preceding_args: &[ty::GenericArg<'tcx>],
|
||||
param: &ty::GenericParamDef,
|
||||
arg: &GenericArg<'tcx>,
|
||||
) -> ty::GenericArg<'tcx> {
|
||||
|
|
@ -526,7 +531,10 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||
(GenericParamDefKind::Const { .. }, GenericArg::Const(ct)) => self
|
||||
.lowerer
|
||||
// Ambig portions of `ConstArg` are handled in the match arm below
|
||||
.lower_const_arg(ct.as_unambig_ct(), FeedConstTy::Param(param.def_id))
|
||||
.lower_const_arg(
|
||||
ct.as_unambig_ct(),
|
||||
FeedConstTy::Param(param.def_id, preceding_args),
|
||||
)
|
||||
.into(),
|
||||
(&GenericParamDefKind::Const { .. }, GenericArg::Infer(inf)) => {
|
||||
self.lowerer.ct_infer(Some(param), inf.span).into()
|
||||
|
|
@ -582,8 +590,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||
let ty = tcx
|
||||
.at(self.span)
|
||||
.type_of(param.def_id)
|
||||
.no_bound_vars()
|
||||
.expect("const parameter types cannot be generic");
|
||||
.instantiate(tcx, preceding_args);
|
||||
if let Err(guar) = ty.error_reported() {
|
||||
return ty::Const::new_error(tcx, guar).into();
|
||||
}
|
||||
|
|
@ -2107,14 +2114,50 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||
pub fn lower_const_arg(
|
||||
&self,
|
||||
const_arg: &hir::ConstArg<'tcx>,
|
||||
feed: FeedConstTy,
|
||||
feed: FeedConstTy<'_, 'tcx>,
|
||||
) -> Const<'tcx> {
|
||||
let tcx = self.tcx();
|
||||
|
||||
if let FeedConstTy::Param(param_def_id) = feed
|
||||
if let FeedConstTy::Param(param_def_id, args) = feed
|
||||
&& let hir::ConstArgKind::Anon(anon) = &const_arg.kind
|
||||
{
|
||||
tcx.feed_anon_const_type(anon.def_id, tcx.type_of(param_def_id));
|
||||
let anon_const_type = tcx.type_of(param_def_id).instantiate(tcx, args);
|
||||
|
||||
// We must error if the instantiated type has any inference variables as we will
|
||||
// use this type to feed the `type_of` and query results must not contain inference
|
||||
// variables otherwise we will ICE.
|
||||
//
|
||||
// We also error if the type contains any regions as effectively any region will wind
|
||||
// up as a region variable in mir borrowck. It would also be somewhat concerning if
|
||||
// hir typeck was using equality but mir borrowck wound up using subtyping as that could
|
||||
// result in a non-infer in hir typeck but a region variable in borrowck.
|
||||
//
|
||||
// FIXME(generic_const_parameter_types): Ideally we remove these errors one day when
|
||||
// we have the ability to intermix typeck of anon const const args with the parent
|
||||
// bodies typeck.
|
||||
if tcx.features().generic_const_parameter_types()
|
||||
&& (anon_const_type.has_free_regions() || anon_const_type.has_erased_regions())
|
||||
{
|
||||
let e = tcx.dcx().span_err(
|
||||
const_arg.span(),
|
||||
"anonymous constants with lifetimes in their type are not yet supported",
|
||||
);
|
||||
tcx.feed_anon_const_type(anon.def_id, ty::EarlyBinder::bind(Ty::new_error(tcx, e)));
|
||||
return ty::Const::new_error(tcx, e);
|
||||
}
|
||||
if anon_const_type.has_non_region_infer() {
|
||||
let e = tcx.dcx().span_err(
|
||||
const_arg.span(),
|
||||
"anonymous constants with inferred types are not yet supported",
|
||||
);
|
||||
tcx.feed_anon_const_type(anon.def_id, ty::EarlyBinder::bind(Ty::new_error(tcx, e)));
|
||||
return ty::Const::new_error(tcx, e);
|
||||
}
|
||||
|
||||
tcx.feed_anon_const_type(
|
||||
anon.def_id,
|
||||
ty::EarlyBinder::bind(tcx.type_of(param_def_id).instantiate(tcx, args)),
|
||||
);
|
||||
}
|
||||
|
||||
let hir_id = const_arg.hir_id;
|
||||
|
|
@ -2230,10 +2273,10 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||
let expr = &tcx.hir_body(anon.body).value;
|
||||
debug!(?expr);
|
||||
|
||||
let ty = tcx
|
||||
.type_of(anon.def_id)
|
||||
.no_bound_vars()
|
||||
.expect("const parameter types cannot be generic");
|
||||
// FIXME(generic_const_parameter_types): We should use the proper generic args
|
||||
// here. It's only used as a hint for literals so doesn't matter too much to use the right
|
||||
// generic arguments, just weaker type inference.
|
||||
let ty = tcx.type_of(anon.def_id).instantiate_identity();
|
||||
|
||||
match self.try_lower_anon_const_lit(ty, expr) {
|
||||
Some(v) => v,
|
||||
|
|
|
|||
|
|
@ -260,7 +260,7 @@ pub fn lower_ty<'tcx>(tcx: TyCtxt<'tcx>, hir_ty: &hir::Ty<'tcx>) -> Ty<'tcx> {
|
|||
pub fn lower_const_arg_for_rustdoc<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
hir_ct: &hir::ConstArg<'tcx>,
|
||||
feed: FeedConstTy,
|
||||
feed: FeedConstTy<'_, 'tcx>,
|
||||
) -> Const<'tcx> {
|
||||
let env_def_id = tcx.hir_get_parent_item(hir_ct.hir_id);
|
||||
collect::ItemCtxt::new(tcx, env_def_id.def_id).lowerer().lower_const_arg(hir_ct, feed)
|
||||
|
|
|
|||
|
|
@ -895,20 +895,22 @@ impl<'a, 'tcx> CastCheck<'tcx> {
|
|||
// e.g. we want to allow `dyn T -> (dyn T,)`, etc.
|
||||
//
|
||||
// We also need to skip auto traits to emit an FCW and not an error.
|
||||
let src_obj = tcx.mk_ty_from_kind(ty::Dynamic(
|
||||
let src_obj = Ty::new_dynamic(
|
||||
tcx,
|
||||
tcx.mk_poly_existential_predicates(
|
||||
&src_tty.without_auto_traits().collect::<Vec<_>>(),
|
||||
),
|
||||
tcx.lifetimes.re_erased,
|
||||
ty::Dyn,
|
||||
));
|
||||
let dst_obj = tcx.mk_ty_from_kind(ty::Dynamic(
|
||||
);
|
||||
let dst_obj = Ty::new_dynamic(
|
||||
tcx,
|
||||
tcx.mk_poly_existential_predicates(
|
||||
&dst_tty.without_auto_traits().collect::<Vec<_>>(),
|
||||
),
|
||||
tcx.lifetimes.re_erased,
|
||||
ty::Dyn,
|
||||
));
|
||||
);
|
||||
|
||||
// `dyn Src = dyn Dst`, this checks for matching traits/generics/projections
|
||||
// This is `fcx.demand_eqtype`, but inlined to give a better error.
|
||||
|
|
|
|||
|
|
@ -522,7 +522,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
pub(crate) fn lower_const_arg(
|
||||
&self,
|
||||
const_arg: &'tcx hir::ConstArg<'tcx>,
|
||||
feed: FeedConstTy,
|
||||
feed: FeedConstTy<'_, 'tcx>,
|
||||
) -> ty::Const<'tcx> {
|
||||
let ct = self.lowerer().lower_const_arg(const_arg, feed);
|
||||
self.register_wf_obligation(
|
||||
|
|
@ -1138,7 +1138,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
.last()
|
||||
.is_some_and(|GenericPathSegment(def_id, _)| tcx.generics_of(*def_id).has_self);
|
||||
|
||||
let (res, self_ctor_args) = if let Res::SelfCtor(impl_def_id) = res {
|
||||
let (res, implicit_args) = if let Res::Def(DefKind::ConstParam, def) = res {
|
||||
// types of const parameters are somewhat special as they are part of
|
||||
// the same environment as the const parameter itself. this means that
|
||||
// unlike most paths `type-of(N)` can return a type naming parameters
|
||||
// introduced by the containing item, rather than provided through `N`.
|
||||
//
|
||||
// for example given `<T, const M: usize, const N: [T; M]>` and some
|
||||
// `let a = N;` expression. The path to `N` would wind up with no args
|
||||
// (as it has no args), but instantiating the early binder on `typeof(N)`
|
||||
// requires providing generic arguments for `[T, M, N]`.
|
||||
(res, Some(ty::GenericArgs::identity_for_item(tcx, tcx.parent(def))))
|
||||
} else if let Res::SelfCtor(impl_def_id) = res {
|
||||
let ty = LoweredTy::from_raw(
|
||||
self,
|
||||
span,
|
||||
|
|
@ -1264,6 +1275,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
|
||||
fn provided_kind(
|
||||
&mut self,
|
||||
preceding_args: &[ty::GenericArg<'tcx>],
|
||||
param: &ty::GenericParamDef,
|
||||
arg: &GenericArg<'tcx>,
|
||||
) -> ty::GenericArg<'tcx> {
|
||||
|
|
@ -1283,7 +1295,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
(GenericParamDefKind::Const { .. }, GenericArg::Const(ct)) => self
|
||||
.fcx
|
||||
// Ambiguous parts of `ConstArg` are handled in the match arms below
|
||||
.lower_const_arg(ct.as_unambig_ct(), FeedConstTy::Param(param.def_id))
|
||||
.lower_const_arg(
|
||||
ct.as_unambig_ct(),
|
||||
FeedConstTy::Param(param.def_id, preceding_args),
|
||||
)
|
||||
.into(),
|
||||
(&GenericParamDefKind::Const { .. }, GenericArg::Infer(inf)) => {
|
||||
self.fcx.ct_infer(Some(param), inf.span).into()
|
||||
|
|
@ -1323,7 +1338,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
let args_raw = self_ctor_args.unwrap_or_else(|| {
|
||||
let args_raw = implicit_args.unwrap_or_else(|| {
|
||||
lower_generic_args(
|
||||
self,
|
||||
def_id,
|
||||
|
|
|
|||
|
|
@ -426,6 +426,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
|
|||
|
||||
fn provided_kind(
|
||||
&mut self,
|
||||
preceding_args: &[ty::GenericArg<'tcx>],
|
||||
param: &ty::GenericParamDef,
|
||||
arg: &GenericArg<'tcx>,
|
||||
) -> ty::GenericArg<'tcx> {
|
||||
|
|
@ -446,7 +447,10 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
|
|||
(GenericParamDefKind::Const { .. }, GenericArg::Const(ct)) => self
|
||||
.cfcx
|
||||
// We handle the ambig portions of `ConstArg` in the match arms below
|
||||
.lower_const_arg(ct.as_unambig_ct(), FeedConstTy::Param(param.def_id))
|
||||
.lower_const_arg(
|
||||
ct.as_unambig_ct(),
|
||||
FeedConstTy::Param(param.def_id, preceding_args),
|
||||
)
|
||||
.into(),
|
||||
(GenericParamDefKind::Const { .. }, GenericArg::Infer(inf)) => {
|
||||
self.cfcx.ct_infer(Some(param), inf.span).into()
|
||||
|
|
|
|||
|
|
@ -224,7 +224,7 @@ impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for Ty<'tcx> {
|
|||
})
|
||||
} else {
|
||||
let tcx = decoder.interner();
|
||||
tcx.mk_ty_from_kind(rustc_type_ir::TyKind::decode(decoder))
|
||||
tcx.mk_ty_from_kind(ty::TyKind::decode(decoder))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -992,12 +992,6 @@ impl<'tcx> ParamEnv<'tcx> {
|
|||
ParamEnv { caller_bounds }
|
||||
}
|
||||
|
||||
/// Returns this same environment but with no caller bounds.
|
||||
#[inline]
|
||||
pub fn without_caller_bounds(self) -> Self {
|
||||
Self::new(ListWithCachedTypeInfo::empty())
|
||||
}
|
||||
|
||||
/// Creates a pair of param-env and value for use in queries.
|
||||
pub fn and<T: TypeVisitable<TyCtxt<'tcx>>>(self, value: T) -> ParamEnvAnd<'tcx, T> {
|
||||
ParamEnvAnd { param_env: self, value }
|
||||
|
|
|
|||
|
|
@ -342,6 +342,7 @@ impl ParamConst {
|
|||
ParamConst::new(def.index, def.name)
|
||||
}
|
||||
|
||||
#[instrument(level = "debug")]
|
||||
pub fn find_ty_from_env<'tcx>(self, env: ParamEnv<'tcx>) -> Ty<'tcx> {
|
||||
let mut candidates = env.caller_bounds().iter().filter_map(|clause| {
|
||||
// `ConstArgHasType` are never desugared to be higher ranked.
|
||||
|
|
@ -461,7 +462,7 @@ impl<'tcx> Ty<'tcx> {
|
|||
|
||||
#[inline]
|
||||
pub fn new_param(tcx: TyCtxt<'tcx>, index: u32, name: Symbol) -> Ty<'tcx> {
|
||||
tcx.mk_ty_from_kind(Param(ParamTy { index, name }))
|
||||
Ty::new(tcx, Param(ParamTy { index, name }))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
|
|||
|
|
@ -102,7 +102,6 @@ pub trait SolverDelegate: Deref<Target = Self::Infcx> + Sized {
|
|||
|
||||
fn is_transmutable(
|
||||
&self,
|
||||
param_env: <Self::Interner as Interner>::ParamEnv,
|
||||
dst: <Self::Interner as Interner>::Ty,
|
||||
src: <Self::Interner as Interner>::Ty,
|
||||
assume: <Self::Interner as Interner>::Const,
|
||||
|
|
|
|||
|
|
@ -1091,12 +1091,11 @@ where
|
|||
|
||||
pub(super) fn is_transmutable(
|
||||
&mut self,
|
||||
param_env: I::ParamEnv,
|
||||
dst: I::Ty,
|
||||
src: I::Ty,
|
||||
assume: I::Const,
|
||||
) -> Result<Certainty, NoSolution> {
|
||||
self.delegate.is_transmutable(param_env, dst, src, assume)
|
||||
self.delegate.is_transmutable(dst, src, assume)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -617,7 +617,6 @@ where
|
|||
)?;
|
||||
|
||||
let certainty = ecx.is_transmutable(
|
||||
goal.param_env,
|
||||
goal.predicate.trait_ref.args.type_at(0),
|
||||
goal.predicate.trait_ref.args.type_at(1),
|
||||
assume,
|
||||
|
|
|
|||
|
|
@ -125,9 +125,6 @@ resolve_const_param_in_enum_discriminant =
|
|||
resolve_const_param_in_non_trivial_anon_const =
|
||||
const parameters may only be used as standalone arguments, i.e. `{$name}`
|
||||
|
||||
resolve_const_param_in_ty_of_const_param =
|
||||
const parameters may not be used in the type of const parameters
|
||||
|
||||
resolve_constructor_private_if_any_field_private =
|
||||
a constructor is private if any of the fields is private
|
||||
|
||||
|
|
@ -250,9 +247,6 @@ resolve_lifetime_param_in_enum_discriminant =
|
|||
resolve_lifetime_param_in_non_trivial_anon_const =
|
||||
lifetime parameters may not be used in const expressions
|
||||
|
||||
resolve_lifetime_param_in_ty_of_const_param =
|
||||
lifetime parameters may not be used in the type of const parameters
|
||||
|
||||
resolve_lowercase_self =
|
||||
attempt to use a non-constant value in a constant
|
||||
.suggestion = try using `Self`
|
||||
|
|
@ -437,9 +431,6 @@ resolve_type_param_in_enum_discriminant =
|
|||
resolve_type_param_in_non_trivial_anon_const =
|
||||
type parameters may not be used in const expressions
|
||||
|
||||
resolve_type_param_in_ty_of_const_param =
|
||||
type parameters may not be used in the type of const parameters
|
||||
|
||||
resolve_undeclared_label =
|
||||
use of undeclared label `{$name}`
|
||||
.label = undeclared label `{$name}`
|
||||
|
|
|
|||
|
|
@ -890,9 +890,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
ResolutionError::ForwardDeclaredGenericParam => {
|
||||
self.dcx().create_err(errs::ForwardDeclaredGenericParam { span })
|
||||
}
|
||||
ResolutionError::ParamInTyOfConstParam { name, param_kind: is_type } => self
|
||||
.dcx()
|
||||
.create_err(errs::ParamInTyOfConstParam { span, name, param_kind: is_type }),
|
||||
ResolutionError::ParamInTyOfConstParam { name } => {
|
||||
self.dcx().create_err(errs::ParamInTyOfConstParam { span, name })
|
||||
}
|
||||
ResolutionError::ParamInNonTrivialAnonConst { name, param_kind: is_type } => {
|
||||
self.dcx().create_err(errs::ParamInNonTrivialAnonConst {
|
||||
span,
|
||||
|
|
|
|||
|
|
@ -347,19 +347,6 @@ pub(crate) struct ParamInTyOfConstParam {
|
|||
#[label]
|
||||
pub(crate) span: Span,
|
||||
pub(crate) name: Symbol,
|
||||
#[subdiagnostic]
|
||||
pub(crate) param_kind: Option<ParamKindInTyOfConstParam>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Subdiagnostic)]
|
||||
pub(crate) enum ParamKindInTyOfConstParam {
|
||||
#[note(resolve_type_param_in_ty_of_const_param)]
|
||||
Type,
|
||||
#[note(resolve_const_param_in_ty_of_const_param)]
|
||||
Const,
|
||||
#[note(resolve_lifetime_param_in_ty_of_const_param)]
|
||||
Lifetime,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
|
|
|
|||
|
|
@ -1131,6 +1131,17 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
return Res::Err;
|
||||
}
|
||||
|
||||
if let RibKind::ConstParamTy = all_ribs[rib_index].kind {
|
||||
if let Some(span) = finalize {
|
||||
self.report_error(
|
||||
span,
|
||||
ResolutionError::ParamInTyOfConstParam { name: rib_ident.name },
|
||||
);
|
||||
}
|
||||
assert_eq!(res, Res::Err);
|
||||
return Res::Err;
|
||||
}
|
||||
|
||||
match res {
|
||||
Res::Local(_) => {
|
||||
use ResolutionError::*;
|
||||
|
|
@ -1209,10 +1220,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
if let Some(span) = finalize {
|
||||
self.report_error(
|
||||
span,
|
||||
ParamInTyOfConstParam {
|
||||
name: rib_ident.name,
|
||||
param_kind: None,
|
||||
},
|
||||
ParamInTyOfConstParam { name: rib_ident.name },
|
||||
);
|
||||
}
|
||||
return Res::Err;
|
||||
|
|
@ -1239,6 +1247,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
| RibKind::MacroDefinition(..)
|
||||
| RibKind::InlineAsmSym
|
||||
| RibKind::AssocItem
|
||||
| RibKind::ConstParamTy
|
||||
| RibKind::ForwardGenericParamBan => {
|
||||
// Nothing to do. Continue.
|
||||
continue;
|
||||
|
|
@ -1292,18 +1301,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
RibKind::Item(has_generic_params, def_kind) => {
|
||||
(has_generic_params, def_kind)
|
||||
}
|
||||
RibKind::ConstParamTy => {
|
||||
if let Some(span) = finalize {
|
||||
self.report_error(
|
||||
span,
|
||||
ResolutionError::ParamInTyOfConstParam {
|
||||
name: rib_ident.name,
|
||||
param_kind: Some(errors::ParamKindInTyOfConstParam::Type),
|
||||
},
|
||||
);
|
||||
}
|
||||
return Res::Err;
|
||||
}
|
||||
};
|
||||
|
||||
if let Some(span) = finalize {
|
||||
|
|
@ -1328,6 +1325,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
| RibKind::MacroDefinition(..)
|
||||
| RibKind::InlineAsmSym
|
||||
| RibKind::AssocItem
|
||||
| RibKind::ConstParamTy
|
||||
| RibKind::ForwardGenericParamBan => continue,
|
||||
|
||||
RibKind::ConstantItem(trivial, _) => {
|
||||
|
|
@ -1361,18 +1359,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
RibKind::Item(has_generic_params, def_kind) => {
|
||||
(has_generic_params, def_kind)
|
||||
}
|
||||
RibKind::ConstParamTy => {
|
||||
if let Some(span) = finalize {
|
||||
self.report_error(
|
||||
span,
|
||||
ResolutionError::ParamInTyOfConstParam {
|
||||
name: rib_ident.name,
|
||||
param_kind: Some(errors::ParamKindInTyOfConstParam::Const),
|
||||
},
|
||||
);
|
||||
}
|
||||
return Res::Err;
|
||||
}
|
||||
};
|
||||
|
||||
// This was an attempt to use a const parameter outside its scope.
|
||||
|
|
|
|||
|
|
@ -227,9 +227,11 @@ impl RibKind<'_> {
|
|||
| RibKind::ConstantItem(..)
|
||||
| RibKind::Module(_)
|
||||
| RibKind::MacroDefinition(_)
|
||||
| RibKind::ConstParamTy
|
||||
| RibKind::InlineAsmSym => false,
|
||||
RibKind::AssocItem | RibKind::Item(..) | RibKind::ForwardGenericParamBan => true,
|
||||
RibKind::ConstParamTy
|
||||
| RibKind::AssocItem
|
||||
| RibKind::Item(..)
|
||||
| RibKind::ForwardGenericParamBan => true,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1570,6 +1572,17 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
|
|||
forward_ty_ban_rib.bindings.insert(Ident::with_dummy_span(kw::SelfUpper), Res::Err);
|
||||
}
|
||||
|
||||
let mut forward_ty_ban_rib_const_param_ty = Rib {
|
||||
bindings: forward_ty_ban_rib.bindings.clone(),
|
||||
patterns_with_skipped_bindings: FxHashMap::default(),
|
||||
kind: RibKind::ConstParamTy,
|
||||
};
|
||||
let mut forward_const_ban_rib_const_param_ty = Rib {
|
||||
bindings: forward_const_ban_rib.bindings.clone(),
|
||||
patterns_with_skipped_bindings: FxHashMap::default(),
|
||||
kind: RibKind::ConstParamTy,
|
||||
};
|
||||
|
||||
self.with_lifetime_rib(LifetimeRibKind::AnonymousReportError, |this| {
|
||||
for param in params {
|
||||
match param.kind {
|
||||
|
|
@ -1592,21 +1605,27 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
|
|||
}
|
||||
|
||||
// Allow all following defaults to refer to this type parameter.
|
||||
forward_ty_ban_rib
|
||||
.bindings
|
||||
.remove(&Ident::with_dummy_span(param.ident.name));
|
||||
let i = &Ident::with_dummy_span(param.ident.name);
|
||||
forward_ty_ban_rib.bindings.remove(i);
|
||||
if this.r.tcx.features().generic_const_parameter_types() {
|
||||
forward_ty_ban_rib_const_param_ty.bindings.remove(i);
|
||||
}
|
||||
}
|
||||
GenericParamKind::Const { ref ty, kw_span: _, ref default } => {
|
||||
// Const parameters can't have param bounds.
|
||||
assert!(param.bounds.is_empty());
|
||||
|
||||
this.ribs[TypeNS].push(Rib::new(RibKind::ConstParamTy));
|
||||
this.ribs[ValueNS].push(Rib::new(RibKind::ConstParamTy));
|
||||
this.with_lifetime_rib(LifetimeRibKind::ConstParamTy, |this| {
|
||||
this.ribs[TypeNS].push(forward_ty_ban_rib_const_param_ty);
|
||||
this.ribs[ValueNS].push(forward_const_ban_rib_const_param_ty);
|
||||
if this.r.tcx.features().generic_const_parameter_types() {
|
||||
this.visit_ty(ty)
|
||||
});
|
||||
this.ribs[TypeNS].pop().unwrap();
|
||||
this.ribs[ValueNS].pop().unwrap();
|
||||
} else {
|
||||
this.with_lifetime_rib(LifetimeRibKind::ConstParamTy, |this| {
|
||||
this.visit_ty(ty)
|
||||
});
|
||||
}
|
||||
forward_const_ban_rib_const_param_ty = this.ribs[ValueNS].pop().unwrap();
|
||||
forward_ty_ban_rib_const_param_ty = this.ribs[TypeNS].pop().unwrap();
|
||||
|
||||
if let Some(expr) = default {
|
||||
this.ribs[TypeNS].push(forward_ty_ban_rib);
|
||||
|
|
@ -1620,9 +1639,11 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
|
|||
}
|
||||
|
||||
// Allow all following defaults to refer to this const parameter.
|
||||
forward_const_ban_rib
|
||||
.bindings
|
||||
.remove(&Ident::with_dummy_span(param.ident.name));
|
||||
let i = &Ident::with_dummy_span(param.ident.name);
|
||||
forward_const_ban_rib.bindings.remove(i);
|
||||
if this.r.tcx.features().generic_const_parameter_types() {
|
||||
forward_const_ban_rib_const_param_ty.bindings.remove(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3052,7 +3052,6 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
|
|||
.create_err(errors::ParamInTyOfConstParam {
|
||||
span: lifetime_ref.ident.span,
|
||||
name: lifetime_ref.ident.name,
|
||||
param_kind: Some(errors::ParamKindInTyOfConstParam::Lifetime),
|
||||
})
|
||||
.emit();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,9 +30,7 @@ use std::sync::Arc;
|
|||
|
||||
use diagnostics::{ImportSuggestion, LabelSuggestion, Suggestion};
|
||||
use effective_visibilities::EffectiveVisibilitiesVisitor;
|
||||
use errors::{
|
||||
ParamKindInEnumDiscriminant, ParamKindInNonTrivialAnonConst, ParamKindInTyOfConstParam,
|
||||
};
|
||||
use errors::{ParamKindInEnumDiscriminant, ParamKindInNonTrivialAnonConst};
|
||||
use imports::{Import, ImportData, ImportKind, NameResolution};
|
||||
use late::{HasGenericParams, PathSource, PatternSource, UnnecessaryQualification};
|
||||
use macros::{MacroRulesBinding, MacroRulesScope, MacroRulesScopeRef};
|
||||
|
|
@ -276,8 +274,10 @@ enum ResolutionError<'ra> {
|
|||
},
|
||||
/// Error E0128: generic parameters with a default cannot use forward-declared identifiers.
|
||||
ForwardDeclaredGenericParam,
|
||||
// FIXME(generic_const_parameter_types): This should give custom output specifying it's only
|
||||
// problematic to use *forward declared* parameters when the feature is enabled.
|
||||
/// ERROR E0770: the type of const parameters must not depend on other generic parameters.
|
||||
ParamInTyOfConstParam { name: Symbol, param_kind: Option<ParamKindInTyOfConstParam> },
|
||||
ParamInTyOfConstParam { name: Symbol },
|
||||
/// generic parameters must not be used inside const evaluations.
|
||||
///
|
||||
/// This error is only emitted when using `min_const_generics`.
|
||||
|
|
|
|||
|
|
@ -1037,6 +1037,7 @@ symbols! {
|
|||
generic_associated_types_extended,
|
||||
generic_const_exprs,
|
||||
generic_const_items,
|
||||
generic_const_parameter_types,
|
||||
generic_param_attrs,
|
||||
generic_pattern_types,
|
||||
get_context,
|
||||
|
|
|
|||
|
|
@ -1189,9 +1189,6 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
let span = obligation.cause.span;
|
||||
|
||||
let mut diag = match ty.kind() {
|
||||
_ if ty.has_param() => {
|
||||
span_bug!(span, "const param tys cannot mention other generic parameters");
|
||||
}
|
||||
ty::Float(_) => {
|
||||
struct_span_code_err!(
|
||||
self.dcx(),
|
||||
|
|
@ -2536,9 +2533,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
return GetSafeTransmuteErrorAndReason::Silent;
|
||||
};
|
||||
|
||||
let Some(assume) =
|
||||
rustc_transmute::Assume::from_const(self.infcx.tcx, obligation.param_env, assume)
|
||||
else {
|
||||
let Some(assume) = rustc_transmute::Assume::from_const(self.infcx.tcx, assume) else {
|
||||
self.dcx().span_delayed_bug(
|
||||
span,
|
||||
"Unable to construct rustc_transmute::Assume where it was previously possible",
|
||||
|
|
@ -2550,11 +2545,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
let src = trait_pred.trait_ref.args.type_at(1);
|
||||
let err_msg = format!("`{src}` cannot be safely transmuted into `{dst}`");
|
||||
|
||||
match rustc_transmute::TransmuteTypeEnv::new(self.infcx).is_transmutable(
|
||||
obligation.cause,
|
||||
src_and_dst,
|
||||
assume,
|
||||
) {
|
||||
match rustc_transmute::TransmuteTypeEnv::new(self.infcx.tcx)
|
||||
.is_transmutable(src_and_dst, assume)
|
||||
{
|
||||
Answer::No(reason) => {
|
||||
let safe_transmute_explanation = match reason {
|
||||
rustc_transmute::Reason::SrcIsNotYetSupported => {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ use rustc_infer::infer::canonical::{
|
|||
Canonical, CanonicalExt as _, CanonicalQueryInput, CanonicalVarInfo, CanonicalVarValues,
|
||||
};
|
||||
use rustc_infer::infer::{InferCtxt, RegionVariableOrigin, TyCtxtInferExt};
|
||||
use rustc_infer::traits::ObligationCause;
|
||||
use rustc_infer::traits::solve::Goal;
|
||||
use rustc_middle::ty::fold::TypeFoldable;
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt as _};
|
||||
|
|
@ -222,7 +221,6 @@ impl<'tcx> rustc_next_trait_solver::delegate::SolverDelegate for SolverDelegate<
|
|||
// register candidates. We probably need to register >1 since we may have an OR of ANDs.
|
||||
fn is_transmutable(
|
||||
&self,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
dst: Ty<'tcx>,
|
||||
src: Ty<'tcx>,
|
||||
assume: ty::Const<'tcx>,
|
||||
|
|
@ -231,16 +229,14 @@ impl<'tcx> rustc_next_trait_solver::delegate::SolverDelegate for SolverDelegate<
|
|||
// which will ICE for region vars.
|
||||
let (dst, src) = self.tcx.erase_regions((dst, src));
|
||||
|
||||
let Some(assume) = rustc_transmute::Assume::from_const(self.tcx, param_env, assume) else {
|
||||
let Some(assume) = rustc_transmute::Assume::from_const(self.tcx, assume) else {
|
||||
return Err(NoSolution);
|
||||
};
|
||||
|
||||
// FIXME(transmutability): This really should be returning nested goals for `Answer::If*`
|
||||
match rustc_transmute::TransmuteTypeEnv::new(&self.0).is_transmutable(
|
||||
ObligationCause::dummy(),
|
||||
rustc_transmute::Types { src, dst },
|
||||
assume,
|
||||
) {
|
||||
match rustc_transmute::TransmuteTypeEnv::new(self.0.tcx)
|
||||
.is_transmutable(rustc_transmute::Types { src, dst }, assume)
|
||||
{
|
||||
rustc_transmute::Answer::Yes => Ok(Certainty::Yes),
|
||||
rustc_transmute::Answer::No(_) | rustc_transmute::Answer::If(_) => Err(NoSolution),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -414,9 +414,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
if self.tcx().features().generic_const_exprs() {
|
||||
assume = crate::traits::evaluate_const(self.infcx, assume, obligation.param_env)
|
||||
}
|
||||
let Some(assume) =
|
||||
rustc_transmute::Assume::from_const(self.infcx.tcx, obligation.param_env, assume)
|
||||
else {
|
||||
let Some(assume) = rustc_transmute::Assume::from_const(self.infcx.tcx, assume) else {
|
||||
return Err(Unimplemented);
|
||||
};
|
||||
|
||||
|
|
@ -424,12 +422,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
let src = predicate.trait_ref.args.type_at(1);
|
||||
|
||||
debug!(?src, ?dst);
|
||||
let mut transmute_env = rustc_transmute::TransmuteTypeEnv::new(self.infcx);
|
||||
let maybe_transmutable = transmute_env.is_transmutable(
|
||||
obligation.cause.clone(),
|
||||
rustc_transmute::Types { dst, src },
|
||||
assume,
|
||||
);
|
||||
let mut transmute_env = rustc_transmute::TransmuteTypeEnv::new(self.infcx.tcx);
|
||||
let maybe_transmutable =
|
||||
transmute_env.is_transmutable(rustc_transmute::Types { dst, src }, assume);
|
||||
|
||||
let fully_flattened = match maybe_transmutable {
|
||||
Answer::No(_) => Err(Unimplemented)?,
|
||||
|
|
|
|||
|
|
@ -1007,7 +1007,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
// depend on its particular value in order to work, so we can clear
|
||||
// out the param env and get better caching.
|
||||
debug!("in global");
|
||||
obligation.param_env = obligation.param_env.without_caller_bounds();
|
||||
obligation.param_env = ty::ParamEnv::empty();
|
||||
}
|
||||
|
||||
let stack = self.push_stack(previous_stack, &obligation);
|
||||
|
|
|
|||
|
|
@ -8,8 +8,6 @@ edition = "2024"
|
|||
rustc_abi = { path = "../rustc_abi", optional = true }
|
||||
rustc_data_structures = { path = "../rustc_data_structures" }
|
||||
rustc_hir = { path = "../rustc_hir", optional = true }
|
||||
rustc_infer = { path = "../rustc_infer", optional = true }
|
||||
rustc_macros = { path = "../rustc_macros", optional = true }
|
||||
rustc_middle = { path = "../rustc_middle", optional = true }
|
||||
rustc_span = { path = "../rustc_span", optional = true }
|
||||
tracing = "0.1"
|
||||
|
|
@ -19,8 +17,6 @@ tracing = "0.1"
|
|||
rustc = [
|
||||
"dep:rustc_abi",
|
||||
"dep:rustc_hir",
|
||||
"dep:rustc_infer",
|
||||
"dep:rustc_macros",
|
||||
"dep:rustc_middle",
|
||||
"dep:rustc_span",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ impl<R> Transitions<R>
|
|||
where
|
||||
R: Ref,
|
||||
{
|
||||
#[allow(dead_code)]
|
||||
#[cfg(test)]
|
||||
fn insert(&mut self, transition: Transition<R>, state: State) {
|
||||
match transition {
|
||||
Transition::Byte(b) => {
|
||||
|
|
@ -86,15 +86,6 @@ impl<R> Dfa<R>
|
|||
where
|
||||
R: Ref,
|
||||
{
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn unit() -> Self {
|
||||
let transitions: Map<State, Transitions<R>> = Map::default();
|
||||
let start = State::new();
|
||||
let accepting = start;
|
||||
|
||||
Self { transitions, start, accepting }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn bool() -> Self {
|
||||
let mut transitions: Map<State, Transitions<R>> = Map::default();
|
||||
|
|
|
|||
|
|
@ -159,11 +159,6 @@ where
|
|||
}
|
||||
Self { transitions, start, accepting }
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn edges_from(&self, start: State) -> Option<&Map<Transition<R>, Set<State>>> {
|
||||
self.transitions.get(&start)
|
||||
}
|
||||
}
|
||||
|
||||
impl State {
|
||||
|
|
|
|||
|
|
@ -237,7 +237,7 @@ pub(crate) mod rustc {
|
|||
|
||||
ty::Tuple(members) => Self::from_tuple((ty, layout), members, cx),
|
||||
|
||||
ty::Array(inner_ty, len) => {
|
||||
ty::Array(inner_ty, _len) => {
|
||||
let FieldsShape::Array { stride, count } = &layout.fields else {
|
||||
return Err(Err::NotYetSupported);
|
||||
};
|
||||
|
|
@ -282,7 +282,6 @@ pub(crate) mod rustc {
|
|||
FieldsShape::Primitive => {
|
||||
assert_eq!(members.len(), 1);
|
||||
let inner_ty = members[0];
|
||||
let inner_layout = layout_of(cx, inner_ty)?;
|
||||
Self::from_ty(inner_ty, cx)
|
||||
}
|
||||
FieldsShape::Arbitrary { offsets, .. } => {
|
||||
|
|
@ -345,7 +344,7 @@ pub(crate) mod rustc {
|
|||
// the enum delegates its layout to the variant at `index`.
|
||||
layout_of_variant(*index, None)
|
||||
}
|
||||
Variants::Multiple { tag, tag_encoding, tag_field, .. } => {
|
||||
Variants::Multiple { tag: _, tag_encoding, tag_field, .. } => {
|
||||
// `Variants::Multiple` denotes an enum with multiple
|
||||
// variants. The layout of such an enum is the disjunction
|
||||
// of the layouts of its tagged variants.
|
||||
|
|
@ -356,7 +355,7 @@ pub(crate) mod rustc {
|
|||
|
||||
let variants = def.discriminants(cx.tcx()).try_fold(
|
||||
Self::uninhabited(),
|
||||
|variants, (idx, ref discriminant)| {
|
||||
|variants, (idx, _discriminant)| {
|
||||
let variant = layout_of_variant(idx, Some(tag_encoding.clone()))?;
|
||||
Result::<Self, Err>::Ok(variants.or(variant))
|
||||
},
|
||||
|
|
@ -414,7 +413,7 @@ pub(crate) mod rustc {
|
|||
|
||||
// Append the fields, in memory order, to the layout.
|
||||
let inverse_memory_index = memory_index.invert_bijective_mapping();
|
||||
for (memory_idx, &field_idx) in inverse_memory_index.iter_enumerated() {
|
||||
for &field_idx in inverse_memory_index.iter() {
|
||||
// Add interfield padding.
|
||||
let padding_needed = offsets[field_idx] - size;
|
||||
let padding = Self::padding(padding_needed.bytes_usize());
|
||||
|
|
@ -468,15 +467,14 @@ pub(crate) mod rustc {
|
|||
|
||||
// This constructor does not support non-`FieldsShape::Union`
|
||||
// layouts. Fields of this shape are all placed at offset 0.
|
||||
let FieldsShape::Union(fields) = layout.fields() else {
|
||||
let FieldsShape::Union(_fields) = layout.fields() else {
|
||||
return Err(Err::NotYetSupported);
|
||||
};
|
||||
|
||||
let fields = &def.non_enum_variant().fields;
|
||||
let fields = fields.iter_enumerated().try_fold(
|
||||
Self::uninhabited(),
|
||||
|fields, (idx, field_def)| {
|
||||
let field_def = Def::Field(field_def);
|
||||
|fields, (idx, _field_def)| {
|
||||
let field_ty = ty_field(cx, (ty, layout), idx);
|
||||
let field_layout = layout_of(cx, field_ty)?;
|
||||
let field = Self::from_ty(field_ty, cx)?;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
// tidy-alphabetical-start
|
||||
#![allow(unused_variables)]
|
||||
#![feature(alloc_layout_extra)]
|
||||
#![feature(never_type)]
|
||||
#![warn(unreachable_pub)]
|
||||
// tidy-alphabetical-end
|
||||
|
|
@ -81,15 +79,12 @@ pub enum Reason<T> {
|
|||
#[cfg(feature = "rustc")]
|
||||
mod rustc {
|
||||
use rustc_hir::lang_items::LangItem;
|
||||
use rustc_infer::infer::InferCtxt;
|
||||
use rustc_macros::TypeVisitable;
|
||||
use rustc_middle::traits::ObligationCause;
|
||||
use rustc_middle::ty::{Const, ParamEnv, Ty, TyCtxt};
|
||||
use rustc_middle::ty::{Const, Ty, TyCtxt};
|
||||
|
||||
use super::*;
|
||||
|
||||
/// The source and destination types of a transmutation.
|
||||
#[derive(TypeVisitable, Debug, Clone, Copy)]
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Types<'tcx> {
|
||||
/// The source type.
|
||||
pub src: Ty<'tcx>,
|
||||
|
|
@ -97,27 +92,22 @@ mod rustc {
|
|||
pub dst: Ty<'tcx>,
|
||||
}
|
||||
|
||||
pub struct TransmuteTypeEnv<'cx, 'tcx> {
|
||||
infcx: &'cx InferCtxt<'tcx>,
|
||||
pub struct TransmuteTypeEnv<'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
}
|
||||
|
||||
impl<'cx, 'tcx> TransmuteTypeEnv<'cx, 'tcx> {
|
||||
pub fn new(infcx: &'cx InferCtxt<'tcx>) -> Self {
|
||||
Self { infcx }
|
||||
impl<'tcx> TransmuteTypeEnv<'tcx> {
|
||||
pub fn new(tcx: TyCtxt<'tcx>) -> Self {
|
||||
Self { tcx }
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
pub fn is_transmutable(
|
||||
&mut self,
|
||||
cause: ObligationCause<'tcx>,
|
||||
types: Types<'tcx>,
|
||||
assume: crate::Assume,
|
||||
) -> crate::Answer<crate::layout::rustc::Ref<'tcx>> {
|
||||
crate::maybe_transmutable::MaybeTransmutableQuery::new(
|
||||
types.src,
|
||||
types.dst,
|
||||
assume,
|
||||
self.infcx.tcx,
|
||||
types.src, types.dst, assume, self.tcx,
|
||||
)
|
||||
.answer()
|
||||
}
|
||||
|
|
@ -125,11 +115,7 @@ mod rustc {
|
|||
|
||||
impl Assume {
|
||||
/// Constructs an `Assume` from a given const-`Assume`.
|
||||
pub fn from_const<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
param_env: ParamEnv<'tcx>,
|
||||
ct: Const<'tcx>,
|
||||
) -> Option<Self> {
|
||||
pub fn from_const<'tcx>(tcx: TyCtxt<'tcx>, ct: Const<'tcx>) -> Option<Self> {
|
||||
use rustc_middle::ty::ScalarInt;
|
||||
use rustc_span::sym;
|
||||
|
||||
|
|
|
|||
|
|
@ -79,12 +79,12 @@ where
|
|||
pub(crate) fn answer(self) -> Answer<<C as QueryContext>::Ref> {
|
||||
let Self { src, dst, assume, context } = self;
|
||||
|
||||
// Unconditionally all `Def` nodes from `src`, without pruning away the
|
||||
// Unconditionally remove all `Def` nodes from `src`, without pruning away the
|
||||
// branches they appear in. This is valid to do for value-to-value
|
||||
// transmutations, but not for `&mut T` to `&mut U`; we will need to be
|
||||
// more sophisticated to handle transmutations between mutable
|
||||
// references.
|
||||
let src = src.prune(&|def| false);
|
||||
let src = src.prune(&|_def| false);
|
||||
|
||||
if src.is_inhabited() && !dst.is_inhabited() {
|
||||
return Answer::No(Reason::DstUninhabited);
|
||||
|
|
@ -96,7 +96,7 @@ where
|
|||
let dst = if assume.safety {
|
||||
// ...if safety is assumed, don't check if they carry safety
|
||||
// invariants; retain all paths.
|
||||
dst.prune(&|def| false)
|
||||
dst.prune(&|_def| false)
|
||||
} else {
|
||||
// ...otherwise, prune away all paths with safety invariants from
|
||||
// the `Dst` layout.
|
||||
|
|
|
|||
|
|
@ -92,7 +92,6 @@ mod bool {
|
|||
|
||||
#[test]
|
||||
fn should_permit_validity_expansion_and_reject_contraction() {
|
||||
let un = layout::Tree::<Def, !>::uninhabited();
|
||||
let b0 = layout::Tree::<Def, !>::from_bits(0);
|
||||
let b1 = layout::Tree::<Def, !>::from_bits(1);
|
||||
let b2 = layout::Tree::<Def, !>::from_bits(2);
|
||||
|
|
|
|||
|
|
@ -85,7 +85,22 @@ pub struct Hidden;
|
|||
pub use self::Hidden as InlinedHidden;
|
||||
```
|
||||
|
||||
The same applies on re-exports themselves: if you have multiple re-exports and some of them have
|
||||
However, if you still want the re-export itself to be visible, you can add the `#[doc(inline)]`
|
||||
attribute on it:
|
||||
|
||||
```rust,ignore (inline)
|
||||
// This struct won't be visible.
|
||||
#[doc(hidden)]
|
||||
pub struct Hidden;
|
||||
|
||||
#[doc(inline)]
|
||||
pub use self::Hidden as InlinedHidden;
|
||||
```
|
||||
|
||||
In this case, you will have `pub use self::Hidden as InlinedHidden;` in the generated documentation
|
||||
but no link to the `Hidden` item.
|
||||
|
||||
So back to `#[doc(hidden)]`: if you have multiple re-exports and some of them have
|
||||
`#[doc(hidden)]`, then these ones (and only these) won't appear in the documentation:
|
||||
|
||||
```rust,ignore (inline)
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ error[E0080]: evaluation of `PrintName::<i32>::VOID` failed
|
|||
--> tests/fail/erroneous_const.rs:LL:CC
|
||||
|
|
||||
LL | const VOID: ! = panic!();
|
||||
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', tests/fail/erroneous_const.rs:LL:CC
|
||||
| ^^^^^^^^ evaluation panicked: explicit panic
|
||||
|
|
||||
= note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
|
|
|
|||
|
|
@ -1019,7 +1019,11 @@ impl Rewrite for ast::Ty {
|
|||
}
|
||||
ast::TyKind::UnsafeBinder(ref binder) => {
|
||||
let mut result = String::new();
|
||||
if let Some(ref lifetime_str) =
|
||||
if binder.generic_params.is_empty() {
|
||||
// We always want to write `unsafe<>` since `unsafe<> Ty`
|
||||
// and `Ty` are distinct types.
|
||||
result.push_str("unsafe<> ")
|
||||
} else if let Some(ref lifetime_str) =
|
||||
rewrite_bound_params(context, shape, &binder.generic_params)
|
||||
{
|
||||
result.push_str("unsafe<");
|
||||
|
|
|
|||
|
|
@ -9,3 +9,6 @@ struct Foo {
|
|||
struct Bar(unsafe<'a> &'a ());
|
||||
|
||||
impl Trait for unsafe<'a> &'a () {}
|
||||
|
||||
fn empty()
|
||||
-> unsafe<> () {}
|
||||
|
|
|
|||
|
|
@ -7,3 +7,5 @@ struct Foo {
|
|||
struct Bar(unsafe<'a> &'a ());
|
||||
|
||||
impl Trait for unsafe<'a> &'a () {}
|
||||
|
||||
fn empty() -> unsafe<> () {}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ extern "Rust" {
|
|||
pub fn test_uninhabited_ret_by_ref() {
|
||||
// CHECK: %_1 = alloca [24 x i8], align {{8|4}}
|
||||
// CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %_1)
|
||||
// CHECK-NEXT: call void @opaque(ptr noalias nocapture noundef nonnull sret([24 x i8]) align {{8|4}} dereferenceable(24) %_1) #2
|
||||
// CHECK-NEXT: call void @opaque({{.*}} sret([24 x i8]) {{.*}} %_1) #2
|
||||
// CHECK-NEXT: unreachable
|
||||
unsafe {
|
||||
opaque();
|
||||
|
|
@ -36,7 +36,7 @@ pub fn test_uninhabited_ret_by_ref() {
|
|||
pub fn test_uninhabited_ret_by_ref_with_arg(rsi: u32) {
|
||||
// CHECK: %_2 = alloca [24 x i8], align {{8|4}}
|
||||
// CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %_2)
|
||||
// CHECK-NEXT: call void @opaque_with_arg(ptr noalias nocapture noundef nonnull sret([24 x i8]) align {{8|4}} dereferenceable(24) %_2, i32 noundef %rsi) #2
|
||||
// CHECK-NEXT: call void @opaque_with_arg({{.*}} sret([24 x i8]) {{.*}} %_2, i32 noundef %rsi) #2
|
||||
// CHECK-NEXT: unreachable
|
||||
unsafe {
|
||||
opaque_with_arg(rsi);
|
||||
|
|
|
|||
|
|
@ -1,15 +1,14 @@
|
|||
// Regression test for #81899.
|
||||
// The `panic!()` below is important to trigger the fixed ICE.
|
||||
|
||||
const _CONST: &[u8] = &f(&[], |_| {});
|
||||
const _CONST: &[u8] = &f(&[], |_| {}); //~ ERROR evaluation of constant value failed
|
||||
//~^ constant
|
||||
|
||||
const fn f<F>(_: &[u8], _: F) -> &[u8]
|
||||
where
|
||||
F: FnMut(&u8),
|
||||
{
|
||||
panic!() //~ ERROR evaluation of constant value failed
|
||||
//~^ panic
|
||||
panic!() //~ inside `f
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -1,19 +1,14 @@
|
|||
error[E0080]: evaluation of constant value failed
|
||||
--> $DIR/issue-81899.rs:11:5
|
||||
--> $DIR/issue-81899.rs:4:24
|
||||
|
|
||||
LL | panic!()
|
||||
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/issue-81899.rs:11:5
|
||||
LL | const _CONST: &[u8] = &f(&[], |_| {});
|
||||
| ^^^^^^^^^^^^^^ evaluation panicked: explicit panic
|
||||
|
|
||||
note: inside `f::<{closure@$DIR/issue-81899.rs:4:31: 4:34}>`
|
||||
--> $DIR/issue-81899.rs:11:5
|
||||
|
|
||||
LL | panic!()
|
||||
| ^^^^^^^^
|
||||
note: inside `_CONST`
|
||||
--> $DIR/issue-81899.rs:4:24
|
||||
|
|
||||
LL | const _CONST: &[u8] = &f(&[], |_| {});
|
||||
| ^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^ the failure occurred here
|
||||
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
note: erroneous constant encountered
|
||||
|
|
|
|||
|
|
@ -1,14 +1,13 @@
|
|||
// Regression test related to issue 88434
|
||||
|
||||
const _CONST: &() = &f(&|_| {});
|
||||
const _CONST: &() = &f(&|_| {}); //~ ERROR evaluation of constant value failed
|
||||
//~^ constant
|
||||
|
||||
const fn f<F>(_: &F)
|
||||
where
|
||||
F: FnMut(&u8),
|
||||
{
|
||||
panic!() //~ ERROR evaluation of constant value failed
|
||||
//~^ panic
|
||||
panic!() //~ inside `f
|
||||
}
|
||||
|
||||
fn main() { }
|
||||
|
|
|
|||
|
|
@ -1,19 +1,14 @@
|
|||
error[E0080]: evaluation of constant value failed
|
||||
--> $DIR/issue-88434-minimal-example.rs:10:5
|
||||
--> $DIR/issue-88434-minimal-example.rs:3:22
|
||||
|
|
||||
LL | panic!()
|
||||
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/issue-88434-minimal-example.rs:10:5
|
||||
LL | const _CONST: &() = &f(&|_| {});
|
||||
| ^^^^^^^^^^ evaluation panicked: explicit panic
|
||||
|
|
||||
note: inside `f::<{closure@$DIR/issue-88434-minimal-example.rs:3:25: 3:28}>`
|
||||
--> $DIR/issue-88434-minimal-example.rs:10:5
|
||||
|
|
||||
LL | panic!()
|
||||
| ^^^^^^^^
|
||||
note: inside `_CONST`
|
||||
--> $DIR/issue-88434-minimal-example.rs:3:22
|
||||
|
|
||||
LL | const _CONST: &() = &f(&|_| {});
|
||||
| ^^^^^^^^^^
|
||||
| ^^^^^^^^ the failure occurred here
|
||||
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
note: erroneous constant encountered
|
||||
|
|
|
|||
|
|
@ -1,14 +1,13 @@
|
|||
// Regression test for issue 88434
|
||||
|
||||
const _CONST: &[u8] = &f(&[], |_| {});
|
||||
const _CONST: &[u8] = &f(&[], |_| {}); //~ ERROR evaluation of constant value failed
|
||||
//~^ constant
|
||||
|
||||
const fn f<F>(_: &[u8], _: F) -> &[u8]
|
||||
where
|
||||
F: FnMut(&u8),
|
||||
{
|
||||
panic!() //~ ERROR evaluation of constant value failed
|
||||
//~^ panic
|
||||
panic!() //~ inside `f
|
||||
}
|
||||
|
||||
fn main() { }
|
||||
|
|
|
|||
|
|
@ -1,19 +1,14 @@
|
|||
error[E0080]: evaluation of constant value failed
|
||||
--> $DIR/issue-88434-removal-index-should-be-less.rs:10:5
|
||||
--> $DIR/issue-88434-removal-index-should-be-less.rs:3:24
|
||||
|
|
||||
LL | panic!()
|
||||
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/issue-88434-removal-index-should-be-less.rs:10:5
|
||||
LL | const _CONST: &[u8] = &f(&[], |_| {});
|
||||
| ^^^^^^^^^^^^^^ evaluation panicked: explicit panic
|
||||
|
|
||||
note: inside `f::<{closure@$DIR/issue-88434-removal-index-should-be-less.rs:3:31: 3:34}>`
|
||||
--> $DIR/issue-88434-removal-index-should-be-less.rs:10:5
|
||||
|
|
||||
LL | panic!()
|
||||
| ^^^^^^^^
|
||||
note: inside `_CONST`
|
||||
--> $DIR/issue-88434-removal-index-should-be-less.rs:3:24
|
||||
|
|
||||
LL | const _CONST: &[u8] = &f(&[], |_| {});
|
||||
| ^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^ the failure occurred here
|
||||
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
note: erroneous constant encountered
|
||||
|
|
|
|||
|
|
@ -2,13 +2,12 @@
|
|||
|
||||
pub trait ConstGenericTrait<const N: u32> {}
|
||||
|
||||
impl ConstGenericTrait<{my_fn(1)}> for () {}
|
||||
impl ConstGenericTrait<{my_fn(1)}> for () {} //~ ERROR E0080
|
||||
|
||||
impl ConstGenericTrait<{my_fn(2)}> for () {}
|
||||
impl ConstGenericTrait<{my_fn(2)}> for () {} //~ ERROR E0080
|
||||
|
||||
const fn my_fn(v: u32) -> u32 {
|
||||
panic!("Some error occurred"); //~ ERROR E0080
|
||||
//~| ERROR E0080
|
||||
panic!("Some error occurred");
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -1,37 +1,27 @@
|
|||
error[E0080]: evaluation of constant value failed
|
||||
--> $DIR/const-errs-dont-conflict-103369.rs:10:5
|
||||
|
|
||||
LL | panic!("Some error occurred");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'Some error occurred', $DIR/const-errs-dont-conflict-103369.rs:10:5
|
||||
|
|
||||
note: inside `my_fn`
|
||||
--> $DIR/const-errs-dont-conflict-103369.rs:10:5
|
||||
|
|
||||
LL | panic!("Some error occurred");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
note: inside `<() as ConstGenericTrait<{my_fn(1)}>>::{constant#0}`
|
||||
--> $DIR/const-errs-dont-conflict-103369.rs:5:25
|
||||
|
|
||||
LL | impl ConstGenericTrait<{my_fn(1)}> for () {}
|
||||
| ^^^^^^^^
|
||||
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error[E0080]: evaluation of constant value failed
|
||||
--> $DIR/const-errs-dont-conflict-103369.rs:10:5
|
||||
|
|
||||
LL | panic!("Some error occurred");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'Some error occurred', $DIR/const-errs-dont-conflict-103369.rs:10:5
|
||||
| ^^^^^^^^ evaluation panicked: Some error occurred
|
||||
|
|
||||
note: inside `my_fn`
|
||||
--> $DIR/const-errs-dont-conflict-103369.rs:10:5
|
||||
|
|
||||
LL | panic!("Some error occurred");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
note: inside `<() as ConstGenericTrait<{my_fn(2)}>>::{constant#0}`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the failure occurred here
|
||||
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error[E0080]: evaluation of constant value failed
|
||||
--> $DIR/const-errs-dont-conflict-103369.rs:7:25
|
||||
|
|
||||
LL | impl ConstGenericTrait<{my_fn(2)}> for () {}
|
||||
| ^^^^^^^^
|
||||
| ^^^^^^^^ evaluation panicked: Some error occurred
|
||||
|
|
||||
note: inside `my_fn`
|
||||
--> $DIR/const-errs-dont-conflict-103369.rs:10:5
|
||||
|
|
||||
LL | panic!("Some error occurred");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the failure occurred here
|
||||
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
|
|
|||
|
|
@ -3,16 +3,12 @@ error[E0770]: the type of const parameters must not depend on other generic para
|
|||
|
|
||||
LL | pub struct Dependent<const N: usize, const X: [u8; N]>([(); N]);
|
||||
| ^ the type must not depend on the parameter `N`
|
||||
|
|
||||
= note: const parameters may not be used in the type of const parameters
|
||||
|
||||
error[E0770]: the type of const parameters must not depend on other generic parameters
|
||||
--> $DIR/const-param-type-depends-on-const-param.rs:15:40
|
||||
|
|
||||
LL | pub struct SelfDependent<const N: [u8; N]>;
|
||||
| ^ the type must not depend on the parameter `N`
|
||||
|
|
||||
= note: const parameters may not be used in the type of const parameters
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -3,16 +3,12 @@ error[E0770]: the type of const parameters must not depend on other generic para
|
|||
|
|
||||
LL | pub struct Dependent<const N: usize, const X: [u8; N]>([(); N]);
|
||||
| ^ the type must not depend on the parameter `N`
|
||||
|
|
||||
= note: const parameters may not be used in the type of const parameters
|
||||
|
||||
error[E0770]: the type of const parameters must not depend on other generic parameters
|
||||
--> $DIR/const-param-type-depends-on-const-param.rs:15:40
|
||||
|
|
||||
LL | pub struct SelfDependent<const N: [u8; N]>;
|
||||
| ^ the type must not depend on the parameter `N`
|
||||
|
|
||||
= note: const parameters may not be used in the type of const parameters
|
||||
|
||||
error: `[u8; N]` is forbidden as the type of a const generic parameter
|
||||
--> $DIR/const-param-type-depends-on-const-param.rs:11:47
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@ error[E0770]: the type of const parameters must not depend on other generic para
|
|||
|
|
||||
LL | struct B<T, const N: T>(PhantomData<[T; N]>);
|
||||
| ^ the type must not depend on the parameter `T`
|
||||
|
|
||||
= note: type parameters may not be used in the type of const parameters
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@ error[E0770]: the type of const parameters must not depend on other generic para
|
|||
|
|
||||
LL | pub struct Dependent<T, const X: T>([(); X]);
|
||||
| ^ the type must not depend on the parameter `T`
|
||||
|
|
||||
= note: type parameters may not be used in the type of const parameters
|
||||
|
||||
error[E0392]: type parameter `T` is never used
|
||||
--> $DIR/const-param-type-depends-on-type-param.rs:11:22
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@ error[E0770]: the type of const parameters must not depend on other generic para
|
|||
|
|
||||
LL | pub struct Dependent<T, const X: T>([(); X]);
|
||||
| ^ the type must not depend on the parameter `T`
|
||||
|
|
||||
= note: type parameters may not be used in the type of const parameters
|
||||
|
||||
error[E0392]: type parameter `T` is never used
|
||||
--> $DIR/const-param-type-depends-on-type-param.rs:11:22
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
#![feature(
|
||||
adt_const_params,
|
||||
unsized_const_params,
|
||||
generic_const_parameter_types,
|
||||
generic_arg_infer
|
||||
)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
use std::marker::ConstParamTy_;
|
||||
|
||||
fn foo<T: ConstParamTy_, const N: usize, const M: [T; N]>() -> [T; N] {
|
||||
loop {}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// Requires inferring `T`/`N` from `12_u8` and `2` respectively.
|
||||
let a = foo::<_, _, { [12_u8; 2] }>();
|
||||
//~^ ERROR: anonymous constants with inferred types are not yet supported
|
||||
|
||||
// Requires inferring `T`/`N`/`12_?i`/`_` from `[u8; 2]`
|
||||
let b: [u8; 2] = foo::<_, _, { [12; _] }>();
|
||||
//~^ ERROR: anonymous constants with inferred types are not yet supported
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
error: anonymous constants with inferred types are not yet supported
|
||||
--> $DIR/bad_inference.rs:17:25
|
||||
|
|
||||
LL | let a = foo::<_, _, { [12_u8; 2] }>();
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: anonymous constants with inferred types are not yet supported
|
||||
--> $DIR/bad_inference.rs:21:34
|
||||
|
|
||||
LL | let b: [u8; 2] = foo::<_, _, { [12; _] }>();
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
//@ check-pass
|
||||
|
||||
#![feature(
|
||||
adt_const_params,
|
||||
unsized_const_params,
|
||||
generic_const_parameter_types,
|
||||
generic_arg_infer
|
||||
)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
use std::marker::ConstParamTy_;
|
||||
|
||||
fn foo<T: ConstParamTy_, const N: usize, const M: [T; N]>() -> [T; N] {
|
||||
M
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let a: [u8; 2] = foo::<u8, 2, { [12; _] }>();
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
#![feature(adt_const_params, generic_const_parameter_types)]
|
||||
#![expect(incomplete_features)]
|
||||
|
||||
use std::marker::PhantomData;
|
||||
|
||||
struct UsesConst<const N: [u8; M], const M: usize>;
|
||||
//~^ ERROR: the type of const parameters must not depend on other generic parameters
|
||||
struct UsesType<const N: [T; 2], T>(PhantomData<T>);
|
||||
//~^ ERROR: the type of const parameters must not depend on other generic parameters
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
error[E0770]: the type of const parameters must not depend on other generic parameters
|
||||
--> $DIR/forward_declared_type.rs:6:32
|
||||
|
|
||||
LL | struct UsesConst<const N: [u8; M], const M: usize>;
|
||||
| ^ the type must not depend on the parameter `M`
|
||||
|
||||
error[E0770]: the type of const parameters must not depend on other generic parameters
|
||||
--> $DIR/forward_declared_type.rs:8:27
|
||||
|
|
||||
LL | struct UsesType<const N: [T; 2], T>(PhantomData<T>);
|
||||
| ^ the type must not depend on the parameter `T`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0770`.
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
//@ check-pass
|
||||
|
||||
#![feature(adt_const_params, generic_arg_infer, generic_const_parameter_types)]
|
||||
#![expect(incomplete_features)]
|
||||
|
||||
struct Bar<const N: usize, const M: [u8; N]>;
|
||||
|
||||
fn foo<const N: usize, const M: [u8; N]>(_: Bar<N, M>) {}
|
||||
|
||||
fn main() {
|
||||
foo(Bar::<2, { [1; 2] }>);
|
||||
foo::<_, _>(Bar::<2, { [1; 2] }>);
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
#![feature(generic_const_parameter_types, adt_const_params, unsized_const_params)]
|
||||
#![expect(incomplete_features)]
|
||||
|
||||
fn foo<'a, const N: &'a u32>() {}
|
||||
|
||||
fn bar() {
|
||||
foo::<'static, { &1_u32 }>();
|
||||
//~^ ERROR: anonymous constants with lifetimes in their type are not yet supported
|
||||
foo::<'_, { &1_u32 }>();
|
||||
//~^ ERROR: anonymous constants with lifetimes in their type are not yet supported
|
||||
}
|
||||
|
||||
fn borrowck<'a, const N: &'static u32, const M: &'a u32>() {
|
||||
foo::<'a, M>();
|
||||
foo::<'static, M>();
|
||||
//~^ ERROR: lifetime may not live long enough
|
||||
foo::<'static, N>();
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
error: anonymous constants with lifetimes in their type are not yet supported
|
||||
--> $DIR/lifetime_dependent_const_param.rs:7:20
|
||||
|
|
||||
LL | foo::<'static, { &1_u32 }>();
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: anonymous constants with lifetimes in their type are not yet supported
|
||||
--> $DIR/lifetime_dependent_const_param.rs:9:15
|
||||
|
|
||||
LL | foo::<'_, { &1_u32 }>();
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: lifetime may not live long enough
|
||||
--> $DIR/lifetime_dependent_const_param.rs:15:5
|
||||
|
|
||||
LL | fn borrowck<'a, const N: &'static u32, const M: &'a u32>() {
|
||||
| -- lifetime `'a` defined here
|
||||
LL | foo::<'a, M>();
|
||||
LL | foo::<'static, M>();
|
||||
| ^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
#![feature(adt_const_params, unsized_const_params, generic_const_parameter_types)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
use std::marker::ConstParamTy_;
|
||||
|
||||
fn foo<const N: usize, const M: [u8; N]>() {}
|
||||
fn bar<T: ConstParamTy_, const M: [T; 2]>() {}
|
||||
|
||||
fn main() {
|
||||
foo::<3, { [1; 2] }>();
|
||||
//~^ ERROR: mismatched type
|
||||
|
||||
bar::<u8, { [2_u16; 2] }>();
|
||||
//~^ ERROR: mismatched type
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
error[E0308]: mismatched types
|
||||
--> $DIR/mismatched_args_with_value.rs:10:16
|
||||
|
|
||||
LL | foo::<3, { [1; 2] }>();
|
||||
| ^^^^^^ expected an array with a size of 3, found one with a size of 2
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/mismatched_args_with_value.rs:13:18
|
||||
|
|
||||
LL | bar::<u8, { [2_u16; 2] }>();
|
||||
| ^^^^^ expected `u8`, found `u16`
|
||||
|
|
||||
help: change the type of the numeric literal from `u16` to `u8`
|
||||
|
|
||||
LL - bar::<u8, { [2_u16; 2] }>();
|
||||
LL + bar::<u8, { [2_u8; 2] }>();
|
||||
|
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
#![feature(adt_const_params, unsized_const_params, generic_const_parameter_types)]
|
||||
#![expect(incomplete_features)]
|
||||
|
||||
use std::marker::{ConstParamTy_, PhantomData};
|
||||
|
||||
struct UsesType<T, const N: usize, const M: [T; N]>(PhantomData<T>);
|
||||
//~^ ERROR: `[T; N]` can't be used as a const parameter type
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
error[E0741]: `[T; N]` can't be used as a const parameter type
|
||||
--> $DIR/no_const_param_ty_bound.rs:6:45
|
||||
|
|
||||
LL | struct UsesType<T, const N: usize, const M: [T; N]>(PhantomData<T>);
|
||||
| ^^^^^^
|
||||
|
|
||||
= note: `T` must implement `UnsizedConstParamTy`, but it does not
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0741`.
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
//@ check-pass
|
||||
|
||||
#![feature(
|
||||
adt_const_params,
|
||||
unsized_const_params,
|
||||
generic_const_parameter_types,
|
||||
generic_arg_infer
|
||||
)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
use std::marker::ConstParamTy_;
|
||||
|
||||
fn foo<U, T: ConstParamTy_, const N: usize, const M: [T; N]>(_: U) -> [T; N] {
|
||||
loop {}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// Check that `_` doesnt cause a "Type of const argument is uninferred" error
|
||||
// as it is not actually used by the type of `M`.
|
||||
let a = foo::<_, u8, 2, { [12; _] }>(true);
|
||||
}
|
||||
|
|
@ -6,15 +6,14 @@ struct T<const B: &'static bool>;
|
|||
impl<const B: &'static bool> T<B> {
|
||||
const fn set_false(&self) {
|
||||
unsafe {
|
||||
*(B as *const bool as *mut bool) = false;
|
||||
//~^ ERROR evaluation of constant value failed [E0080]
|
||||
*(B as *const bool as *mut bool) = false; //~ inside `T
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const _: () = {
|
||||
let x = T::<{ &true }>;
|
||||
x.set_false();
|
||||
x.set_false(); //~ ERROR evaluation of constant value failed [E0080]
|
||||
};
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -1,19 +1,14 @@
|
|||
error[E0080]: evaluation of constant value failed
|
||||
--> $DIR/issue-100313.rs:9:13
|
||||
--> $DIR/issue-100313.rs:16:5
|
||||
|
|
||||
LL | *(B as *const bool as *mut bool) = false;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ writing to ALLOC0 which is read-only
|
||||
LL | x.set_false();
|
||||
| ^^^^^^^^^^^^^ writing to ALLOC0 which is read-only
|
||||
|
|
||||
note: inside `T::<&true>::set_false`
|
||||
--> $DIR/issue-100313.rs:9:13
|
||||
|
|
||||
LL | *(B as *const bool as *mut bool) = false;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
note: inside `_`
|
||||
--> $DIR/issue-100313.rs:17:5
|
||||
|
|
||||
LL | x.set_false();
|
||||
| ^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the failure occurred here
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@ error[E0770]: the type of const parameters must not depend on other generic para
|
|||
|
|
||||
LL | struct Bug<'a, const S: &'a str>(PhantomData<&'a ()>);
|
||||
| ^^ the type must not depend on the parameter `'a`
|
||||
|
|
||||
= note: lifetime parameters may not be used in the type of const parameters
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@ error[E0770]: the type of const parameters must not depend on other generic para
|
|||
|
|
||||
LL | struct Bug<'a, const S: &'a str>(PhantomData<&'a ()>);
|
||||
| ^^ the type must not depend on the parameter `'a`
|
||||
|
|
||||
= note: lifetime parameters may not be used in the type of const parameters
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@ error[E0770]: the type of const parameters must not depend on other generic para
|
|||
|
|
||||
LL | fn foo<const N: usize, const A: [u8; N]>() {}
|
||||
| ^ the type must not depend on the parameter `N`
|
||||
|
|
||||
= note: const parameters may not be used in the type of const parameters
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@ error[E0770]: the type of const parameters must not depend on other generic para
|
|||
|
|
||||
LL | fn foo<const N: usize, const A: [u8; N]>() {}
|
||||
| ^ the type must not depend on the parameter `N`
|
||||
|
|
||||
= note: const parameters may not be used in the type of const parameters
|
||||
|
||||
error: `[u8; N]` is forbidden as the type of a const generic parameter
|
||||
--> $DIR/issue-62878.rs:5:33
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@ error[E0770]: the type of const parameters must not depend on other generic para
|
|||
|
|
||||
LL | fn foo<const LEN: usize, const DATA: [u8; LEN]>() {}
|
||||
| ^^^ the type must not depend on the parameter `LEN`
|
||||
|
|
||||
= note: const parameters may not be used in the type of const parameters
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@ error[E0770]: the type of const parameters must not depend on other generic para
|
|||
|
|
||||
LL | fn foo<const LEN: usize, const DATA: [u8; LEN]>() {}
|
||||
| ^^^ the type must not depend on the parameter `LEN`
|
||||
|
|
||||
= note: const parameters may not be used in the type of const parameters
|
||||
|
||||
error: `[u8; LEN]` is forbidden as the type of a const generic parameter
|
||||
--> $DIR/issue-71169.rs:5:38
|
||||
|
|
|
|||
|
|
@ -3,16 +3,12 @@ error[E0770]: the type of const parameters must not depend on other generic para
|
|||
|
|
||||
LL | pub fn call_me<Args: Sized, const IDX: usize, const FN: unsafe extern "C" fn(Args)>(&self) {
|
||||
| ^^^^ the type must not depend on the parameter `Args`
|
||||
|
|
||||
= note: type parameters may not be used in the type of const parameters
|
||||
|
||||
error[E0770]: the type of const parameters must not depend on other generic parameters
|
||||
--> $DIR/issue-71381.rs:23:40
|
||||
|
|
||||
LL | const FN: unsafe extern "C" fn(Args),
|
||||
| ^^^^ the type must not depend on the parameter `Args`
|
||||
|
|
||||
= note: type parameters may not be used in the type of const parameters
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -3,16 +3,12 @@ error[E0770]: the type of const parameters must not depend on other generic para
|
|||
|
|
||||
LL | pub fn call_me<Args: Sized, const IDX: usize, const FN: unsafe extern "C" fn(Args)>(&self) {
|
||||
| ^^^^ the type must not depend on the parameter `Args`
|
||||
|
|
||||
= note: type parameters may not be used in the type of const parameters
|
||||
|
||||
error[E0770]: the type of const parameters must not depend on other generic parameters
|
||||
--> $DIR/issue-71381.rs:23:40
|
||||
|
|
||||
LL | const FN: unsafe extern "C" fn(Args),
|
||||
| ^^^^ the type must not depend on the parameter `Args`
|
||||
|
|
||||
= note: type parameters may not be used in the type of const parameters
|
||||
|
||||
error: using function pointers as const generic parameters is forbidden
|
||||
--> $DIR/issue-71381.rs:14:61
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@ error[E0770]: the type of const parameters must not depend on other generic para
|
|||
|
|
||||
LL | fn func<A, const F: fn(inner: A)>(outer: A) {
|
||||
| ^ the type must not depend on the parameter `A`
|
||||
|
|
||||
= note: type parameters may not be used in the type of const parameters
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@ error[E0770]: the type of const parameters must not depend on other generic para
|
|||
|
|
||||
LL | fn func<A, const F: fn(inner: A)>(outer: A) {
|
||||
| ^ the type must not depend on the parameter `A`
|
||||
|
|
||||
= note: type parameters may not be used in the type of const parameters
|
||||
|
||||
error: using function pointers as const generic parameters is forbidden
|
||||
--> $DIR/issue-71611.rs:5:21
|
||||
|
|
|
|||
|
|
@ -3,16 +3,12 @@ error[E0770]: the type of const parameters must not depend on other generic para
|
|||
|
|
||||
LL | struct Range<T: PartialOrd, const MIN: T, const MAX: T>(T)
|
||||
| ^ the type must not depend on the parameter `T`
|
||||
|
|
||||
= note: type parameters may not be used in the type of const parameters
|
||||
|
||||
error[E0770]: the type of const parameters must not depend on other generic parameters
|
||||
--> $DIR/issue-88997.rs:8:54
|
||||
|
|
||||
LL | struct Range<T: PartialOrd, const MIN: T, const MAX: T>(T)
|
||||
| ^ the type must not depend on the parameter `T`
|
||||
|
|
||||
= note: type parameters may not be used in the type of const parameters
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@ error[E0770]: the type of const parameters must not depend on other generic para
|
|||
|
|
||||
LL | pub struct Foo<T, const H: T>(T)
|
||||
| ^ the type must not depend on the parameter `T`
|
||||
|
|
||||
= note: type parameters may not be used in the type of const parameters
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -48,9 +48,11 @@ pub static S8: &[u64] = unsafe {
|
|||
pub static R0: &[u32] = unsafe { from_ptr_range(ptr::null()..ptr::null()) };
|
||||
//~^ ERROR it is undefined behavior to use this value
|
||||
pub static R1: &[()] = unsafe { from_ptr_range(ptr::null()..ptr::null()) }; // errors inside libcore
|
||||
//~^ ERROR could not evaluate static initializer
|
||||
pub static R2: &[u32] = unsafe {
|
||||
let ptr = &D0 as *const u32;
|
||||
from_ptr_range(ptr..ptr.add(2)) // errors inside libcore
|
||||
//~^ ERROR could not evaluate static initializer
|
||||
};
|
||||
pub static R4: &[u8] = unsafe {
|
||||
//~^ ERROR: it is undefined behavior to use this value
|
||||
|
|
@ -74,13 +76,16 @@ pub static R7: &[u16] = unsafe {
|
|||
};
|
||||
pub static R8: &[u64] = unsafe {
|
||||
let ptr = (&D4 as *const [u32; 2] as *const u32).byte_add(1).cast::<u64>();
|
||||
from_ptr_range(ptr..ptr.add(1)) //~ inside `R8`
|
||||
from_ptr_range(ptr..ptr.add(1))
|
||||
//~^ ERROR could not evaluate static initializer
|
||||
};
|
||||
|
||||
// This is sneaky: &D0 and &D0 point to different objects
|
||||
// (even if at runtime they have the same address)
|
||||
pub static R9: &[u32] = unsafe { from_ptr_range(&D0..(&D0 as *const u32).add(1)) };
|
||||
//~^ ERROR could not evaluate static initializer
|
||||
pub static R10: &[u32] = unsafe { from_ptr_range(&D0..&D0) };
|
||||
//~^ ERROR could not evaluate static initializer
|
||||
|
||||
const D0: u32 = 0x11111111; // Constant chosen for endianness-independent behavior.
|
||||
const D1: MaybeUninit<&u32> = MaybeUninit::uninit();
|
||||
|
|
|
|||
|
|
@ -100,36 +100,28 @@ LL | pub static R0: &[u32] = unsafe { from_ptr_range(ptr::null()..ptr::null()) }
|
|||
}
|
||||
|
||||
error[E0080]: could not evaluate static initializer
|
||||
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
||||
|
|
||||
= note: the evaluated program panicked at 'assertion failed: 0 < pointee_size && pointee_size <= isize::MAX as usize', $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
||||
|
|
||||
note: inside `std::ptr::const_ptr::<impl *const ()>::offset_from_unsigned`
|
||||
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
||||
note: inside `from_ptr_range::<'_, ()>`
|
||||
--> $SRC_DIR/core/src/slice/raw.rs:LL:COL
|
||||
note: inside `R1`
|
||||
--> $DIR/forbidden_slices.rs:50:33
|
||||
|
|
||||
LL | pub static R1: &[()] = unsafe { from_ptr_range(ptr::null()..ptr::null()) }; // errors inside libcore
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation panicked: assertion failed: 0 < pointee_size && pointee_size <= isize::MAX as usize
|
||||
|
|
||||
note: inside `from_ptr_range::<'_, ()>`
|
||||
--> $SRC_DIR/core/src/slice/raw.rs:LL:COL
|
||||
note: inside `std::ptr::const_ptr::<impl *const ()>::offset_from_unsigned`
|
||||
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
||||
= note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error[E0080]: could not evaluate static initializer
|
||||
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
||||
--> $DIR/forbidden_slices.rs:54:25
|
||||
|
|
||||
= note: out-of-bounds pointer arithmetic: expected a pointer to 8 bytes of memory, but got ALLOC10 which is only 4 bytes from the end of the allocation
|
||||
LL | from_ptr_range(ptr..ptr.add(2)) // errors inside libcore
|
||||
| ^^^^^^^^^^ out-of-bounds pointer arithmetic: expected a pointer to 8 bytes of memory, but got ALLOC10 which is only 4 bytes from the end of the allocation
|
||||
|
|
||||
note: inside `std::ptr::const_ptr::<impl *const u32>::add`
|
||||
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
||||
note: inside `R2`
|
||||
--> $DIR/forbidden_slices.rs:53:25
|
||||
|
|
||||
LL | from_ptr_range(ptr..ptr.add(2)) // errors inside libcore
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error[E0080]: it is undefined behavior to use this value
|
||||
--> $DIR/forbidden_slices.rs:55:1
|
||||
--> $DIR/forbidden_slices.rs:57:1
|
||||
|
|
||||
LL | pub static R4: &[u8] = unsafe {
|
||||
| ^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered uninitialized memory, but expected an integer
|
||||
|
|
@ -140,7 +132,7 @@ LL | pub static R4: &[u8] = unsafe {
|
|||
}
|
||||
|
||||
error[E0080]: it is undefined behavior to use this value
|
||||
--> $DIR/forbidden_slices.rs:60:1
|
||||
--> $DIR/forbidden_slices.rs:62:1
|
||||
|
|
||||
LL | pub static R5: &[u8] = unsafe {
|
||||
| ^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered a pointer, but expected an integer
|
||||
|
|
@ -153,7 +145,7 @@ LL | pub static R5: &[u8] = unsafe {
|
|||
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
|
||||
|
||||
error[E0080]: it is undefined behavior to use this value
|
||||
--> $DIR/forbidden_slices.rs:65:1
|
||||
--> $DIR/forbidden_slices.rs:67:1
|
||||
|
|
||||
LL | pub static R6: &[bool] = unsafe {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered 0x11, but expected a boolean
|
||||
|
|
@ -164,7 +156,7 @@ LL | pub static R6: &[bool] = unsafe {
|
|||
}
|
||||
|
||||
error[E0080]: it is undefined behavior to use this value
|
||||
--> $DIR/forbidden_slices.rs:70:1
|
||||
--> $DIR/forbidden_slices.rs:72:1
|
||||
|
|
||||
LL | pub static R7: &[u16] = unsafe {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered an unaligned reference (required 2 byte alignment but found 1)
|
||||
|
|
@ -175,47 +167,35 @@ LL | pub static R7: &[u16] = unsafe {
|
|||
}
|
||||
|
||||
error[E0080]: could not evaluate static initializer
|
||||
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
||||
--> $DIR/forbidden_slices.rs:79:25
|
||||
|
|
||||
= note: out-of-bounds pointer arithmetic: expected a pointer to 8 bytes of memory, but got ALLOC11+0x1 which is only 7 bytes from the end of the allocation
|
||||
LL | from_ptr_range(ptr..ptr.add(1))
|
||||
| ^^^^^^^^^^ out-of-bounds pointer arithmetic: expected a pointer to 8 bytes of memory, but got ALLOC11+0x1 which is only 7 bytes from the end of the allocation
|
||||
|
|
||||
note: inside `std::ptr::const_ptr::<impl *const u64>::add`
|
||||
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
||||
note: inside `R8`
|
||||
--> $DIR/forbidden_slices.rs:77:25
|
||||
|
|
||||
LL | from_ptr_range(ptr..ptr.add(1))
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error[E0080]: could not evaluate static initializer
|
||||
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
||||
|
|
||||
= note: `ptr_offset_from_unsigned` called on two different pointers that are not both derived from the same allocation
|
||||
|
|
||||
note: inside `std::ptr::const_ptr::<impl *const u32>::offset_from_unsigned`
|
||||
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
||||
note: inside `from_ptr_range::<'_, u32>`
|
||||
--> $SRC_DIR/core/src/slice/raw.rs:LL:COL
|
||||
note: inside `R9`
|
||||
--> $DIR/forbidden_slices.rs:82:34
|
||||
--> $DIR/forbidden_slices.rs:85:34
|
||||
|
|
||||
LL | pub static R9: &[u32] = unsafe { from_ptr_range(&D0..(&D0 as *const u32).add(1)) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0080]: could not evaluate static initializer
|
||||
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `ptr_offset_from_unsigned` called on two different pointers that are not both derived from the same allocation
|
||||
|
|
||||
= note: `ptr_offset_from_unsigned` called on two different pointers that are not both derived from the same allocation
|
||||
|
|
||||
note: inside `std::ptr::const_ptr::<impl *const u32>::offset_from_unsigned`
|
||||
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
||||
note: inside `from_ptr_range::<'_, u32>`
|
||||
--> $SRC_DIR/core/src/slice/raw.rs:LL:COL
|
||||
note: inside `R10`
|
||||
--> $DIR/forbidden_slices.rs:83:35
|
||||
note: inside `std::ptr::const_ptr::<impl *const u32>::offset_from_unsigned`
|
||||
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
||||
|
||||
error[E0080]: could not evaluate static initializer
|
||||
--> $DIR/forbidden_slices.rs:87:35
|
||||
|
|
||||
LL | pub static R10: &[u32] = unsafe { from_ptr_range(&D0..&D0) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ `ptr_offset_from_unsigned` called on two different pointers that are not both derived from the same allocation
|
||||
|
|
||||
note: inside `from_ptr_range::<'_, u32>`
|
||||
--> $SRC_DIR/core/src/slice/raw.rs:LL:COL
|
||||
note: inside `std::ptr::const_ptr::<impl *const u32>::offset_from_unsigned`
|
||||
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
||||
|
||||
error: aborting due to 18 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -1,45 +1,33 @@
|
|||
error[E0080]: evaluation of constant value failed
|
||||
--> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
|
||||
|
|
||||
= note: memory access failed: expected a pointer to 4 bytes of memory, but got ALLOC0+0x4 which is at or beyond the end of the allocation of size 4 bytes
|
||||
|
|
||||
note: inside `std::ptr::read::<u32>`
|
||||
--> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
|
||||
note: inside `_READ`
|
||||
--> $DIR/out_of_bounds_read.rs:10:33
|
||||
|
|
||||
LL | const _READ: u32 = unsafe { ptr::read(PAST_END_PTR) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0080]: evaluation of constant value failed
|
||||
--> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
|
||||
|
|
||||
= note: memory access failed: expected a pointer to 4 bytes of memory, but got ALLOC0+0x4 which is at or beyond the end of the allocation of size 4 bytes
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: expected a pointer to 4 bytes of memory, but got ALLOC0+0x4 which is at or beyond the end of the allocation of size 4 bytes
|
||||
|
|
||||
note: inside `std::ptr::read::<u32>`
|
||||
--> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
|
||||
note: inside `std::ptr::const_ptr::<impl *const u32>::read`
|
||||
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
||||
note: inside `_CONST_READ`
|
||||
|
||||
error[E0080]: evaluation of constant value failed
|
||||
--> $DIR/out_of_bounds_read.rs:11:39
|
||||
|
|
||||
LL | const _CONST_READ: u32 = unsafe { PAST_END_PTR.read() };
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0080]: evaluation of constant value failed
|
||||
--> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
|
||||
|
|
||||
= note: memory access failed: expected a pointer to 4 bytes of memory, but got ALLOC0+0x4 which is at or beyond the end of the allocation of size 4 bytes
|
||||
| ^^^^^^^^^^^^^^^^^^^ memory access failed: expected a pointer to 4 bytes of memory, but got ALLOC0+0x4 which is at or beyond the end of the allocation of size 4 bytes
|
||||
|
|
||||
note: inside `std::ptr::const_ptr::<impl *const u32>::read`
|
||||
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
||||
note: inside `std::ptr::read::<u32>`
|
||||
--> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
|
||||
note: inside `std::ptr::mut_ptr::<impl *mut u32>::read`
|
||||
--> $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
|
||||
note: inside `_MUT_READ`
|
||||
|
||||
error[E0080]: evaluation of constant value failed
|
||||
--> $DIR/out_of_bounds_read.rs:12:37
|
||||
|
|
||||
LL | const _MUT_READ: u32 = unsafe { (PAST_END_PTR as *mut u32).read() };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: expected a pointer to 4 bytes of memory, but got ALLOC0+0x4 which is at or beyond the end of the allocation of size 4 bytes
|
||||
|
|
||||
note: inside `std::ptr::mut_ptr::<impl *mut u32>::read`
|
||||
--> $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
|
||||
note: inside `std::ptr::read::<u32>`
|
||||
--> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -2,19 +2,19 @@ error[E0080]: evaluation of constant value failed
|
|||
--> $DIR/assert-type-intrinsics.rs:11:9
|
||||
|
|
||||
LL | MaybeUninit::<!>::uninit().assume_init();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'aborted execution: attempted to instantiate uninhabited type `!`', $DIR/assert-type-intrinsics.rs:11:36
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation panicked: aborted execution: attempted to instantiate uninhabited type `!`
|
||||
|
||||
error[E0080]: evaluation of constant value failed
|
||||
--> $DIR/assert-type-intrinsics.rs:15:9
|
||||
|
|
||||
LL | intrinsics::assert_mem_uninitialized_valid::<&'static i32>();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'aborted execution: attempted to leave type `&i32` uninitialized, which is invalid', $DIR/assert-type-intrinsics.rs:15:9
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation panicked: aborted execution: attempted to leave type `&i32` uninitialized, which is invalid
|
||||
|
||||
error[E0080]: evaluation of constant value failed
|
||||
--> $DIR/assert-type-intrinsics.rs:19:9
|
||||
|
|
||||
LL | intrinsics::assert_zero_valid::<&'static i32>();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'aborted execution: attempted to zero-initialize type `&i32`, which is invalid', $DIR/assert-type-intrinsics.rs:19:9
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation panicked: aborted execution: attempted to zero-initialize type `&i32`, which is invalid
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -7,12 +7,18 @@ const X: fn(usize) -> usize = double;
|
|||
|
||||
const fn bar(x: fn(usize) -> usize, y: usize) -> usize {
|
||||
x(y)
|
||||
//~^ ERROR evaluation of constant value failed
|
||||
//~| ERROR evaluation of constant value failed
|
||||
//~^ NOTE inside `bar`
|
||||
//~| NOTE the failure occurred here
|
||||
//~| NOTE inside `bar`
|
||||
//~| NOTE the failure occurred here
|
||||
}
|
||||
|
||||
const Y: usize = bar(X, 2); // FIXME: should fail to typeck someday
|
||||
//~^ ERROR evaluation of constant value failed
|
||||
//~| NOTE calling non-const function `double`
|
||||
const Z: usize = bar(double, 2); // FIXME: should fail to typeck someday
|
||||
//~^ ERROR evaluation of constant value failed
|
||||
//~| NOTE calling non-const function `double`
|
||||
|
||||
fn main() {
|
||||
assert_eq!(Y, 4);
|
||||
|
|
|
|||
|
|
@ -1,36 +1,26 @@
|
|||
error[E0080]: evaluation of constant value failed
|
||||
--> $DIR/const_fn_ptr_fail2.rs:9:5
|
||||
|
|
||||
LL | x(y)
|
||||
| ^^^^ calling non-const function `double`
|
||||
|
|
||||
note: inside `bar`
|
||||
--> $DIR/const_fn_ptr_fail2.rs:9:5
|
||||
|
|
||||
LL | x(y)
|
||||
| ^^^^
|
||||
note: inside `Y`
|
||||
--> $DIR/const_fn_ptr_fail2.rs:14:18
|
||||
--> $DIR/const_fn_ptr_fail2.rs:16:18
|
||||
|
|
||||
LL | const Y: usize = bar(X, 2); // FIXME: should fail to typeck someday
|
||||
| ^^^^^^^^^
|
||||
|
||||
error[E0080]: evaluation of constant value failed
|
||||
--> $DIR/const_fn_ptr_fail2.rs:9:5
|
||||
|
|
||||
LL | x(y)
|
||||
| ^^^^ calling non-const function `double`
|
||||
| ^^^^^^^^^ calling non-const function `double`
|
||||
|
|
||||
note: inside `bar`
|
||||
--> $DIR/const_fn_ptr_fail2.rs:9:5
|
||||
|
|
||||
LL | x(y)
|
||||
| ^^^^
|
||||
note: inside `Z`
|
||||
--> $DIR/const_fn_ptr_fail2.rs:15:18
|
||||
| ^^^^ the failure occurred here
|
||||
|
||||
error[E0080]: evaluation of constant value failed
|
||||
--> $DIR/const_fn_ptr_fail2.rs:19:18
|
||||
|
|
||||
LL | const Z: usize = bar(double, 2); // FIXME: should fail to typeck someday
|
||||
| ^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^^ calling non-const function `double`
|
||||
|
|
||||
note: inside `bar`
|
||||
--> $DIR/const_fn_ptr_fail2.rs:9:5
|
||||
|
|
||||
LL | x(y)
|
||||
| ^^^^ the failure occurred here
|
||||
|
||||
warning: skipping const checks
|
||||
|
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ error[E0080]: evaluation of constant value failed
|
|||
--> $DIR/const_panic-normalize-tabs-115498.rs:3:17
|
||||
|
|
||||
LL | struct Bug([u8; panic!{"\t"}]);
|
||||
| ^^^^^^^^^^^^ the evaluated program panicked at ' ', $DIR/const_panic-normalize-tabs-115498.rs:3:17
|
||||
| ^^^^^^^^^^^^ evaluation panicked:
|
||||
|
|
||||
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ error[E0080]: evaluation of constant value failed
|
|||
--> $DIR/const_panic.rs:6:15
|
||||
|
|
||||
LL | const Z: () = std::panic!("cheese");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'cheese', $DIR/const_panic.rs:6:15
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ evaluation panicked: cheese
|
||||
|
|
||||
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `std::panic` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
|
|
@ -10,7 +10,7 @@ error[E0080]: evaluation of constant value failed
|
|||
--> $DIR/const_panic.rs:9:16
|
||||
|
|
||||
LL | const Z2: () = std::panic!();
|
||||
| ^^^^^^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/const_panic.rs:9:16
|
||||
| ^^^^^^^^^^^^^ evaluation panicked: explicit panic
|
||||
|
|
||||
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `std::panic` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
|
|
@ -18,7 +18,7 @@ error[E0080]: evaluation of constant value failed
|
|||
--> $DIR/const_panic.rs:12:15
|
||||
|
|
||||
LL | const Y: () = std::unreachable!();
|
||||
| ^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic.rs:12:15
|
||||
| ^^^^^^^^^^^^^^^^^^^ evaluation panicked: internal error: entered unreachable code
|
||||
|
|
||||
= note: this error originates in the macro `$crate::panic::unreachable_2015` which comes from the expansion of the macro `std::unreachable` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
|
|
@ -26,7 +26,7 @@ error[E0080]: evaluation of constant value failed
|
|||
--> $DIR/const_panic.rs:15:15
|
||||
|
|
||||
LL | const X: () = std::unimplemented!();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'not implemented', $DIR/const_panic.rs:15:15
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ evaluation panicked: not implemented
|
||||
|
|
||||
= note: this error originates in the macro `std::unimplemented` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
|
|
@ -34,7 +34,7 @@ error[E0080]: evaluation of constant value failed
|
|||
--> $DIR/const_panic.rs:18:15
|
||||
|
|
||||
LL | const W: () = std::panic!(MSG);
|
||||
| ^^^^^^^^^^^^^^^^ the evaluated program panicked at 'hello', $DIR/const_panic.rs:18:15
|
||||
| ^^^^^^^^^^^^^^^^ evaluation panicked: hello
|
||||
|
|
||||
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `std::panic` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
|
|
@ -42,7 +42,7 @@ error[E0080]: evaluation of constant value failed
|
|||
--> $DIR/const_panic.rs:21:16
|
||||
|
|
||||
LL | const W2: () = std::panic!("{}", MSG);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'hello', $DIR/const_panic.rs:21:16
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ evaluation panicked: hello
|
||||
|
|
||||
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `std::panic` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
|
|
@ -50,7 +50,7 @@ error[E0080]: evaluation of constant value failed
|
|||
--> $DIR/const_panic.rs:24:20
|
||||
|
|
||||
LL | const Z_CORE: () = core::panic!("cheese");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'cheese', $DIR/const_panic.rs:24:20
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ evaluation panicked: cheese
|
||||
|
|
||||
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `core::panic` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
|
|
@ -58,7 +58,7 @@ error[E0080]: evaluation of constant value failed
|
|||
--> $DIR/const_panic.rs:27:21
|
||||
|
|
||||
LL | const Z2_CORE: () = core::panic!();
|
||||
| ^^^^^^^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/const_panic.rs:27:21
|
||||
| ^^^^^^^^^^^^^^ evaluation panicked: explicit panic
|
||||
|
|
||||
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `core::panic` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
|
|
@ -66,7 +66,7 @@ error[E0080]: evaluation of constant value failed
|
|||
--> $DIR/const_panic.rs:30:20
|
||||
|
|
||||
LL | const Y_CORE: () = core::unreachable!();
|
||||
| ^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic.rs:30:20
|
||||
| ^^^^^^^^^^^^^^^^^^^^ evaluation panicked: internal error: entered unreachable code
|
||||
|
|
||||
= note: this error originates in the macro `$crate::panic::unreachable_2015` which comes from the expansion of the macro `core::unreachable` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
|
|
@ -74,7 +74,7 @@ error[E0080]: evaluation of constant value failed
|
|||
--> $DIR/const_panic.rs:33:20
|
||||
|
|
||||
LL | const X_CORE: () = core::unimplemented!();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'not implemented', $DIR/const_panic.rs:33:20
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ evaluation panicked: not implemented
|
||||
|
|
||||
= note: this error originates in the macro `core::unimplemented` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
|
|
@ -82,7 +82,7 @@ error[E0080]: evaluation of constant value failed
|
|||
--> $DIR/const_panic.rs:36:20
|
||||
|
|
||||
LL | const W_CORE: () = core::panic!(MSG);
|
||||
| ^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'hello', $DIR/const_panic.rs:36:20
|
||||
| ^^^^^^^^^^^^^^^^^ evaluation panicked: hello
|
||||
|
|
||||
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `core::panic` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
|
|
@ -90,7 +90,7 @@ error[E0080]: evaluation of constant value failed
|
|||
--> $DIR/const_panic.rs:39:21
|
||||
|
|
||||
LL | const W2_CORE: () = core::panic!("{}", MSG);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'hello', $DIR/const_panic.rs:39:21
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ evaluation panicked: hello
|
||||
|
|
||||
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `core::panic` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ error[E0080]: evaluation of constant value failed
|
|||
--> $DIR/const_panic_2021.rs:6:15
|
||||
|
|
||||
LL | const A: () = std::panic!("blåhaj");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'blåhaj', $DIR/const_panic_2021.rs:6:15
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ evaluation panicked: blåhaj
|
||||
|
|
||||
= note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `std::panic` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
|
|
@ -10,7 +10,7 @@ error[E0080]: evaluation of constant value failed
|
|||
--> $DIR/const_panic_2021.rs:9:15
|
||||
|
|
||||
LL | const B: () = std::panic!();
|
||||
| ^^^^^^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/const_panic_2021.rs:9:15
|
||||
| ^^^^^^^^^^^^^ evaluation panicked: explicit panic
|
||||
|
|
||||
= note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `std::panic` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
|
|
@ -18,7 +18,7 @@ error[E0080]: evaluation of constant value failed
|
|||
--> $DIR/const_panic_2021.rs:12:15
|
||||
|
|
||||
LL | const C: () = std::unreachable!();
|
||||
| ^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic_2021.rs:12:15
|
||||
| ^^^^^^^^^^^^^^^^^^^ evaluation panicked: internal error: entered unreachable code
|
||||
|
|
||||
= note: this error originates in the macro `$crate::panic::unreachable_2021` which comes from the expansion of the macro `std::unreachable` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
|
|
@ -26,7 +26,7 @@ error[E0080]: evaluation of constant value failed
|
|||
--> $DIR/const_panic_2021.rs:15:15
|
||||
|
|
||||
LL | const D: () = std::unimplemented!();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'not implemented', $DIR/const_panic_2021.rs:15:15
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ evaluation panicked: not implemented
|
||||
|
|
||||
= note: this error originates in the macro `std::unimplemented` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
|
|
@ -34,7 +34,7 @@ error[E0080]: evaluation of constant value failed
|
|||
--> $DIR/const_panic_2021.rs:18:15
|
||||
|
|
||||
LL | const E: () = std::panic!("{}", MSG);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'hello', $DIR/const_panic_2021.rs:18:15
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ evaluation panicked: hello
|
||||
|
|
||||
= note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `std::panic` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
|
|
@ -42,7 +42,7 @@ error[E0080]: evaluation of constant value failed
|
|||
--> $DIR/const_panic_2021.rs:21:20
|
||||
|
|
||||
LL | const A_CORE: () = core::panic!("shark");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'shark', $DIR/const_panic_2021.rs:21:20
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ evaluation panicked: shark
|
||||
|
|
||||
= note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `core::panic` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
|
|
@ -50,7 +50,7 @@ error[E0080]: evaluation of constant value failed
|
|||
--> $DIR/const_panic_2021.rs:24:20
|
||||
|
|
||||
LL | const B_CORE: () = core::panic!();
|
||||
| ^^^^^^^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/const_panic_2021.rs:24:20
|
||||
| ^^^^^^^^^^^^^^ evaluation panicked: explicit panic
|
||||
|
|
||||
= note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `core::panic` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
|
|
@ -58,7 +58,7 @@ error[E0080]: evaluation of constant value failed
|
|||
--> $DIR/const_panic_2021.rs:27:20
|
||||
|
|
||||
LL | const C_CORE: () = core::unreachable!();
|
||||
| ^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic_2021.rs:27:20
|
||||
| ^^^^^^^^^^^^^^^^^^^^ evaluation panicked: internal error: entered unreachable code
|
||||
|
|
||||
= note: this error originates in the macro `$crate::panic::unreachable_2021` which comes from the expansion of the macro `core::unreachable` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
|
|
@ -66,7 +66,7 @@ error[E0080]: evaluation of constant value failed
|
|||
--> $DIR/const_panic_2021.rs:30:20
|
||||
|
|
||||
LL | const D_CORE: () = core::unimplemented!();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'not implemented', $DIR/const_panic_2021.rs:30:20
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ evaluation panicked: not implemented
|
||||
|
|
||||
= note: this error originates in the macro `core::unimplemented` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
|
|
@ -74,7 +74,7 @@ error[E0080]: evaluation of constant value failed
|
|||
--> $DIR/const_panic_2021.rs:33:20
|
||||
|
|
||||
LL | const E_CORE: () = core::panic!("{}", MSG);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'hello', $DIR/const_panic_2021.rs:33:20
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ evaluation panicked: hello
|
||||
|
|
||||
= note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `core::panic` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ error[E0080]: evaluation of constant value failed
|
|||
--> $DIR/const_panic_libcore_bin.rs:8:15
|
||||
|
|
||||
LL | const Z: () = panic!("cheese");
|
||||
| ^^^^^^^^^^^^^^^^ the evaluated program panicked at 'cheese', $DIR/const_panic_libcore_bin.rs:8:15
|
||||
| ^^^^^^^^^^^^^^^^ evaluation panicked: cheese
|
||||
|
|
||||
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
|
|
@ -10,7 +10,7 @@ error[E0080]: evaluation of constant value failed
|
|||
--> $DIR/const_panic_libcore_bin.rs:11:15
|
||||
|
|
||||
LL | const Y: () = unreachable!();
|
||||
| ^^^^^^^^^^^^^^ the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic_libcore_bin.rs:11:15
|
||||
| ^^^^^^^^^^^^^^ evaluation panicked: internal error: entered unreachable code
|
||||
|
|
||||
= note: this error originates in the macro `$crate::panic::unreachable_2015` which comes from the expansion of the macro `unreachable` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
|
|
@ -18,7 +18,7 @@ error[E0080]: evaluation of constant value failed
|
|||
--> $DIR/const_panic_libcore_bin.rs:14:15
|
||||
|
|
||||
LL | const X: () = unimplemented!();
|
||||
| ^^^^^^^^^^^^^^^^ the evaluated program panicked at 'not implemented', $DIR/const_panic_libcore_bin.rs:14:15
|
||||
| ^^^^^^^^^^^^^^^^ evaluation panicked: not implemented
|
||||
|
|
||||
= note: this error originates in the macro `unimplemented` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
|
|
|
|||
|
|
@ -12,11 +12,10 @@ const fn b() -> u32 {
|
|||
}
|
||||
|
||||
const fn c() -> u32 {
|
||||
b()
|
||||
//~^ ERROR evaluation of constant value failed
|
||||
//~| NOTE the evaluated program panicked
|
||||
//~| NOTE inside
|
||||
b() //~ NOTE inside `c`
|
||||
//~^ NOTE the failure occurred here
|
||||
}
|
||||
|
||||
const X: u32 = c();
|
||||
//~^ NOTE inside
|
||||
//~^ ERROR evaluation of constant value failed
|
||||
//~| NOTE hey
|
||||
|
|
|
|||
|
|
@ -1,19 +1,14 @@
|
|||
error[E0080]: evaluation of constant value failed
|
||||
--> $DIR/const_panic_track_caller.rs:15:5
|
||||
--> $DIR/const_panic_track_caller.rs:19:16
|
||||
|
|
||||
LL | b()
|
||||
| ^^^ the evaluated program panicked at 'hey', $DIR/const_panic_track_caller.rs:15:5
|
||||
LL | const X: u32 = c();
|
||||
| ^^^ evaluation panicked: hey
|
||||
|
|
||||
note: inside `c`
|
||||
--> $DIR/const_panic_track_caller.rs:15:5
|
||||
|
|
||||
LL | b()
|
||||
| ^^^
|
||||
note: inside `X`
|
||||
--> $DIR/const_panic_track_caller.rs:21:16
|
||||
|
|
||||
LL | const X: u32 = c();
|
||||
| ^^^
|
||||
| ^^^ the failure occurred here
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -2,11 +2,10 @@
|
|||
#![feature(const_heap)]
|
||||
use std::intrinsics;
|
||||
|
||||
const FOO: i32 = foo();
|
||||
const FOO: i32 = foo(); //~ error: evaluation of constant value failed
|
||||
const fn foo() -> i32 {
|
||||
unsafe {
|
||||
let _ = intrinsics::const_allocate(4, 3) as *mut i32;
|
||||
//~^ error: evaluation of constant value failed
|
||||
let _ = intrinsics::const_allocate(4, 3) as *mut i32; //~ inside `foo`
|
||||
}
|
||||
1
|
||||
}
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue