Rollup merge of #143640 - oli-obk:const-fn-traits, r=compiler-errors

Constify `Fn*` traits

r? `@compiler-errors` `@fee1-dead`

this should unlock a few things. A few `const_closures` tests have broken even more than before, but that feature is marked as incomplete anyway

cc rust-lang/rust#67792
This commit is contained in:
Matthias Krüger
2025-07-10 20:28:49 +02:00
committed by GitHub
28 changed files with 146 additions and 626 deletions

View File

@@ -82,13 +82,6 @@ hir_typeck_cast_unknown_pointer = cannot cast {$to ->
hir_typeck_const_continue_bad_label = hir_typeck_const_continue_bad_label =
`#[const_continue]` must break to a labeled block that participates in a `#[loop_match]` `#[const_continue]` must break to a labeled block that participates in a `#[loop_match]`
hir_typeck_const_select_must_be_const = this argument must be a `const fn`
.help = consult the documentation on `const_eval_select` for more information
hir_typeck_const_select_must_be_fn = this argument must be a function item
.note = expected a function item, found {$ty}
.help = consult the documentation on `const_eval_select` for more information
hir_typeck_continue_labeled_block = hir_typeck_continue_labeled_block =
`continue` pointing to a labeled block `continue` pointing to a labeled block
.label = labeled blocks cannot be `continue`'d .label = labeled blocks cannot be `continue`'d

View File

@@ -578,29 +578,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
} }
if let Some(def_id) = def_id
&& self.tcx.def_kind(def_id) == hir::def::DefKind::Fn
&& self.tcx.is_intrinsic(def_id, sym::const_eval_select)
{
let fn_sig = self.resolve_vars_if_possible(fn_sig);
for idx in 0..=1 {
let arg_ty = fn_sig.inputs()[idx + 1];
let span = arg_exprs.get(idx + 1).map_or(call_expr.span, |arg| arg.span);
// Check that second and third argument of `const_eval_select` must be `FnDef`, and additionally that
// the second argument must be `const fn`. The first argument must be a tuple, but this is already expressed
// in the function signature (`F: FnOnce<ARG>`), so I did not bother to add another check here.
//
// This check is here because there is currently no way to express a trait bound for `FnDef` types only.
if let ty::FnDef(def_id, _args) = *arg_ty.kind() {
if idx == 0 && !self.tcx.is_const_fn(def_id) {
self.dcx().emit_err(errors::ConstSelectMustBeConst { span });
}
} else {
self.dcx().emit_err(errors::ConstSelectMustBeFn { span, ty: arg_ty });
}
}
}
fn_sig.output() fn_sig.output()
} }

View File

@@ -605,24 +605,6 @@ impl Subdiagnostic for RemoveSemiForCoerce {
} }
} }
#[derive(Diagnostic)]
#[diag(hir_typeck_const_select_must_be_const)]
#[help]
pub(crate) struct ConstSelectMustBeConst {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(hir_typeck_const_select_must_be_fn)]
#[note]
#[help]
pub(crate) struct ConstSelectMustBeFn<'a> {
#[primary_span]
pub span: Span,
pub ty: Ty<'a>,
}
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(hir_typeck_union_pat_multiple_fields)] #[diag(hir_typeck_union_pat_multiple_fields)]
pub(crate) struct UnionPatMultipleFields { pub(crate) struct UnionPatMultipleFields {

View File

@@ -529,7 +529,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// process any deferred resolutions. // process any deferred resolutions.
let deferred_call_resolutions = self.remove_deferred_call_resolutions(closure_def_id); let deferred_call_resolutions = self.remove_deferred_call_resolutions(closure_def_id);
for deferred_call_resolution in deferred_call_resolutions { for deferred_call_resolution in deferred_call_resolutions {
deferred_call_resolution.resolve(self); deferred_call_resolution.resolve(&mut FnCtxt::new(
self,
self.param_env,
closure_def_id,
));
} }
} }

View File

