Skip to content

Commit fa2db5a

Browse files
committed
Auto merge of rust-lang#120131 - oli-obk:pattern_types_syntax, r=compiler-errors
Implement minimal, internal-only pattern types in the type system rebase of rust-lang#107606 You can create pattern types with `std::pat::pattern_type!(ty is pat)`. The feature is incomplete and will panic on you if you use any pattern other than integral range patterns. The only way to create or deconstruct a pattern type is via `transmute`. This PR's implementation differs from the MCP's text. Specifically > This means you could implement different traits for different pattern types with the same base type. Thus, we just forbid implementing any traits for pattern types. is violated in this PR. The reason is that we do need impls after all in order to make them usable as fields. constants of type `std::time::Nanoseconds` struct are used in patterns, so the type must be structural-eq, which it only can be if you derive several traits on it. It doesn't need to be structural-eq recursively, so we can just manually implement the relevant traits on the pattern type and use the pattern type as a private field. Waiting on: * [x] move all unrelated commits into their own PRs. * [x] fix niche computation (see 2db07f9) * [x] add lots more tests * [x] T-types MCP rust-lang/types-team#126 to finish * [x] some commit cleanup * [x] full self-review * [x] remove 61bd325, it's not necessary anymore I think. * [ ] ~~make sure we never accidentally leak pattern types to user code (add stability checks or feature gate checks and appopriate tests)~~ we don't even do this for the new float primitives * [x] get approval that [the scope expansion to trait impls](https://rust-lang.zulipchat.com/#narrow/stream/326866-t-types.2Fnominated/topic/Pattern.20types.20types-team.23126/near/427670099) is ok r? `@BoxyUwU`
2 parents ce82fa4 + c838803 commit fa2db5a

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

clippy_lints/src/dereference.rs

+2
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,7 @@ impl TyCoercionStability {
821821
| TyKind::Array(..)
822822
| TyKind::Ptr(_)
823823
| TyKind::BareFn(_)
824+
| TyKind::Pat(..)
824825
| TyKind::Never
825826
| TyKind::Tup(_)
826827
| TyKind::Path(_) => Self::Deref,
@@ -869,6 +870,7 @@ impl TyCoercionStability {
869870
| ty::Int(_)
870871
| ty::Uint(_)
871872
| ty::Array(..)
873+
| ty::Pat(..)
872874
| ty::Float(_)
873875
| ty::RawPtr(..)
874876
| ty::FnPtr(_)

clippy_utils/src/hir_utils.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1068,6 +1068,10 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
10681068
self.hash_ty(ty);
10691069
self.hash_array_length(len);
10701070
},
1071+
TyKind::Pat(ty, pat) => {
1072+
self.hash_ty(ty);
1073+
self.hash_pat(pat);
1074+
},
10711075
TyKind::Ptr(ref mut_ty) => {
10721076
self.hash_ty(mut_ty.ty);
10731077
mut_ty.mutbl.hash(&mut self.s);

0 commit comments

Comments
 (0)