Skip to content

Rollup of 18 pull requests #139612

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

Closed
wants to merge 45 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
a11fbee
Small code improvement in rustdoc hidden stripper
GuillaumeGomez Mar 7, 2025
e89c849
Clean up librustdoc::html::render to be better encapsulated
xizheyin Mar 17, 2025
abe6e88
Allow drivers to supply a list of extra symbols to intern
Alexendoo Mar 19, 2025
f9770e7
Test linking and running no_std binaries
madsmtm Mar 24, 2025
b8c4c16
Suppress missing field error when autoderef bottoms out in infer
compiler-errors Apr 5, 2025
34e9759
compiletest: Trim whitespace from environment variable names
Zalathar Apr 8, 2025
a0d9c87
Inline `calc_default_binding_mode`
Nadrieril Apr 6, 2025
9f57903
Insert adjustments incrementally
Nadrieril Apr 6, 2025
19950b5
Turn the peeling loop into a recursive call
Nadrieril Apr 6, 2025
38adb99
Reorganize `check_pat_inner`
Nadrieril Apr 6, 2025
6588018
Return a type from `check_pat_inner`
Nadrieril Apr 6, 2025
f458151
Remove redundant assignment
Nadrieril Apr 6, 2025
12311ef
fix title of offset_of_enum feature
programmerjake Apr 8, 2025
f151cea
emit a better error message for using the macro incorrectly
ZuseZ4 Apr 9, 2025
f419b18
Return early on an error path in `parse_item_impl`.
nnethercote Apr 8, 2025
7ae5c7f
Avoid an empty trait name in impl blocks.
nnethercote Apr 9, 2025
b2aa9d0
Remove some dead or leftover code related to rustc-intrinsic abi removal
oli-obk Apr 8, 2025
cf68565
Temporarily leave the review rotation
fmease Apr 9, 2025
32c8f7d
librustdoc: remove IndexItem::new, use previous fields constructor
xizheyin Apr 9, 2025
67ff336
saethlin is back from vacation
saethlin Apr 9, 2025
50d0ce1
Ensure `swap_nonoverlapping` is really always untyped
scottmcm Feb 22, 2025
b06a88f
Add a Miri test for 134713
scottmcm Feb 22, 2025
8b227a4
rustdoc: Enable Markdown extensions when looking for doctests
camelid Apr 9, 2025
63dcac8
skip `tests/codegen/swap-small-types` when debug assertions are on
scottmcm Apr 9, 2025
7103aea
Tracking issue template: fine-grained information on style update status
joshtriplett Apr 9, 2025
d21ee7e
Update `compiler-builtins` to 0.1.153
tgross35 Apr 9, 2025
99b048c
compiletest: update to Edition 2024
jieyouxu Apr 10, 2025
37c9a3c
Rollup merge of #137412 - scottmcm:redo-swap, r=cuviper
Zalathar Apr 10, 2025
d5f5509
Rollup merge of #138167 - GuillaumeGomez:rustdoc-hidden-stripper-impr…
Zalathar Apr 10, 2025
3a9ab8d
Rollup merge of #138605 - xizheyin:issue-138567, r=GuillaumeGomez
Zalathar Apr 10, 2025
af220c3
Rollup merge of #138682 - Alexendoo:extra-symbols, r=fee1-dead
Zalathar Apr 10, 2025
b7a7423
Rollup merge of #138904 - madsmtm:apple-test-no-std, r=tgross35
Zalathar Apr 10, 2025
0f80846
Rollup merge of #139423 - compiler-errors:field-autoderef, r=oli-obk
Zalathar Apr 10, 2025
6171b06
Rollup merge of #139449 - Nadrieril:peel-recursive, r=lcnr
Zalathar Apr 10, 2025
f5b6e88
Rollup merge of #139507 - Zalathar:trim-env-name, r=jieyouxu
Zalathar Apr 10, 2025
b316fb7
Rollup merge of #139530 - oli-obk:rustc-intrinsic-cleanup, r=RalfJung
Zalathar Apr 10, 2025
3657f4d
Rollup merge of #139560 - programmerjake:patch-5, r=jieyouxu
Zalathar Apr 10, 2025
a41c699
Rollup merge of #139563 - EnzymeAD:better-autodiff-err, r=jieyouxu
Zalathar Apr 10, 2025
49e0b9e
Rollup merge of #139568 - nnethercote:empty-trait-name, r=compiler-er…
Zalathar Apr 10, 2025
3358dce
Rollup merge of #139580 - fmease:unrotate, r=fmease
Zalathar Apr 10, 2025
13faa56
Rollup merge of #139589 - saethlin:vacation, r=camelid
Zalathar Apr 10, 2025
aacbcd1
Rollup merge of #139592 - camelid:doctest-md-opts, r=notriddle
Zalathar Apr 10, 2025
9145955
Rollup merge of #139599 - joshtriplett:style-tracking, r=traviscross
Zalathar Apr 10, 2025
57db7af
Rollup merge of #139600 - tgross35:update-builtins, r=tgross35
Zalathar Apr 10, 2025
e43645e
Rollup merge of #139606 - jieyouxu:compiletest-edition2024, r=compile…
Zalathar Apr 10, 2025
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
Prev Previous commit
Next Next commit
Reorganize check_pat_inner
  • Loading branch information
