Skip to content

Commit 45aa3f5

Browse files
Jules-Bertholetlcnr
authored andcommitted
Remove ref_pat_everywhere
1 parent a0a8728 commit 45aa3f5

File tree

8 files changed

+14
-191
lines changed

8 files changed

+14
-191
lines changed

compiler/rustc_feature/src/removed.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ declare_features! (
181181
(removed, pushpop_unsafe, "1.2.0", None, None),
182182
(removed, quad_precision_float, "1.0.0", None, None),
183183
(removed, quote, "1.33.0", Some(29601), None),
184+
(removed, ref_pat_everywhere, "1.79.0", Some(123076), Some("superseded by `ref_pat_eat_one_layer_2024")),
184185
(removed, reflect, "1.0.0", Some(27749), None),
185186
/// Allows using the `#[register_attr]` attribute.
186187
(removed, register_attr, "1.65.0", Some(66080),

compiler/rustc_feature/src/unstable.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,8 +573,6 @@ declare_features! (
573573
(unstable, raw_ref_op, "1.41.0", Some(64490)),
574574
/// Makes `&` and `&mut` patterns eat only one layer of references in Rust 2024.
575575
(incomplete, ref_pat_eat_one_layer_2024, "1.79.0", Some(123076)),
576-
/// Allows `&` and `&mut` patterns to consume match-ergonomics-inserted references.
577-
(incomplete, ref_pat_everywhere, "1.79.0", Some(123076)),
578576
/// Allows using the `#[register_tool]` attribute.
579577
(unstable, register_tool, "1.41.0", Some(66079)),
580578
/// Allows the `#[repr(i128)]` attribute for enums.

compiler/rustc_hir_typeck/src/pat.rs

Lines changed: 13 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2126,46 +2126,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
21262126
mut expected: Ty<'tcx>,
21272127
mut pat_info: PatInfo<'tcx, '_>,
21282128
) -> Ty<'tcx> {
2129-
// FIXME: repace with `bool` once final decision on 1 vs 2 layers is made
2130-
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
2131-
enum MatchErgonomicsMode {
2132-
EatOneLayer,
2133-
EatTwoLayers,
2134-
Legacy,
2135-
}
2136-
2137-
let match_ergonomics_mode =
2138-
if pat.span.at_least_rust_2024() && self.tcx.features().ref_pat_eat_one_layer_2024 {
2139-
MatchErgonomicsMode::EatOneLayer
2140-
} else if self.tcx.features().ref_pat_everywhere {
2141-
MatchErgonomicsMode::EatTwoLayers
2142-
} else {
2143-
MatchErgonomicsMode::Legacy
2144-
};
2129+
let new_match_ergonomics =
2130+
pat.span.at_least_rust_2024() && self.tcx.features().ref_pat_eat_one_layer_2024;
21452131

2146-
let mut inherited_ref_mutbl_match = false;
2147-
if match_ergonomics_mode != MatchErgonomicsMode::Legacy {
2132+
if new_match_ergonomics {
21482133
if pat_mutbl == Mutability::Not {
21492134
// Prevent the inner pattern from binding with `ref mut`.
21502135
pat_info.max_ref_mutbl = pat_info.max_ref_mutbl.cap_to_weakly_not(
21512136
inner.span.find_ancestor_inside(pat.span).map(|end| pat.span.until(end)),
21522137
);
21532138
}
21542139

2155-
if let ByRef::Yes(inh_mut) = pat_info.binding_mode {
2156-
inherited_ref_mutbl_match = pat_mutbl <= inh_mut;
2157-
}
2158-
2159-
if inherited_ref_mutbl_match {
2160-
pat_info.binding_mode = ByRef::No;
2161-
if match_ergonomics_mode == MatchErgonomicsMode::EatOneLayer {
2162-
self.typeck_results.borrow_mut().skipped_ref_pats_mut().insert(pat.hir_id);
2163-
self.check_pat(inner, expected, pat_info);
2164-
return expected;
2165-
}
2166-
} else if match_ergonomics_mode == MatchErgonomicsMode::EatOneLayer
2167-
&& pat_mutbl == Mutability::Mut
2140+
if let ByRef::Yes(inh_mut) = pat_info.binding_mode
2141+
&& pat_mutbl <= inh_mut
21682142
{
2143+
pat_info.binding_mode = ByRef::No;
2144+
self.typeck_results.borrow_mut().skipped_ref_pats_mut().insert(pat.hir_id);
2145+
self.check_pat(inner, expected, pat_info);
2146+
return expected;
2147+
} else if pat_mutbl == Mutability::Mut {
21692148
// `&mut` patterns pell off `&` references
21702149
let (new_expected, new_bm, max_ref_mutbl) = self.peel_off_references(
21712150
pat,
@@ -2205,33 +2184,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
22052184
// the bad interactions of the given hack detailed in (note_1).
22062185
debug!("check_pat_ref: expected={:?}", expected);
22072186
match *expected.kind() {
2208-
ty::Ref(_, r_ty, r_mutbl) if r_mutbl == pat_mutbl => {
2209-
if r_mutbl == Mutability::Not
2210-
&& match_ergonomics_mode != MatchErgonomicsMode::Legacy
2211-
{
2187+
ty::Ref(_, r_ty, r_mutbl) if r_mutbl >= pat_mutbl && new_match_ergonomics => {
2188+
if r_mutbl == Mutability::Not {
22122189
pat_info.max_ref_mutbl = MutblCap::Not;
22132190
}
22142191

22152192
(expected, r_ty)
22162193
}
22172194

2218-
// `&` pattern eats `&mut` reference
2219-
ty::Ref(_, r_ty, Mutability::Mut)
2220-
if pat_mutbl == Mutability::Not
2221-
&& match_ergonomics_mode != MatchErgonomicsMode::Legacy =>
2222-
{
2223-
(expected, r_ty)
2224-
}
2225-
2226-
_ if inherited_ref_mutbl_match
2227-
&& match_ergonomics_mode == MatchErgonomicsMode::EatTwoLayers =>
2228-
{
2229-
// We already matched against a match-ergonmics inserted reference,
2230-
// so we don't need to match against a reference from the original type.
2231-
// Save this info for use in lowering later
2232-
self.typeck_results.borrow_mut().skipped_ref_pats_mut().insert(pat.hir_id);
2233-
(expected, expected)
2234-
}
2195+
ty::Ref(_, r_ty, r_mutbl) if r_mutbl == pat_mutbl => (expected, r_ty),
22352196

22362197
_ => {
22372198
let inner_ty = self.next_ty_var(inner.span);

tests/ui/feature-gates/feature-gate-ref_pat_everywhere.rs

Lines changed: 0 additions & 14 deletions
This file was deleted.

tests/ui/feature-gates/feature-gate-ref_pat_everywhere.stderr

Lines changed: 0 additions & 49 deletions
This file was deleted.

tests/ui/match/ref_pat_everywhere-fail.rs

Lines changed: 0 additions & 12 deletions
This file was deleted.

tests/ui/match/ref_pat_everywhere-fail.stderr

Lines changed: 0 additions & 38 deletions
This file was deleted.

tests/ui/match/ref_pat_everywhere.rs

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)