Skip to content

Commit f103cf5

Browse files
committed
Auto merge of #64182 - Centril:rollup-fmohja1, r=Centril
Rollup of 5 pull requests Successful merges: - #63676 (Use wasi crate for Core API) - #64094 (Improve searching in rustdoc and add tests) - #64111 (or-patterns: Uniformly use `PatKind::Or` in AST & Fix/Cleanup resolve) - #64156 (Assume non-git LLVM is fresh if the stamp file exists) - #64175 (Fix invalid span generation when it should be div) Failed merges: - #63806 (Upgrade rand to 0.7) r? @ghost
2 parents 6187684 + e13ea1e commit f103cf5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1800
-1084
lines changed

Diff for: Cargo.lock

+12
Original file line numberDiff line numberDiff line change
@@ -3870,6 +3870,7 @@ dependencies = [
38703870
"rustc_msan",
38713871
"rustc_tsan",
38723872
"unwind",
3873+
"wasi",
38733874
]
38743875

38753876
[[package]]
@@ -4686,6 +4687,17 @@ dependencies = [
46864687
"try-lock",
46874688
]
46884689

4690+
[[package]]
4691+
name = "wasi"
4692+
version = "0.7.0"
4693+
source = "registry+https://github.com/rust-lang/crates.io-index"
4694+
checksum = "b89c3ce4ce14bdc6fb6beaf9ec7928ca331de5df7e5ea278375642a2f478570d"
4695+
dependencies = [
4696+
"compiler_builtins",
4697+
"rustc-std-workspace-alloc",
4698+
"rustc-std-workspace-core",
4699+
]
4700+
46894701
[[package]]
46904702
name = "winapi"
46914703
version = "0.2.8"

Diff for: src/bootstrap/native.rs

+14-13
Original file line numberDiff line numberDiff line change
@@ -81,26 +81,29 @@ impl Step for Llvm {
8181
(info, "src/llvm-project/llvm", builder.llvm_out(target), dir.join("bin"))
8282
};
8383

84-
if !llvm_info.is_git() {
85-
println!(
86-
"git could not determine the LLVM submodule commit hash. \
87-
Assuming that an LLVM build is necessary.",
88-
);
89-
}
90-
9184
let build_llvm_config = llvm_config_ret_dir
9285
.join(exe("llvm-config", &*builder.config.build));
9386
let done_stamp = out_dir.join("llvm-finished-building");
9487

