Skip to content

Commit d3a6b64

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 2f19122 commit d3a6b64

File tree

27 files changed

+818
-54
lines changed

27 files changed

+818
-54
lines changed

compiler/rustc_ast/src/ast.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1075,20 +1075,23 @@ pub enum LocalKind {
10751075
/// Local declaration with an initializer and an `else` clause.
10761076
/// Example: `let Some(x) = y else { return };`
10771077
InitElse(P<Expr>, P<Block>),
1078+
/// Local declaration with an initializer living through the temporary lifetime.
1079+
/// Example: `super let x = y;`
1080+
Super(P<Expr>),
10781081
}
10791082

10801083
impl LocalKind {
10811084
pub fn init(&self) -> Option<&Expr> {
10821085
match self {
10831086
Self::Decl => None,
1084-
Self::Init(i) | Self::InitElse(i, _) => Some(i),
1087+
Self::Init(i) | Self::InitElse(i, _) | Self::Super(i) => Some(i),
10851088
}
10861089
}
10871090

10881091
pub fn init_else_opt(&self) -> Option<(&Expr, Option<&Block>)> {
10891092
match self {
10901093
Self::Decl => None,
1091-
Self::Init(init) => Some((init, None)),
1094+
Self::Init(init) | Self::Super(init) => Some((init, None)),
10921095
Self::InitElse(init, els) => Some((init, Some(els))),
10931096
}
10941097
}

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
@@ -2371,6 +2371,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
23712371
source,
23722372
span: self.lower_span(span),
23732373
ty: None,
2374+
is_super: false,
23742375
};
23752376
self.stmt(span, hir::StmtKind::Local(self.arena.alloc(local)))
23762377
}

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
@@ -532,6 +532,8 @@ declare_features! (
532532
(unstable, never_type, "1.13.0", Some(35121)),
533533
/// Allows diverging expressions to fall back to `!` rather than `()`.
534534
(unstable, never_type_fallback, "1.41.0", Some(65992)),
535+
/// Allows new temporary lifetime rules
536+
(unstable, new_temp_lifetime, "1.72.0", Some(99999)),
535537
/// Allows `#![no_core]`.
536538
(unstable, no_core, "1.3.0", Some(29639)),
537539
/// Allows the use of `no_sanitize` attribute.

compiler/rustc_hir/src/hir.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1227,6 +1227,7 @@ pub struct Local<'hir> {
12271227
/// Else block for a `let...else` binding.
12281228
pub els: Option<&'hir Block<'hir>>,
12291229
pub hir_id: HirId,
1230+
pub is_super: bool,
12301231
pub span: Span,
12311232
/// Can be `ForLoopDesugar` if the `let` statement is part of a `for` loop
12321233
/// 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);
@@ -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)