Skip to content

Commit a32fb2f

Browse files
Remove ref_pat_everywhere
1 parent b21b74b commit a32fb2f

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
@@ -571,8 +571,6 @@ declare_features! (
571571
(unstable, raw_ref_op, "1.41.0", Some(64490)),
572572
/// Makes `&` and `&mut` patterns eat only one layer of references in Rust 2024.
573573
(incomplete, ref_pat_eat_one_layer_2024, "1.79.0", Some(123076)),
574-
/// Allows `&` and `&mut` patterns to consume match-ergonomics-inserted references.
575-
(incomplete, ref_pat_everywhere, "1.79.0", Some(123076)),
576574
/// Allows using the `#[register_tool]` attribute.
577575
(unstable, register_tool, "1.41.0", Some(66079)),
578576
/// 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
@@ -2125,46 +2125,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
21252125
mut expected: Ty<'tcx>,
21262126
mut pat_info: PatInfo<'tcx, '_>,
21272127
) -> Ty<'tcx> {
2128-
// FIXME: repace with `bool` once final decision on 1 vs 2 layers is made
2129-
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
2130-
enum MatchErgonomicsMode {
2131-
EatOneLayer,
2132-
EatTwoLayers,
2133-
Legacy,
2134-
}
2135-
2136-
let match_ergonomics_mode =
2137-
if pat.span.at_least_rust_2024() && self.tcx.features().ref_pat_eat_one_layer_2024 {
2138-
MatchErgonomicsMode::EatOneLayer
2139-
} else if self.tcx.features().ref_pat_everywhere {
2140-
MatchErgonomicsMode::EatTwoLayers
2141-
} else {
2142-
MatchErgonomicsMode::Legacy
2143-
};
2128+
let new_match_ergonomics =
2129+
pat.span.at_least_rust_2024() && self.tcx.features().ref_pat_eat_one_layer_2024;
21442130

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

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

22142191
(expected, r_ty)
22152192
}
22162193

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

22352196
_ => {
22362197
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)