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

Rollup of 16 pull requests #94784

Closed
wants to merge 44 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
6620244
Make some `Clone` impls `const`
lilasta Dec 11, 2021
9054fbb
mirror mention of intent of From
asquared31415 Jan 3, 2022
04b3162
Add collect_into
frengor Feb 20, 2022
5941fef
Constify slice indexing
fee1-dead Feb 22, 2022
4654a91
Constify slice index for strings
fee1-dead Mar 6, 2022
b328688
Statically compile libstdc++ everywhere if asked
Mar 8, 2022
0d92752
Suggest `if let`/`let_else` for refutable pat in `let`
estebank Mar 8, 2022
c3a998e
Do not suggest `let_else` if no bindings would be introduced
estebank Mar 8, 2022
a5216cf
Unify inherent impl blocks by wrapping them into a div
GuillaumeGomez Mar 8, 2022
fbd9c28
Update GUI tests for impl blocks path changes
GuillaumeGomez Mar 8, 2022
4e067e8
Improve rustdoc book
Urgau Mar 8, 2022
40e4bd2
treat all mir::Constant values as ConstantKind::Val
b-naber Feb 16, 2022
8a811a1
bless tests
b-naber Feb 16, 2022
26fe550
normalization change and rebase
b-naber Mar 8, 2022
5226395
Fix soundness issue in scoped threads.
m-ou-se Mar 5, 2022
7a481ff
Properly abort when thread result panics on drop.
m-ou-se Mar 5, 2022
1c06eb7
Remove outdated comment.
m-ou-se Mar 9, 2022
b97d875
Add soundness test for dropping scoped thread results before joining.
m-ou-se Mar 9, 2022
491350c
Ignore `close_read_wakes_up` test on SGX platform
raoulstrackx Mar 9, 2022
18bb2dd
manually bless 32-bit stderr
b-naber Mar 9, 2022
e346920
Also take in account mdbook redirect in linkchecker
Urgau Mar 9, 2022
021c3b0
keep ERROR in message
b-naber Mar 9, 2022
e54d4ab
Use MaybeUninit in VecDeque to remove the undefined behavior of slice
JmPotato Mar 1, 2022
4d56c15
Add documentation about lifetimes to thread::scope.
m-ou-se Mar 9, 2022
6781016
Add miri to the well known conditional compilation names and values
Urgau Mar 9, 2022
915f9a5
Warn users about || in let chain expressions
c410-f3r Mar 9, 2022
8073a88
Implement macro meta-variable expressions
c410-f3r Mar 9, 2022
63eddb3
Add tracking issue
frengor Mar 9, 2022
ed0ed70
Rollup merge of #91804 - woppopo:const_clone, r=oli-obk
Dylan-DPC Mar 9, 2022
0754c96
Rollup merge of #92541 - asquared31415:from-docs, r=m-ou-se
Dylan-DPC Mar 9, 2022
3f13f0b
Rollup merge of #93057 - frengor:iter_collect_into, r=m-ou-se
Dylan-DPC Mar 9, 2022
de7a97c
Rollup merge of #94059 - b-naber:constantkind-val-transformation, r=lcnr
Dylan-DPC Mar 9, 2022
753d931
Rollup merge of #94368 - c410-f3r:metaaaaaaaaaaaaaaaaaaaaaaaaaaa, r=p…
Dylan-DPC Mar 9, 2022
3440019
Rollup merge of #94472 - JmPotato:use_maybeuninit_for_vecdeque, r=m-o…
Dylan-DPC Mar 9, 2022
e3c33bb
Rollup merge of #94644 - m-ou-se:scoped-threads-drop-soundness, r=jos…
Dylan-DPC Mar 9, 2022
30bb973
Rollup merge of #94657 - fee1-dead:const_slice_index, r=oli-obk
Dylan-DPC Mar 9, 2022
72d8cf1
Rollup merge of #94719 - jonhoo:enable-static-lld, r=Mark-Simulacrum
Dylan-DPC Mar 9, 2022
fca8dba
Rollup merge of #94739 - estebank:suggest-let-else, r=oli-obk
Dylan-DPC Mar 9, 2022
668c607
Rollup merge of #94740 - GuillaumeGomez:unify-impl-blocks, r=notriddle
Dylan-DPC Mar 9, 2022
f2baf2f
Rollup merge of #94753 - Urgau:rustdoc-book-improvements, r=Guillaume…
Dylan-DPC Mar 9, 2022
67fa033
Rollup merge of #94754 - c410-f3r:nice-error, r=lcnr
Dylan-DPC Mar 9, 2022
1ccd44f
Rollup merge of #94763 - m-ou-se:scoped-threads-lifetime-docs, r=Mark…
Dylan-DPC Mar 9, 2022
f7b1fcf
Rollup merge of #94768 - fortanix:raoul/fix_close_read_wakes_up_test_…
Dylan-DPC Mar 9, 2022
3257f81
Rollup merge of #94772 - Urgau:check-cfg-miri, r=petrochenkov
Dylan-DPC Mar 9, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 65 additions & 39 deletions compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ struct AstValidator<'a> {
/// certain positions.
is_assoc_ty_bound_banned: bool,

