Skip to content

Commit 7f869e6

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 c401f09 commit 7f869e6

File tree

27 files changed

+798
-47
lines changed

27 files changed

+798
-47
lines changed

compiler/rustc_ast/src/ast.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1063,20 +1063,23 @@ pub enum LocalKind {
10631063
/// Local declaration with an initializer and an `else` clause.
10641064
/// Example: `let Some(x) = y else { return };`
10651065
InitElse(P<Expr>, P<Block>),
1066+
/// Local declaration with an initializer living through the temporary lifetime.
1067+
/// Example: `super let x = y;`
1068+
Super(P<Expr>),
10661069
}
10671070

10681071
impl LocalKind {
10691072
pub fn init(&self) -> Option<&Expr> {
10701073
match self {
10711074
Self::Decl => None,
1072-
Self::Init(i) | Self::InitElse(i, _) => Some(i),
1075+
Self::Init(i) | Self::InitElse(i, _) | Self::Super(i) => Some(i),
10731076
}
10741077
}
10751078

10761079
pub fn init_else_opt(&self) -> Option<(&Expr, Option<&Block>)> {
10771080
match self {
10781081
Self::Decl => None,
1079-
Self::Init(init) => Some((init, None)),
1082+
Self::Init(init) | Self::Super(init) => Some((init, None)),
10801083
Self::InitElse(init, els) => Some((init, Some(els))),
10811084
}
10821085
}

compiler/rustc_ast/src/mut_visit.rs

+1-1
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

+10-1
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

+1
Original file line numberDiff line numberDiff line change
@@ -2391,6 +2391,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
23912391
source,
23922392
span: self.lower_span(span),
23932393
ty: None,
2394+
is_super: false,
23942395
};
23952396
self.stmt(span, hir::StmtKind::Local(self.arena.alloc(local)))
23962397
}

compiler/rustc_ast_pretty/src/pprust/state.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,9 @@ impl<'a> State<'a> {
10741074
self.print_outer_attributes(&loc.attrs);
10751075
self.space_if_not_bol();
10761076
self.ibox(INDENT_UNIT);
1077+
if matches!(loc.kind, ast::LocalKind::Super(..)) {
1078+
self.word_nbsp("super")
1079+
}
10771080
self.word_nbsp("let");
10781081

10791082
self.ibox(INDENT_UNIT);

compiler/rustc_feature/src/unstable.rs

+2
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,8 @@ declare_features! (
539539
(unstable, never_type, "1.13.0", Some(35121)),
540540
/// Allows diverging expressions to fall back to `!` rather than `()`.
541541
(unstable, never_type_fallback, "1.41.0", Some(65992)),
542+
/// Allows new temporary lifetime rules
543+
(unstable, new_temp_lifetime, "1.72.0", Some(99999)),
542544
/// Allows `#![no_core]`.
543545
(unstable, no_core, "1.3.0", Some(29639)),
544546
/// Allows the use of `no_sanitize` attribute.

compiler/rustc_hir/src/hir.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1245,6 +1245,7 @@ pub struct Local<'hir> {
12451245
/// Else block for a `let...else` binding.
12461246
pub els: Option<&'hir Block<'hir>>,
12471247
pub hir_id: HirId,
1248+
pub is_super: bool,
12481249
pub span: Span,
12491250
/// Can be `ForLoopDesugar` if the `let` statement is part of a `for` loop
12501251
/// desugaring. Otherwise will be `Normal`.

compiler/rustc_hir_analysis/src/check/mod.rs

+3
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)