@@ -1,7 +1,8 @@
use rustc_hir::{self as hir, LangItem}; use rustc_hir::{self as hir, LangItem};
use rustc_infer::infer::{BoundRegionConversionTime, DefineOpaqueTypes}; use rustc_infer::infer::{BoundRegionConversionTime, DefineOpaqueTypes};
use rustc_infer::traits::{ use rustc_infer::traits::{
ImplDerivedHostCause, ImplSource, Obligation, ObligationCauseCode, PredicateObligation, ImplDerivedHostCause, ImplSource, Obligation, ObligationCause, ObligationCauseCode,
PredicateObligation,
}; };
use rustc_middle::span_bug; use rustc_middle::span_bug;
use rustc_middle::traits::query::NoSolution; use rustc_middle::traits::query::NoSolution;
@@ -303,6 +304,9 @@ fn evaluate_host_effect_from_builtin_impls<'tcx>(
) -> Result<ThinVec<PredicateObligation<'tcx>>, EvaluationFailure> { ) -> Result<ThinVec<PredicateObligation<'tcx>>, EvaluationFailure> {
match selcx.tcx().as_lang_item(obligation.predicate.def_id()) { match selcx.tcx().as_lang_item(obligation.predicate.def_id()) {
Some(LangItem::Destruct) => evaluate_host_effect_for_destruct_goal(selcx, obligation), Some(LangItem::Destruct) => evaluate_host_effect_for_destruct_goal(selcx, obligation),
Some(LangItem::Fn | LangItem::FnMut | LangItem::FnOnce) => {
evaluate_host_effect_for_fn_goal(selcx, obligation)
}
_ => Err(EvaluationFailure::NoSolution), _ => Err(EvaluationFailure::NoSolution),
} }
} }
@@ -398,6 +402,51 @@ fn evaluate_host_effect_for_destruct_goal<'tcx>(
.collect()) .collect())
} }
// NOTE: Keep this in sync with `extract_fn_def_from_const_callable` in the new solver.
fn evaluate_host_effect_for_fn_goal<'tcx>(
selcx: &mut SelectionContext<'_, 'tcx>,
obligation: &HostEffectObligation<'tcx>,
) -> Result<ThinVec<PredicateObligation<'tcx>>, EvaluationFailure> {
let tcx = selcx.tcx();
let self_ty = obligation.predicate.self_ty();
let (def, args) = match *self_ty.kind() {
ty::FnDef(def, args) => (def, args),
// We may support function pointers at some point in the future
ty::FnPtr(..) => return Err(EvaluationFailure::NoSolution),
// Closures could implement `[const] Fn`,
// but they don't really need to right now.
ty::Closure(..) | ty::CoroutineClosure(_, _) => {
return Err(EvaluationFailure::NoSolution);
}
// Everything else needs explicit impls or cannot have an impl
_ => return Err(EvaluationFailure::NoSolution),
};
match tcx.constness(def) {
hir::Constness::Const => Ok(tcx
.const_conditions(def)
.instantiate(tcx, args)
.into_iter()
.map(|(c, span)| {
let code = ObligationCauseCode::WhereClause(def, span);
let cause =
ObligationCause::new(obligation.cause.span, obligation.cause.body_id, code);
Obligation::new(
tcx,
cause,
obligation.param_env,
c.to_host_effect_clause(tcx, obligation.predicate.constness),
)
})
.collect()),
hir::Constness::NotConst => Err(EvaluationFailure::NoSolution),
}
}
fn evaluate_host_effect_from_selection_candidate<'tcx>( fn evaluate_host_effect_from_selection_candidate<'tcx>(
selcx: &mut SelectionContext<'_, 'tcx>, selcx: &mut SelectionContext<'_, 'tcx>,
obligation: &HostEffectObligation<'tcx>, obligation: &HostEffectObligation<'tcx>,

View File

@@ -2279,7 +2279,7 @@ pub const fn const_eval_select<ARG: Tuple, F, G, RET>(
) -> RET ) -> RET
where where
G: FnOnce<ARG, Output = RET>, G: FnOnce<ARG, Output = RET>,
F: FnOnce<ARG, Output = RET>; F: const FnOnce<ARG, Output = RET>;
/// A macro to make it easier to invoke const_eval_select. Use as follows: /// A macro to make it easier to invoke const_eval_select. Use as follows:
/// ```rust,ignore (just a macro example) /// ```rust,ignore (just a macro example)

View File

