1
Fork 0

Auto merge of #134716 - Zalathar:rollup-1h4q8cc, r=Zalathar

Rollup of 5 pull requests

Successful merges:

 - #134638 (Fix effect predicates from item bounds in old solver)
 - #134662 (Fix safety docs for `dyn Any + Send {+ Sync}`)
 - #134689 (core: fix const ptr::swap_nonoverlapping when there are pointers at odd offsets)
 - #134699 (Belay new reviews for workingjubilee)
 - #134701 (Correctly note item kind in `NonConstFunctionCall` error message)

r? `@ghost`
`@rustbot` modify labels: rollup
This commit is contained in:
bors 2024-12-24 03:33:09 +00:00
commit d3e71fd2d3
104 changed files with 429 additions and 234 deletions

View file

@ -253,7 +253,7 @@ const_eval_non_const_fmt_macro_call =
cannot call non-const formatting macro in {const_eval_const_context}s
const_eval_non_const_fn_call =
cannot call non-const fn `{$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_impl =
impl defined here, but it is not `const`

View file

@ -304,6 +304,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
}
_ => ccx.dcx().create_err(errors::NonConstFnCall {
span,
def_descr: ccx.tcx.def_descr(callee),
def_path_str: ccx.tcx.def_path_str_with_args(callee, args),
kind: ccx.const_kind(),
}),

View file

@ -192,6 +192,7 @@ pub(crate) struct NonConstFnCall {
#[primary_span]
pub span: Span,
pub def_path_str: String,
pub def_descr: &'static str,
pub kind: ConstContext,
}

View file

@ -7,7 +7,7 @@ fn create_some() -> Option<u8> {
Some(1)
}
// error: cannot call non-const fn `create_some` in constants
// error: cannot call non-const function `create_some` in constants
const FOO: Option<u8> = create_some();
```

View file

