-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use more slice patterns inside the compiler #128762
Conversation
This comment has been minimized.
This comment has been minimized.
0257ce3
to
8868f91
Compare
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. |
r? compiler |
This comment has been minimized.
This comment has been minimized.
compiler/rustc_ast/src/ast.rs
Outdated
@@ -585,7 +585,7 @@ impl Pat { | |||
} | |||
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@@ -292,9 +292,9 @@ impl<'tcx> Cx<'tcx> { | |||
} else { | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to invert this check.
@@ -898,8 +898,8 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { | |||
self.param_env, | |||
adt_def.non_enum_variant().fields[field].ty(self.tcx, args), | |||
); | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:( this is kinda annoying to have to do, but I guess at least equally annoying as fields.raw[0]
.
8868f91
to
b6070a0
Compare
b6070a0
to
a3e3eca
Compare
This comment has been minimized.
This comment has been minimized.
a3e3eca
to
c4c518d
Compare
@bors r+ |
…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