'const fn' in trait are rejected in the AST, this feature gate check is a NOP

This commit is contained in:
Ralf Jung 2021-04-25 11:02:08 +02:00
parent 5da10c0121
commit 75bab0782a
6 changed files with 14 additions and 61 deletions

View File

@ -586,12 +586,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
fn visit_assoc_item(&mut self, i: &'a ast::AssocItem, ctxt: AssocCtxt) {
let is_fn = match i.kind {
ast::AssocItemKind::Fn(box ast::FnKind(_, ref sig, _, _)) => {
if let (ast::Const::Yes(_), AssocCtxt::Trait) = (sig.header.constness, ctxt) {
gate_feature_post!(&self, const_fn, i.span, "const fn is unstable");
}
true
}
ast::AssocItemKind::Fn(_) => true,
ast::AssocItemKind::TyAlias(box ast::TyAliasKind(_, ref generics, _, ref ty)) => {
if let (Some(_), AssocCtxt::Trait) = (ty, ctxt) {
gate_feature_post!(

View File

@ -1,5 +1,5 @@
// Test that const fn is illegal in a trait declaration, whether or
// not a default is provided.
// not a default is provided, and even with the feature gate.
#![feature(const_fn)]

View File

@ -3,10 +3,8 @@
const fn foo() -> usize { 0 } // ok
trait Foo {
const fn foo() -> u32; //~ ERROR const fn is unstable
//~| ERROR functions in traits cannot be declared const
const fn bar() -> u32 { 0 } //~ ERROR const fn is unstable
//~| ERROR functions in traits cannot be declared const
const fn foo() -> u32; //~ ERROR functions in traits cannot be declared const
const fn bar() -> u32 { 0 } //~ ERROR functions in traits cannot be declared const
}
impl Foo for u32 {

View File

@ -5,36 +5,17 @@ LL | const fn foo() -> u32;
| ^^^^^ functions in traits cannot be const
error[E0379]: functions in traits cannot be declared const
--> $DIR/feature-gate-const_fn.rs:8:5
--> $DIR/feature-gate-const_fn.rs:7:5
|
LL | const fn bar() -> u32 { 0 }
| ^^^^^ functions in traits cannot be const
error[E0379]: functions in traits cannot be declared const
--> $DIR/feature-gate-const_fn.rs:13:5
--> $DIR/feature-gate-const_fn.rs:11:5
|
LL | const fn foo() -> u32 { 0 }
| ^^^^^ functions in traits cannot be const
error[E0658]: const fn is unstable
--> $DIR/feature-gate-const_fn.rs:6:5
|
LL | const fn foo() -> u32;
| ^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
= help: add `#![feature(const_fn)]` to the crate attributes to enable
error: aborting due to 3 previous errors
error[E0658]: const fn is unstable
--> $DIR/feature-gate-const_fn.rs:8:5
|
LL | const fn bar() -> u32 { 0 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
= help: add `#![feature(const_fn)]` to the crate attributes to enable
error: aborting due to 5 previous errors
Some errors have detailed explanations: E0379, E0658.
For more information about an error, try `rustc --explain E0379`.
For more information about this error, try `rustc --explain E0379`.

View File

@ -3,10 +3,8 @@
const fn foo() -> usize { 0 } // stabilized
trait Foo {
const fn foo() -> u32; //~ ERROR const fn is unstable
//~| ERROR functions in traits cannot be declared const
const fn bar() -> u32 { 0 } //~ ERROR const fn is unstable
//~| ERROR functions in traits cannot be declared const
const fn foo() -> u32; //~ ERROR functions in traits cannot be declared const
const fn bar() -> u32 { 0 } //~ ERROR functions in traits cannot be declared const
}
impl Foo for u32 {

View File

@ -5,36 +5,17 @@ LL | const fn foo() -> u32;
| ^^^^^ functions in traits cannot be const
error[E0379]: functions in traits cannot be declared const
--> $DIR/feature-gate-min_const_fn.rs:8:5
--> $DIR/feature-gate-min_const_fn.rs:7:5
|
LL | const fn bar() -> u32 { 0 }
| ^^^^^ functions in traits cannot be const
error[E0379]: functions in traits cannot be declared const
--> $DIR/feature-gate-min_const_fn.rs:13:5
--> $DIR/feature-gate-min_const_fn.rs:11:5
|
LL | const fn foo() -> u32 { 0 }
| ^^^^^ functions in traits cannot be const
error[E0658]: const fn is unstable
--> $DIR/feature-gate-min_const_fn.rs:6:5
|
LL | const fn foo() -> u32;
| ^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
= help: add `#![feature(const_fn)]` to the crate attributes to enable
error: aborting due to 3 previous errors
error[E0658]: const fn is unstable
--> $DIR/feature-gate-min_const_fn.rs:8:5
|
LL | const fn bar() -> u32 { 0 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
= help: add `#![feature(const_fn)]` to the crate attributes to enable
error: aborting due to 5 previous errors
Some errors have detailed explanations: E0379, E0658.
For more information about an error, try `rustc --explain E0379`.
For more information about this error, try `rustc --explain E0379`.