mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-30 22:12:15 +00:00
Gate const closures even when they appear in macros
This commit is contained in:
parent
bd4355500a
commit
c3159b851a
@ -422,14 +422,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
|
||||
ast::ExprKind::TryBlock(_) => {
|
||||
gate_feature_post!(&self, try_blocks, e.span, "`try` expression is experimental");
|
||||
}
|
||||
ast::ExprKind::Closure(box ast::Closure { constness: ast::Const::Yes(_), .. }) => {
|
||||
gate_feature_post!(
|
||||
&self,
|
||||
const_closures,
|
||||
e.span,
|
||||
"const closures are experimental"
|
||||
);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
visit::walk_expr(self, e)
|
||||
@ -592,6 +584,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
|
||||
gate_all!(associated_const_equality, "associated const equality is incomplete");
|
||||
gate_all!(yeet_expr, "`do yeet` expression is experimental");
|
||||
gate_all!(dyn_star, "`dyn*` trait objects are experimental");
|
||||
gate_all!(const_closures, "const closures are experimental");
|
||||
|
||||
// All uses of `gate_all!` below this point were added in #65742,
|
||||
// and subsequently disabled (with the non-early gating readded).
|
||||
|
@ -2105,7 +2105,7 @@ impl<'a> Parser<'a> {
|
||||
ClosureBinder::NotPresent
|
||||
};
|
||||
|
||||
let constness = self.parse_closure_constness(Case::Sensitive);
|
||||
let constness = self.parse_closure_constness();
|
||||
|
||||
let movability =
|
||||
if self.eat_keyword(kw::Static) { Movability::Static } else { Movability::Movable };
|
||||
|
@ -1196,9 +1196,13 @@ impl<'a> Parser<'a> {
|
||||
self.parse_constness_(case, false)
|
||||
}
|
||||
|
||||
/// Parses constness for closures
|
||||
fn parse_closure_constness(&mut self, case: Case) -> Const {
|
||||
self.parse_constness_(case, true)
|
||||
/// Parses constness for closures (case sensitive, feature-gated)
|
||||
fn parse_closure_constness(&mut self) -> Const {
|
||||
let constness = self.parse_constness_(Case::Sensitive, true);
|
||||
if let Const::Yes(span) = constness {
|
||||
self.sess.gated_spans.gate(sym::const_closures, span);
|
||||
}
|
||||
constness
|
||||
}
|
||||
|
||||
fn parse_constness_(&mut self, case: Case, is_closure: bool) -> Const {
|
||||
|
@ -1,5 +1,13 @@
|
||||
// gate-test-const_closures
|
||||
|
||||
fn main() {
|
||||
(const || {})();
|
||||
//~^ ERROR: const closures are experimental
|
||||
}
|
||||
|
||||
macro_rules! e {
|
||||
($e:expr) => {}
|
||||
}
|
||||
|
||||
e!((const || {}));
|
||||
//~^ ERROR const closures are experimental
|
||||
|
@ -1,12 +1,21 @@
|
||||
error[E0658]: const closures are experimental
|
||||
--> $DIR/gate.rs:3:6
|
||||
--> $DIR/gate.rs:4:6
|
||||
|
|
||||
LL | (const || {})();
|
||||
| ^^^^^^^^^^^
|
||||
| ^^^^^
|
||||
|
|
||||
= note: see issue #106003 <https://github.com/rust-lang/rust/issues/106003> for more information
|
||||
= help: add `#![feature(const_closures)]` to the crate attributes to enable
|
||||
|
||||
error: aborting due to previous error
|
||||
error[E0658]: const closures are experimental
|
||||
--> $DIR/gate.rs:12:5
|
||||
|
|
||||
LL | e!((const || {}));
|
||||
| ^^^^^
|
||||
|
|
||||
= note: see issue #106003 <https://github.com/rust-lang/rust/issues/106003> for more information
|
||||
= help: add `#![feature(const_closures)]` to the crate attributes to enable
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
||||
|
Loading…
Reference in New Issue
Block a user