Auto merge of #89933 - est31:let_else, r=michaelwoerister
Adopt let_else across the compiler This performs a substitution of code following the pattern: ``` let <id> = if let <pat> = ... { identity } else { ... : ! }; ``` To simplify it to: ``` let <pat> = ... { identity } else { ... : ! }; ``` By adopting the `let_else` feature (cc #87335). The PR also updates the syn crate because the currently used version of the crate doesn't support `let_else` syntax yet. Note: Generally I'm the person who *removes* usages of unstable features from the compiler, not adds more usages of them, but in this instance I think it hopefully helps the feature get stabilized sooner and in a better state. I have written a [comment](https://github.com/rust-lang/rust/issues/87335#issuecomment-944846205) on the tracking issue about my experience and what I feel could be improved before stabilization of `let_else`.
This commit is contained in:
commit
1af55d19c7
54 changed files with 76 additions and 150 deletions
|
@ -39,6 +39,7 @@
|
|||
#![feature(new_uninit)]
|
||||
#![feature(nll)]
|
||||
#![feature(once_cell)]
|
||||
#![feature(let_else)]
|
||||
#![feature(min_specialization)]
|
||||
#![feature(trusted_len)]
|
||||
#![feature(in_band_lifetimes)]
|
||||
|
|
|
@ -221,9 +221,7 @@ pub fn suggest_constraining_type_param(
|
|||
) -> bool {
|
||||
let param = generics.params.iter().find(|p| p.name.ident().as_str() == param_name);
|
||||
|
||||
let param = if let Some(param) = param {
|
||||
param
|
||||
} else {
|
||||
let Some(param) = param else {
|
||||
return false;
|
||||
};
|
||||
|
||||
|
|
|
@ -755,17 +755,14 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
|
|||
}
|
||||
|
||||
// Extract the number of elements from the layout of the array field:
|
||||
let len = if let Ok(TyAndLayout {
|
||||
let Ok(TyAndLayout {
|
||||
layout: Layout { fields: FieldsShape::Array { count, .. }, .. },
|
||||
..
|
||||
}) = self.layout_of(f0_ty)
|
||||
{
|
||||
count
|
||||
} else {
|
||||
}) = self.layout_of(f0_ty) else {
|
||||
return Err(LayoutError::Unknown(ty));
|
||||
};
|
||||
|
||||
(*e_ty, *len, true)
|
||||
(*e_ty, *count, true)
|
||||
} else {
|
||||
// First ADT field is not an array:
|
||||
(f0_ty, def.non_enum_variant().fields.len() as _, false)
|
||||
|
@ -787,9 +784,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
|
|||
|
||||
// Compute the ABI of the element type:
|
||||
let e_ly = self.layout_of(e_ty)?;
|
||||
let e_abi = if let Abi::Scalar(scalar) = e_ly.abi {
|
||||
scalar
|
||||
} else {
|
||||
let Abi::Scalar(e_abi) = e_ly.abi else {
|
||||
// This error isn't caught in typeck, e.g., if
|
||||
// the element type of the vector is generic.
|
||||
tcx.sess.fatal(&format!(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue