Skip to content

Commit f2455f7

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 75c68cf commit f2455f7

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
@@ -1058,20 +1058,23 @@ pub enum LocalKind {
10581058
/// Local declaration with an initializer and an `else` clause.
10591059
/// Example: `let Some(x) = y else { return };`
10601060
InitElse(P<Expr>, P<Block>),
1061+
/// Local declaration with an initializer living through the temporary lifetime.
1062+
/// Example: `super let x = y;`
1063+
Super(P<Expr>),
10611064
}
10621065

10631066
impl LocalKind {
10641067
pub fn init(&self) -> Option<&Expr> {
10651068
match self {
10661069
Self::Decl => None,
1067-
Self::Init(i) | Self::InitElse(i, _) => Some(i),
1070+
Self::Init(i) | Self::InitElse(i, _) | Self::Super(i) => Some(i),
10681071
}
10691072
}
10701073

10711074
pub fn init_else_opt(&self) -> Option<(&Expr, Option<&Block>)> {
10721075
match self {
10731076
Self::Decl => None,
1074-
Self::Init(init) => Some((init, None)),
1077+
Self::Init(init) | Self::Super(init) => Some((init, None)),
10751078
Self::InitElse(init, els) => Some((init, Some(els))),
10761079
}
10771080
}

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
@@ -2407,6 +2407,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24072407
source,
24082408
span: self.lower_span(span),
24092409
ty: None,
2410+
is_super: false,
24102411
};
24112412
self.stmt(span, hir::StmtKind::Local(self.arena.alloc(local)))
24122413
}

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
@@ -536,6 +536,8 @@ declare_features! (
536536
(unstable, never_type, "1.13.0", Some(35121)),
537537
/// Allows diverging expressions to fall back to `!` rather than `()`.
538538
(unstable, never_type_fallback, "1.41.0", Some(65992)),
539+
/// Allows new temporary lifetime rules
540+
(unstable, new_temp_lifetime, "1.72.0", Some(99999)),
539541
/// Allows `#![no_core]`.
540542
(unstable, no_core, "1.3.0", Some(29639)),
541543
/// Allows the use of `no_sanitize` attribute.

compiler/rustc_hir/src/hir.rs

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

compiler/rustc_hir_analysis/src/check/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ mod entry;
6969
pub mod intrinsic;
7070
pub mod intrinsicck;
7171
mod region;
72+
mod scope_map;
7273
pub mod wfcheck;
7374

7475
pub use check::check_abi;
@@ -104,6 +105,7 @@ use crate::util::common::indenter;
104105

105106
use self::compare_impl_item::collect_return_position_impl_trait_in_trait_tys;
106107
use self::region::region_scope_tree;
108+
use self::scope_map::body_scope_map;
107109

108110
pub fn provide(providers: &mut Providers) {
109111
wfcheck::provide(providers);
@@ -113,6 +115,7 @@ pub fn provide(providers: &mut Providers) {
113115
collect_return_position_impl_trait_in_trait_tys,
114116
compare_impl_const: compare_impl_item::compare_impl_const_raw,
115117
check_coroutine_obligations: check::check_coroutine_obligations,
118+
body_scope_map,
116119
..*providers
117120
};
118121
}

0 commit comments

Comments
 (0)