Skip to content

Commit 809267a

Browse files
committed
Add the feature gate for the super let experiment.
1 parent 5cc6072 commit 809267a

File tree

7 files changed

+39
-1
lines changed

7 files changed

+39
-1
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

+1
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
512512
gate_all!(contracts, "contracts are incomplete");
513513
gate_all!(contracts_internals, "contract internal machinery is for internal use only");
514514
gate_all!(where_clause_attrs, "attributes in `where` clause are unstable");
515+
gate_all!(super_let, "`super let` is experimental");
515516

516517
if !visitor.features.never_patterns() {
517518
if let Some(spans) = spans.get(&sym::never_patterns) {

compiler/rustc_feature/src/unstable.rs

+2
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,8 @@ declare_features! (
630630
(unstable, strict_provenance_lints, "1.61.0", Some(130351)),
631631
/// Allows string patterns to dereference values to match them.
632632
(unstable, string_deref_patterns, "1.67.0", Some(87121)),
633+
/// Allows `super let` statements.
634+
(unstable, super_let, "CURRENT_RUSTC_VERSION", Some(139076)),
633635
/// Allows subtrait items to shadow supertrait items.
634636
(unstable, supertrait_item_shadowing, "1.86.0", Some(89151)),
635637
/// Allows using `#[thread_local]` on `static` items.

compiler/rustc_parse/src/parser/stmt.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,20 @@ impl<'a> Parser<'a> {
7373
});
7474
}
7575

76-
let stmt = if self.token.is_keyword(kw::Let) {
76+
let stmt = if self.token.is_keyword(kw::Super) && self.is_keyword_ahead(1, &[kw::Let]) {
77+
self.collect_tokens(None, attrs, force_collect, |this, attrs| {
78+
this.expect_keyword(exp!(Super))?;
79+
this.psess.gated_spans.gate(sym::super_let, this.prev_token.span);
80+
this.expect_keyword(exp!(Let))?;
81+
let local = this.parse_local(attrs)?; // FIXME(mara): implement super let
82+
let trailing = Trailing::from(capture_semi && this.token == token::Semi);
83+
Ok((
84+
this.mk_stmt(lo.to(this.prev_token.span), StmtKind::Let(local)),
85+
trailing,
86+
UsePreAttrPos::No,
87+
))
88+
})?
89+
} else if self.token.is_keyword(kw::Let) {
7790
self.collect_tokens(None, attrs, force_collect, |this, attrs| {
7891
this.expect_keyword(exp!(Let))?;
7992
let local = this.parse_local(attrs)?;

compiler/rustc_parse/src/parser/token_type.rs

+4
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ pub enum TokenType {
114114
KwSelfUpper,
115115
KwStatic,
116116
KwStruct,
117+
KwSuper,
117118
KwTrait,
118119
KwTry,
119120
KwType,
@@ -250,6 +251,7 @@ impl TokenType {
250251
KwSelfUpper,
251252
KwStatic,
252253
KwStruct,
254+
KwSuper,
253255
KwTrait,
254256
KwTry,
255257
KwType,
@@ -324,6 +326,7 @@ impl TokenType {
324326
TokenType::KwSelfUpper => Some(kw::SelfUpper),
325327
TokenType::KwStatic => Some(kw::Static),
326328
TokenType::KwStruct => Some(kw::Struct),
329+
TokenType::KwSuper => Some(kw::Super),
327330
TokenType::KwTrait => Some(kw::Trait),
328331
TokenType::KwTry => Some(kw::Try),
329332
TokenType::KwType => Some(kw::Type),
@@ -549,6 +552,7 @@ macro_rules! exp {
549552
(SelfUpper) => { exp!(@kw, SelfUpper, KwSelfUpper) };
550553
(Static) => { exp!(@kw, Static, KwStatic) };
551554
(Struct) => { exp!(@kw, Struct, KwStruct) };
555+
(Super) => { exp!(@kw, Super, KwSuper) };
552556
(Trait) => { exp!(@kw, Trait, KwTrait) };
553557
(Try) => { exp!(@kw, Try, KwTry) };
554558
(Type) => { exp!(@kw, Type, KwType) };

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2036,6 +2036,7 @@ symbols! {
20362036
sub_assign,
20372037
sub_with_overflow,
20382038
suggestion,
2039+
super_let,
20392040
supertrait_item_shadowing,
20402041
surface_async_drop_in_place,
20412042
sym,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn main() {
2+
super let a = 1;
3+
//~^ ERROR `super let` is experimental
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0658]: `super let` is experimental
2+
--> $DIR/feature-gate-super-let.rs:2:5
3+
|
4+
LL | super let a = 1;
5+
| ^^^^^
6+
|
7+
= note: see issue #139076 <https://github.com/rust-lang/rust/issues/139076> for more information
8+
= help: add `#![feature(super_let)]` to the crate attributes to enable
9+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10+
11+
error: aborting due to 1 previous error
12+
13+
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)