@@ -72,7 +72,8 @@ use crate::marker::Tuple;
)] )]
#[fundamental] // so that regex can rely that `&str: !FnMut` #[fundamental] // so that regex can rely that `&str: !FnMut`
#[must_use = "closures are lazy and do nothing unless called"] #[must_use = "closures are lazy and do nothing unless called"]
// FIXME(const_trait_impl) #[const_trait] #[const_trait]
#[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")]
pub trait Fn<Args: Tuple>: FnMut<Args> { pub trait Fn<Args: Tuple>: FnMut<Args> {
/// Performs the call operation. /// Performs the call operation.
#[unstable(feature = "fn_traits", issue = "29625")] #[unstable(feature = "fn_traits", issue = "29625")]
@@ -159,7 +160,8 @@ pub trait Fn<Args: Tuple>: FnMut<Args> {
)] )]
#[fundamental] // so that regex can rely that `&str: !FnMut` #[fundamental] // so that regex can rely that `&str: !FnMut`
#[must_use = "closures are lazy and do nothing unless called"] #[must_use = "closures are lazy and do nothing unless called"]
// FIXME(const_trait_impl) #[const_trait] #[const_trait]
#[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")]
pub trait FnMut<Args: Tuple>: FnOnce<Args> { pub trait FnMut<Args: Tuple>: FnOnce<Args> {
/// Performs the call operation. /// Performs the call operation.
#[unstable(feature = "fn_traits", issue = "29625")] #[unstable(feature = "fn_traits", issue = "29625")]
@@ -238,7 +240,8 @@ pub trait FnMut<Args: Tuple>: FnOnce<Args> {
)] )]
#[fundamental] // so that regex can rely that `&str: !FnMut` #[fundamental] // so that regex can rely that `&str: !FnMut`
#[must_use = "closures are lazy and do nothing unless called"] #[must_use = "closures are lazy and do nothing unless called"]
// FIXME(const_trait_impl) #[const_trait] #[const_trait]
#[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")]
pub trait FnOnce<Args: Tuple> { pub trait FnOnce<Args: Tuple> {
/// The returned type after the call operator is used. /// The returned type after the call operator is used.
#[lang = "fn_once_output"] #[lang = "fn_once_output"]
@@ -254,9 +257,10 @@ mod impls {
use crate::marker::Tuple; use crate::marker::Tuple;
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl<A: Tuple, F: ?Sized> Fn<A> for &F #[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")]
impl<A: Tuple, F: ?Sized> const Fn<A> for &F
where where
F: Fn<A>, F: ~const Fn<A>,
{ {
extern "rust-call" fn call(&self, args: A) -> F::Output { extern "rust-call" fn call(&self, args: A) -> F::Output {
(**self).call(args) (**self).call(args)
@@ -264,9 +268,10 @@ mod impls {
} }
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl<A: Tuple, F: ?Sized> FnMut<A> for &F #[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")]
impl<A: Tuple, F: ?Sized> const FnMut<A> for &F
where where
F: Fn<A>, F: ~const Fn<A>,
{ {
extern "rust-call" fn call_mut(&mut self, args: A) -> F::Output { extern "rust-call" fn call_mut(&mut self, args: A) -> F::Output {
(**self).call(args) (**self).call(args)
@@ -274,9 +279,10 @@ mod impls {
} }
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl<A: Tuple, F: ?Sized> FnOnce<A> for &F #[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")]
impl<A: Tuple, F: ?Sized> const FnOnce<A> for &F
where where
F: Fn<A>, F: ~const Fn<A>,
{ {
type Output = F::Output; type Output = F::Output;
@@ -286,9 +292,10 @@ mod impls {
} }
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl<A: Tuple, F: ?Sized> FnMut<A> for &mut F #[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")]
impl<A: Tuple, F: ?Sized> const FnMut<A> for &mut F
where where
F: FnMut<A>, F: ~const FnMut<A>,
{ {
extern "rust-call" fn call_mut(&mut self, args: A) -> F::Output { extern "rust-call" fn call_mut(&mut self, args: A) -> F::Output {
(*self).call_mut(args) (*self).call_mut(args)
@@ -296,9 +303,10 @@ mod impls {
} }
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl<A: Tuple, F: ?Sized> FnOnce<A> for &mut F #[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")]
impl<A: Tuple, F: ?Sized> const FnOnce<A> for &mut F
where where
F: FnMut<A>, F: ~const FnMut<A>,
{ {
type Output = F::Output; type Output = F::Output;
extern "rust-call" fn call_once(self, args: A) -> F::Output { extern "rust-call" fn call_once(self, args: A) -> F::Output {

View File

@@ -4,151 +4,6 @@ error[E0635]: unknown feature `const_fn_trait_ref_impls`
LL | #![feature(const_fn_trait_ref_impls)] LL | #![feature(const_fn_trait_ref_impls)]
| ^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^
error: `[const]` can only be applied to `#[const_trait]` traits
--> $DIR/fn_trait_refs.rs:14:8
|
LL | T: [const] Fn<()> + [const] Destruct,
| ^^^^^^^ can't be applied to `Fn`
|
note: `Fn` can't be used with `[const]` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
error: `[const]` can only be applied to `#[const_trait]` traits
--> $DIR/fn_trait_refs.rs:14:8
|
LL | T: [const] Fn<()> + [const] Destruct,
| ^^^^^^^ can't be applied to `Fn`
|
note: `Fn` can't be used with `[const]` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error: `[const]` can only be applied to `#[const_trait]` traits
--> $DIR/fn_trait_refs.rs:14:8
|
LL | T: [const] Fn<()> + [const] Destruct,
| ^^^^^^^ can't be applied to `Fn`
|
note: `Fn` can't be used with `[const]` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error: `[const]` can only be applied to `#[const_trait]` traits
--> $DIR/fn_trait_refs.rs:21:8
|
LL | T: [const] FnMut<()> + [const] Destruct,
| ^^^^^^^ can't be applied to `FnMut`
|
note: `FnMut` can't be used with `[const]` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
error: `[const]` can only be applied to `#[const_trait]` traits
--> $DIR/fn_trait_refs.rs:21:8
|
LL | T: [const] FnMut<()> + [const] Destruct,
| ^^^^^^^ can't be applied to `FnMut`
|
note: `FnMut` can't be used with `[const]` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error: `[const]` can only be applied to `#[const_trait]` traits
--> $DIR/fn_trait_refs.rs:21:8
|
LL | T: [const] FnMut<()> + [const] Destruct,
| ^^^^^^^ can't be applied to `FnMut`
|
note: `FnMut` can't be used with `[const]` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error: `[const]` can only be applied to `#[const_trait]` traits
--> $DIR/fn_trait_refs.rs:28:8
|
LL | T: [const] FnOnce<()>,
| ^^^^^^^ can't be applied to `FnOnce`
|
note: `FnOnce` can't be used with `[const]` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
error: `[const]` can only be applied to `#[const_trait]` traits
--> $DIR/fn_trait_refs.rs:28:8
|
LL | T: [const] FnOnce<()>,
| ^^^^^^^ can't be applied to `FnOnce`
|
note: `FnOnce` can't be used with `[const]` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error: `[const]` can only be applied to `#[const_trait]` traits
--> $DIR/fn_trait_refs.rs:28:8
|
LL | T: [const] FnOnce<()>,
| ^^^^^^^ can't be applied to `FnOnce`
|
note: `FnOnce` can't be used with `[const]` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error: `[const]` can only be applied to `#[const_trait]` traits
--> $DIR/fn_trait_refs.rs:35:8
|
LL | T: [const] Fn<()> + [const] Destruct,
| ^^^^^^^ can't be applied to `Fn`
|
note: `Fn` can't be used with `[const]` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
error: `[const]` can only be applied to `#[const_trait]` traits
--> $DIR/fn_trait_refs.rs:35:8
|
LL | T: [const] Fn<()> + [const] Destruct,
| ^^^^^^^ can't be applied to `Fn`
|
note: `Fn` can't be used with `[const]` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error: `[const]` can only be applied to `#[const_trait]` traits
--> $DIR/fn_trait_refs.rs:35:8
|
LL | T: [const] Fn<()> + [const] Destruct,
| ^^^^^^^ can't be applied to `Fn`
|
note: `Fn` can't be used with `[const]` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error: `[const]` can only be applied to `#[const_trait]` traits
--> $DIR/fn_trait_refs.rs:49:8
|
LL | T: [const] FnMut<()> + [const] Destruct,
| ^^^^^^^ can't be applied to `FnMut`
|
note: `FnMut` can't be used with `[const]` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
error: `[const]` can only be applied to `#[const_trait]` traits
--> $DIR/fn_trait_refs.rs:49:8
|
LL | T: [const] FnMut<()> + [const] Destruct,
| ^^^^^^^ can't be applied to `FnMut`
|
note: `FnMut` can't be used with `[const]` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error: `[const]` can only be applied to `#[const_trait]` traits
--> $DIR/fn_trait_refs.rs:49:8
|
LL | T: [const] FnMut<()> + [const] Destruct,
| ^^^^^^^ can't be applied to `FnMut`
|
note: `FnMut` can't be used with `[const]` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error[E0277]: the trait bound `(i32, i32, i32): const PartialEq` is not satisfied error[E0277]: the trait bound `(i32, i32, i32): const PartialEq` is not satisfied
--> $DIR/fn_trait_refs.rs:71:17 --> $DIR/fn_trait_refs.rs:71:17
| |
@@ -161,31 +16,7 @@ error[E0277]: the trait bound `(i32, i32): const PartialEq` is not satisfied
LL | assert!(test_two == (2, 2)); LL | assert!(test_two == (2, 2));
| ^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^
error[E0015]: cannot call non-const closure in constant functions error: aborting due to 3 previous errors
--> $DIR/fn_trait_refs.rs:16:5
|
LL | f()
| ^^^
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
error[E0015]: cannot call non-const closure in constant functions Some errors have detailed explanations: E0277, E0635.
--> $DIR/fn_trait_refs.rs:23:5 For more information about an error, try `rustc --explain E0277`.
|
LL | f()
| ^^^
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
error[E0015]: cannot call non-const closure in constant functions
--> $DIR/fn_trait_refs.rs:30:5
|
LL | f()
| ^^^
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
error: aborting due to 21 previous errors
Some errors have detailed explanations: E0015, E0277, E0635.
For more information about an error, try `rustc --explain E0015`.

View File

@@ -1,30 +1,3 @@
error: `[const]` can only be applied to `#[const_trait]` traits
--> $DIR/unstable-const-fn-in-libcore.rs:19:32
|
LL | const fn unwrap_or_else<F: [const] FnOnce() -> T>(self, f: F) -> T {
| ^^^^^^^ can't be applied to `FnOnce`
|
note: `FnOnce` can't be used with `[const]` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
error: `[const]` can only be applied to `#[const_trait]` traits
--> $DIR/unstable-const-fn-in-libcore.rs:19:32
|
LL | const fn unwrap_or_else<F: [const] FnOnce() -> T>(self, f: F) -> T {
| ^^^^^^^ can't be applied to `FnOnce`
|
note: `FnOnce` can't be used with `[const]` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error[E0015]: cannot call non-const closure in constant functions
--> $DIR/unstable-const-fn-in-libcore.rs:24:26
|
LL | Opt::None => f(),
| ^^^
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
error[E0493]: destructor of `F` cannot be evaluated at compile-time error[E0493]: destructor of `F` cannot be evaluated at compile-time
--> $DIR/unstable-const-fn-in-libcore.rs:19:61 --> $DIR/unstable-const-fn-in-libcore.rs:19:61
| |
@@ -43,7 +16,6 @@ LL | const fn unwrap_or_else<F: [const] FnOnce() -> T>(self, f: F) -> T {
LL | } LL | }
| - value is dropped here | - value is dropped here
error: aborting due to 5 previous errors error: aborting due to 2 previous errors
Some errors have detailed explanations: E0015, E0493. For more information about this error, try `rustc --explain E0493`.
For more information about an error, try `rustc --explain E0015`.

View File

@@ -1,22 +1,3 @@
error: `[const]` can only be applied to `#[const_trait]` traits
--> $DIR/normalize-tait-in-const.rs:27:35
|
LL | const fn with_positive<F: for<'a> [const] Fn(&'a Alias<'a>) + [const] Destruct>(fun: F) {
| ^^^^^^^ can't be applied to `Fn`
|
note: `Fn` can't be used with `[const]` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
error: `[const]` can only be applied to `#[const_trait]` traits
--> $DIR/normalize-tait-in-const.rs:27:35
|
LL | const fn with_positive<F: for<'a> [const] Fn(&'a Alias<'a>) + [const] Destruct>(fun: F) {
| ^^^^^^^ can't be applied to `Fn`
|
note: `Fn` can't be used with `[const]` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error: unconstrained opaque type error: unconstrained opaque type
--> $DIR/normalize-tait-in-const.rs:14:26 --> $DIR/normalize-tait-in-const.rs:14:26
| |
@@ -44,15 +25,6 @@ note: this item must have a `#[define_opaque(foo::Alias)]` attribute to be able
LL | pub const fn filter_positive<'a>() -> &'a Alias<'a> { LL | pub const fn filter_positive<'a>() -> &'a Alias<'a> {
| ^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^
error[E0015]: cannot call non-const closure in constant functions error: aborting due to 2 previous errors
--> $DIR/normalize-tait-in-const.rs:28:5
|
LL | fun(filter_positive());
| ^^^^^^^^^^^^^^^^^^^^^^
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
error: aborting due to 5 previous errors For more information about this error, try `rustc --explain E0308`.
Some errors have detailed explanations: E0015, E0308.
For more information about an error, try `rustc --explain E0015`.

View File

@@ -5,13 +5,10 @@ use std::intrinsics::const_eval_select;
const fn not_fn_items() { const fn not_fn_items() {
const_eval_select((), || {}, || {}); const_eval_select((), || {}, || {});
//~^ ERROR this argument must be a function item //~^ ERROR const FnOnce()` is not satisfied
//~| ERROR this argument must be a function item
const_eval_select((), 42, 0xDEADBEEF); const_eval_select((), 42, 0xDEADBEEF);
//~^ ERROR expected a `FnOnce()` closure //~^ ERROR expected a `FnOnce()` closure
//~| ERROR expected a `FnOnce()` closure //~| ERROR expected a `FnOnce()` closure
//~| ERROR this argument must be a function item
//~| ERROR this argument must be a function item
} }
const fn foo(n: i32) -> i32 { const fn foo(n: i32) -> i32 {
@@ -40,7 +37,7 @@ const fn args_ty_mismatch() {
const fn non_const_fn() { const fn non_const_fn() {
const_eval_select((1,), bar, bar); const_eval_select((1,), bar, bar);
//~^ ERROR this argument must be a `const fn` //~^ ERROR the trait bound `fn(i32) -> bool {bar}: const FnOnce(i32)` is not satisfied
} }
fn main() {} fn main() {}

View File

@@ -1,23 +1,16 @@
error: this argument must be a function item error[E0277]: the trait bound `{closure@$DIR/const-eval-select-bad.rs:7:27: 7:29}: const FnOnce()` is not satisfied
--> $DIR/const-eval-select-bad.rs:7:27 --> $DIR/const-eval-select-bad.rs:7:27
| |
LL | const_eval_select((), || {}, || {}); LL | const_eval_select((), || {}, || {});
| ^^^^^ | ----------------- ^^^^^
| |
| required by a bound introduced by this call
| |
= note: expected a function item, found {closure@$DIR/const-eval-select-bad.rs:7:27: 7:29} note: required by a bound in `const_eval_select`
= help: consult the documentation on `const_eval_select` for more information --> $SRC_DIR/core/src/intrinsics/mod.rs:LL:COL
error: this argument must be a function item
--> $DIR/const-eval-select-bad.rs:7:34
|
LL | const_eval_select((), || {}, || {});
| ^^^^^
|
= note: expected a function item, found {closure@$DIR/const-eval-select-bad.rs:7:34: 7:36}
= help: consult the documentation on `const_eval_select` for more information
error[E0277]: expected a `FnOnce()` closure, found `{integer}` error[E0277]: expected a `FnOnce()` closure, found `{integer}`
--> $DIR/const-eval-select-bad.rs:10:27 --> $DIR/const-eval-select-bad.rs:9:27
| |
LL | const_eval_select((), 42, 0xDEADBEEF); LL | const_eval_select((), 42, 0xDEADBEEF);
| ----------------- ^^ expected an `FnOnce()` closure, found `{integer}` | ----------------- ^^ expected an `FnOnce()` closure, found `{integer}`
@@ -30,7 +23,7 @@ note: required by a bound in `const_eval_select`
--> $SRC_DIR/core/src/intrinsics/mod.rs:LL:COL --> $SRC_DIR/core/src/intrinsics/mod.rs:LL:COL
error[E0277]: expected a `FnOnce()` closure, found `{integer}` error[E0277]: expected a `FnOnce()` closure, found `{integer}`
--> $DIR/const-eval-select-bad.rs:10:31 --> $DIR/const-eval-select-bad.rs:9:31
| |
LL | const_eval_select((), 42, 0xDEADBEEF); LL | const_eval_select((), 42, 0xDEADBEEF);
| ----------------- ^^^^^^^^^^ expected an `FnOnce()` closure, found `{integer}` | ----------------- ^^^^^^^^^^ expected an `FnOnce()` closure, found `{integer}`
@@ -42,26 +35,8 @@ LL | const_eval_select((), 42, 0xDEADBEEF);
note: required by a bound in `const_eval_select` note: required by a bound in `const_eval_select`
--> $SRC_DIR/core/src/intrinsics/mod.rs:LL:COL --> $SRC_DIR/core/src/intrinsics/mod.rs:LL:COL
error: this argument must be a function item
--> $DIR/const-eval-select-bad.rs:10:27
|
LL | const_eval_select((), 42, 0xDEADBEEF);
| ^^
|
= note: expected a function item, found {integer}
= help: consult the documentation on `const_eval_select` for more information
error: this argument must be a function item
--> $DIR/const-eval-select-bad.rs:10:31
|
LL | const_eval_select((), 42, 0xDEADBEEF);
| ^^^^^^^^^^
|
= note: expected a function item, found {integer}
= help: consult the documentation on `const_eval_select` for more information
error[E0271]: expected `bar` to return `i32`, but it returns `bool` error[E0271]: expected `bar` to return `i32`, but it returns `bool`
--> $DIR/const-eval-select-bad.rs:32:34 --> $DIR/const-eval-select-bad.rs:29:34
| |
LL | const_eval_select((1,), foo, bar); LL | const_eval_select((1,), foo, bar);
| ----------------- ^^^ expected `i32`, found `bool` | ----------------- ^^^ expected `i32`, found `bool`
@@ -72,7 +47,7 @@ note: required by a bound in `const_eval_select`
--> $SRC_DIR/core/src/intrinsics/mod.rs:LL:COL --> $SRC_DIR/core/src/intrinsics/mod.rs:LL:COL
error[E0631]: type mismatch in function arguments error[E0631]: type mismatch in function arguments
--> $DIR/const-eval-select-bad.rs:37:32 --> $DIR/const-eval-select-bad.rs:34:32
| |
LL | const fn foo(n: i32) -> i32 { LL | const fn foo(n: i32) -> i32 {
| --------------------------- found signature defined here | --------------------------- found signature defined here
@@ -91,15 +66,18 @@ help: consider wrapping the function in a closure
LL | const_eval_select((true,), |arg0: bool| foo(/* i32 */), baz); LL | const_eval_select((true,), |arg0: bool| foo(/* i32 */), baz);
| ++++++++++++ +++++++++++ | ++++++++++++ +++++++++++
error: this argument must be a `const fn` error[E0277]: the trait bound `fn(i32) -> bool {bar}: const FnOnce(i32)` is not satisfied
--> $DIR/const-eval-select-bad.rs:42:29 --> $DIR/const-eval-select-bad.rs:39:29
| |
LL | const_eval_select((1,), bar, bar); LL | const_eval_select((1,), bar, bar);
| ^^^ | ----------------- ^^^
| |
| required by a bound introduced by this call
| |
= help: consult the documentation on `const_eval_select` for more information note: required by a bound in `const_eval_select`
--> $SRC_DIR/core/src/intrinsics/mod.rs:LL:COL
error: aborting due to 9 previous errors error: aborting due to 6 previous errors
Some errors have detailed explanations: E0271, E0277, E0631. Some errors have detailed explanations: E0271, E0277, E0631.
For more information about an error, try `rustc --explain E0271`. For more information about an error, try `rustc --explain E0271`.

View File

@@ -5,7 +5,7 @@
pub const _: () = { pub const _: () = {
assert!((const || true)()); assert!((const || true)());
//~^ ERROR cannot call non-const closure in constants //~^ ERROR }: [const] Fn()` is not satisfied
}; };
fn main() {} fn main() {}

View File

@@ -1,12 +1,9 @@
error[E0015]: cannot call non-const closure in constants error[E0277]: the trait bound `{closure@$DIR/call.rs:7:14: 7:22}: [const] Fn()` is not satisfied
--> $DIR/call.rs:7:13 --> $DIR/call.rs:7:13
| |
LL | assert!((const || true)()); LL | assert!((const || true)());
| ^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^
|
= note: closures need an RFC before allowed to be called in constants
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
error: aborting due to 1 previous error error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0015`. For more information about this error, try `rustc --explain E0277`.

View File

@@ -1,31 +1,9 @@
error: `[const]` can only be applied to `#[const_trait]` traits error[E0277]: the trait bound `{closure@$DIR/const-closure-parse-not-item.rs:8:5: 8:18}: [const] Fn()` is not satisfied
--> $DIR/const-closure-parse-not-item.rs:7:25 --> $DIR/const-closure-parse-not-item.rs:7:20
| |
LL | const fn test() -> impl [const] Fn() { LL | const fn test() -> impl [const] Fn() {
| ^^^^^^^ can't be applied to `Fn` | ^^^^^^^^^^^^^^^^^
|
note: `Fn` can't be used with `[const]` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
error: `[const]` can only be applied to `#[const_trait]` traits error: aborting due to 1 previous error
--> $DIR/const-closure-parse-not-item.rs:7:25
|
LL | const fn test() -> impl [const] Fn() {
| ^^^^^^^ can't be applied to `Fn`
|
note: `Fn` can't be used with `[const]` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error: `[const]` can only be applied to `#[const_trait]` traits
--> $DIR/const-closure-parse-not-item.rs:7:25
|
LL | const fn test() -> impl [const] Fn() {
| ^^^^^^^ can't be applied to `Fn`
|
note: `Fn` can't be used with `[const]` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0277`.

View File

@@ -1,30 +1,9 @@
error: `[const]` can only be applied to `#[const_trait]` traits error[E0277]: the trait bound `(): const Tr` is not satisfied
--> $DIR/const-closure-trait-method-fail.rs:14:32 --> $DIR/const-closure-trait-method-fail.rs:18:23
| |
LL | const fn need_const_closure<T: [const] FnOnce(()) -> i32>(x: T) -> i32 { LL | const _: () = assert!(need_const_closure(Tr::a) == 42);
| ^^^^^^^ can't be applied to `FnOnce` | ^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: `FnOnce` can't be used with `[const]` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
error: `[const]` can only be applied to `#[const_trait]` traits error: aborting due to 1 previous error
--> $DIR/const-closure-trait-method-fail.rs:14:32
|
LL | const fn need_const_closure<T: [const] FnOnce(()) -> i32>(x: T) -> i32 {
| ^^^^^^^ can't be applied to `FnOnce`
|
note: `FnOnce` can't be used with `[const]` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error[E0015]: cannot call non-const closure in constant functions For more information about this error, try `rustc --explain E0277`.
--> $DIR/const-closure-trait-method-fail.rs:15:5
|
LL | x(())
| ^^^^^
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0015`.

View File

@@ -1,5 +1,6 @@
//@ known-bug: #110395 //@ check-pass
// FIXME check-pass //@ revisions: next old
//@[next] compile-flags: -Znext-solver
#![feature(const_trait_impl)] #![feature(const_trait_impl)]
#[const_trait] #[const_trait]

View File

@@ -1,30 +0,0 @@
error: `[const]` can only be applied to `#[const_trait]` traits
--> $DIR/const-closure-trait-method.rs:14:32
|
LL | const fn need_const_closure<T: [const] FnOnce(()) -> i32>(x: T) -> i32 {
| ^^^^^^^ can't be applied to `FnOnce`
|
note: `FnOnce` can't be used with `[const]` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
error: `[const]` can only be applied to `#[const_trait]` traits
--> $DIR/const-closure-trait-method.rs:14:32
|
LL | const fn need_const_closure<T: [const] FnOnce(()) -> i32>(x: T) -> i32 {
| ^^^^^^^ can't be applied to `FnOnce`
|
note: `FnOnce` can't be used with `[const]` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error[E0015]: cannot call non-const closure in constant functions
--> $DIR/const-closure-trait-method.rs:15:5
|
LL | x(())
| ^^^^^
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0015`.

View File

@@ -1,5 +1,6 @@
//@ known-bug: #110395 //@ check-pass
// FIXME check-pass //@ revisions: next old
//@[next] compile-flags: -Znext-solver
#![feature(const_trait_impl)] #![feature(const_trait_impl)]

View File

@@ -1,103 +0,0 @@
error: `[const]` can only be applied to `#[const_trait]` traits
--> $DIR/const-closures.rs:8:12
|
LL | F: [const] FnOnce() -> u8,
| ^^^^^^^ can't be applied to `FnOnce`
|
note: `FnOnce` can't be used with `[const]` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
error: `[const]` can only be applied to `#[const_trait]` traits
--> $DIR/const-closures.rs:9:12
|
LL | F: [const] FnMut() -> u8,
| ^^^^^^^ can't be applied to `FnMut`
|
note: `FnMut` can't be used with `[const]` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
error: `[const]` can only be applied to `#[const_trait]` traits
--> $DIR/const-closures.rs:10:12
|
LL | F: [const] Fn() -> u8,
| ^^^^^^^ can't be applied to `Fn`
|
note: `Fn` can't be used with `[const]` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
error: `[const]` can only be applied to `#[const_trait]` traits
--> $DIR/const-closures.rs:8:12
|
LL | F: [const] FnOnce() -> u8,
| ^^^^^^^ can't be applied to `FnOnce`
|
note: `FnOnce` can't be used with `[const]` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error: `[const]` can only be applied to `#[const_trait]` traits
--> $DIR/const-closures.rs:9:12
|
LL | F: [const] FnMut() -> u8,
| ^^^^^^^ can't be applied to `FnMut`
|
note: `FnMut` can't be used with `[const]` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error: `[const]` can only be applied to `#[const_trait]` traits
--> $DIR/const-closures.rs:10:12
|
LL | F: [const] Fn() -> u8,
| ^^^^^^^ can't be applied to `Fn`
|
note: `Fn` can't be used with `[const]` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error: `[const]` can only be applied to `#[const_trait]` traits
--> $DIR/const-closures.rs:23:20
|
LL | const fn answer<F: [const] Fn() -> u8>(f: &F) -> u8 {
| ^^^^^^^ can't be applied to `Fn`
|
note: `Fn` can't be used with `[const]` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
error: `[const]` can only be applied to `#[const_trait]` traits
--> $DIR/const-closures.rs:23:20
|
LL | const fn answer<F: [const] Fn() -> u8>(f: &F) -> u8 {
| ^^^^^^^ can't be applied to `Fn`
|
note: `Fn` can't be used with `[const]` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error[E0015]: cannot call non-const closure in constant functions
--> $DIR/const-closures.rs:24:5
|
LL | f() + f()
| ^^^
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
error[E0015]: cannot call non-const closure in constant functions
--> $DIR/const-closures.rs:24:11
|
LL | f() + f()
| ^^^
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
error[E0015]: cannot call non-const closure in constant functions
--> $DIR/const-closures.rs:12:5
|
LL | f() * 7
| ^^^
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
error: aborting due to 11 previous errors
For more information about this error, try `rustc --explain E0015`.

View File

@@ -1,3 +1,4 @@
//@ known-bug: #110395
//@ compile-flags: -Znext-solver //@ compile-flags: -Znext-solver
#![feature(const_closures, const_trait_impl)] #![feature(const_closures, const_trait_impl)]
#![allow(incomplete_features)] #![allow(incomplete_features)]
@@ -11,7 +12,7 @@ impl Foo for () {
} }
fn main() { fn main() {
(const || { (()).foo() })(); (const || (()).foo())();
//~^ ERROR: cannot call non-const method `<() 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 // FIXME(const_trait_impl) this should probably say constant closures
} }

View File

@@ -1,11 +1,9 @@
error[E0015]: cannot call non-const method `<() as Foo>::foo` in constant functions error[E0277]: the trait bound `{closure@$DIR/const_closure-const_trait_impl-ice-113381.rs:15:6: 15:14}: [const] Fn()` is not satisfied
--> $DIR/const_closure-const_trait_impl-ice-113381.rs:14:22 --> $DIR/const_closure-const_trait_impl-ice-113381.rs:15:5
| |
LL | (const || { (()).foo() })(); LL | (const || (()).foo())();
| ^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
error: aborting due to 1 previous error error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0015`. For more information about this error, try `rustc --explain E0277`.

View File

@@ -1,16 +1,14 @@
#![feature(const_trait_impl)] #![feature(const_trait_impl)]
const fn test() -> impl [const] Fn() { const fn test() -> impl [const] Fn() {
//~^ ERROR `[const]` can only be applied to `#[const_trait]` traits //~^ ERROR: }: [const] Fn()` is not satisfied
//~| ERROR `[const]` can only be applied to `#[const_trait]` traits
//~| ERROR `[const]` can only be applied to `#[const_trait]` traits
const move || { //~ ERROR const closures are experimental const move || { //~ ERROR const closures are experimental
let sl: &[u8] = b"foo"; let sl: &[u8] = b"foo";
match sl { match sl {
[first, remainder @ ..] => { [first, remainder @ ..] => {
assert_eq!(first, &b'f'); assert_eq!(first, &b'f');
//~^ ERROR cannot call non-const function // FIXME(const_closures) ^ ERROR cannot call non-const function
} }
[] => panic!(), [] => panic!(),
} }

View File

@@ -1,5 +1,5 @@
error[E0658]: const closures are experimental error[E0658]: const closures are experimental
--> $DIR/ice-112822-expected-type-for-param.rs:7:5 --> $DIR/ice-112822-expected-type-for-param.rs:5:5
| |
LL | const move || { LL | const move || {
| ^^^^^ | ^^^^^
@@ -8,45 +8,13 @@ LL | const move || {
= help: add `#![feature(const_closures)]` to the crate attributes to enable = help: add `#![feature(const_closures)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
error: `[const]` can only be applied to `#[const_trait]` traits error[E0277]: the trait bound `{closure@$DIR/ice-112822-expected-type-for-param.rs:5:5: 5:18}: [const] Fn()` is not satisfied
--> $DIR/ice-112822-expected-type-for-param.rs:3:25 --> $DIR/ice-112822-expected-type-for-param.rs:3:20
| |
LL | const fn test() -> impl [const] Fn() { LL | const fn test() -> impl [const] Fn() {
| ^^^^^^^ can't be applied to `Fn` | ^^^^^^^^^^^^^^^^^
|
note: `Fn` can't be used with `[const]` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
error: `[const]` can only be applied to `#[const_trait]` traits error: aborting due to 2 previous errors
--> $DIR/ice-112822-expected-type-for-param.rs:3:25
|
LL | const fn test() -> impl [const] Fn() {
| ^^^^^^^ can't be applied to `Fn`
|
note: `Fn` can't be used with `[const]` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error: `[const]` can only be applied to `#[const_trait]` traits Some errors have detailed explanations: E0277, E0658.
--> $DIR/ice-112822-expected-type-for-param.rs:3:25 For more information about an error, try `rustc --explain E0277`.
|
LL | const fn test() -> impl [const] Fn() {
| ^^^^^^^ can't be applied to `Fn`
|
note: `Fn` can't be used with `[const]` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
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');
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= 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: aborting due to 5 previous errors
Some errors have detailed explanations: E0015, E0658.
For more information about an error, try `rustc --explain E0015`.

View File

@@ -1,8 +0,0 @@
#![allow(incomplete_features)]
#![feature(generic_const_exprs, const_trait_impl)]
const fn with_positive<F: [const] Fn()>() {}
//~^ ERROR `[const]` can only be applied to `#[const_trait]` traits
//~| ERROR `[const]` can only be applied to `#[const_trait]` traits
pub fn main() {}

View File

@@ -1,21 +0,0 @@
error: `[const]` can only be applied to `#[const_trait]` traits
--> $DIR/ice-123664-unexpected-bound-var.rs:4:27
|
LL | const fn with_positive<F: [const] Fn()>() {}
| ^^^^^^^ can't be applied to `Fn`
|
note: `Fn` can't be used with `[const]` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
error: `[const]` can only be applied to `#[const_trait]` traits
--> $DIR/ice-123664-unexpected-bound-var.rs:4:27
|
LL | const fn with_positive<F: [const] Fn()>() {}
| ^^^^^^^ can't be applied to `Fn`
|
note: `Fn` can't be used with `[const]` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error: aborting due to 2 previous errors

View File

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

View File

@@ -1,11 +1,9 @@
error[E0015]: cannot call non-const method `<() as Foo>::foo` in constant functions error[E0277]: the trait bound `{closure@$DIR/non-const-op-const-closure-non-const-outer.rs:13:6: 13:14}: [const] Fn()` is not satisfied
--> $DIR/non-const-op-const-closure-non-const-outer.rs:13:22 --> $DIR/non-const-op-const-closure-non-const-outer.rs:13:5
| |
LL | (const || { (()).foo() })(); LL | (const || { (()).foo() })();
| ^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
error: aborting due to 1 previous error error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0015`. For more information about this error, try `rustc --explain E0277`.