Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Next Next commit
Remove ref_pat_everywhere
  • Loading branch information
Jules-Bertholet committed May 15, 2024
commit a32fb2f8aa0780af750189356a06d501a72698b7
1 change: 1 addition & 0 deletions compiler/rustc_feature/src/removed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ declare_features! (
(removed, pushpop_unsafe, "1.2.0", None, None),
(removed, quad_precision_float, "1.0.0", None, None),
(removed, quote, "1.33.0", Some(29601), None),
(removed, ref_pat_everywhere, "1.79.0", Some(123076), Some("superseded by `ref_pat_eat_one_layer_2024")),
(removed, reflect, "1.0.0", Some(27749), None),
/// Allows using the `#[register_attr]` attribute.
(removed, register_attr, "1.65.0", Some(66080),
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,8 +571,6 @@ declare_features! (
(unstable, raw_ref_op, "1.41.0", Some(64490)),
/// Makes `&` and `&mut` patterns eat only one layer of references in Rust 2024.
(incomplete, ref_pat_eat_one_layer_2024, "1.79.0", Some(123076)),
/// Allows `&` and `&mut` patterns to consume match-ergonomics-inserted references.
(incomplete, ref_pat_everywhere, "1.79.0", Some(123076)),
/// Allows using the `#[register_tool]` attribute.
(unstable, register_tool, "1.41.0", Some(66079)),
/// Allows the `#[repr(i128)]` attribute for enums.
Expand Down
65 changes: 13 additions & 52 deletions compiler/rustc_hir_typeck/src/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2125,46 +2125,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
mut expected: Ty<'tcx>,
mut pat_info: PatInfo<'tcx, '_>,
) -> Ty<'tcx> {
// FIXME: repace with `bool` once final decision on 1 vs 2 layers is made
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum MatchErgonomicsMode {
EatOneLayer,
EatTwoLayers,
Legacy,
}

let match_ergonomics_mode =
if pat.span.at_least_rust_2024() && self.tcx.features().ref_pat_eat_one_layer_2024 {
MatchErgonomicsMode::EatOneLayer
} else if self.tcx.features().ref_pat_everywhere {
MatchErgonomicsMode::EatTwoLayers
} else {
MatchErgonomicsMode::Legacy
};
let new_match_ergonomics =
pat.span.at_least_rust_2024() && self.tcx.features().ref_pat_eat_one_layer_2024;

let mut inherited_ref_mutbl_match = false;
if match_ergonomics_mode != MatchErgonomicsMode::Legacy {
if new_match_ergonomics {
if pat_mutbl == Mutability::Not {
// Prevent the inner pattern from binding with `ref mut`.
pat_info.max_ref_mutbl = pat_info.max_ref_mutbl.cap_to_weakly_not(
inner.span.find_ancestor_inside(pat.span).map(|end| pat.span.until(end)),
);
}

if let ByRef::Yes(inh_mut) = pat_info.binding_mode {
inherited_ref_mutbl_match = pat_mutbl <= inh_mut;
}

if inherited_ref_mutbl_match {
pat_info.binding_mode = ByRef::No;
if match_ergonomics_mode == MatchErgonomicsMode::EatOneLayer {
self.typeck_results.borrow_mut().skipped_ref_pats_mut().insert(pat.hir_id);
self.check_pat(inner, expected, pat_info);
return expected;
}
} else if match_ergonomics_mode == MatchErgonomicsMode::EatOneLayer
&& pat_mutbl == Mutability::Mut
if let ByRef::Yes(inh_mut) = pat_info.binding_mode
&& pat_mutbl <= inh_mut
{
pat_info.binding_mode = ByRef::No;
self.typeck_results.borrow_mut().skipped_ref_pats_mut().insert(pat.hir_id);
self.check_pat(inner, expected, pat_info);
return expected;
} else if pat_mutbl == Mutability::Mut {
// `&mut` patterns pell off `&` references
let (new_expected, new_bm, max_ref_mutbl) = self.peel_off_references(
pat,
Expand Down Expand Up @@ -2204,33 +2183,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// the bad interactions of the given hack detailed in (note_1).
debug!("check_pat_ref: expected={:?}", expected);
match *expected.kind() {
ty::Ref(_, r_ty, r_mutbl) if r_mutbl == pat_mutbl => {
if r_mutbl == Mutability::Not
&& match_ergonomics_mode != MatchErgonomicsMode::Legacy
{
ty::Ref(_, r_ty, r_mutbl) if r_mutbl >= pat_mutbl && new_match_ergonomics => {
if r_mutbl == Mutability::Not {
pat_info.max_ref_mutbl = MutblCap::Not;
}

(expected, r_ty)
}

// `&` pattern eats `&mut` reference
ty::Ref(_, r_ty, Mutability::Mut)
if pat_mutbl == Mutability::Not
&& match_ergonomics_mode != MatchErgonomicsMode::Legacy =>
{
(expected, r_ty)
}

_ if inherited_ref_mutbl_match
&& match_ergonomics_mode == MatchErgonomicsMode::EatTwoLayers =>
{
// We already matched against a match-ergonmics inserted reference,
// so we don't need to match against a reference from the original type.
// Save this info for use in lowering later
self.typeck_results.borrow_mut().skipped_ref_pats_mut().insert(pat.hir_id);
(expected, expected)
}
ty::Ref(_, r_ty, r_mutbl) if r_mutbl == pat_mutbl => (expected, r_ty),

_ => {
let inner_ty = self.next_ty_var(inner.span);
Expand Down
14 changes: 0 additions & 14 deletions tests/ui/feature-gates/feature-gate-ref_pat_everywhere.rs

This file was deleted.

49 changes: 0 additions & 49 deletions tests/ui/feature-gates/feature-gate-ref_pat_everywhere.stderr

This file was deleted.

12 changes: 0 additions & 12 deletions tests/ui/match/ref_pat_everywhere-fail.rs

This file was deleted.

38 changes: 0 additions & 38 deletions tests/ui/match/ref_pat_everywhere-fail.stderr

This file was deleted.

24 changes: 0 additions & 24 deletions tests/ui/match/ref_pat_everywhere.rs

This file was deleted.