about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_hir_typeck/messages.ftl7
-rw-r--r--compiler/rustc_hir_typeck/src/callee.rs23
-rw-r--r--compiler/rustc_hir_typeck/src/errors.rs18
-rw-r--r--compiler/rustc_trait_selection/src/traits/effects.rs7
-rw-r--r--library/core/src/intrinsics/mod.rs2
-rw-r--r--tests/ui/intrinsics/const-eval-select-bad.rs7
-rw-r--r--tests/ui/intrinsics/const-eval-select-bad.stderr58
7 files changed, 23 insertions, 99 deletions
diff --git a/compiler/rustc_hir_typeck/messages.ftl b/compiler/rustc_hir_typeck/messages.ftl
index c21b16c9f9f..bac4d70103c 100644
--- a/compiler/rustc_hir_typeck/messages.ftl
+++ b/compiler/rustc_hir_typeck/messages.ftl
@@ -82,13 +82,6 @@ hir_typeck_cast_unknown_pointer = cannot cast {$to ->
 hir_typeck_const_continue_bad_label =
     `#[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 =
     `continue` pointing to a labeled block
     .label = labeled blocks cannot be `continue`'d
diff --git a/compiler/rustc_hir_typeck/src/callee.rs b/compiler/rustc_hir_typeck/src/callee.rs
index 7611f8ac3e1..48bb45de53e 100644
--- a/compiler/rustc_hir_typeck/src/callee.rs
+++ b/compiler/rustc_hir_typeck/src/callee.rs
@@ -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()
     }
 
diff --git a/compiler/rustc_hir_typeck/src/errors.rs b/compiler/rustc_hir_typeck/src/errors.rs
index 3606c778fc4..a8bb6956f10 100644
--- a/compiler/rustc_hir_typeck/src/errors.rs
+++ b/compiler/rustc_hir_typeck/src/errors.rs
@@ -606,24 +606,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)]
 #[diag(hir_typeck_union_pat_multiple_fields)]
 pub(crate) struct UnionPatMultipleFields {
     #[primary_span]
diff --git a/compiler/rustc_trait_selection/src/traits/effects.rs b/compiler/rustc_trait_selection/src/traits/effects.rs
index d24f861723b..d694a092853 100644
--- a/compiler/rustc_trait_selection/src/traits/effects.rs
+++ b/compiler/rustc_trait_selection/src/traits/effects.rs
@@ -416,12 +416,9 @@ fn evaluate_host_effect_for_fn_goal<'tcx>(
         // We may support function pointers at some point in the future
         ty::FnPtr(..) => return Err(EvaluationFailure::NoSolution),
 
-        // Coroutines could implement `[const] Fn`,
+        // Closures could implement `[const] Fn`,
         // but they don't really need to right now.
-        ty::Closure(..)
-        | ty::CoroutineClosure(_, _)
-        | ty::Coroutine(_, _)
-        | ty::CoroutineWitness(_, _) => {
+        ty::Closure(..) | ty::CoroutineClosure(_, _) => {
             return Err(EvaluationFailure::NoSolution);
         }
 
diff --git a/library/core/src/intrinsics/mod.rs b/library/core/src/intrinsics/mod.rs
index 791d10eda6d..1ac0c7ff89b 100644
--- a/library/core/src/intrinsics/mod.rs
+++ b/library/core/src/intrinsics/mod.rs
@@ -2279,7 +2279,7 @@ pub const fn const_eval_select<ARG: Tuple, F, G, RET>(
 ) -> RET
 where
     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:
 /// ```rust,ignore (just a macro example)
diff --git a/tests/ui/intrinsics/const-eval-select-bad.rs b/tests/ui/intrinsics/const-eval-select-bad.rs
index 3365d57af7c..f4071251299 100644
--- a/tests/ui/intrinsics/const-eval-select-bad.rs
+++ b/tests/ui/intrinsics/const-eval-select-bad.rs
@@ -5,13 +5,10 @@ use std::intrinsics::const_eval_select;
 
 const fn not_fn_items() {
     const_eval_select((), || {}, || {});
-    //~^ ERROR this argument must be a function item
-    //~| ERROR this argument must be a function item
+    //~^ ERROR const FnOnce()` is not satisfied
     const_eval_select((), 42, 0xDEADBEEF);
     //~^ 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 {
@@ -40,7 +37,7 @@ const fn args_ty_mismatch() {
 
 const fn non_const_fn() {
     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() {}
diff --git a/tests/ui/intrinsics/const-eval-select-bad.stderr b/tests/ui/intrinsics/const-eval-select-bad.stderr
index bb159bed282..d701f5ea909 100644
--- a/tests/ui/intrinsics/const-eval-select-bad.stderr
+++ b/tests/ui/intrinsics/const-eval-select-bad.stderr
@@ -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
    |
 LL |     const_eval_select((), || {}, || {});
-   |                           ^^^^^
-   |
-   = note: expected a function item, found {closure@$DIR/const-eval-select-bad.rs:7:27: 7:29}
-   = 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:7:34
-   |
-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:34: 7:36}
-   = 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[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);
    |     -----------------     ^^ 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
 
 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);
    |     -----------------         ^^^^^^^^^^ 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`
   --> $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`
-  --> $DIR/const-eval-select-bad.rs:32:34
+  --> $DIR/const-eval-select-bad.rs:29:34
    |
 LL |     const_eval_select((1,), foo, bar);
    |     -----------------            ^^^ 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
 
 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 {
    | --------------------------- 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);
    |                                ++++++++++++    +++++++++++
 
-error: this argument must be a `const fn`
-  --> $DIR/const-eval-select-bad.rs:42:29
+error[E0277]: the trait bound `fn(i32) -> bool {bar}: const FnOnce(i32)` is not satisfied
+  --> $DIR/const-eval-select-bad.rs:39:29
    |
 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.
 For more information about an error, try `rustc --explain E0271`.