95-
if let Some(llvm_commit) = llvm_info.sha() {
96-
if done_stamp.exists() {
88+
if done_stamp.exists() {
89+
if let Some(llvm_commit) = llvm_info.sha() {
9790
let done_contents = t!(fs::read(&done_stamp));
9891

9992
// If LLVM was already built previously and the submodule's commit didn't change
10093
// from the previous build, then no action is required.
10194
if done_contents == llvm_commit.as_bytes() {
102-
return build_llvm_config
95+
return build_llvm_config;
10396
}
97+
} else {
98+
builder.info(
99+
"Could not determine the LLVM submodule commit hash. \
100+
Assuming that an LLVM rebuild is not necessary.",
101+
);
102+
builder.info(&format!(
103+
"To force LLVM to rebuild, remove the file `{}`",
104+
done_stamp.display()
105+
));
106+
return build_llvm_config;
104107
}
105108
}
106109

@@ -303,9 +306,7 @@ impl Step for Llvm {
303306

304307
cfg.build();
305308

306-
if let Some(llvm_commit) = llvm_info.sha() {
307-
t!(fs::write(&done_stamp, llvm_commit));
308-
}
309+
t!(fs::write(&done_stamp, llvm_info.sha().unwrap_or("")));
309310

310311
build_llvm_config
311312
}

Diff for: src/librustc/hir/lowering.rs

+33-8
Original file line numberDiff line numberDiff line change
@@ -425,19 +425,44 @@ impl<'a> LoweringContext<'a> {
425425

426426
impl<'tcx, 'interner> Visitor<'tcx> for MiscCollector<'tcx, 'interner> {
427427
fn visit_pat(&mut self, p: &'tcx Pat) {
428-
match p.node {
428+
if let PatKind::Paren(..) | PatKind::Rest = p.node {
429429
// Doesn't generate a HIR node
430-
PatKind::Paren(..) | PatKind::Rest => {},
431-
_ => {
432-
if let Some(owner) = self.hir_id_owner {
433-
self.lctx.lower_node_id_with_owner(p.id, owner);
434-
}
435-
}
436-
};
430+
} else if let Some(owner) = self.hir_id_owner {
431+
self.lctx.lower_node_id_with_owner(p.id, owner);
432+
}
437433

438434
visit::walk_pat(self, p)
439435
}
440436

437+
// HACK(or_patterns; Centril | dlrobertson): Avoid creating
438+
// HIR nodes for `PatKind::Or` for the top level of a `ast::Arm`.
439+
// This is a temporary hack that should go away once we push down
440+
// `arm.pats: HirVec<P<Pat>>` -> `arm.pat: P<Pat>` to HIR. // Centril
441+
fn visit_arm(&mut self, arm: &'tcx Arm) {
442+
match &arm.pat.node {
443+
PatKind::Or(pats) => pats.iter().for_each(|p| self.visit_pat(p)),
444+
_ => self.visit_pat(&arm.pat),
445+
}
446+
walk_list!(self, visit_expr, &arm.guard);
447+
self.visit_expr(&arm.body);
448+
walk_list!(self, visit_attribute, &arm.attrs);
449+
}
450+
451+
// HACK(or_patterns; Centril | dlrobertson): Same as above. // Centril
452+
fn visit_expr(&mut self, e: &'tcx Expr) {
453+
if let ExprKind::Let(pat, scrutinee) = &e.node {
454+
walk_list!(self, visit_attribute, e.attrs.iter());
455+
match &pat.node {
456+
PatKind::Or(pats) => pats.iter().for_each(|p| self.visit_pat(p)),
457+
_ => self.visit_pat(&pat),
458+
}
459+
self.visit_expr(scrutinee);
460+
self.visit_expr_post(e);
461+
return;
462+
}
463+
visit::walk_expr(self, e)
464+
}
465+
441466
fn visit_item(&mut self, item: &'tcx Item) {
442467
let hir_id = self.lctx.allocate_hir_id_counter(item.id);
443468

Diff for: src/librustc/hir/lowering/expr.rs

+39-38
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl LoweringContext<'_> {
6868
let ohs = P(self.lower_expr(ohs));
6969
hir::ExprKind::AddrOf(m, ohs)
7070
}
71-
ExprKind::Let(ref pats, ref scrutinee) => self.lower_expr_let(e.span, pats, scrutinee),
71+
ExprKind::Let(ref pat, ref scrutinee) => self.lower_expr_let(e.span, pat, scrutinee),
7272
ExprKind::If(ref cond, ref then, ref else_opt) => {
7373
self.lower_expr_if(e.span, cond, then, else_opt.as_deref())
7474
}
@@ -227,16 +227,11 @@ impl LoweringContext<'_> {
227227
}
228228
}
229229

230-
/// Emit an error and lower `ast::ExprKind::Let(pats, scrutinee)` into:
230+
/// Emit an error and lower `ast::ExprKind::Let(pat, scrutinee)` into:
231231
/// ```rust
232232
/// match scrutinee { pats => true, _ => false }
233233
/// ```
234-
fn lower_expr_let(
235-
&mut self,
236-
span: Span,
237-
pats: &[AstP<Pat>],
238-
scrutinee: &Expr
239-
) -> hir::ExprKind {
234+
fn lower_expr_let(&mut self, span: Span, pat: &Pat, scrutinee: &Expr) -> hir::ExprKind {
240235
// If we got here, the `let` expression is not allowed.
241236
self.sess
242237
.struct_span_err(span, "`let` expressions are not supported here")
@@ -246,23 +241,23 @@ impl LoweringContext<'_> {
246241

247242
// For better recovery, we emit:
248243
// ```
249-
// match scrutinee { pats => true, _ => false }
244+
// match scrutinee { pat => true, _ => false }
250245
// ```
251246
// While this doesn't fully match the user's intent, it has key advantages:
252247
// 1. We can avoid using `abort_if_errors`.
253-
// 2. We can typeck both `pats` and `scrutinee`.
254-
// 3. `pats` is allowed to be refutable.
248+
// 2. We can typeck both `pat` and `scrutinee`.
249+
// 3. `pat` is allowed to be refutable.
255250
// 4. The return type of the block is `bool` which seems like what the user wanted.
256251
let scrutinee = self.lower_expr(scrutinee);
257252
let then_arm = {
258-
let pats = pats.iter().map(|pat| self.lower_pat(pat)).collect();
253+
let pat = self.lower_pat_top_hack(pat);
259254
let expr = self.expr_bool(span, true);
260-
self.arm(pats, P(expr))
255+
self.arm(pat, P(expr))
261256
};
262257
let else_arm = {
263-
let pats = hir_vec![self.pat_wild(span)];
258+
let pat = self.pat_wild(span);
264259
let expr = self.expr_bool(span, false);
265-
self.arm(pats, P(expr))
260+
self.arm(hir_vec![pat], P(expr))
266261
};
267262
hir::ExprKind::Match(
268263
P(scrutinee),
@@ -291,13 +286,12 @@ impl LoweringContext<'_> {
291286
// Handle then + scrutinee:
292287
let then_blk = self.lower_block(then, false);
293288
let then_expr = self.expr_block(then_blk, ThinVec::new());
294-
let (then_pats, scrutinee, desugar) = match cond.node {
289+
let (then_pat, scrutinee, desugar) = match cond.node {
295290
// `<pat> => <then>`:
296-
ExprKind::Let(ref pats, ref scrutinee) => {
291+
ExprKind::Let(ref pat, ref scrutinee) => {
297292
let scrutinee = self.lower_expr(scrutinee);
298-
let pats = pats.iter().map(|pat| self.lower_pat(pat)).collect();
299-
let desugar = hir::MatchSource::IfLetDesugar { contains_else_clause };
300-
(pats, scrutinee, desugar)
293+
let pat = self.lower_pat_top_hack(pat);
294+
(pat, scrutinee, hir::MatchSource::IfLetDesugar { contains_else_clause })
301295
}
302296
// `true => <then>`:
303297
_ => {
@@ -312,13 +306,11 @@ impl LoweringContext<'_> {
312306
// to preserve drop semantics since `if cond { ... }` does not
313307
// let temporaries live outside of `cond`.
314308
let cond = self.expr_drop_temps(span_block, P(cond), ThinVec::new());
315-
316-
let desugar = hir::MatchSource::IfDesugar { contains_else_clause };
317-
let pats = hir_vec![self.pat_bool(span, true)];
318-
(pats, cond, desugar)
309+
let pat = self.pat_bool(span, true);
310+
(hir_vec![pat], cond, hir::MatchSource::IfDesugar { contains_else_clause })
319311
}
320312
};
321-
let then_arm = self.arm(then_pats, P(then_expr));
313+
let then_arm = self.arm(then_pat, P(then_expr));
322314

323315
hir::ExprKind::Match(P(scrutinee), vec![then_arm, else_arm].into(), desugar)
324316
}
@@ -345,8 +337,8 @@ impl LoweringContext<'_> {
345337
// Handle then + scrutinee:
346338
let then_blk = self.lower_block(body, false);
347339
let then_expr = self.expr_block(then_blk, ThinVec::new());
348-
let (then_pats, scrutinee, desugar, source) = match cond.node {
349-
ExprKind::Let(ref pats, ref scrutinee) => {
340+
let (then_pat, scrutinee, desugar, source) = match cond.node {
341+
ExprKind::Let(ref pat, ref scrutinee) => {
350342
// to:
351343
//
352344
// [opt_ident]: loop {
@@ -356,9 +348,8 @@ impl LoweringContext<'_> {
356348
// }
357349
// }
358350
let scrutinee = self.with_loop_condition_scope(|t| t.lower_expr(scrutinee));
359-
let pats = pats.iter().map(|pat| self.lower_pat(pat)).collect();
360-
let desugar = hir::MatchSource::WhileLetDesugar;
361-
(pats, scrutinee, desugar, hir::LoopSource::WhileLet)
351+
let pat = self.lower_pat_top_hack(pat);
352+
(pat, scrutinee, hir::MatchSource::WhileLetDesugar, hir::LoopSource::WhileLet)
362353
}
363354
_ => {
364355
// We desugar: `'label: while $cond $body` into:
@@ -383,14 +374,12 @@ impl LoweringContext<'_> {
383374
// to preserve drop semantics since `while cond { ... }` does not
384375
// let temporaries live outside of `cond`.
385376
let cond = self.expr_drop_temps(span_block, P(cond), ThinVec::new());
386-
387-
let desugar = hir::MatchSource::WhileDesugar;
388377
// `true => <then>`:
389-
let pats = hir_vec![self.pat_bool(span, true)];
390-
(pats, cond, desugar, hir::LoopSource::While)
378+
let pat = self.pat_bool(span, true);
379+
(hir_vec![pat], cond, hir::MatchSource::WhileDesugar, hir::LoopSource::While)
391380
}
392381
};
393-
let then_arm = self.arm(then_pats, P(then_expr));
382+
let then_arm = self.arm(then_pat, P(then_expr));
394383

395384
// `match <scrutinee> { ... }`
396385
let match_expr = self.expr_match(
@@ -440,7 +429,7 @@ impl LoweringContext<'_> {
440429
hir::Arm {
441430
hir_id: self.next_id(),
442431
attrs: self.lower_attrs(&arm.attrs),
443-
pats: arm.pats.iter().map(|x| self.lower_pat(x)).collect(),
432+
pats: self.lower_pat_top_hack(&arm.pat),
444433
guard: match arm.guard {
445434
Some(ref x) => Some(hir::Guard::If(P(self.lower_expr(x)))),
446435
_ => None,
@@ -450,6 +439,16 @@ impl LoweringContext<'_> {
450439
}
451440
}
452441

442+
/// HACK(or_patterns; Centril | dlrobertson): For now we don't push down top level or-patterns
443+
/// `p | q` into `hir::PatKind::Or(...)` as post-lowering bits of the compiler are not ready
444+
/// to deal with it. This should by fixed by pushing it down to HIR and then HAIR.
445+
fn lower_pat_top_hack(&mut self, pat: &Pat) -> HirVec<P<hir::Pat>> {
446+
match pat.node {
447+
PatKind::Or(ref ps) => ps.iter().map(|x| self.lower_pat(x)).collect(),
448+
_ => hir_vec![self.lower_pat(pat)],
449+
}
450+
}
451+
453452
pub(super) fn make_async_expr(
454453
&mut self,
455454
capture_clause: CaptureBy,
@@ -1255,7 +1254,6 @@ impl LoweringContext<'_> {
12551254
ThinVec::from(attrs.clone()),
12561255
));
12571256
let ok_pat = self.pat_ok(span, val_pat);
1258-
12591257
self.arm(hir_vec![ok_pat], val_expr)
12601258
};
12611259

@@ -1486,7 +1484,10 @@ impl LoweringContext<'_> {
14861484
}
14871485
}
14881486

1489-
fn arm(&mut self, pats: hir::HirVec<P<hir::Pat>>, expr: P<hir::Expr>) -> hir::Arm {
1487+
/// HACK(or_patterns; Centril | dlrobertson): For now we don't push down top level or-patterns
1488+
/// `p | q` into `hir::PatKind::Or(...)` as post-lowering bits of the compiler are not ready
1489+
/// to deal with it. This should by fixed by pushing it down to HIR and then HAIR.
1490+
fn arm(&mut self, pats: HirVec<P<hir::Pat>>, expr: P<hir::Expr>) -> hir::Arm {
14901491
hir::Arm {
14911492
hir_id: self.next_id(),
14921493
attrs: hir_vec![],

Diff for: src/librustc_lint/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ impl EarlyLintPass for UnusedDocComment {
772772
}
773773

774774
fn check_arm(&mut self, cx: &EarlyContext<'_>, arm: &ast::Arm) {
775-
let arm_span = arm.pats[0].span.with_hi(arm.body.span.hi());
775+
let arm_span = arm.pat.span.with_hi(arm.body.span.hi());
776776
self.warn_if_doc(cx, arm_span, "match arms", false, &arm.attrs);
777777
}
778778

Diff for: src/librustc_lint/unused.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -493,10 +493,8 @@ impl EarlyLintPass for UnusedParens {
493493
fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &ast::Expr) {
494494
use syntax::ast::ExprKind::*;
495495
let (value, msg, followed_by_block, left_pos, right_pos) = match e.node {
496-
Let(ref pats, ..) => {
497-
for p in pats {
498-
self.check_unused_parens_pat(cx, p, false, false);
499-
}
496+
Let(ref pat, ..) => {
497+
self.check_unused_parens_pat(cx, pat, false, false);
500498
return;
501499
}
502500

@@ -594,9 +592,7 @@ impl EarlyLintPass for UnusedParens {
594592
}
595593

596594
fn check_arm(&mut self, cx: &EarlyContext<'_>, arm: &ast::Arm) {
597-
for p in &arm.pats {
598-
self.check_unused_parens_pat(cx, p, false, false);
599-
}
595+
self.check_unused_parens_pat(cx, &arm.pat, false, false);
600596
}
601597
}
602598

0 commit comments

Comments
 (0)