Make the non-const part swappable in the diagnostic
This commit is contained in:
parent
b321cd5573
commit
5a9f0be0bd
3 changed files with 63 additions and 41 deletions
|
@ -12,8 +12,6 @@ const_eval_already_reported =
|
||||||
const_eval_assume_false =
|
const_eval_assume_false =
|
||||||
`assume` called with `false`
|
`assume` called with `false`
|
||||||
|
|
||||||
const_eval_await_non_const =
|
|
||||||
cannot convert `{$ty}` into a future in {const_eval_const_context}s
|
|
||||||
const_eval_bounds_check_failed =
|
const_eval_bounds_check_failed =
|
||||||
indexing out of bounds: the len is {$len} but the index is {$index}
|
indexing out of bounds: the len is {$len} but the index is {$index}
|
||||||
const_eval_call_nonzero_intrinsic =
|
const_eval_call_nonzero_intrinsic =
|
||||||
|
@ -23,9 +21,6 @@ const_eval_closure_call =
|
||||||
closures need an RFC before allowed to be called in {const_eval_const_context}s
|
closures need an RFC before allowed to be called in {const_eval_const_context}s
|
||||||
const_eval_closure_fndef_not_const =
|
const_eval_closure_fndef_not_const =
|
||||||
function defined here, but it is not `const`
|
function defined here, but it is not `const`
|
||||||
const_eval_closure_non_const =
|
|
||||||
cannot call non-const closure in {const_eval_const_context}s
|
|
||||||
|
|
||||||
const_eval_conditionally_const_call =
|
const_eval_conditionally_const_call =
|
||||||
cannot call conditionally-const {$def_descr} `{$def_path_str}` in {const_eval_const_context}s
|
cannot call conditionally-const {$def_descr} `{$def_path_str}` in {const_eval_const_context}s
|
||||||
|
|
||||||
|
@ -62,10 +57,6 @@ const_eval_dealloc_incorrect_layout =
|
||||||
const_eval_dealloc_kind_mismatch =
|
const_eval_dealloc_kind_mismatch =
|
||||||
deallocating {$alloc}, which is {$alloc_kind} memory, using {$kind} deallocation operation
|
deallocating {$alloc}, which is {$alloc_kind} memory, using {$kind} deallocation operation
|
||||||
|
|
||||||
const_eval_deref_coercion_non_const =
|
|
||||||
cannot perform deref coercion on `{$ty}` in {const_eval_const_context}s
|
|
||||||
.note = attempting to deref into `{$target_ty}`
|
|
||||||
.target_note = deref defined here
|
|
||||||
const_eval_deref_function_pointer =
|
const_eval_deref_function_pointer =
|
||||||
accessing {$allocation} which contains a function
|
accessing {$allocation} which contains a function
|
||||||
const_eval_deref_vtable_pointer =
|
const_eval_deref_vtable_pointer =
|
||||||
|
@ -109,9 +100,6 @@ const_eval_extern_type_field = `extern type` field does not have a known offset
|
||||||
|
|
||||||
const_eval_fn_ptr_call =
|
const_eval_fn_ptr_call =
|
||||||
function pointers need an RFC before allowed to be called in {const_eval_const_context}s
|
function pointers need an RFC before allowed to be called in {const_eval_const_context}s
|
||||||
const_eval_for_loop_into_iter_non_const =
|
|
||||||
cannot use `for` loop on `{$ty}` in {const_eval_const_context}s
|
|
||||||
|
|
||||||
const_eval_frame_note = {$times ->
|
const_eval_frame_note = {$times ->
|
||||||
[0] {const_eval_frame_note_inner}
|
[0] {const_eval_frame_note_inner}
|
||||||
*[other] [... {$times} additional calls {const_eval_frame_note_inner} ...]
|
*[other] [... {$times} additional calls {const_eval_frame_note_inner} ...]
|
||||||
|
@ -216,9 +204,6 @@ const_eval_long_running =
|
||||||
.label = the const evaluator is currently interpreting this expression
|
.label = the const evaluator is currently interpreting this expression
|
||||||
.help = the constant being evaluated
|
.help = the constant being evaluated
|
||||||
|
|
||||||
const_eval_match_eq_non_const = cannot match on `{$ty}` in {const_eval_const_context}s
|
|
||||||
.note = `{$ty}` cannot be compared in compile-time, and therefore cannot be used in `match`es
|
|
||||||
|
|
||||||
const_eval_max_num_nodes_in_const = maximum number of nodes exceeded in constant {$global_const_id}
|
const_eval_max_num_nodes_in_const = maximum number of nodes exceeded in constant {$global_const_id}
|
||||||
|
|
||||||
const_eval_memory_access_test = memory access failed
|
const_eval_memory_access_test = memory access failed
|
||||||
|
@ -249,17 +234,46 @@ const_eval_mutable_ref_escaping =
|
||||||
If you really want global mutable state, try using an interior mutable `static` or a `static mut`.
|
If you really want global mutable state, try using an interior mutable `static` or a `static mut`.
|
||||||
|
|
||||||
const_eval_nested_static_in_thread_local = #[thread_local] does not support implicit nested statics, please create explicit static items and refer to them instead
|
const_eval_nested_static_in_thread_local = #[thread_local] does not support implicit nested statics, please create explicit static items and refer to them instead
|
||||||
|
|
||||||
|
const_eval_non_const_await =
|
||||||
|
cannot convert `{$ty}` into a future in {const_eval_const_context}s
|
||||||
|
|
||||||
|
const_eval_non_const_closure =
|
||||||
|
cannot call {$non}-const closure in {const_eval_const_context}s
|
||||||
|
|
||||||
|
const_eval_non_const_deref_coercion =
|
||||||
|
cannot perform {$non}-const deref coercion on `{$ty}` in {const_eval_const_context}s
|
||||||
|
.note = attempting to deref into `{$target_ty}`
|
||||||
|
.target_note = deref defined here
|
||||||
|
|
||||||
const_eval_non_const_fmt_macro_call =
|
const_eval_non_const_fmt_macro_call =
|
||||||
cannot call non-const formatting macro in {const_eval_const_context}s
|
cannot call {$non}-const formatting macro in {const_eval_const_context}s
|
||||||
|
|
||||||
const_eval_non_const_fn_call =
|
const_eval_non_const_fn_call =
|
||||||
cannot call non-const {$def_descr} `{$def_path_str}` in {const_eval_const_context}s
|
cannot call {$non}-const {$def_descr} `{$def_path_str}` in {const_eval_const_context}s
|
||||||
|
|
||||||
|
const_eval_non_const_for_loop_into_iter =
|
||||||
|
cannot use `for` loop on `{$ty}` in {const_eval_const_context}s
|
||||||
|
|
||||||
const_eval_non_const_impl =
|
const_eval_non_const_impl =
|
||||||
impl defined here, but it is not `const`
|
impl defined here, but it is not `const`
|
||||||
|
|
||||||
const_eval_non_const_intrinsic =
|
const_eval_non_const_intrinsic =
|
||||||
cannot call non-const intrinsic `{$name}` in {const_eval_const_context}s
|
cannot call {$non}-const intrinsic `{$name}` in {const_eval_const_context}s
|
||||||
|
|
||||||
|
const_eval_non_const_match_eq = cannot match on `{$ty}` in {const_eval_const_context}s
|
||||||
|
.note = `{$ty}` cannot be compared in compile-time, and therefore cannot be used in `match`es
|
||||||
|
|
||||||
|
const_eval_non_const_operator =
|
||||||
|
cannot call {$non}-const operator in {const_eval_const_context}s
|
||||||
|
|
||||||
|
const_eval_non_const_question_branch =
|
||||||
|
`?` is not allowed on `{$ty}` in {const_eval_const_context}s
|
||||||
|
const_eval_non_const_question_from_residual =
|
||||||
|
`?` is not allowed on `{$ty}` in {const_eval_const_context}s
|
||||||
|
|
||||||
|
const_eval_non_const_try_block_from_output =
|
||||||
|
`try` block cannot convert `{$ty}` to the result in {const_eval_const_context}s
|
||||||
|
|
||||||
const_eval_not_enough_caller_args =
|
const_eval_not_enough_caller_args =
|
||||||
calling a function with fewer arguments than it requires
|
calling a function with fewer arguments than it requires
|
||||||
|
@ -281,8 +295,6 @@ const_eval_offset_from_unsigned_overflow =
|
||||||
*[false] offset
|
*[false] offset
|
||||||
} than second: {$a_offset} < {$b_offset}
|
} than second: {$a_offset} < {$b_offset}
|
||||||
|
|
||||||
const_eval_operator_non_const =
|
|
||||||
cannot call non-const operator in {const_eval_const_context}s
|
|
||||||
const_eval_overflow_arith =
|
const_eval_overflow_arith =
|
||||||
arithmetic overflow in `{$intrinsic}`
|
arithmetic overflow in `{$intrinsic}`
|
||||||
const_eval_overflow_shift =
|
const_eval_overflow_shift =
|
||||||
|
@ -325,11 +337,6 @@ const_eval_ptr_as_bytes_1 =
|
||||||
const_eval_ptr_as_bytes_2 =
|
const_eval_ptr_as_bytes_2 =
|
||||||
the absolute address of a pointer is not known at compile-time, so such operations are not supported
|
the absolute address of a pointer is not known at compile-time, so such operations are not supported
|
||||||
|
|
||||||
const_eval_question_branch_non_const =
|
|
||||||
`?` is not allowed on `{$ty}` in {const_eval_const_context}s
|
|
||||||
const_eval_question_from_residual_non_const =
|
|
||||||
`?` is not allowed on `{$ty}` in {const_eval_const_context}s
|
|
||||||
|
|
||||||
const_eval_range = in the range {$lo}..={$hi}
|
const_eval_range = in the range {$lo}..={$hi}
|
||||||
const_eval_range_lower = greater or equal to {$lo}
|
const_eval_range_lower = greater or equal to {$lo}
|
||||||
const_eval_range_singular = equal to {$lo}
|
const_eval_range_singular = equal to {$lo}
|
||||||
|
@ -379,8 +386,6 @@ const_eval_too_generic =
|
||||||
const_eval_too_many_caller_args =
|
const_eval_too_many_caller_args =
|
||||||
calling a function with more arguments than it expected
|
calling a function with more arguments than it expected
|
||||||
|
|
||||||
const_eval_try_block_from_output_non_const =
|
|
||||||
`try` block cannot convert `{$ty}` to the result in {const_eval_const_context}s
|
|
||||||
const_eval_unallowed_fn_pointer_call = function pointer calls are not allowed in {const_eval_const_context}s
|
const_eval_unallowed_fn_pointer_call = function pointer calls are not allowed in {const_eval_const_context}s
|
||||||
|
|
||||||
const_eval_unallowed_heap_allocations =
|
const_eval_unallowed_heap_allocations =
|
||||||
|
|
|
@ -130,7 +130,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
|
||||||
let ConstCx { tcx, typing_env, .. } = *ccx;
|
let ConstCx { tcx, typing_env, .. } = *ccx;
|
||||||
let caller = ccx.def_id();
|
let caller = ccx.def_id();
|
||||||
|
|
||||||
let diag_trait = |err, self_ty: Ty<'_>, trait_id| {
|
let note_trait_if_possible = |err, self_ty: Ty<'_>, trait_id| {
|
||||||
let trait_ref = TraitRef::from_method(tcx, trait_id, args);
|
let trait_ref = TraitRef::from_method(tcx, trait_id, args);
|
||||||
|
|
||||||
match self_ty.kind() {
|
match self_ty.kind() {
|
||||||
|
@ -183,6 +183,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
|
||||||
span,
|
span,
|
||||||
ty: self_ty,
|
ty: self_ty,
|
||||||
kind: ccx.const_kind(),
|
kind: ccx.const_kind(),
|
||||||
|
non: "non",
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -226,9 +227,10 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
|
||||||
span,
|
span,
|
||||||
kind: ccx.const_kind(),
|
kind: ccx.const_kind(),
|
||||||
note,
|
note,
|
||||||
|
non: "non",
|
||||||
});
|
});
|
||||||
|
|
||||||
diag_trait(&mut err, self_ty, fn_trait_id);
|
note_trait_if_possible(&mut err, self_ty, fn_trait_id);
|
||||||
err
|
err
|
||||||
}
|
}
|
||||||
CallKind::Operator { trait_id, self_ty, .. } => {
|
CallKind::Operator { trait_id, self_ty, .. } => {
|
||||||
|
@ -237,6 +239,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
|
||||||
span,
|
span,
|
||||||
kind: ccx.const_kind(),
|
kind: ccx.const_kind(),
|
||||||
ty: self_ty,
|
ty: self_ty,
|
||||||
|
non: "non",
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
let mut sugg = None;
|
let mut sugg = None;
|
||||||
|
@ -282,10 +285,11 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
|
||||||
span,
|
span,
|
||||||
kind: ccx.const_kind(),
|
kind: ccx.const_kind(),
|
||||||
sugg,
|
sugg,
|
||||||
|
non: "non",
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
diag_trait(&mut err, self_ty, trait_id);
|
note_trait_if_possible(&mut err, self_ty, trait_id);
|
||||||
err
|
err
|
||||||
}
|
}
|
||||||
CallKind::DerefCoercion { deref_target, deref_target_ty, self_ty } => {
|
CallKind::DerefCoercion { deref_target, deref_target_ty, self_ty } => {
|
||||||
|
@ -302,19 +306,21 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
|
||||||
kind: ccx.const_kind(),
|
kind: ccx.const_kind(),
|
||||||
target_ty: deref_target_ty,
|
target_ty: deref_target_ty,
|
||||||
deref_target: target,
|
deref_target: target,
|
||||||
|
non: "non",
|
||||||
});
|
});
|
||||||
|
|
||||||
diag_trait(&mut err, self_ty, tcx.require_lang_item(LangItem::Deref, Some(span)));
|
note_trait_if_possible(&mut err, self_ty, tcx.require_lang_item(LangItem::Deref, Some(span)));
|
||||||
err
|
err
|
||||||
}
|
}
|
||||||
_ if tcx.opt_parent(callee) == tcx.get_diagnostic_item(sym::ArgumentMethods) => {
|
_ if tcx.opt_parent(callee) == tcx.get_diagnostic_item(sym::ArgumentMethods) => {
|
||||||
ccx.dcx().create_err(errors::NonConstFmtMacroCall { span, kind: ccx.const_kind() })
|
ccx.dcx().create_err(errors::NonConstFmtMacroCall { span, kind: ccx.const_kind(), non: "non" })
|
||||||
}
|
}
|
||||||
_ => ccx.dcx().create_err(errors::NonConstFnCall {
|
_ => ccx.dcx().create_err(errors::NonConstFnCall {
|
||||||
span,
|
span,
|
||||||
def_descr: ccx.tcx.def_descr(callee),
|
def_descr: ccx.tcx.def_descr(callee),
|
||||||
def_path_str: ccx.tcx.def_path_str_with_args(callee, args),
|
def_path_str: ccx.tcx.def_path_str_with_args(callee, args),
|
||||||
kind: ccx.const_kind(),
|
kind: ccx.const_kind(),
|
||||||
|
non: "non",
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -174,6 +174,7 @@ pub(crate) struct NonConstFmtMacroCall {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
pub kind: ConstContext,
|
pub kind: ConstContext,
|
||||||
|
pub non: &'static str,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
|
@ -194,6 +195,7 @@ pub(crate) struct NonConstFnCall {
|
||||||
pub def_path_str: String,
|
pub def_path_str: String,
|
||||||
pub def_descr: &'static str,
|
pub def_descr: &'static str,
|
||||||
pub kind: ConstContext,
|
pub kind: ConstContext,
|
||||||
|
pub non: &'static str,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
|
@ -293,68 +295,75 @@ pub struct RawBytesNote {
|
||||||
// FIXME(fee1-dead) do not use stringly typed `ConstContext`
|
// FIXME(fee1-dead) do not use stringly typed `ConstContext`
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
#[diag(const_eval_match_eq_non_const, code = E0015)]
|
#[diag(const_eval_non_const_match_eq, code = E0015)]
|
||||||
#[note]
|
#[note]
|
||||||
pub struct NonConstMatchEq<'tcx> {
|
pub struct NonConstMatchEq<'tcx> {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
pub ty: Ty<'tcx>,
|
pub ty: Ty<'tcx>,
|
||||||
pub kind: ConstContext,
|
pub kind: ConstContext,
|
||||||
|
pub non: &'static str,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
#[diag(const_eval_for_loop_into_iter_non_const, code = E0015)]
|
#[diag(const_eval_non_const_for_loop_into_iter, code = E0015)]
|
||||||
pub struct NonConstForLoopIntoIter<'tcx> {
|
pub struct NonConstForLoopIntoIter<'tcx> {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
pub ty: Ty<'tcx>,
|
pub ty: Ty<'tcx>,
|
||||||
pub kind: ConstContext,
|
pub kind: ConstContext,
|
||||||
|
pub non: &'static str,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
#[diag(const_eval_question_branch_non_const, code = E0015)]
|
#[diag(const_eval_non_const_question_branch, code = E0015)]
|
||||||
pub struct NonConstQuestionBranch<'tcx> {
|
pub struct NonConstQuestionBranch<'tcx> {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
pub ty: Ty<'tcx>,
|
pub ty: Ty<'tcx>,
|
||||||
pub kind: ConstContext,
|
pub kind: ConstContext,
|
||||||
|
pub non: &'static str,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
#[diag(const_eval_question_from_residual_non_const, code = E0015)]
|
#[diag(const_eval_non_const_question_from_residual, code = E0015)]
|
||||||
pub struct NonConstQuestionFromResidual<'tcx> {
|
pub struct NonConstQuestionFromResidual<'tcx> {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
pub ty: Ty<'tcx>,
|
pub ty: Ty<'tcx>,
|
||||||
pub kind: ConstContext,
|
pub kind: ConstContext,
|
||||||
|
pub non: &'static str,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
#[diag(const_eval_try_block_from_output_non_const, code = E0015)]
|
#[diag(const_eval_non_const_try_block_from_output, code = E0015)]
|
||||||
pub struct NonConstTryBlockFromOutput<'tcx> {
|
pub struct NonConstTryBlockFromOutput<'tcx> {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
pub ty: Ty<'tcx>,
|
pub ty: Ty<'tcx>,
|
||||||
pub kind: ConstContext,
|
pub kind: ConstContext,
|
||||||
|
pub non: &'static str,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
#[diag(const_eval_await_non_const, code = E0015)]
|
#[diag(const_eval_non_const_await, code = E0015)]
|
||||||
pub struct NonConstAwait<'tcx> {
|
pub struct NonConstAwait<'tcx> {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
pub ty: Ty<'tcx>,
|
pub ty: Ty<'tcx>,
|
||||||
pub kind: ConstContext,
|
pub kind: ConstContext,
|
||||||
|
pub non: &'static str,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
#[diag(const_eval_closure_non_const, code = E0015)]
|
#[diag(const_eval_non_const_closure, code = E0015)]
|
||||||
pub struct NonConstClosure {
|
pub struct NonConstClosure {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
pub kind: ConstContext,
|
pub kind: ConstContext,
|
||||||
#[subdiagnostic]
|
#[subdiagnostic]
|
||||||
pub note: Option<NonConstClosureNote>,
|
pub note: Option<NonConstClosureNote>,
|
||||||
|
pub non: &'static str,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Subdiagnostic)]
|
#[derive(Subdiagnostic)]
|
||||||
|
@ -381,17 +390,18 @@ pub struct ConsiderDereferencing {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
#[diag(const_eval_operator_non_const, code = E0015)]
|
#[diag(const_eval_non_const_operator, code = E0015)]
|
||||||
pub struct NonConstOperator {
|
pub struct NonConstOperator {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
pub kind: ConstContext,
|
pub kind: ConstContext,
|
||||||
#[subdiagnostic]
|
#[subdiagnostic]
|
||||||
pub sugg: Option<ConsiderDereferencing>,
|
pub sugg: Option<ConsiderDereferencing>,
|
||||||
|
pub non: &'static str,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
#[diag(const_eval_deref_coercion_non_const, code = E0015)]
|
#[diag(const_eval_non_const_deref_coercion, code = E0015)]
|
||||||
#[note]
|
#[note]
|
||||||
pub struct NonConstDerefCoercion<'tcx> {
|
pub struct NonConstDerefCoercion<'tcx> {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
|
@ -401,6 +411,7 @@ pub struct NonConstDerefCoercion<'tcx> {
|
||||||
pub target_ty: Ty<'tcx>,
|
pub target_ty: Ty<'tcx>,
|
||||||
#[note(const_eval_target_note)]
|
#[note(const_eval_target_note)]
|
||||||
pub deref_target: Option<Span>,
|
pub deref_target: Option<Span>,
|
||||||
|
pub non: &'static str,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue