Uh oh!
There was an error while loading. Please reload this page.
Use more slice patterns inside the compiler - #128762
Conversation
This comment has been minimized.
This comment has been minimized.
0257ce3 to
8868f91Comparerustbot
commented
Aug 7, 2024
Some changes occurred in match checking cc @Nadrieril Some changes occurred in coverage instrumentation. cc @Zalathar Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt These commits modify compiler targets. |
fmease
commented
Aug 7, 2024
r? compiler |
This comment has been minimized.
This comment has been minimized.
| // A slice/array pattern `[P]` can be reparsed as `[T]`, an unsized array, | ||
| // when `P` can be reparsed as a type `T`. | ||
| PatKind::Slice(pats) if pats.len() == 1 => pats[0].to_ty().map(TyKind::Slice)?, | ||
| PatKind::Slice(pats) if let [pat] = &**pats => pat.to_ty().map(TyKind::Slice)?, |
There was a problem hiding this comment.
I would kinda prefer we spell this as pats.as_slice() or &pats[..].
&** is kinda an eyesore, and the implicit autoderef of either strategies makes it less annoying if we change around the underlying type reprs.
| let attrs = tcx.hir().attrs(expr.hir_id); | ||
| if attrs.iter().any(|a| a.name_or_empty() == sym::rustc_box) { | ||
| if attrs.len() != 1 { | ||
| if let [attr] = attrs { |
There was a problem hiding this comment.
You need to invert this check.
| ); | ||
| if fields.len() == 1 { | ||
| let src_ty = fields.raw[0].ty(self.body, self.tcx); | ||
| if let [field] = &*fields.raw { |
There was a problem hiding this comment.
:( this is kinda annoying to have to do, but I guess at least equally annoying as fields.raw[0].
8868f91 to
b6070a0Compareb6070a0 to
a3e3ecaCompare
This comment has been minimized.
This comment has been minimized.
a3e3eca to
c4c518dComparecompiler-errors
commented
Aug 10, 2024
@bors r+ |
bors
commented
Aug 10, 2024
…iler-errors Use more slice patterns inside the compiler Nothing super noteworthy. Just replacing the common 'fragile' pattern of "length check followed by indexing or unwrap" with slice patterns for legibility and 'robustness'. r? ghost
…iaskrgr Rollup of 6 pull requests Successful merges: - rust-lang#120314 (core: optimise Debug impl for ascii::Char) - rust-lang#128536 (Preliminary cleanup of `WitnessPat` hoisting/printing) - rust-lang#128592 (Promote aarch64-apple-darwin to Tier 1) - rust-lang#128762 (Use more slice patterns inside the compiler) - rust-lang#128875 (rm `import.used`) - rust-lang#128882 (make LocalWaker::will_wake consistent with Waker::will_wake) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#128762 - fmease:use-more-slice-pats, r=compiler-errors Use more slice patterns inside the compiler Nothing super noteworthy. Just replacing the common 'fragile' pattern of "length check followed by indexing or unwrap" with slice patterns for legibility and 'robustness'. r? ghost
Nothing super noteworthy. Just replacing the common 'fragile' pattern of "length check followed by indexing or unwrap" with slice patterns for legibility and 'robustness'.
r? ghost