Nadrieril committed Apr 8, 2025
commit 38adb9931cd934fefe2a2f65ca0071612c9ec583
118 changes: 61 additions & 57 deletions compiler/rustc_hir_typeck/src/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
expected: Ty<'tcx>,
pat_info: PatInfo<'tcx>,
) {
let PatInfo { binding_mode, max_ref_mutbl, top_info: ti, current_depth, .. } = pat_info;
let PatInfo { mut binding_mode, mut max_ref_mutbl, current_depth, .. } = pat_info;
#[cfg(debug_assertions)]
if binding_mode == ByRef::Yes(Mutability::Mut)
&& max_ref_mutbl != MutblCap::Mut
Expand All @@ -346,72 +346,76 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
span_bug!(pat.span, "Pattern mutability cap violated!");
}

let (expected, binding_mode, max_ref_mutbl) = match adjust_mode {
if !pat.default_binding_modes {
// When we perform destructuring assignment, we disable default match bindings, which
// are unintuitive in this context.
_ if !pat.default_binding_modes => (expected, ByRef::No, MutblCap::Mut),
AdjustMode::Pass => (expected, binding_mode, max_ref_mutbl),
// Peel an immediately nested `& mut?` from the expected type if possible and return the
// new expected type and binding default binding mode.
AdjustMode::Peel => {
let expected = self.try_structurally_resolve_type(pat.span, expected);
// Peel off a `&` or `&mut` from the scrutinee type. For each ampersand peeled off,
// update the binding mode and push the original type into the adjustments vector.
//
// See the examples in `tests/ui/rfcs/rfc-2005-default-binding-mode`.
if let ty::Ref(_, inner_ty, inner_mutability) = *expected.kind() {
debug!("inspecting {:?}", expected);

debug!("current discriminant is Ref, inserting implicit deref");
// Preserve the reference type. We'll need it later during THIR lowering.
self.typeck_results
.borrow_mut()
.pat_adjustments_mut()
.entry(pat.hir_id)
.or_default()
.push(expected);

let mut binding_mode = ByRef::Yes(match binding_mode {
// If default binding mode is by value, make it `ref` or `ref mut`
// (depending on whether we observe `&` or `&mut`).
ByRef::No |
// When `ref mut`, stay a `ref mut` (on `&mut`) or downgrade to `ref` (on `&`).
ByRef::Yes(Mutability::Mut) => inner_mutability,
// Once a `ref`, always a `ref`.
// This is because a `& &mut` cannot mutate the underlying value.
ByRef::Yes(Mutability::Not) => Mutability::Not,
});

if self.downgrade_mut_inside_shared() {
binding_mode = binding_mode.cap_ref_mutability(max_ref_mutbl.as_mutbl());
}
let mut max_ref_mutbl = max_ref_mutbl;
if binding_mode == ByRef::Yes(Mutability::Not) {
max_ref_mutbl = MutblCap::Not;
}
debug!("default binding mode is now {:?}", binding_mode);
let pat_info = PatInfo { binding_mode, max_ref_mutbl, ..pat_info };
return self.check_pat_inner(
pat,
opt_path_res,
adjust_mode,
inner_ty,
pat_info,
);
} else {
(expected, binding_mode, max_ref_mutbl)
}
}
binding_mode = ByRef::No;
max_ref_mutbl = MutblCap::Mut;
};
// Resolve type if needed.
let expected = if let AdjustMode::Peel = adjust_mode
&& pat.default_binding_modes
{
self.try_structurally_resolve_type(pat.span, expected)
} else {
expected
};
let old_pat_info = pat_info;
let pat_info = PatInfo {
binding_mode,
max_ref_mutbl,
top_info: ti,
decl_origin: pat_info.decl_origin,
current_depth: current_depth + 1,
top_info: old_pat_info.top_info,
decl_origin: old_pat_info.decl_origin,
};

let ty = match pat.kind {
// Peel off a `&` or `&mut` from the scrutinee type. See the examples in
// `tests/ui/rfcs/rfc-2005-default-binding-mode`.
_ if let AdjustMode::Peel = adjust_mode
&& pat.default_binding_modes
&& let ty::Ref(_, inner_ty, inner_mutability) = *expected.kind() =>
{
debug!("inspecting {:?}", expected);

debug!("current discriminant is Ref, inserting implicit deref");
// Preserve the reference type. We'll need it later during THIR lowering.
self.typeck_results
.borrow_mut()
.pat_adjustments_mut()
.entry(pat.hir_id)
.or_default()
.push(expected);

binding_mode = ByRef::Yes(match binding_mode {
// If default binding mode is by value, make it `ref` or `ref mut`
// (depending on whether we observe `&` or `&mut`).
ByRef::No |
// When `ref mut`, stay a `ref mut` (on `&mut`) or downgrade to `ref` (on `&`).
ByRef::Yes(Mutability::Mut) => inner_mutability,
// Once a `ref`, always a `ref`.
// This is because a `& &mut` cannot mutate the underlying value.
ByRef::Yes(Mutability::Not) => Mutability::Not,
});

if self.downgrade_mut_inside_shared() {
binding_mode = binding_mode.cap_ref_mutability(max_ref_mutbl.as_mutbl());
}
if binding_mode == ByRef::Yes(Mutability::Not) {
max_ref_mutbl = MutblCap::Not;
}
debug!("default binding mode is now {:?}", binding_mode);

// Use the old pat info to keep `current_depth` to its old value.
let new_pat_info = PatInfo { binding_mode, max_ref_mutbl, ..old_pat_info };
return self.check_pat_inner(
pat,
opt_path_res,
adjust_mode,
inner_ty,
new_pat_info,
);
}
PatKind::Missing | PatKind::Wild | PatKind::Err(_) => expected,
// We allow any type here; we ensure that the type is uninhabited during match checking.
PatKind::Never => expected,
Expand Down