@ -1,13 +1,15 @@
use rustc_hir as hir;
use rustc_infer::infer::{BoundRegionConversionTime, DefineOpaqueTypes, InferCtxt};
use rustc_infer::infer::{BoundRegionConversionTime, DefineOpaqueTypes};
use rustc_infer::traits::{ImplSource, Obligation, PredicateObligation};
use rustc_middle::span_bug;
use rustc_middle::ty::fast_reject::DeepRejectCtxt;
use rustc_middle::ty::{self, TypingMode};
use rustc_type_ir::elaborate::elaborate;
use rustc_type_ir::solve::NoSolution;
use thin_vec::ThinVec;
use thin_vec::{ThinVec, thin_vec};
use super::SelectionContext;
use super::normalize::normalize_with_depth_to;
pub type HostEffectObligation<'tcx> = Obligation<'tcx, ty::HostEffectPredicate<'tcx>>;
@ -38,6 +40,12 @@ pub fn evaluate_host_effect_obligation<'tcx>(
Err(EvaluationFailure::NoSolution) => {}
}
match evaluate_host_effect_from_item_bounds(selcx, obligation) {
Ok(result) => return Ok(result),
Err(EvaluationFailure::Ambiguous) => return Err(EvaluationFailure::Ambiguous),
Err(EvaluationFailure::NoSolution) => {}
}
match evaluate_host_effect_from_selection_candiate(selcx, obligation) {
Ok(result) => return Ok(result),
Err(EvaluationFailure::Ambiguous) => return Err(EvaluationFailure::Ambiguous),
@ -48,24 +56,45 @@ pub fn evaluate_host_effect_obligation<'tcx>(
}
fn match_candidate<'tcx>(
infcx: &InferCtxt<'tcx>,
selcx: &mut SelectionContext<'_, 'tcx>,
obligation: &HostEffectObligation<'tcx>,
candidate: ty::Binder<'tcx, ty::HostEffectPredicate<'tcx>>,
candidate_is_unnormalized: bool,
more_nested: impl FnOnce(&mut SelectionContext<'_, 'tcx>, &mut ThinVec<PredicateObligation<'tcx>>),
) -> Result<ThinVec<PredicateObligation<'tcx>>, NoSolution> {
if !candidate.skip_binder().constness.satisfies(obligation.predicate.constness) {
return Err(NoSolution);
}
let candidate = infcx.instantiate_binder_with_fresh_vars(
let mut candidate = selcx.infcx.instantiate_binder_with_fresh_vars(
obligation.cause.span,
BoundRegionConversionTime::HigherRankedType,
candidate,
);
let mut nested = infcx
.at(&obligation.cause, obligation.param_env)
.eq(DefineOpaqueTypes::Yes, obligation.predicate.trait_ref, candidate.trait_ref)?
.into_obligations();
let mut nested = thin_vec![];
// Unlike param-env bounds, item bounds may not be normalized.
if candidate_is_unnormalized {
candidate = normalize_with_depth_to(
selcx,
obligation.param_env,
obligation.cause.clone(),
obligation.recursion_depth,
candidate,
&mut nested,
);
}
nested.extend(
selcx
.infcx
.at(&obligation.cause, obligation.param_env)
.eq(DefineOpaqueTypes::Yes, obligation.predicate.trait_ref, candidate.trait_ref)?
.into_obligations(),
);
more_nested(selcx, &mut nested);
for nested in &mut nested {
nested.set_depth_from_parent(obligation.recursion_depth);
@ -82,41 +111,121 @@ fn evaluate_host_effect_from_bounds<'tcx>(
let drcx = DeepRejectCtxt::relate_rigid_rigid(selcx.tcx());
let mut candidate = None;
for predicate in obligation.param_env.caller_bounds() {
let bound_predicate = predicate.kind();
if let ty::ClauseKind::HostEffect(data) = predicate.kind().skip_binder() {
let data = bound_predicate.rebind(data);
if data.skip_binder().trait_ref.def_id != obligation.predicate.trait_ref.def_id {
continue;
}
for clause in obligation.param_env.caller_bounds() {
let bound_clause = clause.kind();
let ty::ClauseKind::HostEffect(data) = bound_clause.skip_binder() else {
continue;
};
let data = bound_clause.rebind(data);
if data.skip_binder().trait_ref.def_id != obligation.predicate.trait_ref.def_id {
continue;
}
if !drcx.args_may_unify(
obligation.predicate.trait_ref.args,
data.skip_binder().trait_ref.args,
) {
continue;
}
if !drcx
.args_may_unify(obligation.predicate.trait_ref.args, data.skip_binder().trait_ref.args)
{
continue;
}
let is_match = infcx.probe(|_| match_candidate(infcx, obligation, data).is_ok());
let is_match =
infcx.probe(|_| match_candidate(selcx, obligation, data, false, |_, _| {}).is_ok());
if is_match {
if candidate.is_some() {
return Err(EvaluationFailure::Ambiguous);
} else {
candidate = Some(data);
}
if is_match {
if candidate.is_some() {
return Err(EvaluationFailure::Ambiguous);
} else {
candidate = Some(data);
}
}
}
if let Some(data) = candidate {
Ok(match_candidate(infcx, obligation, data)
Ok(match_candidate(selcx, obligation, data, false, |_, _| {})
.expect("candidate matched before, so it should match again"))
} else {
Err(EvaluationFailure::NoSolution)
}
}
fn evaluate_host_effect_from_item_bounds<'tcx>(
selcx: &mut SelectionContext<'_, 'tcx>,
obligation: &HostEffectObligation<'tcx>,
) -> Result<ThinVec<PredicateObligation<'tcx>>, EvaluationFailure> {
let infcx = selcx.infcx;
let tcx = infcx.tcx;
let drcx = DeepRejectCtxt::relate_rigid_rigid(selcx.tcx());
let mut candidate = None;
let mut consider_ty = obligation.predicate.self_ty();
while let ty::Alias(kind @ (ty::Projection | ty::Opaque), alias_ty) = *consider_ty.kind() {
if tcx.is_conditionally_const(alias_ty.def_id) {
for clause in elaborate(
tcx,
tcx.explicit_implied_const_bounds(alias_ty.def_id)
.iter_instantiated_copied(tcx, alias_ty.args)
.map(|(trait_ref, _)| {
trait_ref.to_host_effect_clause(tcx, obligation.predicate.constness)
}),
) {
let bound_clause = clause.kind();
let ty::ClauseKind::HostEffect(data) = bound_clause.skip_binder() else {
unreachable!("should not elaborate non-HostEffect from HostEffect")
};
let data = bound_clause.rebind(data);
if data.skip_binder().trait_ref.def_id != obligation.predicate.trait_ref.def_id {
continue;
}
if !drcx.args_may_unify(
obligation.predicate.trait_ref.args,
data.skip_binder().trait_ref.args,
) {
continue;
}
let is_match = infcx
.probe(|_| match_candidate(selcx, obligation, data, true, |_, _| {}).is_ok());
if is_match {
if candidate.is_some() {
return Err(EvaluationFailure::Ambiguous);
} else {
candidate = Some((data, alias_ty));
}
}
}
}
if kind != ty::Projection {
break;
}
consider_ty = alias_ty.self_ty();
}
if let Some((data, alias_ty)) = candidate {
Ok(match_candidate(selcx, obligation, data, true, |selcx, nested| {
// An alias bound only holds if we also check the const conditions
// of the alias, so we need to register those, too.
let const_conditions = normalize_with_depth_to(
selcx,
obligation.param_env,
obligation.cause.clone(),
obligation.recursion_depth,
tcx.const_conditions(alias_ty.def_id).instantiate(tcx, alias_ty.args),
nested,
);
nested.extend(const_conditions.into_iter().map(|(trait_ref, _)| {
obligation
.with(tcx, trait_ref.to_host_effect_clause(tcx, obligation.predicate.constness))
}));
})
.expect("candidate matched before, so it should match again"))
} else {
Err(EvaluationFailure::NoSolution)
}
}
fn evaluate_host_effect_from_selection_candiate<'tcx>(
selcx: &mut SelectionContext<'_, 'tcx>,
obligation: &HostEffectObligation<'tcx>,

View file

@ -423,7 +423,8 @@ impl dyn Any + Send {
///
/// # Safety
///
/// Same as the method on the type `dyn Any`.
/// The contained value must be of type `T`. Calling this method
/// with the incorrect type is *undefined behavior*.
#[unstable(feature = "downcast_unchecked", issue = "90850")]
#[inline]
pub unsafe fn downcast_ref_unchecked<T: Any>(&self) -> &T {
@ -451,7 +452,8 @@ impl dyn Any + Send {
///
/// # Safety
///
/// Same as the method on the type `dyn Any`.
/// The contained value must be of type `T`. Calling this method
/// with the incorrect type is *undefined behavior*.
#[unstable(feature = "downcast_unchecked", issue = "90850")]
#[inline]
pub unsafe fn downcast_mut_unchecked<T: Any>(&mut self) -> &mut T {
@ -552,6 +554,10 @@ impl dyn Any + Send + Sync {
/// assert_eq!(*x.downcast_ref_unchecked::<usize>(), 1);
/// }
/// ```
/// # Safety
///
/// The contained value must be of type `T`. Calling this method
/// with the incorrect type is *undefined behavior*.
#[unstable(feature = "downcast_unchecked", issue = "90850")]
#[inline]
pub unsafe fn downcast_ref_unchecked<T: Any>(&self) -> &T {
@ -576,6 +582,10 @@ impl dyn Any + Send + Sync {
///
/// assert_eq!(*x.downcast_ref::<usize>().unwrap(), 2);
/// ```
/// # Safety
///
/// The contained value must be of type `T`. Calling this method
/// with the incorrect type is *undefined behavior*.
#[unstable(feature = "downcast_unchecked", issue = "90850")]
#[inline]
pub unsafe fn downcast_mut_unchecked<T: Any>(&mut self) -> &mut T {

View file

@ -3795,7 +3795,7 @@ where
/// See [`const_eval_select()`] for the rules and requirements around that intrinsic.
pub(crate) macro const_eval_select {
(
@capture { $($arg:ident : $ty:ty = $val:expr),* $(,)? } $( -> $ret:ty )? :
@capture$([$($binders:tt)*])? { $($arg:ident : $ty:ty = $val:expr),* $(,)? } $( -> $ret:ty )? :
if const
$(#[$compiletime_attr:meta])* $compiletime:block
else
@ -3803,7 +3803,7 @@ pub(crate) macro const_eval_select {
) => {
// Use the `noinline` arm, after adding explicit `inline` attributes
$crate::intrinsics::const_eval_select!(
@capture { $($arg : $ty = $val),* } $(-> $ret)? :
@capture$([$($binders)*])? { $($arg : $ty = $val),* } $(-> $ret)? :
#[noinline]
if const
#[inline] // prevent codegen on this function
@ -3817,7 +3817,7 @@ pub(crate) macro const_eval_select {
},
// With a leading #[noinline], we don't add inline attributes
(
@capture { $($arg:ident : $ty:ty = $val:expr),* $(,)? } $( -> $ret:ty )? :
@capture$([$($binders:tt)*])? { $($arg:ident : $ty:ty = $val:expr),* $(,)? } $( -> $ret:ty )? :
#[noinline]
if const
$(#[$compiletime_attr:meta])* $compiletime:block
@ -3825,12 +3825,12 @@ pub(crate) macro const_eval_select {
$(#[$runtime_attr:meta])* $runtime:block
) => {{
$(#[$runtime_attr])*
fn runtime($($arg: $ty),*) $( -> $ret )? {
fn runtime$(<$($binders)*>)?($($arg: $ty),*) $( -> $ret )? {
$runtime
}
$(#[$compiletime_attr])*
const fn compiletime($($arg: $ty),*) $( -> $ret )? {
const fn compiletime$(<$($binders)*>)?($($arg: $ty),*) $( -> $ret )? {
// Don't warn if one of the arguments is unused.
$(let _ = $arg;)*
@ -3842,14 +3842,14 @@ pub(crate) macro const_eval_select {
// We support leaving away the `val` expressions for *all* arguments
// (but not for *some* arguments, that's too tricky).
(
@capture { $($arg:ident : $ty:ty),* $(,)? } $( -> $ret:ty )? :
@capture$([$($binders:tt)*])? { $($arg:ident : $ty:ty),* $(,)? } $( -> $ret:ty )? :
if const
$(#[$compiletime_attr:meta])* $compiletime:block
else
$(#[$runtime_attr:meta])* $runtime:block
) => {
$crate::intrinsics::const_eval_select!(
@capture { $($arg : $ty = $arg),* } $(-> $ret)? :
@capture$([$($binders)*])? { $($arg : $ty = $arg),* } $(-> $ret)? :
if const
$(#[$compiletime_attr])* $compiletime
else

View file

@ -395,6 +395,7 @@
#![allow(clippy::not_unsafe_ptr_arg_deref)]
use crate::cmp::Ordering;
use crate::intrinsics::const_eval_select;
use crate::marker::FnPtr;
use crate::mem::{self, MaybeUninit, SizedTypeProperties};
use crate::{fmt, hash, intrinsics, ub_checks};
@ -1074,25 +1075,6 @@ pub const unsafe fn swap<T>(x: *mut T, y: *mut T) {
#[rustc_const_unstable(feature = "const_swap_nonoverlapping", issue = "133668")]
#[rustc_diagnostic_item = "ptr_swap_nonoverlapping"]
pub const unsafe fn swap_nonoverlapping<T>(x: *mut T, y: *mut T, count: usize) {
#[allow(unused)]
macro_rules! attempt_swap_as_chunks {
($ChunkTy:ty) => {
if mem::align_of::<T>() >= mem::align_of::<$ChunkTy>()
&& mem::size_of::<T>() % mem::size_of::<$ChunkTy>() == 0
{
let x: *mut $ChunkTy = x.cast();
let y: *mut $ChunkTy = y.cast();
let count = count * (mem::size_of::<T>() / mem::size_of::<$ChunkTy>());
// SAFETY: these are the same bytes that the caller promised were
// ok, just typed as `MaybeUninit<ChunkTy>`s instead of as `T`s.
// The `if` condition above ensures that we're not violating
// alignment requirements, and that the division is exact so
// that we don't lose any bytes off the end.
return unsafe { swap_nonoverlapping_simple_untyped(x, y, count) };
}
};
}
ub_checks::assert_unsafe_precondition!(
check_language_ub,
"ptr::swap_nonoverlapping requires that both pointer arguments are aligned and non-null \
@ -1111,19 +1093,48 @@ pub const unsafe fn swap_nonoverlapping<T>(x: *mut T, y: *mut T, count: usize) {
}
);
// Split up the slice into small power-of-two-sized chunks that LLVM is able
// to vectorize (unless it's a special type with more-than-pointer alignment,
// because we don't want to pessimize things like slices of SIMD vectors.)
if mem::align_of::<T>() <= mem::size_of::<usize>()
&& (!mem::size_of::<T>().is_power_of_two()
|| mem::size_of::<T>() > mem::size_of::<usize>() * 2)
{
attempt_swap_as_chunks!(usize);
attempt_swap_as_chunks!(u8);
}
const_eval_select!(
@capture[T] { x: *mut T, y: *mut T, count: usize }:
if const {
// At compile-time we want to always copy this in chunks of `T`, to ensure that if there
// are pointers inside `T` we will copy them in one go rather than trying to copy a part
// of a pointer (which would not work).
// SAFETY: Same preconditions as this function
unsafe { swap_nonoverlapping_simple_untyped(x, y, count) }
} else {
macro_rules! attempt_swap_as_chunks {
($ChunkTy:ty) => {
if mem::align_of::<T>() >= mem::align_of::<$ChunkTy>()
&& mem::size_of::<T>() % mem::size_of::<$ChunkTy>() == 0
{
let x: *mut $ChunkTy = x.cast();
let y: *mut $ChunkTy = y.cast();
let count = count * (mem::size_of::<T>() / mem::size_of::<$ChunkTy>());
// SAFETY: these are the same bytes that the caller promised were
// ok, just typed as `MaybeUninit<ChunkTy>`s instead of as `T`s.
// The `if` condition above ensures that we're not violating
// alignment requirements, and that the division is exact so
// that we don't lose any bytes off the end.
return unsafe { swap_nonoverlapping_simple_untyped(x, y, count) };
}
};
}
// SAFETY: Same preconditions as this function
unsafe { swap_nonoverlapping_simple_untyped(x, y, count) }
// Split up the slice into small power-of-two-sized chunks that LLVM is able
// to vectorize (unless it's a special type with more-than-pointer alignment,
// because we don't want to pessimize things like slices of SIMD vectors.)
if mem::align_of::<T>() <= mem::size_of::<usize>()
&& (!mem::size_of::<T>().is_power_of_two()
|| mem::size_of::<T>() > mem::size_of::<usize>() * 2)
{
attempt_swap_as_chunks!(usize);
attempt_swap_as_chunks!(u8);
}
// SAFETY: Same preconditions as this function
unsafe { swap_nonoverlapping_simple_untyped(x, y, count) }
}
)
}
/// Same behavior and safety conditions as [`swap_nonoverlapping`]

View file

@ -16,6 +16,7 @@
#![feature(const_black_box)]
#![feature(const_eval_select)]
#![feature(const_swap)]
#![feature(const_swap_nonoverlapping)]
#![feature(const_trait_impl)]
#![feature(core_intrinsics)]
#![feature(core_io_borrowed_buf)]

View file

@ -860,7 +860,10 @@ fn swap_copy_untyped() {
}
#[test]
fn test_const_copy() {
fn test_const_copy_ptr() {
// `copy` and `copy_nonoverlapping` are thin layers on top of intrinsics. Ensure they correctly
// deal with pointers even when the pointers cross the boundary from one "element" being copied
// to another.
const {
let ptr1 = &1;
let mut ptr2 = &666;
@ -899,21 +902,61 @@ fn test_const_copy() {
}
#[test]
fn test_const_swap() {
const {
let mut ptr1 = &1;
let mut ptr2 = &666;
fn test_const_swap_ptr() {
// The `swap` functions are implemented in the library, they are not primitives.
// Only `swap_nonoverlapping` takes a count; pointers that cross multiple elements
// are *not* supported.
// We put the pointer at an odd offset in the type and copy them as an array of bytes,
// which should catch most of the ways that the library implementation can get it wrong.
// Swap ptr1 and ptr2, bytewise. `swap` does not take a count
// so the best we can do is use an array.
type T = [u8; mem::size_of::<&i32>()];
#[cfg(target_pointer_width = "32")]
type HalfPtr = i16;
#[cfg(target_pointer_width = "64")]
type HalfPtr = i32;
#[repr(C, packed)]
#[allow(unused)]
struct S {
f1: HalfPtr,
// Crucially this field is at an offset that is not a multiple of the pointer size.
ptr: &'static i32,
// Make sure the entire type does not have a power-of-2 size:
// make it 3 pointers in size. This used to hit a bug in `swap_nonoverlapping`.
f2: [HalfPtr; 3],
}
// Ensure the entire thing is usize-aligned, so in principle this
// looks like it could be eligible for a `usize` copying loop.
#[cfg_attr(target_pointer_width = "32", repr(align(4)))]
#[cfg_attr(target_pointer_width = "64", repr(align(8)))]
struct A(S);
const {
let mut s1 = A(S { ptr: &1, f1: 0, f2: [0; 3] });
let mut s2 = A(S { ptr: &666, f1: 0, f2: [0; 3] });
// Swap ptr1 and ptr2, as an array.
type T = [u8; mem::size_of::<A>()];
unsafe {
ptr::swap(ptr::from_mut(&mut ptr1).cast::<T>(), ptr::from_mut(&mut ptr2).cast::<T>());
ptr::swap(ptr::from_mut(&mut s1).cast::<T>(), ptr::from_mut(&mut s2).cast::<T>());
}
// Make sure they still work.
assert!(*ptr1 == 666);
assert!(*ptr2 == 1);
assert!(*s1.0.ptr == 666);
assert!(*s2.0.ptr == 1);
// Swap them back, again as an array.
unsafe {
ptr::swap_nonoverlapping(
ptr::from_mut(&mut s1).cast::<T>(),
ptr::from_mut(&mut s2).cast::<T>(),
1,
);
}
// Make sure they still work.
assert!(*s1.0.ptr == 1);
assert!(*s2.0.ptr == 666);
};
}

View file

@ -52,7 +52,7 @@ help: enable `#![feature(const_trait_impl)]` in your crate and mark `Bar` as `#[
LL | #[const_trait] trait Bar: ~const Foo {}
| ++++++++++++++
error[E0015]: cannot call non-const fn `<T as Foo>::a` in constant functions
error[E0015]: cannot call non-const method `<T as Foo>::a` in constant functions
--> const-super-trait.rs:10:7
|
LL | x.a();

View file

@ -32,7 +32,7 @@ help: mark `Bar` as `#[const_trait]` to allow it to have `const` implementations
LL | #[const_trait] trait Bar: ~const Foo {}
| ++++++++++++++
error[E0015]: cannot call non-const fn `<T as Foo>::a` in constant functions
error[E0015]: cannot call non-const method `<T as Foo>::a` in constant functions
--> const-super-trait.rs:10:7
|
LL | x.a();

View file

@ -50,7 +50,7 @@ note: `Bar` can't be used with `~const` because it isn't annotated with `#[const
7 | trait Bar: ~const Foo {}
| ^^^^^^^^^^^^^^^^^^^^^
error[E0015]: cannot call non-const fn `<T as Foo>::a` in constant functions
error[E0015]: cannot call non-const method `<T as Foo>::a` in constant functions
--> const-super-trait.rs:10:7
|
10 | x.a();

View file

@ -40,7 +40,7 @@ note: `Bar` can't be used with `~const` because it isn't annotated with `#[const
7 | trait Bar: ~const Foo {}
| ^^^^^^^^^^^^^^^^^^^^^
error[E0015]: cannot call non-const fn `<T as Foo>::a` in constant functions
error[E0015]: cannot call non-const method `<T as Foo>::a` in constant functions
--> const-super-trait.rs:10:7
|
10 | x.a();

View file

@ -8,4 +8,4 @@ fn main() {}
fn non_const_fn(x: i32) -> i32 { x }
global_asm!("/* {} */", const non_const_fn(0));
//~^ERROR: cannot call non-const fn
//~^ERROR: cannot call non-const function

View file

@ -1,4 +1,4 @@
error[E0015]: cannot call non-const fn `non_const_fn` in constants
error[E0015]: cannot call non-const function `non_const_fn` in constants
--> $DIR/non-const.rs:10:31
|
LL | global_asm!("/* {} */", const non_const_fn(0));

View file

@ -2,7 +2,7 @@ struct Project;
struct Value;
static settings_dir: String = format!("");
//~^ ERROR cannot call non-const fn
//~^ ERROR cannot call non-const function
fn from_string(_: String) -> Value {
Value

View file

@ -1,4 +1,4 @@
error[E0015]: cannot call non-const fn `format` in statics
error[E0015]: cannot call non-const function `format` in statics
--> $DIR/issue-64453.rs:4:31
|
LL | static settings_dir: String = format!("");

View file

@ -1,4 +1,4 @@
error[E0015]: cannot call non-const fn `Foo::{constant#0}::Foo::<17>::value` in constants
error[E0015]: cannot call non-const associated function `Foo::{constant#0}::Foo::<17>::value` in constants
--> $DIR/nested-type.rs:15:5
|
LL | Foo::<17>::value()

View file

@ -1,4 +1,4 @@
error[E0015]: cannot call non-const fn `Foo::{constant#0}::Foo::<17>::value` in constants
error[E0015]: cannot call non-const associated function `Foo::{constant#0}::Foo::<17>::value` in constants
--> $DIR/nested-type.rs:15:5
|
LL | Foo::<17>::value()

View file

@ -13,7 +13,7 @@ struct Foo<const N: [u8; {
}
Foo::<17>::value()
//~^ ERROR cannot call non-const fn
//~^ ERROR cannot call non-const associated function
}]>;
//[min]~^^^^^^^^^^^^ ERROR `[u8; {

View file

@ -4,5 +4,5 @@ fn f(x: usize) -> usize {
fn main() {
let _ = [0; f(2)];
//~^ ERROR cannot call non-const fn
//~^ ERROR cannot call non-const function
}

View file

@ -1,4 +1,4 @@
error[E0015]: cannot call non-const fn `f` in constants
error[E0015]: cannot call non-const function `f` in constants
--> $DIR/const-call.rs:6:17
|
LL | let _ = [0; f(2)];

View file

@ -1,14 +1,14 @@
const fn failure() {
panic!("{:?}", 0);
//~^ ERROR cannot call non-const formatting macro in constant functions
//~| ERROR cannot call non-const fn `Arguments::<'_>::new_v1::<1, 1>` in constant functions
//~| ERROR cannot call non-const associated function `Arguments::<'_>::new_v1::<1, 1>` in constant functions
}
const fn print() {
println!("{:?}", 0);
//~^ ERROR cannot call non-const formatting macro in constant functions
//~| ERROR cannot call non-const fn `Arguments::<'_>::new_v1::<2, 1>` in constant functions
//~| ERROR cannot call non-const fn `_print` in constant functions
//~| ERROR cannot call non-const associated function `Arguments::<'_>::new_v1::<2, 1>` in constant functions
//~| ERROR cannot call non-const function `_print` in constant functions
}
fn main() {}

View file

@ -7,7 +7,7 @@ LL | panic!("{:?}", 0);
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= note: this error originates in the macro `$crate::const_format_args` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0015]: cannot call non-const fn `Arguments::<'_>::new_v1::<1, 1>` in constant functions
error[E0015]: cannot call non-const associated function `Arguments::<'_>::new_v1::<1, 1>` in constant functions
--> $DIR/format.rs:2:5
|
LL | panic!("{:?}", 0);
@ -25,7 +25,7 @@ LL | println!("{:?}", 0);
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0015]: cannot call non-const fn `Arguments::<'_>::new_v1::<2, 1>` in constant functions
error[E0015]: cannot call non-const associated function `Arguments::<'_>::new_v1::<2, 1>` in constant functions
--> $DIR/format.rs:8:5
|
LL | println!("{:?}", 0);
@ -34,7 +34,7 @@ LL | println!("{:?}", 0);
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0015]: cannot call non-const fn `_print` in constant functions
error[E0015]: cannot call non-const function `_print` in constant functions
--> $DIR/format.rs:8:5
|
LL | println!("{:?}", 0);

View file

@ -1,4 +1,4 @@
error[E0015]: cannot call non-const fn `core::slice::<impl [()]>::get_unchecked::<std::ops::Range<usize>>` in constants
error[E0015]: cannot call non-const method `core::slice::<impl [()]>::get_unchecked::<std::ops::Range<usize>>` in constants
--> $DIR/ub-slice-get-unchecked.rs:7:29
|
LL | const B: &[()] = unsafe { A.get_unchecked(3..1) };

View file

@ -5,7 +5,7 @@ extern "C" {
const extern "C" fn bar() {
unsafe {
regular_in_block();
//~^ ERROR: cannot call non-const fn
//~^ ERROR: cannot call non-const function
}
}
@ -14,7 +14,7 @@ extern "C" fn regular() {}
const extern "C" fn foo() {
unsafe {
regular();
//~^ ERROR: cannot call non-const fn
//~^ ERROR: cannot call non-const function
}
}

View file

@ -1,4 +1,4 @@
error[E0015]: cannot call non-const fn `regular_in_block` in constant functions
error[E0015]: cannot call non-const function `regular_in_block` in constant functions
--> $DIR/const-extern-fn-call-extern-fn.rs:7:9
|
LL | regular_in_block();
@ -6,7 +6,7 @@ LL | regular_in_block();
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
error[E0015]: cannot call non-const fn `regular` in constant functions
error[E0015]: cannot call non-const function `regular` in constant functions
--> $DIR/const-extern-fn-call-extern-fn.rs:16:9
|
LL | regular();

View file

@ -1,4 +1,4 @@
error[E0015]: cannot call non-const fn `random` in constant functions
error[E0015]: cannot call non-const function `random` in constant functions
--> $DIR/const-fn-not-safe-for-const.rs:14:5
|
LL | random()

View file

@ -8,7 +8,7 @@ fn non_const() -> Thing {
}
pub const Q: i32 = match non_const() {
//~^ ERROR cannot call non-const fn
//~^ ERROR cannot call non-const function
Thing::This => 1,
Thing::That => 0
};

View file

@ -1,4 +1,4 @@
error[E0015]: cannot call non-const fn `non_const` in constants
error[E0015]: cannot call non-const function `non_const` in constants
--> $DIR/issue-46843.rs:10:26
|
LL | pub const Q: i32 = match non_const() {

View file

@ -1,4 +1,4 @@
error[E0015]: cannot call non-const fn `Y::foo` in statics
error[E0015]: cannot call non-const function `Y::foo` in statics
--> $DIR/issue-16538.rs:11:23
|
LL | static foo: &Y::X = &*Y::foo(Y::x as *const Y::X);

View file

@ -8,7 +8,7 @@ const bad : u32 = {
const bad_two : u32 = {
{
invalid();
//~^ ERROR: cannot call non-const fn `invalid`
//~^ ERROR: cannot call non-const function `invalid`
0
}
};
@ -30,7 +30,7 @@ static bad_four : u32 = {
static bad_five : u32 = {
{
invalid();
//~^ ERROR: cannot call non-const fn `invalid`
//~^ ERROR: cannot call non-const function `invalid`
0
}
};
@ -52,7 +52,7 @@ static mut bad_seven : u32 = {
static mut bad_eight : u32 = {
{
invalid();
//~^ ERROR: cannot call non-const fn `invalid`
//~^ ERROR: cannot call non-const function `invalid`
0
}
};

View file

@ -1,4 +1,4 @@
error[E0015]: cannot call non-const fn `invalid` in constants
error[E0015]: cannot call non-const function `invalid` in constants
--> $DIR/issue-32829-2.rs:10:9
|
LL | invalid();
@ -6,7 +6,7 @@ LL | invalid();
|
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
error[E0015]: cannot call non-const fn `invalid` in statics
error[E0015]: cannot call non-const function `invalid` in statics
--> $DIR/issue-32829-2.rs:32:9
|
LL | invalid();
@ -15,7 +15,7 @@ LL | invalid();
= note: calls in statics are limited to constant functions, tuple structs and tuple variants
= note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`
error[E0015]: cannot call non-const fn `invalid` in statics
error[E0015]: cannot call non-const function `invalid` in statics
--> $DIR/issue-32829-2.rs:54:9
|
LL | invalid();

View file

@ -1,7 +1,7 @@
fn xyz() -> u8 { 42 }
const NUM: u8 = xyz();
//~^ ERROR cannot call non-const fn
//~^ ERROR cannot call non-const function
fn main() {
match 1 {

View file

@ -1,4 +1,4 @@
error[E0015]: cannot call non-const fn `xyz` in constants
error[E0015]: cannot call non-const function `xyz` in constants
--> $DIR/issue-43105.rs:3:17
|
LL | const NUM: u8 = xyz();

View file

@ -1,7 +1,7 @@
const fn foo(a: i32) -> Vec<i32> {
vec![1, 2, 3]
//~^ ERROR allocations are not allowed
//~| ERROR cannot call non-const fn
//~| ERROR cannot call non-const method
}
fn main() {}

View file

@ -6,7 +6,7 @@ LL | vec![1, 2, 3]
|
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0015]: cannot call non-const fn `slice::<impl [i32]>::into_vec::<std::alloc::Global>` in constant functions
error[E0015]: cannot call non-const method `slice::<impl [i32]>::into_vec::<std::alloc::Global>` in constant functions
--> $DIR/bad_const_fn_body_ice.rs:2:5
|
LL | vec![1, 2, 3]

View file

@ -6,6 +6,6 @@ fn bar() -> Foo {
}
static foo: Foo = bar();
//~^ ERROR cannot call non-const fn
//~^ ERROR cannot call non-const function
fn main() {}

View file

@ -1,4 +1,4 @@
error[E0015]: cannot call non-const fn `bar` in statics
error[E0015]: cannot call non-const function `bar` in statics
--> $DIR/mir_check_nonconst.rs:8:19
|
LL | static foo: Foo = bar();

View file

@ -7,6 +7,8 @@ note: inside `std::ptr::read::<MaybeUninit<MaybeUninit<u8>>>`
--> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
note: inside `std::ptr::swap_nonoverlapping_simple_untyped::<MaybeUninit<u8>>`
--> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
note: inside `swap_nonoverlapping::compiletime::<MaybeUninit<u8>>`
--> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
note: inside `swap_nonoverlapping::<MaybeUninit<u8>>`
--> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
note: inside `X`
@ -20,6 +22,7 @@ note: inside `X`
| |_________^
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
= note: this error originates in the macro `$crate::intrinsics::const_eval_select` which comes from the expansion of the macro `const_eval_select` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 1 previous error

View file

@ -3,5 +3,5 @@
#![allow(warnings)]
const CON: Vec<i32> = vec![1, 2, 3]; //~ ERROR E0010
//~| ERROR cannot call non-const fn
//~| ERROR cannot call non-const method
fn main() {}

View file

@ -7,7 +7,7 @@ LL | const CON: Vec<i32> = vec![1, 2, 3];
= note: The runtime heap is not yet available at compile-time, so no runtime heap allocations can be created.
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0015]: cannot call non-const fn `slice::<impl [i32]>::into_vec::<std::alloc::Global>` in constants
error[E0015]: cannot call non-const method `slice::<impl [i32]>::into_vec::<std::alloc::Global>` in constants
--> $DIR/E0010-teach.rs:5:23
|
LL | const CON: Vec<i32> = vec![1, 2, 3];

View file

@ -1,5 +1,5 @@
#![allow(warnings)]
const CON: Vec<i32> = vec![1, 2, 3]; //~ ERROR E0010
//~| ERROR cannot call non-const fn
//~| ERROR cannot call non-const method
fn main() {}

View file

@ -6,7 +6,7 @@ LL | const CON: Vec<i32> = vec![1, 2, 3];
|
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0015]: cannot call non-const fn `slice::<impl [i32]>::into_vec::<std::alloc::Global>` in constants
error[E0015]: cannot call non-const method `slice::<impl [i32]>::into_vec::<std::alloc::Global>` in constants
--> $DIR/E0010.rs:3:23
|
LL | const CON: Vec<i32> = vec![1, 2, 3];

View file

@ -3,6 +3,6 @@ fn create_some() -> Option<u8> {
}
const FOO: Option<u8> = create_some();
//~^ ERROR cannot call non-const fn `create_some` in constants [E0015]
//~^ ERROR cannot call non-const function `create_some` in constants [E0015]
fn main() {}

View file

@ -1,4 +1,4 @@
error[E0015]: cannot call non-const fn `create_some` in constants
error[E0015]: cannot call non-const function `create_some` in constants
--> $DIR/E0015.rs:5:25
|
LL | const FOO: Option<u8> = create_some();

View file

@ -4,14 +4,14 @@
const fn f() {
if false {
become not_const();
//~^ error: cannot call non-const fn `not_const` in constant functions
//~^ error: cannot call non-const function `not_const` in constant functions
}
}
const fn g((): ()) {
if false {
become yes_const(not_const());
//~^ error: cannot call non-const fn `not_const` in constant functions
//~^ error: cannot call non-const function `not_const` in constant functions
}
}

View file

@ -1,4 +1,4 @@
error[E0015]: cannot call non-const fn `not_const` in constant functions
error[E0015]: cannot call non-const function `not_const` in constant functions
--> $DIR/constck.rs:6:16
|
LL | become not_const();
@ -6,7 +6,7 @@ LL | become not_const();
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
error[E0015]: cannot call non-const fn `not_const` in constant functions
error[E0015]: cannot call non-const function `not_const` in constant functions
--> $DIR/constck.rs:13:26
|
LL | become yes_const(not_const());

View file

@ -3,6 +3,6 @@ use std::cell::RefCell;
// Regression test for issue 7364
static boxed: Box<RefCell<isize>> = Box::new(RefCell::new(0));
//~^ ERROR `RefCell<isize>` cannot be shared between threads safely [E0277]
//~| ERROR cannot call non-const fn
//~| ERROR cannot call non-const associated function
fn main() { }

View file

@ -11,7 +11,7 @@ note: required because it appears within the type `Box<RefCell<isize>>`
--> $SRC_DIR/alloc/src/boxed.rs:LL:COL
= note: shared static variables must have a type that implements `Sync`
error[E0015]: cannot call non-const fn `Box::<RefCell<isize>>::new` in statics
error[E0015]: cannot call non-const associated function `Box::<RefCell<isize>>::new` in statics
--> $DIR/issue-7364.rs:4:37
|
LL | static boxed: Box<RefCell<isize>> = Box::new(RefCell::new(0));

View file

@ -1,4 +1,4 @@
error[E0015]: cannot call non-const fn `<Dim3 as Dim>::dim` in constants
error[E0015]: cannot call non-const associated function `<Dim3 as Dim>::dim` in constants
--> $DIR/issue-39559-2.rs:14:24
|
LL | let array: [usize; Dim3::dim()]
@ -6,7 +6,7 @@ LL | let array: [usize; Dim3::dim()]
|
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
error[E0015]: cannot call non-const fn `<Dim3 as Dim>::dim` in constants
error[E0015]: cannot call non-const associated function `<Dim3 as Dim>::dim` in constants
--> $DIR/issue-39559-2.rs:16:15
|
LL | = [0; Dim3::dim()];

View file

@ -1,4 +1,4 @@
static mut a: Box<isize> = Box::new(3);
//~^ ERROR cannot call non-const fn
//~^ ERROR cannot call non-const associated function
fn main() {}

View file

@ -1,4 +1,4 @@
error[E0015]: cannot call non-const fn `Box::<isize>::new` in statics
error[E0015]: cannot call non-const associated function `Box::<isize>::new` in statics
--> $DIR/static-mut-not-constant.rs:1:28
|
LL | static mut a: Box<isize> = Box::new(3);

View file

@ -1,4 +1,4 @@
error[E0015]: cannot call non-const fn `foo` in statics
error[E0015]: cannot call non-const function `foo` in statics
--> $DIR/static-vec-repeat-not-constant.rs:3:25
|
LL | static a: [isize; 2] = [foo(); 2];

View file

@ -89,7 +89,7 @@ static mut STATIC13: SafeStruct =
static mut STATIC14: SafeStruct = SafeStruct {
field1: SafeEnum::Variant1,
field2: SafeEnum::Variant4("str".to_string()), //~ ERROR cannot call non-const fn
field2: SafeEnum::Variant4("str".to_string()), //~ ERROR cannot call non-const method
};
static STATIC15: &'static [Vec<MyOwned>] = &[

View file

@ -19,7 +19,7 @@ LL | static STATIC11: Vec<MyOwned> = vec![MyOwned];
|
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0015]: cannot call non-const fn `slice::<impl [MyOwned]>::into_vec::<std::alloc::Global>` in statics
error[E0015]: cannot call non-const method `slice::<impl [MyOwned]>::into_vec::<std::alloc::Global>` in statics
--> $DIR/check-values-constraints.rs:81:33
|
LL | static STATIC11: Vec<MyOwned> = vec![MyOwned];
@ -29,7 +29,7 @@ LL | static STATIC11: Vec<MyOwned> = vec![MyOwned];
= note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0015]: cannot call non-const fn `<str as ToString>::to_string` in statics
error[E0015]: cannot call non-const method `<str as ToString>::to_string` in statics
--> $DIR/check-values-constraints.rs:92:38
|
LL | field2: SafeEnum::Variant4("str".to_string()),
@ -46,7 +46,7 @@ LL | vec![MyOwned],
|
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0015]: cannot call non-const fn `slice::<impl [MyOwned]>::into_vec::<std::alloc::Global>` in statics
error[E0015]: cannot call non-const method `slice::<impl [MyOwned]>::into_vec::<std::alloc::Global>` in statics
--> $DIR/check-values-constraints.rs:96:5
|
LL | vec![MyOwned],
@ -64,7 +64,7 @@ LL | vec![MyOwned],
|
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0015]: cannot call non-const fn `slice::<impl [MyOwned]>::into_vec::<std::alloc::Global>` in statics
error[E0015]: cannot call non-const method `slice::<impl [MyOwned]>::into_vec::<std::alloc::Global>` in statics
--> $DIR/check-values-constraints.rs:98:5
|
LL | vec![MyOwned],
@ -82,7 +82,7 @@ LL | &vec![MyOwned],
|
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0015]: cannot call non-const fn `slice::<impl [MyOwned]>::into_vec::<std::alloc::Global>` in statics
error[E0015]: cannot call non-const method `slice::<impl [MyOwned]>::into_vec::<std::alloc::Global>` in statics
--> $DIR/check-values-constraints.rs:103:6
|
LL | &vec![MyOwned],
@ -100,7 +100,7 @@ LL | &vec![MyOwned],
|
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0015]: cannot call non-const fn `slice::<impl [MyOwned]>::into_vec::<std::alloc::Global>` in statics
error[E0015]: cannot call non-const method `slice::<impl [MyOwned]>::into_vec::<std::alloc::Global>` in statics
--> $DIR/check-values-constraints.rs:105:6
|
LL | &vec![MyOwned],
@ -118,7 +118,7 @@ LL | static STATIC19: Vec<isize> = vec![3];
|
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0015]: cannot call non-const fn `slice::<impl [isize]>::into_vec::<std::alloc::Global>` in statics
error[E0015]: cannot call non-const method `slice::<impl [isize]>::into_vec::<std::alloc::Global>` in statics
--> $DIR/check-values-constraints.rs:111:31
|
LL | static STATIC19: Vec<isize> = vec![3];
@ -136,7 +136,7 @@ LL | static x: Vec<isize> = vec![3];
|
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0015]: cannot call non-const fn `slice::<impl [isize]>::into_vec::<std::alloc::Global>` in statics
error[E0015]: cannot call non-const method `slice::<impl [isize]>::into_vec::<std::alloc::Global>` in statics
--> $DIR/check-values-constraints.rs:117:32
|
LL | static x: Vec<isize> = vec![3];

View file

@ -1,4 +1,5 @@
//@ compile-flags: -Znext-solver
//@ revisions: current next
//@[next] compile-flags: -Znext-solver
//@ check-pass
#![feature(const_trait_impl)]

View file

@ -1,5 +1,4 @@
//@ compile-flags: -Znext-solver
//@ known-bug: unknown
//@ check-pass
#![feature(const_trait_impl, generic_const_exprs)]
#![allow(incomplete_features)]

View file

@ -1,35 +0,0 @@
error: `-Znext-solver=globally` and `generic_const_exprs` are incompatible, using them at the same time is not allowed
--> $DIR/assoc-type-const-bound-usage-1.rs:4:30
|
LL | #![feature(const_trait_impl, generic_const_exprs)]
| ^^^^^^^^^^^^^^^^^^^
|
= help: remove one of these features
error[E0284]: type annotations needed: cannot normalize `unqualified<T>::{constant#0}`
--> $DIR/assoc-type-const-bound-usage-1.rs:15:37
|
LL | fn unqualified<T: const Trait>() -> Type<{ T::Assoc::func() }> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot normalize `unqualified<T>::{constant#0}`
error[E0284]: type annotations needed: cannot normalize `qualified<T>::{constant#0}`
--> $DIR/assoc-type-const-bound-usage-1.rs:19:35
|
LL | fn qualified<T: const Trait>() -> Type<{ <T as Trait>::Assoc::func() }> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot normalize `qualified<T>::{constant#0}`
error[E0284]: type annotations needed: cannot normalize `unqualified<T>::{constant#0}`
--> $DIR/assoc-type-const-bound-usage-1.rs:16:5
|
LL | Type
| ^^^^ cannot normalize `unqualified<T>::{constant#0}`
error[E0284]: type annotations needed: cannot normalize `qualified<T>::{constant#0}`
--> $DIR/assoc-type-const-bound-usage-1.rs:20:5
|
LL | Type
| ^^^^ cannot normalize `qualified<T>::{constant#0}`
error: aborting due to 5 previous errors
For more information about this error, try `rustc --explain E0284`.

View file

@ -0,0 +1,15 @@
error[E0277]: the trait bound `U: ~const Other` is not satisfied
--> $DIR/assoc-type-const-bound-usage-fail-2.rs:24:5
|
LL | T::Assoc::<U>::func();
| ^^^^^^^^^^^^^
error[E0277]: the trait bound `U: ~const Other` is not satisfied
--> $DIR/assoc-type-const-bound-usage-fail-2.rs:27:5
|
LL | <T as Trait>::Assoc::<U>::func();
| ^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0277`.

View file

@ -1,11 +1,11 @@
error[E0277]: the trait bound `<T as Trait>::Assoc<U>: ~const Trait` is not satisfied
--> $DIR/assoc-type-const-bound-usage-fail-2.rs:23:5
--> $DIR/assoc-type-const-bound-usage-fail-2.rs:24:5
|
LL | T::Assoc::<U>::func();
| ^^^^^^^^^^^^^
error[E0277]: the trait bound `<T as Trait>::Assoc<U>: ~const Trait` is not satisfied
--> $DIR/assoc-type-const-bound-usage-fail-2.rs:25:5
--> $DIR/assoc-type-const-bound-usage-fail-2.rs:27:5
|
LL | <T as Trait>::Assoc::<U>::func();
| ^^^^^^^^^^^^^^^^^^^^^^^^

View file

@ -1,4 +1,5 @@
//@ compile-flags: -Znext-solver
//@ revisions: current next
//@[next] compile-flags: -Znext-solver
// Check that `~const` item bounds only hold if the where clauses on the
// associated type are also const.
@ -21,9 +22,11 @@ trait Other {}
const fn fails<T: ~const Trait, U: Other>() {
T::Assoc::<U>::func();
//~^ ERROR the trait bound `<T as Trait>::Assoc<U>: ~const Trait` is not satisfied
//[current]~^ ERROR the trait bound `U: ~const Other` is not satisfied
//[next]~^^ ERROR the trait bound `<T as Trait>::Assoc<U>: ~const Trait` is not satisfied
<T as Trait>::Assoc::<U>::func();
//~^ ERROR the trait bound `<T as Trait>::Assoc<U>: ~const Trait` is not satisfied
//[current]~^ ERROR the trait bound `U: ~const Other` is not satisfied
//[next]~^^ ERROR the trait bound `<T as Trait>::Assoc<U>: ~const Trait` is not satisfied
}
const fn works<T: ~const Trait, U: ~const Other>() {

View file

@ -1,11 +1,11 @@
error[E0277]: the trait bound `T: ~const Trait` is not satisfied
--> $DIR/assoc-type-const-bound-usage-fail.rs:16:5
--> $DIR/assoc-type-const-bound-usage-fail.rs:17:5
|
LL | T::Assoc::func();
| ^^^^^^^^
error[E0277]: the trait bound `T: ~const Trait` is not satisfied
--> $DIR/assoc-type-const-bound-usage-fail.rs:18:5
--> $DIR/assoc-type-const-bound-usage-fail.rs:19:5
|
LL | <T as Trait>::Assoc::func();
| ^^^^^^^^^^^^^^^^^^^

View file

@ -0,0 +1,15 @@
error[E0277]: the trait bound `T: ~const Trait` is not satisfied
--> $DIR/assoc-type-const-bound-usage-fail.rs:17:5
|
LL | T::Assoc::func();
| ^^^^^^^^
error[E0277]: the trait bound `T: ~const Trait` is not satisfied
--> $DIR/assoc-type-const-bound-usage-fail.rs:19:5
|
LL | <T as Trait>::Assoc::func();
| ^^^^^^^^^^^^^^^^^^^
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0277`.

View file

@ -1,4 +1,5 @@
//@ compile-flags: -Znext-solver
//@ revisions: current next
//@[next] compile-flags: -Znext-solver
// Check that `~const` item bounds only hold if the parent trait is `~const`.
// i.e. check that we validate the const conditions for the associated type

View file

@ -1,11 +1,11 @@
error[E0277]: the trait bound `NonConstAdd: ~const Add` is not satisfied
--> $DIR/assoc-type.rs:36:16
--> $DIR/assoc-type.rs:37:16
|
LL | type Bar = NonConstAdd;
| ^^^^^^^^^^^
|
note: required by a bound in `Foo::Bar`
--> $DIR/assoc-type.rs:32:15
--> $DIR/assoc-type.rs:33:15
|
LL | type Bar: ~const Add;
| ^^^^^^ required by this bound in `Foo::Bar`

View file

@ -0,0 +1,15 @@
error[E0277]: the trait bound `NonConstAdd: ~const Add` is not satisfied
--> $DIR/assoc-type.rs:37:16
|
LL | type Bar = NonConstAdd;
| ^^^^^^^^^^^
|
note: required by a bound in `Foo::Bar`
--> $DIR/assoc-type.rs:33:15
|
LL | type Bar: ~const Add;
| ^^^^^^ required by this bound in `Foo::Bar`
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0277`.

View file

@ -1,4 +1,5 @@
//@ compile-flags: -Znext-solver
//@ revisions: current next
//@[next] compile-flags: -Znext-solver
#![feature(const_trait_impl)]

View file

@ -7,7 +7,7 @@ LL | impl const PartialEq for Int {
= note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
= note: adding a non-const method body in the future would be a breaking change
error[E0015]: cannot call non-const fn `<Int as PartialEq>::eq` in constant functions
error[E0015]: cannot call non-const method `<Int as PartialEq>::eq` in constant functions
--> $DIR/call-const-trait-method-pass.rs:20:15
|
LL | !self.eq(other)

View file

@ -17,7 +17,7 @@ note: `PartialEq` can't be used with `~const` because it isn't annotated with `#
--> $SRC_DIR/core/src/cmp.rs:LL:COL
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error[E0015]: cannot call non-const fn `<T as PartialEq>::eq` in constant functions
error[E0015]: cannot call non-const method `<T as PartialEq>::eq` in constant functions
--> $DIR/call-generic-in-impl.rs:12:9
|
LL | PartialEq::eq(self, other)

View file

@ -53,7 +53,7 @@ LL | *t == *t
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
error[E0015]: cannot call non-const fn `<S as PartialEq>::eq` in constant functions
error[E0015]: cannot call non-const method `<S as PartialEq>::eq` in constant functions
--> $DIR/call-generic-method-chain.rs:16:15
|
LL | !self.eq(other)

View file

@ -53,7 +53,7 @@ LL | *t == *t
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
error[E0015]: cannot call non-const fn `<S as PartialEq>::eq` in constant functions
error[E0015]: cannot call non-const method `<S as PartialEq>::eq` in constant functions
--> $DIR/call-generic-method-dup-bound.rs:14:15
|
LL | !self.eq(other)

View file

@ -34,7 +34,7 @@ LL | *t == *t
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
error[E0015]: cannot call non-const fn `<S as PartialEq>::eq` in constant functions
error[E0015]: cannot call non-const method `<S as PartialEq>::eq` in constant functions
--> $DIR/call-generic-method-pass.rs:16:15
|
LL | !self.eq(other)

View file

@ -12,7 +12,7 @@ fn non_const() {}
impl const T for S {
fn foo() { non_const() }
//~^ ERROR cannot call non-const fn
//~^ ERROR cannot call non-const function
}
fn main() {}

View file

@ -1,4 +1,4 @@
error[E0015]: cannot call non-const fn `non_const` in constant functions
error[E0015]: cannot call non-const function `non_const` in constant functions
--> $DIR/const-check-fns-in-const-impl.rs:14:16
|
LL | fn foo() { non_const() }

View file

@ -12,6 +12,6 @@ impl Foo for () {
fn main() {
(const || { (()).foo() })();
//~^ ERROR: cannot call non-const fn `<() as Foo>::foo` in constant functions
//~^ ERROR: cannot call non-const method `<() as Foo>::foo` in constant functions
// FIXME(const_trait_impl) this should probably say constant closures
}

View file

@ -1,4 +1,4 @@
error[E0015]: cannot call non-const fn `<() as Foo>::foo` in constant functions
error[E0015]: cannot call non-const method `<() as Foo>::foo` in constant functions
--> $DIR/const_closure-const_trait_impl-ice-113381.rs:14:22
|
LL | (const || { (()).foo() })();

View file

@ -8,7 +8,7 @@ LL | #[derive_const(Default)]
= note: adding a non-const method body in the future would be a breaking change
= note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0015]: cannot call non-const fn `<A as Default>::default` in constant functions
error[E0015]: cannot call non-const associated function `<A as Default>::default` in constant functions
--> $DIR/derive-const-non-const-type.rs:11:14
|
LL | #[derive_const(Default)]

View file

@ -48,7 +48,7 @@ LL | #[derive_const(Default, PartialEq)]
= note: adding a non-const method body in the future would be a breaking change
= note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0015]: cannot call non-const fn `<S as Default>::default` in constants
error[E0015]: cannot call non-const associated function `<S as Default>::default` in constants
--> $DIR/derive-const-use.rs:18:35
|
LL | const _: () = assert!(S((), A) == S::default());
@ -64,7 +64,7 @@ LL | const _: () = assert!(S((), A) == S::default());
|
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
error[E0015]: cannot call non-const fn `<() as Default>::default` in constant functions
error[E0015]: cannot call non-const associated function `<() as Default>::default` in constant functions
--> $DIR/derive-const-use.rs:16:14
|
LL | #[derive_const(Default, PartialEq)]
@ -75,7 +75,7 @@ LL | pub struct S((), A);
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0015]: cannot call non-const fn `<A as Default>::default` in constant functions
error[E0015]: cannot call non-const associated function `<A as Default>::default` in constant functions
--> $DIR/derive-const-use.rs:16:18
|
LL | #[derive_const(Default, PartialEq)]

View file

@ -10,7 +10,7 @@ const fn test() -> impl ~const Fn() {
match sl {
[first, remainder @ ..] => {
assert_eq!(first, &b'f');
//~^ ERROR cannot call non-const fn
//~^ ERROR cannot call non-const function
//~| ERROR cannot call non-const operator
}
[] => panic!(),

View file

@ -46,7 +46,7 @@ LL | assert_eq!(first, &b'f');
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0015]: cannot call non-const fn `core::panicking::assert_failed::<&u8, &u8>` in constant functions
error[E0015]: cannot call non-const function `core::panicking::assert_failed::<&u8, &u8>` in constant functions
--> $DIR/ice-112822-expected-type-for-param.rs:12:17
|
LL | assert_eq!(first, &b'f');

View file

@ -24,7 +24,7 @@ impl Trait for () {
const fn foo() {
().foo();
//~^ ERROR cannot call non-const fn `<() as Trait>::foo` in constant functions
//~^ ERROR cannot call non-const method `<() as Trait>::foo` in constant functions
}
const UWU: () = foo();

View file

@ -7,7 +7,7 @@ LL | fn foo(self);
LL | fn foo<T>(self) {
| ^ found 1 type parameter
error[E0015]: cannot call non-const fn `<() as Trait>::foo` in constant functions
error[E0015]: cannot call non-const method `<() as Trait>::foo` in constant functions
--> $DIR/inline-incorrect-early-bound-in-ctfe.rs:26:8
|
LL | ().foo();

View file

@ -6,7 +6,7 @@ trait Tr {
fn req(&self);
fn prov(&self) {
println!("lul"); //~ ERROR: cannot call non-const fn `_print` in constant functions
println!("lul"); //~ ERROR: cannot call non-const function `_print` in constant functions
self.req();
}
}

View file

@ -1,4 +1,4 @@
error[E0015]: cannot call non-const fn `_print` in constant functions
error[E0015]: cannot call non-const function `_print` in constant functions
--> $DIR/issue-79450.rs:9:9
|
LL | println!("lul");

View file

@ -9,7 +9,7 @@ pub trait A {
pub const fn foo<T: A>() -> bool {
T::assoc()
//FIXME ~^ ERROR the trait bound
//FIXME ~| ERROR cannot call non-const fn
//FIXME ~| ERROR cannot call non-const function
}
fn main() {}

View file

@ -1,4 +1,4 @@
error[E0015]: cannot call non-const fn `<T as A>::assoc` in constant functions
error[E0015]: cannot call non-const associated function `<T as A>::assoc` in constant functions
--> $DIR/issue-88155.rs:10:5
|
LL | T::assoc()

View file

@ -11,5 +11,5 @@ impl Foo for () {
fn main() {
(const || { (()).foo() })();
//~^ ERROR: cannot call non-const fn
//~^ ERROR: cannot call non-const method
}

View file

@ -1,4 +1,4 @@
error[E0015]: cannot call non-const fn `<() as Foo>::foo` in constant functions
error[E0015]: cannot call non-const method `<() as Foo>::foo` in constant functions
--> $DIR/non-const-op-const-closure-non-const-outer.rs:13:22
|
LL | (const || { (()).foo() })();

View file

@ -17,7 +17,7 @@ note: `From` can't be used with `~const` because it isn't annotated with `#[cons
--> $SRC_DIR/core/src/convert/mod.rs:LL:COL
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error[E0015]: cannot call non-const fn `<B as From<A>>::from` in constant functions
error[E0015]: cannot call non-const associated function `<B as From<A>>::from` in constant functions
--> $DIR/non-const-op-in-closure-in-const.rs:12:9
|
LL | B::from(self)

View file

@ -4,7 +4,7 @@ error[E0635]: unknown feature `const_default_impls`
LL | #![cfg_attr(gated, feature(const_trait_impl, const_default_impls))]
| ^^^^^^^^^^^^^^^^^^^
error[E0015]: cannot call non-const fn `<Vec<usize> as Default>::default` in constant functions
error[E0015]: cannot call non-const associated function `<Vec<usize> as Default>::default` in constant functions
--> $DIR/std-impl-gate.rs:13:5
|
LL | Default::default()

View file

@ -11,7 +11,7 @@ fn non_const_context() -> Vec<usize> {
const fn const_context() -> Vec<usize> {
Default::default()
//[stock]~^ ERROR cannot call non-const fn
//[stock]~^ ERROR cannot call non-const associated function
}
fn main() {

View file

@ -1,4 +1,4 @@
error[E0015]: cannot call non-const fn `<Vec<usize> as Default>::default` in constant functions
error[E0015]: cannot call non-const associated function `<Vec<usize> as Default>::default` in constant functions
--> $DIR/std-impl-gate.rs:13:5
|
LL | Default::default()

View file

@ -45,7 +45,7 @@ help: mark `Foo` as `#[const_trait]` to allow it to have `const` implementations
LL | #[const_trait] trait Foo {
| ++++++++++++++
error[E0015]: cannot call non-const fn `<T as Foo>::a` in constant functions
error[E0015]: cannot call non-const method `<T as Foo>::a` in constant functions
--> $DIR/super-traits-fail-2.rs:20:7
|
LL | x.a();

View file

@ -57,7 +57,7 @@ help: mark `Foo` as `#[const_trait]` to allow it to have `const` implementations
LL | #[const_trait] trait Foo {
| ++++++++++++++
error[E0015]: cannot call non-const fn `<T as Foo>::a` in constant functions
error[E0015]: cannot call non-const method `<T as Foo>::a` in constant functions
--> $DIR/super-traits-fail-2.rs:20:7
|
LL | x.a();

View file

@ -19,7 +19,7 @@ trait Bar: ~const Foo {}
const fn foo<T: Bar>(x: &T) {
x.a();
//[yy,yn]~^ ERROR the trait bound `T: ~const Foo`
//[nn,ny]~^^ ERROR cannot call non-const fn `<T as Foo>::a` in constant functions
//[nn,ny]~^^ ERROR cannot call non-const method `<T as Foo>::a` in constant functions
}
fn main() {}

View file

@ -88,7 +88,7 @@ help: enable `#![feature(const_trait_impl)]` in your crate and mark `Bar` as `#[
LL | #[const_trait] trait Bar: ~const Foo {}
| ++++++++++++++
error[E0015]: cannot call non-const fn `<T as Foo>::a` in constant functions
error[E0015]: cannot call non-const method `<T as Foo>::a` in constant functions
--> $DIR/super-traits-fail-3.rs:36:7
|
LL | x.a();

View file

@ -88,7 +88,7 @@ help: enable `#![feature(const_trait_impl)]` in your crate and mark `Bar` as `#[
LL | #[const_trait] trait Bar: ~const Foo {}
| ++++++++++++++
error[E0015]: cannot call non-const fn `<T as Foo>::a` in constant functions
error[E0015]: cannot call non-const method `<T as Foo>::a` in constant functions
--> $DIR/super-traits-fail-3.rs:36:7
|
LL | x.a();

View file

@ -35,7 +35,7 @@ const fn foo<T: ~const Bar>(x: &T) {
//[nyy,nyn,nny,nnn]~^^^ ERROR: const trait impls are experimental
x.a();
//[yyn]~^ ERROR: the trait bound `T: ~const Foo` is not satisfied
//[ynn,yny,nny,nnn]~^^ ERROR: cannot call non-const fn `<T as Foo>::a` in constant functions
//[ynn,yny,nny,nnn]~^^ ERROR: cannot call non-const method `<T as Foo>::a` in constant functions
//[nyy,nyn]~^^^ ERROR: cannot call conditionally-const method `<T as Foo>::a` in constant functions
}

Some files were not shown because too many files have changed in this diff Show more