Skip to content

Commit b1d45f6

Browse files
committed
Remove const_eval_select hack
1 parent 543c860 commit b1d45f6

File tree

7 files changed

+23
-99
lines changed

7 files changed

+23
-99
lines changed

compiler/rustc_hir_typeck/messages.ftl

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,6 @@ hir_typeck_cast_unknown_pointer = cannot cast {$to ->
8282
hir_typeck_const_continue_bad_label =
8383
`#[const_continue]` must break to a labeled block that participates in a `#[loop_match]`
8484
85-
hir_typeck_const_select_must_be_const = this argument must be a `const fn`
86-
.help = consult the documentation on `const_eval_select` for more information
87-
88-
hir_typeck_const_select_must_be_fn = this argument must be a function item
89-
.note = expected a function item, found {$ty}
90-
.help = consult the documentation on `const_eval_select` for more information
91-
9285
hir_typeck_continue_labeled_block =
9386
`continue` pointing to a labeled block
9487
.label = labeled blocks cannot be `continue`'d

compiler/rustc_hir_typeck/src/callee.rs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -578,29 +578,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
578578
}
579579
}
580580

581-
if let Some(def_id) = def_id
582-
&& self.tcx.def_kind(def_id) == hir::def::DefKind::Fn
583-
&& self.tcx.is_intrinsic(def_id, sym::const_eval_select)
584-
{
585-
let fn_sig = self.resolve_vars_if_possible(fn_sig);
586-
for idx in 0..=1 {
587-
let arg_ty = fn_sig.inputs()[idx + 1];
588-
let span = arg_exprs.get(idx + 1).map_or(call_expr.span, |arg| arg.span);
589-
// Check that second and third argument of `const_eval_select` must be `FnDef`, and additionally that
590-
// the second argument must be `const fn`. The first argument must be a tuple, but this is already expressed
591-
// in the function signature (`F: FnOnce<ARG>`), so I did not bother to add another check here.
592-
//
593-
// This check is here because there is currently no way to express a trait bound for `FnDef` types only.
594-
if let ty::FnDef(def_id, _args) = *arg_ty.kind() {
595-
if idx == 0 && !self.tcx.is_const_fn(def_id) {
596-
self.dcx().emit_err(errors::ConstSelectMustBeConst { span });
597-
}
598-
} else {
599-
self.dcx().emit_err(errors::ConstSelectMustBeFn { span, ty: arg_ty });
600-
}
601-
}
602-
}
603-
604581
fn_sig.output()
605582
}
606583

compiler/rustc_hir_typeck/src/errors.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -605,24 +605,6 @@ impl Subdiagnostic for RemoveSemiForCoerce {
605605
}
606606
}
607607

