Skip to content

Commit fe8f026

Browse files
committed
Auto merge of #78889 - Dylan-DPC:rollup-6zjhahf, r=Dylan-DPC
Rollup of 12 pull requests Successful merges: - #77640 (Refactor IntErrorKind to avoid "underflow" terminology) - #78026 (Define `fs::hard_link` to not follow symlinks.) - #78114 (Recognize `private_intra_doc_links` as a lint) - #78228 (Promote aarch64-unknown-linux-gnu to Tier 1) - #78345 (Fix handling of item names for HIR) - #78437 (BTreeMap: stop mistaking node for an orderly place) - #78476 (fix some incorrect aliasing in the BTree) - #78674 (inliner: Use substs_for_mir_body) - #78748 (Implement destructuring assignment for tuples) - #78868 (Fix tab focus on restyled switches) - #78878 (Avoid overlapping cfg attributes when both macOS and aarch64) - #78882 (Nicer hunk headers for rust files) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 1773f60 + 92adac9 commit fe8f026

File tree

56 files changed

+797
-391
lines changed

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

+797
-391
lines changed

Diff for: .gitattributes

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* text=auto eol=lf
44
*.cpp rust
55
*.h rust
6-
*.rs rust
6+
*.rs rust diff=rust
77
*.fixed linguist-language=Rust
88
src/etc/installer/gfx/* binary
99
*.woff binary

Diff for: .github/workflows/ci.yml

+5-110
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ jobs:
154154
strategy:
155155
matrix:
156156
include:
157+
- name: aarch64-gnu
158+
os:
159+
- self-hosted
160+
- ARM64
161+
- linux
157162
- name: arm-android
158163
os: ubuntu-latest-xl
159164
env: {}
@@ -497,116 +502,6 @@ jobs:
497502
AWS_ACCESS_KEY_ID: "${{ env.ARTIFACTS_AWS_ACCESS_KEY_ID }}"
498503
AWS_SECRET_ACCESS_KEY: "${{ secrets[format('AWS_SECRET_ACCESS_KEY_{0}', env.ARTIFACTS_AWS_ACCESS_KEY_ID)] }}"
499504
if: "success() && !env.SKIP_JOB && (github.event_name == 'push' || env.DEPLOY == '1' || env.DEPLOY_ALT == '1')"
500-
auto-fallible:
501-
name: auto-fallible
502-
env:
503-
CI_JOB_NAME: "${{ matrix.name }}"
504-
SCCACHE_BUCKET: rust-lang-gha-caches
505-
DEPLOY_BUCKET: rust-lang-gha
506-
TOOLSTATE_REPO: "https://github.com/pietroalbini/rust-toolstate"
507-
TOOLSTATE_ISSUES_API_URL: "https://api.github.com/repos/pietroalbini/rust-toolstate/issues"
508-
TOOLSTATE_PUBLISH: 1
509-
CACHES_AWS_ACCESS_KEY_ID: AKIA46X5W6CZOMUQATD5
510-
ARTIFACTS_AWS_ACCESS_KEY_ID: AKIA46X5W6CZH5AYXDVF
511-
CACHE_DOMAIN: ci-caches-gha.rust-lang.org
512-
if: "github.event_name == 'push' && github.ref == 'refs/heads/auto' && github.repository == 'rust-lang-ci/rust'"
513-
strategy:
514-
fail-fast: false
515-
matrix:
516-
include:
517-
- name: aarch64-gnu
518-
os:
519-
- self-hosted
520-
- ARM64
521-
- linux
522-
timeout-minutes: 600
523-
runs-on: "${{ matrix.os }}"
524-
steps:
525-
- name: disable git crlf conversion
526-
run: git config --global core.autocrlf false
527-
- name: checkout the source code
528-
uses: actions/checkout@v2
529-
with:
530-
fetch-depth: 2
531-
- name: configure the PR in which the error message will be posted
532-
run: "echo \"[CI_PR_NUMBER=$num]\""
533-
env:
534-
num: "${{ github.event.number }}"
535-
if: "success() && !env.SKIP_JOBS && github.event_name == 'pull_request'"
536-
- name: add extra environment variables
537-
run: src/ci/scripts/setup-environment.sh
538-
env:
539-
EXTRA_VARIABLES: "${{ toJson(matrix.env) }}"
540-
if: success() && !env.SKIP_JOB
541-
- name: decide whether to skip this job
542-
run: src/ci/scripts/should-skip-this.sh
543-
if: success() && !env.SKIP_JOB
544-
- name: configure GitHub Actions to kill the build when outdated
545-
uses: rust-lang/simpleinfra/github-actions/cancel-outdated-builds@master
546-
with:
547-
github_token: "${{ secrets.github_token }}"
548-
if: "success() && !env.SKIP_JOB && github.ref != 'refs/heads/try'"
549-
- name: collect CPU statistics
550-
run: src/ci/scripts/collect-cpu-stats.sh
551-
if: success() && !env.SKIP_JOB
552-
- name: show the current environment
553-
run: src/ci/scripts/dump-environment.sh
554-
if: success() && !env.SKIP_JOB
555-
- name: install awscli
556-
run: src/ci/scripts/install-awscli.sh
557-
if: success() && !env.SKIP_JOB
558-
- name: install sccache
559-
run: src/ci/scripts/install-sccache.sh
560-
if: success() && !env.SKIP_JOB
561-
- name: select Xcode
562-
run: src/ci/scripts/select-xcode.sh
563-
if: success() && !env.SKIP_JOB
564-
- name: install clang
565-
run: src/ci/scripts/install-clang.sh
566-
if: success() && !env.SKIP_JOB
567-
- name: install WIX
568-
run: src/ci/scripts/install-wix.sh
569-
if: success() && !env.SKIP_JOB
570-
- name: ensure the build happens on a partition with enough space
571-
run: src/ci/scripts/symlink-build-dir.sh
572-
if: success() && !env.SKIP_JOB
573-
- name: disable git crlf conversion
574-
run: src/ci/scripts/disable-git-crlf-conversion.sh
575-
if: success() && !env.SKIP_JOB
576-
- name: install MSYS2
577-
run: src/ci/scripts/install-msys2.sh
578-
if: success() && !env.SKIP_JOB
579-
- name: install MinGW
580-
run: src/ci/scripts/install-mingw.sh
581-
if: success() && !env.SKIP_JOB
582-
- name: install ninja
583-
run: src/ci/scripts/install-ninja.sh
584-
if: success() && !env.SKIP_JOB
585-
- name: enable ipv6 on Docker
586-
run: src/ci/scripts/enable-docker-ipv6.sh
587-
if: success() && !env.SKIP_JOB
588-
- name: disable git crlf conversion
589-
run: src/ci/scripts/disable-git-crlf-conversion.sh
590-
if: success() && !env.SKIP_JOB
591-
- name: checkout submodules
592-
run: src/ci/scripts/checkout-submodules.sh
593-
if: success() && !env.SKIP_JOB
594-
- name: ensure line endings are correct
595-
run: src/ci/scripts/verify-line-endings.sh
596-
if: success() && !env.SKIP_JOB
597-
- name: run the build
598-
run: src/ci/scripts/run-build-from-ci.sh
599-
env:
600-
AWS_ACCESS_KEY_ID: "${{ env.CACHES_AWS_ACCESS_KEY_ID }}"
601-
AWS_SECRET_ACCESS_KEY: "${{ secrets[format('AWS_SECRET_ACCESS_KEY_{0}', env.CACHES_AWS_ACCESS_KEY_ID)] }}"
602-
TOOLSTATE_REPO_ACCESS_TOKEN: "${{ secrets.TOOLSTATE_REPO_ACCESS_TOKEN }}"
603-
if: success() && !env.SKIP_JOB
604-
- name: upload artifacts to S3
605-
run: src/ci/scripts/upload-artifacts.sh
606-
env:
607-
AWS_ACCESS_KEY_ID: "${{ env.ARTIFACTS_AWS_ACCESS_KEY_ID }}"
608-
AWS_SECRET_ACCESS_KEY: "${{ secrets[format('AWS_SECRET_ACCESS_KEY_{0}', env.ARTIFACTS_AWS_ACCESS_KEY_ID)] }}"
609-
if: "success() && !env.SKIP_JOB && (github.event_name == 'push' || env.DEPLOY == '1' || env.DEPLOY_ALT == '1')"
610505
try:
611506
name: try
612507
env:

Diff for: compiler/rustc_ast_lowering/src/expr.rs

+130-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use rustc_data_structures::thin_vec::ThinVec;
99
use rustc_errors::struct_span_err;
1010
use rustc_hir as hir;
1111
use rustc_hir::def::Res;
12+
use rustc_session::parse::feature_err;
1213
use rustc_span::hygiene::ForLoopLoc;
1314
use rustc_span::source_map::{respan, DesugaringKind, Span, Spanned};
1415
use rustc_span::symbol::{sym, Ident, Symbol};
@@ -146,7 +147,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
146147
hir::ExprKind::Block(self.lower_block(blk, opt_label.is_some()), opt_label)
147148
}
148149
ExprKind::Assign(ref el, ref er, span) => {
149-
hir::ExprKind::Assign(self.lower_expr(el), self.lower_expr(er), span)
150+
self.lower_expr_assign(el, er, span, e.span)
150151
}
151152
ExprKind::AssignOp(op, ref el, ref er) => hir::ExprKind::AssignOp(
152153
self.lower_binop(op),
@@ -840,6 +841,134 @@ impl<'hir> LoweringContext<'_, 'hir> {
840841
})
841842
}
842843

844+
/// Destructure the LHS of complex assignments.
845+
/// For instance, lower `(a, b) = t` to `{ let (lhs1, lhs2) = t; a = lhs1; b = lhs2; }`.
846+
fn lower_expr_assign(
847+
&mut self,
848+
lhs: &Expr,
849+
rhs: &Expr,
850+
eq_sign_span: Span,
851+
whole_span: Span,
852+
) -> hir::ExprKind<'hir> {
853+
// Return early in case of an ordinary assignment.
854+
fn is_ordinary(lhs: &Expr) -> bool {
855+
match &lhs.kind {
856+
ExprKind::Tup(..) => false,
857+
ExprKind::Paren(e) => {
858+
match e.kind {
859+
// We special-case `(..)` for consistency with patterns.
860+
ExprKind::Range(None, None, RangeLimits::HalfOpen) => false,
861+
_ => is_ordinary(e),
862+
}
863+
}
864+
_ => true,
865+
}
866+
}
867+
if is_ordinary(lhs) {
868+
return hir::ExprKind::Assign(self.lower_expr(lhs), self.lower_expr(rhs), eq_sign_span);
869+
}
870+
if !self.sess.features_untracked().destructuring_assignment {
871+
feature_err(
872+
&self.sess.parse_sess,
873+
sym::destructuring_assignment,
874+
eq_sign_span,
875+
"destructuring assignments are unstable",
876+
)
877+
.span_label(lhs.span, "cannot assign to this expression")
878+
.emit();
879+
}
880+
881+
let mut assignments = vec![];
882+
883+
// The LHS becomes a pattern: `(lhs1, lhs2)`.
884+
let pat = self.destructure_assign(lhs, eq_sign_span, &mut assignments);
885+
let rhs = self.lower_expr(rhs);
886+
887+
// Introduce a `let` for destructuring: `let (lhs1, lhs2) = t`.
888+
let destructure_let = self.stmt_let_pat(
889+
ThinVec::new(),
890+
whole_span,
891+
Some(rhs),
892+
pat,
893+
hir::LocalSource::AssignDesugar(eq_sign_span),
894+
);
895+
896+
// `a = lhs1; b = lhs2;`.
897+
let stmts = self
898+
.arena
899+
.alloc_from_iter(std::iter::once(destructure_let).chain(assignments.into_iter()));
900+
901+
// Wrap everything in a block.
902+
hir::ExprKind::Block(&self.block_all(whole_span, stmts, None), None)
903+
}
904+
905+
/// Convert the LHS of a destructuring assignment to a pattern.
906+
/// Each sub-assignment is recorded in `assignments`.
907+
fn destructure_assign(
908+
&mut self,
909+
lhs: &Expr,
910+
eq_sign_span: Span,
911+
assignments: &mut Vec<hir::Stmt<'hir>>,
912+
) -> &'hir hir::Pat<'hir> {
913+
match &lhs.kind {
914+
// Tuples.
915+
ExprKind::Tup(elements) => {
916+
let (pats, rest) =
917+
self.destructure_sequence(elements, "tuple", eq_sign_span, assignments);
918+
let tuple_pat = hir::PatKind::Tuple(pats, rest.map(|r| r.0));
919+
return self.pat_without_dbm(lhs.span, tuple_pat);
920+
}
921+
ExprKind::Paren(e) => {
922+
// We special-case `(..)` for consistency with patterns.
923+
if let ExprKind::Range(None, None, RangeLimits::HalfOpen) = e.kind {
924+
let tuple_pat = hir::PatKind::Tuple(&[], Some(0));
925+
return self.pat_without_dbm(lhs.span, tuple_pat);
926+
} else {
927+
return self.destructure_assign(e, eq_sign_span, assignments);
928+
}
929+
}
930+
_ => {}
931+
}
932+
// Treat all other cases as normal lvalue.
933+
let ident = Ident::new(sym::lhs, lhs.span);
934+
let (pat, binding) = self.pat_ident(lhs.span, ident);
935+
let ident = self.expr_ident(lhs.span, ident, binding);
936+
let assign = hir::ExprKind::Assign(self.lower_expr(lhs), ident, eq_sign_span);
937+
let expr = self.expr(lhs.span, assign, ThinVec::new());
938+
assignments.push(self.stmt_expr(lhs.span, expr));
939+
pat
940+
}
941+
942+
/// Destructure a sequence of expressions occurring on the LHS of an assignment.
943+
/// Such a sequence occurs in a tuple (struct)/slice.
944+
/// Return a sequence of corresponding patterns, and the index and the span of `..` if it
945+
/// exists.
946+
/// Each sub-assignment is recorded in `assignments`.
947+
fn destructure_sequence(
948+
&mut self,
949+
elements: &[AstP<Expr>],
950+
ctx: &str,
951+
eq_sign_span: Span,
952+
assignments: &mut Vec<hir::Stmt<'hir>>,
953+
) -> (&'hir [&'hir hir::Pat<'hir>], Option<(usize, Span)>) {
954+
let mut rest = None;
955+
let elements =
956+
self.arena.alloc_from_iter(elements.iter().enumerate().filter_map(|(i, e)| {
957+
// Check for `..` pattern.
958+
if let ExprKind::Range(None, None, RangeLimits::HalfOpen) = e.kind {
959+
if let Some((_, prev_span)) = rest {
960+
self.ban_extra_rest_pat(e.span, prev_span, ctx);
961+
} else {
962+
rest = Some((i, e.span));
963+
}
964+
None
965+
} else {
966+
Some(self.destructure_assign(e, eq_sign_span, assignments))
967+
}
968+
}));
969+
(elements, rest)
970+
}
971+
843972
/// Desugar `<start>..=<end>` into `std::ops::RangeInclusive::new(<start>, <end>)`.
844973
fn lower_expr_range_closed(&mut self, span: Span, e1: &Expr, e2: &Expr) -> hir::ExprKind<'hir> {
845974
let e1 = self.lower_expr_mut(e1);

Diff for: compiler/rustc_ast_lowering/src/lib.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -2531,6 +2531,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
25312531
hir_id,
25322532
kind: hir::PatKind::Binding(bm, hir_id, ident.with_span_pos(span), None),
25332533
span,
2534+
default_binding_modes: true,
25342535
}),
25352536
hir_id,
25362537
)
@@ -2541,7 +2542,21 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
25412542
}
25422543

25432544
fn pat(&mut self, span: Span, kind: hir::PatKind<'hir>) -> &'hir hir::Pat<'hir> {
2544-
self.arena.alloc(hir::Pat { hir_id: self.next_id(), kind, span })
2545+
self.arena.alloc(hir::Pat {
2546+
hir_id: self.next_id(),
2547+
kind,
2548+
span,
2549+
default_binding_modes: true,
2550+
})
2551+
}
2552+
2553+
fn pat_without_dbm(&mut self, span: Span, kind: hir::PatKind<'hir>) -> &'hir hir::Pat<'hir> {
2554+
self.arena.alloc(hir::Pat {
2555+
hir_id: self.next_id(),
2556+
kind,
2557+
span,
2558+
default_binding_modes: false,
2559+
})
25452560
}
25462561

25472562
fn ty_path(

Diff for: compiler/rustc_ast_lowering/src/pat.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
273273

274274
/// Construct a `Pat` with the `HirId` of `p.id` lowered.
275275
fn pat_with_node_id_of(&mut self, p: &Pat, kind: hir::PatKind<'hir>) -> &'hir hir::Pat<'hir> {
276-
self.arena.alloc(hir::Pat { hir_id: self.lower_node_id(p.id), kind, span: p.span })
276+
self.arena.alloc(hir::Pat {
277+
hir_id: self.lower_node_id(p.id),
278+
kind,
279+
span: p.span,
280+
default_binding_modes: true,
281+
})
277282
}
278283

279284
/// Emit a friendly error for extra `..` patterns in a tuple/tuple struct/slice pattern.
280-
fn ban_extra_rest_pat(&self, sp: Span, prev_sp: Span, ctx: &str) {
285+
crate fn ban_extra_rest_pat(&self, sp: Span, prev_sp: Span, ctx: &str) {
281286
self.diagnostic()
282287
.struct_span_err(sp, &format!("`..` can only be used once per {} pattern", ctx))
283288
.span_label(sp, &format!("can only be used once per {} pattern", ctx))

Diff for: compiler/rustc_codegen_cranelift/src/common.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -361,13 +361,11 @@ impl<'tcx, M: Module> FunctionCx<'_, 'tcx, M> {
361361
where
362362
T: TypeFoldable<'tcx> + Copy,
363363
{
364-
if let Some(substs) = self.instance.substs_for_mir_body() {
365-
self.tcx
366-
.subst_and_normalize_erasing_regions(substs, ty::ParamEnv::reveal_all(), value)
367-
} else {
368-
self.tcx
369-
.normalize_erasing_regions(ty::ParamEnv::reveal_all(), *value)
370-
}
364+
self.instance.subst_mir_and_normalize_erasing_regions(
365+
self.tcx,
366+
ty::ParamEnv::reveal_all(),
367+
value
368+
)
371369
}
372370

373371
pub(crate) fn clif_type(&self, ty: Ty<'tcx>) -> Option<Type> {

Diff for: compiler/rustc_codegen_ssa/src/mir/mod.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
9292
T: Copy + TypeFoldable<'tcx>,
9393
{
9494
debug!("monomorphize: self.instance={:?}", self.instance);
95-
if let Some(substs) = self.instance.substs_for_mir_body() {
96-
self.cx.tcx().subst_and_normalize_erasing_regions(
97-
substs,
98-
ty::ParamEnv::reveal_all(),
99-
&value,
100-
)
101-
} else {
102-
self.cx.tcx().normalize_erasing_regions(ty::ParamEnv::reveal_all(), *value)
103-
}
95+
self.instance.subst_mir_and_normalize_erasing_regions(
96+
self.cx.tcx(),
97+
ty::ParamEnv::reveal_all(),
98+
value,
99+
)
104100
}
105101
}
106102

Diff for: compiler/rustc_feature/src/active.rs

+3
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,9 @@ declare_features! (
610610
/// Allows unsized fn parameters.
611611
(active, unsized_fn_params, "1.49.0", Some(48055), None),
612612

613+
/// Allows the use of destructuring assignments.
614+
(active, destructuring_assignment, "1.49.0", Some(71126), None),
615+
613616
// -------------------------------------------------------------------------
614617
// feature-group-end: actual feature gates
615618
// -------------------------------------------------------------------------

0 commit comments

Comments
 (0)