Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new temporary lifetime feature gate and super let keyword #119043

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1067,20 +1067,23 @@ pub enum LocalKind {
/// Local declaration with an initializer and an `else` clause.
/// Example: `let Some(x) = y else { return };`
InitElse(P<Expr>, P<Block>),
/// Local declaration with an initializer living through the temporary lifetime.
/// Example: `super let x = y;`
Super(P<Expr>),
}

impl LocalKind {
pub fn init(&self) -> Option<&Expr> {
match self {
Self::Decl => None,
Self::Init(i) | Self::InitElse(i, _) => Some(i),
Self::Init(i) | Self::InitElse(i, _) | Self::Super(i) => Some(i),
}
}

pub fn init_else_opt(&self) -> Option<(&Expr, Option<&Block>)> {
match self {
Self::Decl => None,
Self::Init(init) => Some((init, None)),
Self::Init(init) | Self::Super(init) => Some((init, None)),
Self::InitElse(init, els) => Some((init, Some(els))),
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast/src/mut_visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ pub fn noop_visit_local<T: MutVisitor>(local: &mut P<Local>, vis: &mut T) {
visit_opt(ty, |ty| vis.visit_ty(ty));
match kind {
LocalKind::Decl => {}
LocalKind::Init(init) => {
LocalKind::Init(init) | LocalKind::Super(init) => {
vis.visit_expr(init);
}
LocalKind::InitElse(init, els) => {
Expand Down
11 changes: 10 additions & 1 deletion compiler/rustc_ast_lowering/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let span = self.lower_span(l.span);
let source = hir::LocalSource::Normal;
self.lower_attrs(hir_id, &l.attrs);
self.arena.alloc(hir::Local { hir_id, ty, pat, init, els, span, source })
self.arena.alloc(hir::Local {
hir_id,
ty,
pat,
init,
els,
span,
source,
is_super: matches!(l.kind, LocalKind::Super(..)),
})
}

fn lower_block_check_mode(&mut self, b: &BlockCheckMode) -> hir::BlockCheckMode {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2342,6 +2342,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
source,
span: self.lower_span(span),
ty: None,
is_super: false,
};
self.stmt(span, hir::StmtKind::Local(self.arena.alloc(local)))
}
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,9 @@ impl<'a> State<'a> {
self.print_outer_attributes(&loc.attrs);
self.space_if_not_bol();
self.ibox(INDENT_UNIT);
if matches!(loc.kind, ast::LocalKind::Super(..)) {
self.word_nbsp("super")
}
self.word_nbsp("let");

self.ibox(INDENT_UNIT);
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,8 @@ declare_features! (
(unstable, never_type, "1.13.0", Some(35121)),
/// Allows diverging expressions to fall back to `!` rather than `()`.
(unstable, never_type_fallback, "1.41.0", Some(65992)),
/// Allows new temporary lifetime rules
(unstable, new_temp_lifetime, "1.72.0", Some(99999)),
/// Allows `#![no_core]`.
(unstable, no_core, "1.3.0", Some(29639)),
/// Allows the use of `no_sanitize` attribute.
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1232,6 +1232,7 @@ pub struct Local<'hir> {
/// Else block for a `let...else` binding.
pub els: Option<&'hir Block<'hir>>,
pub hir_id: HirId,
pub is_super: bool,
pub span: Span,
/// Can be `ForLoopDesugar` if the `let` statement is part of a `for` loop
/// desugaring. Otherwise will be `Normal`.
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_hir_analysis/src/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ mod errs;
pub mod intrinsic;
pub mod intrinsicck;
mod region;
mod scope_map;
pub mod wfcheck;

pub use check::check_abi;
Expand Down Expand Up @@ -105,6 +106,7 @@ use crate::util::common::indenter;

use self::compare_impl_item::collect_return_position_impl_trait_in_trait_tys;
use self::region::region_scope_tree;
use self::scope_map::body_scope_map;

pub fn provide(providers: &mut Providers) {
wfcheck::provide(providers);
Expand All @@ -114,6 +116,7 @@ pub fn provide(providers: &mut Providers) {
collect_return_position_impl_trait_in_trait_tys,
compare_impl_const: compare_impl_item::compare_impl_const_raw,
check_coroutine_obligations: check::check_coroutine_obligations,
body_scope_map,
..*providers
};
}
Expand Down