Auto merge of #77464 - ecstatic-morse:const-fn-impl-trait, r=oli-obk
Give `impl Trait` in a `const fn` its own feature gate ...previously it was gated under `#![feature(const_fn)]`. I think we actually want to do this in all const-contexts? If so, this should be `#![feature(const_impl_trait)]` instead. I don't think there's any way to make use of `impl Trait` within a `const` initializer. cc #77463 r? `@oli-obk`
This commit is contained in:
commit
4437b4b150
11 changed files with 34 additions and 31 deletions
|
@ -3,12 +3,8 @@ An unstable feature in `const` contexts was used.
|
||||||
Erroneous code example:
|
Erroneous code example:
|
||||||
|
|
||||||
```compile_fail,E0723
|
```compile_fail,E0723
|
||||||
trait T {}
|
const fn foo<T: Copy>(_: T) { // error!
|
||||||
|
// ...
|
||||||
impl T for () {}
|
|
||||||
|
|
||||||
const fn foo() -> impl T { // error: `impl Trait` in const fn is unstable
|
|
||||||
()
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -18,11 +14,7 @@ feature flag:
|
||||||
```
|
```
|
||||||
#![feature(const_fn)]
|
#![feature(const_fn)]
|
||||||
|
|
||||||
trait T {}
|
const fn foo<T: Copy>(_: T) { // ok!
|
||||||
|
// ...
|
||||||
impl T for () {}
|
|
||||||
|
|
||||||
const fn foo() -> impl T {
|
|
||||||
()
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
|
@ -596,6 +596,9 @@ declare_features! (
|
||||||
/// Allows rustc to inject a default alloc_error_handler
|
/// Allows rustc to inject a default alloc_error_handler
|
||||||
(active, default_alloc_error_handler, "1.48.0", Some(66741), None),
|
(active, default_alloc_error_handler, "1.48.0", Some(66741), None),
|
||||||
|
|
||||||
|
/// Allows argument and return position `impl Trait` in a `const fn`.
|
||||||
|
(active, const_impl_trait, "1.48.0", Some(77463), None),
|
||||||
|
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
// feature-group-end: actual feature gates
|
// feature-group-end: actual feature gates
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
|
|
|
@ -558,12 +558,17 @@ pub mod ty {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ImplTrait;
|
pub struct ImplTrait;
|
||||||
impl NonConstOp for ImplTrait {
|
impl NonConstOp for ImplTrait {
|
||||||
fn status_in_item(&self, ccx: &ConstCx<'_, '_>) -> Status {
|
fn status_in_item(&self, _: &ConstCx<'_, '_>) -> Status {
|
||||||
mcf_status_in_item(ccx)
|
Status::Unstable(sym::const_impl_trait)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
||||||
mcf_build_error(ccx, span, "`impl Trait` in const fn is unstable")
|
feature_err(
|
||||||
|
&ccx.tcx.sess.parse_sess,
|
||||||
|
sym::const_impl_trait,
|
||||||
|
span,
|
||||||
|
&format!("`impl Trait` is not allowed in {}s", ccx.const_kind()),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -359,6 +359,7 @@ symbols! {
|
||||||
const_fn_union,
|
const_fn_union,
|
||||||
const_generics,
|
const_generics,
|
||||||
const_if_match,
|
const_if_match,
|
||||||
|
const_impl_trait,
|
||||||
const_in_array_repeat_expressions,
|
const_in_array_repeat_expressions,
|
||||||
const_indexing,
|
const_indexing,
|
||||||
const_let,
|
const_let,
|
||||||
|
|
|
@ -83,6 +83,7 @@
|
||||||
#![feature(const_fn)]
|
#![feature(const_fn)]
|
||||||
#![feature(const_fn_union)]
|
#![feature(const_fn_union)]
|
||||||
#![feature(const_assume)]
|
#![feature(const_assume)]
|
||||||
|
#![cfg_attr(not(bootstrap), feature(const_impl_trait))]
|
||||||
#![cfg_attr(not(bootstrap), feature(const_fn_floating_point_arithmetic))]
|
#![cfg_attr(not(bootstrap), feature(const_fn_floating_point_arithmetic))]
|
||||||
#![cfg_attr(not(bootstrap), feature(const_fn_fn_ptr_basics))]
|
#![cfg_attr(not(bootstrap), feature(const_fn_fn_ptr_basics))]
|
||||||
#![feature(const_generics)]
|
#![feature(const_generics)]
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
|
// gate-test-const_impl_trait
|
||||||
|
|
||||||
struct AlanTuring<T>(T);
|
struct AlanTuring<T>(T);
|
||||||
const fn no_rpit2() -> AlanTuring<impl std::fmt::Debug> {
|
const fn no_rpit2() -> AlanTuring<impl std::fmt::Debug> { //~ `impl Trait`
|
||||||
//~^ ERROR `impl Trait` in const fn is unstable
|
|
||||||
AlanTuring(0)
|
AlanTuring(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
const fn no_rpit() -> impl std::fmt::Debug {} //~ ERROR `impl Trait` in const fn is unstable
|
const fn no_rpit() -> impl std::fmt::Debug {} //~ `impl Trait`
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -1,21 +1,21 @@
|
||||||
error[E0723]: `impl Trait` in const fn is unstable
|
error[E0658]: `impl Trait` is not allowed in constant functions
|
||||||
--> $DIR/min_const_fn_impl_trait.rs:2:24
|
--> $DIR/min_const_fn_impl_trait.rs:4:24
|
||||||
|
|
|
|
||||||
LL | const fn no_rpit2() -> AlanTuring<impl std::fmt::Debug> {
|
LL | const fn no_rpit2() -> AlanTuring<impl std::fmt::Debug> {
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
= note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
|
= note: see issue #77463 <https://github.com/rust-lang/rust/issues/77463> for more information
|
||||||
= help: add `#![feature(const_fn)]` to the crate attributes to enable
|
= help: add `#![feature(const_impl_trait)]` to the crate attributes to enable
|
||||||
|
|
||||||
error[E0723]: `impl Trait` in const fn is unstable
|
error[E0658]: `impl Trait` is not allowed in constant functions
|
||||||
--> $DIR/min_const_fn_impl_trait.rs:7:23
|
--> $DIR/min_const_fn_impl_trait.rs:8:23
|
||||||
|
|
|
|
||||||
LL | const fn no_rpit() -> impl std::fmt::Debug {}
|
LL | const fn no_rpit() -> impl std::fmt::Debug {}
|
||||||
| ^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
= note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
|
= note: see issue #77463 <https://github.com/rust-lang/rust/issues/77463> for more information
|
||||||
= help: add `#![feature(const_fn)]` to the crate attributes to enable
|
= help: add `#![feature(const_impl_trait)]` to the crate attributes to enable
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0723`.
|
For more information about this error, try `rustc --explain E0658`.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// check-pass
|
// check-pass
|
||||||
#![feature(const_fn, const_fn_fn_ptr_basics)]
|
#![feature(const_impl_trait, const_fn_fn_ptr_basics)]
|
||||||
#![feature(type_alias_impl_trait)]
|
#![feature(type_alias_impl_trait)]
|
||||||
|
|
||||||
type Foo = impl Fn() -> usize;
|
type Foo = impl Fn() -> usize;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// check-pass
|
// check-pass
|
||||||
|
|
||||||
#![feature(const_fn, generators, generator_trait, type_alias_impl_trait)]
|
#![feature(const_impl_trait, generators, generator_trait, type_alias_impl_trait)]
|
||||||
|
|
||||||
use std::ops::Generator;
|
use std::ops::Generator;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#![feature(const_fn, type_alias_impl_trait)]
|
#![feature(const_impl_trait, type_alias_impl_trait)]
|
||||||
|
|
||||||
type Bar = impl Send;
|
type Bar = impl Send;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#![feature(const_fn, type_alias_impl_trait)]
|
#![feature(const_impl_trait, type_alias_impl_trait)]
|
||||||
|
|
||||||
type Foo = impl Send;
|
type Foo = impl Send;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue