Skip to content

Commit 73259dc

Browse files
first version of super let syntax support
smoke tests of the new syntax move new_temp_lifetime into query restore classic scoping rules
1 parent 9aa232e commit 73259dc

File tree

27 files changed

+798
-47
lines changed

27 files changed

+798
-47
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,20 +1067,23 @@ pub enum LocalKind {
10671067
/// Local declaration with an initializer and an `else` clause.
10681068
/// Example: `let Some(x) = y else { return };`
10691069
InitElse(P<Expr>, P<Block>),
1070+
/// Local declaration with an initializer living through the temporary lifetime.
1071+
/// Example: `super let x = y;`
1072+
Super(P<Expr>),
10701073
}
10711074

10721075
impl LocalKind {
10731076
pub fn init(&self) -> Option<&Expr> {
10741077
match self {
10751078
Self::Decl => None,
1076-
Self::Init(i) | Self::InitElse(i, _) => Some(i),
1079+
Self::Init(i) | Self::InitElse(i, _) | Self::Super(i) => Some(i),
10771080
}
10781081
}
10791082

10801083
pub fn init_else_opt(&self) -> Option<(&Expr, Option<&Block>)> {
10811084
match self {
10821085
Self::Decl => None,
1083-
Self::Init(init) => Some((init, None)),
1086+
Self::Init(init) | Self::Super(init) => Some((init, None)),
10841087
Self::InitElse(init, els) => Some((init, Some(els))),
10851088
}
10861089
}

compiler/rustc_ast/src/mut_visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ pub fn noop_visit_local<T: MutVisitor>(local: &mut P<Local>, vis: &mut T) {
609609
visit_opt(ty, |ty| vis.visit_ty(ty));
610610
match kind {
611611
LocalKind::Decl => {}
612-
LocalKind::Init(init) => {
612+
LocalKind::Init(init) | LocalKind::Super(init) => {
613613
vis.visit_expr(init);
614614
}
615615
LocalKind::InitElse(init, els) => {

compiler/rustc_ast_lowering/src/block.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
9797
let span = self.lower_span(l.span);
9898
let source = hir::LocalSource::Normal;
9999
self.lower_attrs(hir_id, &l.attrs);
100-
self.arena.alloc(hir::Local { hir_id, ty, pat, init, els, span, source })
100+
self.arena.alloc(hir::Local {
101+
hir_id,
102+
ty,
103+
pat,
104+
init,
105+
els,
106+
span,
107+
source,
108+
is_super: matches!(l.kind, LocalKind::Super(..)),
109+
})
101110
}
102111

103112
fn lower_block_check_mode(&mut self, b: &BlockCheckMode) -> hir::BlockCheckMode {

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2342,6 +2342,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
23422342
source,
23432343
span: self.lower_span(span),
23442344
ty: None,
2345+
is_super: false,
23452346
};
23462347
self.stmt(span, hir::StmtKind::Local(self.arena.alloc(local)))
23472348
}

compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,6 +1090,9 @@ impl<'a> State<'a> {
10901090
self.print_outer_attributes(&loc.attrs);
10911091
self.space_if_not_bol();
10921092
self.ibox(INDENT_UNIT);
1093+
if matches!(loc.kind, ast::LocalKind::Super(..)) {
1094+
self.word_nbsp("super")
1095+
}
10931096
self.word_nbsp("let");
10941097

10951098
self.ibox(INDENT_UNIT);

compiler/rustc_feature/src/unstable.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,8 @@ declare_features! (
537537
(unstable, never_type, "1.13.0", Some(35121)),
538538
/// Allows diverging expressions to fall back to `!` rather than `()`.
539539
(unstable, never_type_fallback, "1.41.0", Some(65992)),
540+
/// Allows new temporary lifetime rules
541+
(unstable, new_temp_lifetime, "1.72.0", Some(99999)),
540542
/// Allows `#![no_core]`.
541543
(unstable, no_core, "1.3.0", Some(29639)),
542544
/// Allows the use of `no_sanitize` attribute.

compiler/rustc_hir/src/hir.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,6 +1232,7 @@ pub struct Local<'hir> {
12321232
/// Else block for a `let...else` binding.
12331233
pub els: Option<&'hir Block<'hir>>,
12341234
pub hir_id: HirId,
1235+
pub is_super: bool,
12351236
pub span: Span,
12361237
/// Can be `ForLoopDesugar` if the `let` statement is part of a `for` loop
12371238
/// desugaring. Otherwise will be `Normal`.

compiler/rustc_hir_analysis/src/check/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ mod errs;
7070
pub mod intrinsic;
7171
pub mod intrinsicck;
7272
mod region;
73+
mod scope_map;
7374
pub mod wfcheck;
7475

7576
pub use check::check_abi;
@@ -105,6 +106,7 @@ use crate::util::common::indenter;
105106

106107
use self::compare_impl_item::collect_return_position_impl_trait_in_trait_tys;
107108
use self::region::region_scope_tree;
109+
use self::scope_map::body_scope_map;
108110

109111
pub fn provide(providers: &mut Providers) {
110112
wfcheck::provide(providers);
@@ -114,6 +116,7 @@ pub fn provide(providers: &mut Providers) {
114116
collect_return_position_impl_trait_in_trait_tys,
115117
compare_impl_const: compare_impl_item::compare_impl_const_raw,
116118
check_coroutine_obligations: check::check_coroutine_obligations,
119+
body_scope_map,
117120
..*providers
118121
};
119122
}

0 commit comments

Comments
 (0)