Auto merge of #87140 - camsteffen:pat-slice-refs, r=oli-obk
Remove refs from Pat slices Changes `PatKind::Or(&'hir [&'hir Pat<'hir>])` to `PatKind::Or(&'hir [Pat<'hir>])` and others. This is more consistent with `ExprKind`, saves a little memory, and is a little easier to use.
This commit is contained in:
@@ -255,7 +255,7 @@ pub fn in_macro(span: Span) -> bool {
|
||||
}
|
||||
|
||||
/// Checks if given pattern is a wildcard (`_`)
|
||||
pub fn is_wild<'tcx>(pat: &impl std::ops::Deref<Target = Pat<'tcx>>) -> bool {
|
||||
pub fn is_wild(pat: &Pat<'_>) -> bool {
|
||||
matches!(pat.kind, PatKind::Wild)
|
||||
}
|
||||
|
||||
@@ -1023,8 +1023,8 @@ pub fn is_refutable(cx: &LateContext<'_>, pat: &Pat<'_>) -> bool {
|
||||
)
|
||||
}
|
||||
|
||||
fn are_refutable<'a, I: Iterator<Item = &'a Pat<'a>>>(cx: &LateContext<'_>, mut i: I) -> bool {
|
||||
i.any(|pat| is_refutable(cx, pat))
|
||||
fn are_refutable<'a, I: IntoIterator<Item = &'a Pat<'a>>>(cx: &LateContext<'_>, i: I) -> bool {
|
||||
i.into_iter().any(|pat| is_refutable(cx, pat))
|
||||
}
|
||||
|
||||
match pat.kind {
|
||||
@@ -1035,23 +1035,23 @@ pub fn is_refutable(cx: &LateContext<'_>, pat: &Pat<'_>) -> bool {
|
||||
PatKind::Path(ref qpath) => is_enum_variant(cx, qpath, pat.hir_id),
|
||||
PatKind::Or(pats) => {
|
||||
// TODO: should be the honest check, that pats is exhaustive set
|
||||
are_refutable(cx, pats.iter().map(|pat| &**pat))
|
||||
are_refutable(cx, pats)
|
||||
},
|
||||
PatKind::Tuple(pats, _) => are_refutable(cx, pats.iter().map(|pat| &**pat)),
|
||||
PatKind::Tuple(pats, _) => are_refutable(cx, pats),
|
||||
PatKind::Struct(ref qpath, fields, _) => {
|
||||
is_enum_variant(cx, qpath, pat.hir_id) || are_refutable(cx, fields.iter().map(|field| &*field.pat))
|
||||
},
|
||||
PatKind::TupleStruct(ref qpath, pats, _) => {
|
||||
is_enum_variant(cx, qpath, pat.hir_id) || are_refutable(cx, pats.iter().map(|pat| &**pat))
|
||||
is_enum_variant(cx, qpath, pat.hir_id) || are_refutable(cx, pats)
|
||||
},
|
||||
PatKind::Slice(head, ref middle, tail) => {
|
||||
PatKind::Slice(head, middle, tail) => {
|
||||
match &cx.typeck_results().node_type(pat.hir_id).kind() {
|
||||
rustc_ty::Slice(..) => {
|
||||
// [..] is the only irrefutable slice pattern.
|
||||
!head.is_empty() || middle.is_none() || !tail.is_empty()
|
||||
},
|
||||
rustc_ty::Array(..) => {
|
||||
are_refutable(cx, head.iter().chain(middle).chain(tail.iter()).map(|pat| &**pat))
|
||||
are_refutable(cx, head.iter().chain(middle).chain(tail.iter()))
|
||||
},
|
||||
_ => {
|
||||
// unreachable!()
|
||||
@@ -1066,7 +1066,7 @@ pub fn is_refutable(cx: &LateContext<'_>, pat: &Pat<'_>) -> bool {
|
||||
/// the function once on the given pattern.
|
||||
pub fn recurse_or_patterns<'tcx, F: FnMut(&'tcx Pat<'tcx>)>(pat: &'tcx Pat<'tcx>, mut f: F) {
|
||||
if let PatKind::Or(pats) = pat.kind {
|
||||
pats.iter().copied().for_each(f);
|
||||
pats.iter().for_each(f);
|
||||
} else {
|
||||
f(pat);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user