/// Used to allow `let` expressions in certain syntactic locations.
is_let_allowed: bool,
/// See [ForbiddenLetReason]
forbidden_let_reason: Option<ForbiddenLetReason>,

lint_buffer: &'a mut LintBuffer,
}
Expand Down Expand Up @@ -103,20 +103,28 @@ impl<'a> AstValidator<'a> {
self.is_tilde_const_allowed = old;
}

fn with_let_allowed(&mut self, allowed: bool, f: impl FnOnce(&mut Self, bool)) {
let old = mem::replace(&mut self.is_let_allowed, allowed);
fn with_let_management(
&mut self,
forbidden_let_reason: Option<ForbiddenLetReason>,
f: impl FnOnce(&mut Self, Option<ForbiddenLetReason>),
) {
let old = mem::replace(&mut self.forbidden_let_reason, forbidden_let_reason);
f(self, old);
self.is_let_allowed = old;
self.forbidden_let_reason = old;
}

/// Emits an error banning the `let` expression provided in the given location.
fn ban_let_expr(&self, expr: &'a Expr) {
fn ban_let_expr(&self, expr: &'a Expr, forbidden_let_reason: ForbiddenLetReason) {
let sess = &self.session;
if sess.opts.unstable_features.is_nightly_build() {
sess.struct_span_err(expr.span, "`let` expressions are not supported here")
.note("only supported directly in conditions of `if`- and `while`-expressions")
.note("as well as when nested within `&&` and parentheses in those conditions")
.emit();
let err = "`let` expressions are not supported here";
let mut diag = sess.struct_span_err(expr.span, err);
diag.note("only supported directly in conditions of `if` and `while` expressions");
diag.note("as well as when nested within `&&` and parentheses in those conditions");
if let ForbiddenLetReason::ForbiddenWithOr(span) = forbidden_let_reason {
diag.span_note(span, "`||` operators are not allowed in let chain expressions");
}
diag.emit();
} else {
sess.struct_span_err(expr.span, "expected expression, found statement (`let`)")
.note("variable declaration using `let` is a statement")
Expand Down Expand Up @@ -988,39 +996,48 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
}

fn visit_expr(&mut self, expr: &'a Expr) {
self.with_let_allowed(false, |this, let_allowed| match &expr.kind {
ExprKind::If(cond, then, opt_else) => {
this.visit_block(then);
walk_list!(this, visit_expr, opt_else);
this.with_let_allowed(true, |this, _| this.visit_expr(cond));
return;
}
ExprKind::Let(..) if !let_allowed => this.ban_let_expr(expr),
ExprKind::Match(expr, arms) => {
this.visit_expr(expr);
for arm in arms {
this.visit_expr(&arm.body);
this.visit_pat(&arm.pat);
walk_list!(this, visit_attribute, &arm.attrs);
if let Some(ref guard) = arm.guard {
if let ExprKind::Let(_, ref expr, _) = guard.kind {
this.with_let_allowed(true, |this, _| this.visit_expr(expr));
self.with_let_management(Some(ForbiddenLetReason::GenericForbidden), |this, forbidden_let_reason| {
match &expr.kind {
ExprKind::Binary(Spanned { node: BinOpKind::Or, span }, lhs, rhs) => {
let forbidden_let_reason = Some(ForbiddenLetReason::ForbiddenWithOr(*span));
this.with_let_management(forbidden_let_reason, |this, _| this.visit_expr(lhs));
this.with_let_management(forbidden_let_reason, |this, _| this.visit_expr(rhs));
}
ExprKind::If(cond, then, opt_else) => {
this.visit_block(then);
walk_list!(this, visit_expr, opt_else);
this.with_let_management(None, |this, _| this.visit_expr(cond));
return;
}
ExprKind::Let(..) if let Some(elem) = forbidden_let_reason => {
this.ban_let_expr(expr, elem);
},
ExprKind::Match(scrutinee, arms) => {
this.visit_expr(scrutinee);
for arm in arms {
this.visit_expr(&arm.body);
this.visit_pat(&arm.pat);
walk_list!(this, visit_attribute, &arm.attrs);
if let Some(guard) = &arm.guard && let ExprKind::Let(_, guard_expr, _) = &guard.kind {
this.with_let_management(None, |this, _| {
this.visit_expr(guard_expr)
});
return;
}
}
}
ExprKind::Paren(_) | ExprKind::Binary(Spanned { node: BinOpKind::And, .. }, ..) => {
this.with_let_management(forbidden_let_reason, |this, _| visit::walk_expr(this, expr));
return;
}
ExprKind::While(cond, then, opt_label) => {
walk_list!(this, visit_label, opt_label);
this.visit_block(then);
this.with_let_management(None, |this, _| this.visit_expr(cond));
return;
}
_ => visit::walk_expr(this, expr),
}
ExprKind::Paren(_) | ExprKind::Binary(Spanned { node: BinOpKind::And, .. }, ..) => {
this.with_let_allowed(let_allowed, |this, _| visit::walk_expr(this, expr));
return;
}
ExprKind::While(cond, then, opt_label) => {
walk_list!(this, visit_label, opt_label);
this.visit_block(then);
this.with_let_allowed(true, |this, _| this.visit_expr(cond));
return;
}
_ => visit::walk_expr(this, expr),
});
}

Expand Down Expand Up @@ -1772,10 +1789,19 @@ pub fn check_crate(session: &Session, krate: &Crate, lints: &mut LintBuffer) ->
is_tilde_const_allowed: false,
is_impl_trait_banned: false,
is_assoc_ty_bound_banned: false,
is_let_allowed: false,
forbidden_let_reason: Some(ForbiddenLetReason::GenericForbidden),
lint_buffer: lints,
};
visit::walk_crate(&mut validator, krate);

validator.has_proc_macro_decls
}

/// Used to forbid `let` expressions in certain syntactic locations.
#[derive(Clone, Copy)]
enum ForbiddenLetReason {
/// A let chain with the `||` operator
ForbiddenWithOr(Span),
/// `let` is not valid and the source environment is not important
GenericForbidden,
}
6 changes: 4 additions & 2 deletions compiler/rustc_ast_passes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
//!
//! The crate also contains other misc AST visitors, e.g. `node_count` and `show_span`.

#![feature(iter_is_partitioned)]
#![allow(rustc::potential_query_instability)]
#![feature(box_patterns)]
#![feature(if_let_guard)]
#![feature(iter_is_partitioned)]
#![feature(let_chains)]
#![feature(let_else)]
#![recursion_limit = "256"]
#![allow(rustc::potential_query_instability)]

pub mod ast_validation;
pub mod feature_gate;
Expand Down
Loading