608-
#[derive(Diagnostic)]
609-
#[diag(hir_typeck_const_select_must_be_const)]
610-
#[help]
611-
pub(crate) struct ConstSelectMustBeConst {
612-
#[primary_span]
613-
pub span: Span,
614-
}
615-
616-
#[derive(Diagnostic)]
617-
#[diag(hir_typeck_const_select_must_be_fn)]
618-
#[note]
619-
#[help]
620-
pub(crate) struct ConstSelectMustBeFn<'a> {
621-
#[primary_span]
622-
pub span: Span,
623-
pub ty: Ty<'a>,
624-
}
625-
626608
#[derive(Diagnostic)]
627609
#[diag(hir_typeck_union_pat_multiple_fields)]
628610
pub(crate) struct UnionPatMultipleFields {

compiler/rustc_trait_selection/src/traits/effects.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -416,12 +416,9 @@ fn evaluate_host_effect_for_fn_goal<'tcx>(
416416
// We may support function pointers at some point in the future
417417
ty::FnPtr(..) => return Err(EvaluationFailure::NoSolution),
418418

419-
// Coroutines could implement `[const] Fn`,
419+
// Closures could implement `[const] Fn`,
420420
// but they don't really need to right now.
421-
ty::Closure(..)
422-
| ty::CoroutineClosure(_, _)
423-
| ty::Coroutine(_, _)
424-
| ty::CoroutineWitness(_, _) => {
421+
ty::Closure(..) | ty::CoroutineClosure(_, _) => {
425422
return Err(EvaluationFailure::NoSolution);
426423
}
427424

library/core/src/intrinsics/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2279,7 +2279,7 @@ pub const fn const_eval_select<ARG: Tuple, F, G, RET>(
22792279
) -> RET
22802280
where
22812281
G: FnOnce<ARG, Output = RET>,
2282-
F: FnOnce<ARG, Output = RET>;
2282+
F: const FnOnce<ARG, Output = RET>;
22832283

22842284
/// A macro to make it easier to invoke const_eval_select. Use as follows:
22852285
/// ```rust,ignore (just a macro example)

tests/ui/intrinsics/const-eval-select-bad.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,10 @@ use std::intrinsics::const_eval_select;
55

66
const fn not_fn_items() {
77
const_eval_select((), || {}, || {});
8-
//~^ ERROR this argument must be a function item
9-
//~| ERROR this argument must be a function item
8+
//~^ ERROR const FnOnce()` is not satisfied
109
const_eval_select((), 42, 0xDEADBEEF);
1110
//~^ ERROR expected a `FnOnce()` closure
1211
//~| ERROR expected a `FnOnce()` closure
13-
//~| ERROR this argument must be a function item
14-
//~| ERROR this argument must be a function item
1512
}
1613

1714
const fn foo(n: i32) -> i32 {
@@ -40,7 +37,7 @@ const fn args_ty_mismatch() {
4037

4138
const fn non_const_fn() {
4239
const_eval_select((1,), bar, bar);
43-
//~^ ERROR this argument must be a `const fn`
40+
//~^ ERROR the trait bound `fn(i32) -> bool {bar}: const FnOnce(i32)` is not satisfied
4441
}
4542

4643
fn main() {}
Lines changed: 18 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,16 @@
1-
error: this argument must be a function item
1+
error[E0277]: the trait bound `{closure@$DIR/const-eval-select-bad.rs:7:27: 7:29}: const FnOnce()` is not satisfied
22
--> $DIR/const-eval-select-bad.rs:7:27
33
|
44
LL | const_eval_select((), || {}, || {});
5-
| ^^^^^
6-
|
7-
= note: expected a function item, found {closure@$DIR/const-eval-select-bad.rs:7:27: 7:29}
8-
= help: consult the documentation on `const_eval_select` for more information
9-
10-
error: this argument must be a function item
11-
--> $DIR/const-eval-select-bad.rs:7:34
12-
|
13-
LL | const_eval_select((), || {}, || {});
14-
| ^^^^^
5+
| ----------------- ^^^^^
6+
| |
7+
| required by a bound introduced by this call
158
|
16-
= note: expected a function item, found {closure@$DIR/const-eval-select-bad.rs:7:34: 7:36}
17-
= help: consult the documentation on `const_eval_select` for more information
9+
note: required by a bound in `const_eval_select`
10+
--> $SRC_DIR/core/src/intrinsics/mod.rs:LL:COL
1811

1912
error[E0277]: expected a `FnOnce()` closure, found `{integer}`
20-
--> $DIR/const-eval-select-bad.rs:10:27
13+
--> $DIR/const-eval-select-bad.rs:9:27
2114
|
2215
LL | const_eval_select((), 42, 0xDEADBEEF);
2316
| ----------------- ^^ expected an `FnOnce()` closure, found `{integer}`
@@ -30,7 +23,7 @@ note: required by a bound in `const_eval_select`
3023
--> $SRC_DIR/core/src/intrinsics/mod.rs:LL:COL
3124

3225
error[E0277]: expected a `FnOnce()` closure, found `{integer}`
33-
--> $DIR/const-eval-select-bad.rs:10:31
26+
--> $DIR/const-eval-select-bad.rs:9:31
3427
|
3528
LL | const_eval_select((), 42, 0xDEADBEEF);
3629
| ----------------- ^^^^^^^^^^ expected an `FnOnce()` closure, found `{integer}`
@@ -42,26 +35,8 @@ LL | const_eval_select((), 42, 0xDEADBEEF);
4235
note: required by a bound in `const_eval_select`
4336
--> $SRC_DIR/core/src/intrinsics/mod.rs:LL:COL
4437

45-
error: this argument must be a function item
46-
--> $DIR/const-eval-select-bad.rs:10:27
47-
|
48-
LL | const_eval_select((), 42, 0xDEADBEEF);
49-
| ^^
50-
|
51-
= note: expected a function item, found {integer}
52-
= help: consult the documentation on `const_eval_select` for more information
53-
54-
error: this argument must be a function item
55-
--> $DIR/const-eval-select-bad.rs:10:31
56-
|
57-
LL | const_eval_select((), 42, 0xDEADBEEF);
58-
| ^^^^^^^^^^
59-
|
60-
= note: expected a function item, found {integer}
61-
= help: consult the documentation on `const_eval_select` for more information
62-
6338
error[E0271]: expected `bar` to return `i32`, but it returns `bool`
64-
--> $DIR/const-eval-select-bad.rs:32:34
39+
--> $DIR/const-eval-select-bad.rs:29:34
6540
|
6641
LL | const_eval_select((1,), foo, bar);
6742
| ----------------- ^^^ expected `i32`, found `bool`
@@ -72,7 +47,7 @@ note: required by a bound in `const_eval_select`
7247
--> $SRC_DIR/core/src/intrinsics/mod.rs:LL:COL
7348

7449
error[E0631]: type mismatch in function arguments
75-
--> $DIR/const-eval-select-bad.rs:37:32
50+
--> $DIR/const-eval-select-bad.rs:34:32
7651
|
7752
LL | const fn foo(n: i32) -> i32 {
7853
| --------------------------- found signature defined here
@@ -91,15 +66,18 @@ help: consider wrapping the function in a closure
9166
LL | const_eval_select((true,), |arg0: bool| foo(/* i32 */), baz);
9267
| ++++++++++++ +++++++++++
9368

94-
error: this argument must be a `const fn`
95-
--> $DIR/const-eval-select-bad.rs:42:29
69+
error[E0277]: the trait bound `fn(i32) -> bool {bar}: const FnOnce(i32)` is not satisfied
70+
--> $DIR/const-eval-select-bad.rs:39:29
9671
|
9772
LL | const_eval_select((1,), bar, bar);
98-
| ^^^
73+
| ----------------- ^^^
74+
| |
75+
| required by a bound introduced by this call
9976
|
100-
= help: consult the documentation on `const_eval_select` for more information
77+
note: required by a bound in `const_eval_select`
78+
--> $SRC_DIR/core/src/intrinsics/mod.rs:LL:COL
10179

102-
error: aborting due to 9 previous errors
80+
error: aborting due to 6 previous errors
10381

10482
Some errors have detailed explanations: E0271, E0277, E0631.
10583
For more information about an error, try `rustc --explain E0271`.

0 commit comments

Comments
 (0)