Skip to content

Commit 3388e6d

Browse files
authored
Rollup merge of rust-lang#93590 - est31:let_else, r=lcnr
More let_else adoptions Continuation of rust-lang#89933, rust-lang#91018, rust-lang#91481, rust-lang#93046.
2 parents 799bded + 670f5c6 commit 3388e6d

File tree

10 files changed

+208
-226
lines changed

10 files changed

+208
-226
lines changed

compiler/rustc_ast_lowering/src/item.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -471,9 +471,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
471471
// two imports.
472472
for new_node_id in [id1, id2] {
473473
let new_id = self.resolver.local_def_id(new_node_id);
474-
let res = if let Some(res) = resolutions.next() {
475-
res
476-
} else {
474+
let Some(res) = resolutions.next() else {
477475
// Associate an HirId to both ids even if there is no resolution.
478476
let _old = self
479477
.node_id_to_hir_id

compiler/rustc_ast_lowering/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
3333
#![feature(crate_visibility_modifier)]
3434
#![feature(box_patterns)]
35+
#![feature(let_else)]
3536
#![feature(never_type)]
3637
#![recursion_limit = "256"]
3738
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]

compiler/rustc_attr/src/builtin.rs

+67-71
Original file line numberDiff line numberDiff line change
@@ -217,85 +217,81 @@ where
217217
let mut issue_num = None;
218218
let mut is_soft = false;
219219
for meta in metas {
220-
if let Some(mi) = meta.meta_item() {
221-
match mi.name_or_empty() {
222-
sym::feature => {
223-
if !get(mi, &mut feature) {
224-
continue 'outer;
225-
}
220+
let Some(mi) = meta.meta_item() else {
221+
handle_errors(
222+
&sess.parse_sess,
223+
meta.span(),
224+
AttrError::UnsupportedLiteral("unsupported literal", false),
225+
);
226+
continue 'outer;
227+
};
228+
match mi.name_or_empty() {
229+
sym::feature => {
230+
if !get(mi, &mut feature) {
231+
continue 'outer;
226232
}
227-
sym::reason => {
228-
if !get(mi, &mut reason) {
229-
continue 'outer;
230-
}
233+
}
234+
sym::reason => {
235+
if !get(mi, &mut reason) {
236+
continue 'outer;
237+
}
238+
}
239+
sym::issue => {
240+
if !get(mi, &mut issue) {
241+
continue 'outer;
231242
}
232-
sym::issue => {
233-
if !get(mi, &mut issue) {
234-
continue 'outer;
235-
}
236243

237-
// These unwraps are safe because `get` ensures the meta item
238-
// is a name/value pair string literal.
239-
issue_num = match issue.unwrap().as_str() {
240-
"none" => None,
241-
issue => {
242-
let emit_diag = |msg: &str| {
243-
struct_span_err!(
244-
diagnostic,
245-
mi.span,
246-
E0545,
247-
"`issue` must be a non-zero numeric string \
248-
or \"none\"",
249-
)
250-
.span_label(
251-
mi.name_value_literal_span().unwrap(),
252-
msg,
253-
)
254-
.emit();
255-
};
256-
match issue.parse() {
257-
Ok(0) => {
258-
emit_diag(
259-
"`issue` must not be \"0\", \
260-
use \"none\" instead",
261-
);
262-
continue 'outer;
263-
}
264-
Ok(num) => NonZeroU32::new(num),
265-
Err(err) => {
266-
emit_diag(&err.to_string());
267-
continue 'outer;
268-
}
244+
// These unwraps are safe because `get` ensures the meta item
245+
// is a name/value pair string literal.
246+
issue_num = match issue.unwrap().as_str() {
247+
"none" => None,
248+
issue => {
249+
let emit_diag = |msg: &str| {
250+
struct_span_err!(
251+
diagnostic,
252+
mi.span,
253+
E0545,
254+
"`issue` must be a non-zero numeric string \
255+
or \"none\"",
256+
)
257+
.span_label(mi.name_value_literal_span().unwrap(), msg)
258+
.emit();
259+
};
260+
match issue.parse() {
261+
Ok(0) => {
262+
emit_diag(
263+
"`issue` must not be \"0\", \
264+
use \"none\" instead",
265+
);
266+
continue 'outer;
267+
}
268+
Ok(num) => NonZeroU32::new(num),
269+
Err(err) => {
270+
emit_diag(&err.to_string());
271+
continue 'outer;
269272
}
270273
}
271-
};
272-
}
273-
sym::soft => {
274-
if !mi.is_word() {
275-
let msg = "`soft` should not have any arguments";
276-
sess.parse_sess.span_diagnostic.span_err(mi.span, msg);
277274
}
278-
is_soft = true;
279-
}
280-
_ => {
281-
handle_errors(
282-
&sess.parse_sess,
283-
meta.span(),
284-
AttrError::UnknownMetaItem(
285-
pprust::path_to_string(&mi.path),
286-
&["feature", "reason", "issue", "soft"],
287-
),
288-
);
289-
continue 'outer;
275+
};
276+
}
277+
sym::soft => {
278+
if !mi.is_word() {
279+
let msg = "`soft` should not have any arguments";
280+
sess.parse_sess.span_diagnostic.span_err(mi.span, msg);
290281
}
282+
is_soft = true;
283+
}
284+
_ => {
285+
handle_errors(
286+
&sess.parse_sess,
287+
meta.span(),
288+
AttrError::UnknownMetaItem(
289+
pprust::path_to_string(&mi.path),
290+
&["feature", "reason", "issue", "soft"],
291+
),
292+
);
293+
continue 'outer;
291294
}
292-
} else {
293-
handle_errors(
294-
&sess.parse_sess,
295-
meta.span(),
296-
AttrError::UnsupportedLiteral("unsupported literal", false),
297-
);
298-
continue 'outer;
299295
}
300296
}
301297

compiler/rustc_attr/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
//! The goal is to move the definition of `MetaItem` and things that don't need to be in `syntax`
55
//! to this crate.
66
7+
#![feature(let_else)]
8+
79
#[macro_use]
810
extern crate rustc_macros;
911

compiler/rustc_borrowck/src/diagnostics/region_name.rs

+65-72
Original file line numberDiff line numberDiff line change
@@ -311,43 +311,39 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
311311
ty::BoundRegionKind::BrEnv => {
312312
let def_ty = self.regioncx.universal_regions().defining_ty;
313313

314-
if let DefiningTy::Closure(_, substs) = def_ty {
315-
let args_span = if let hir::ExprKind::Closure(_, _, _, span, _) =
316-
tcx.hir().expect_expr(self.mir_hir_id()).kind
317-
{
318-
span
319-
} else {
320-
bug!("Closure is not defined by a closure expr");
321-
};
322-
let region_name = self.synthesize_region_name();
323-
324-
let closure_kind_ty = substs.as_closure().kind_ty();
325-
let note = match closure_kind_ty.to_opt_closure_kind() {
326-
Some(ty::ClosureKind::Fn) => {
327-
"closure implements `Fn`, so references to captured variables \
328-
can't escape the closure"
329-
}
330-
Some(ty::ClosureKind::FnMut) => {
331-
"closure implements `FnMut`, so references to captured variables \
332-
can't escape the closure"
333-
}
334-
Some(ty::ClosureKind::FnOnce) => {
335-
bug!("BrEnv in a `FnOnce` closure");
336-
}
337-
None => bug!("Closure kind not inferred in borrow check"),
338-
};
339-
340-
Some(RegionName {
341-
name: region_name,
342-
source: RegionNameSource::SynthesizedFreeEnvRegion(
343-
args_span,
344-
note.to_string(),
345-
),
346-
})
347-
} else {
314+
let DefiningTy::Closure(_, substs) = def_ty else {
348315
// Can't have BrEnv in functions, constants or generators.
349316
bug!("BrEnv outside of closure.");
350-
}
317+
};
318+
let hir::ExprKind::Closure(_, _, _, args_span, _) =
319+
tcx.hir().expect_expr(self.mir_hir_id()).kind else {
320+
bug!("Closure is not defined by a closure expr");
321+
};
322+
let region_name = self.synthesize_region_name();
323+
324+
let closure_kind_ty = substs.as_closure().kind_ty();
325+
let note = match closure_kind_ty.to_opt_closure_kind() {
326+
Some(ty::ClosureKind::Fn) => {
327+
"closure implements `Fn`, so references to captured variables \
328+
can't escape the closure"
329+
}
330+
Some(ty::ClosureKind::FnMut) => {
331+
"closure implements `FnMut`, so references to captured variables \
332+
can't escape the closure"
333+
}
334+
Some(ty::ClosureKind::FnOnce) => {
335+
bug!("BrEnv in a `FnOnce` closure");
336+
}
337+
None => bug!("Closure kind not inferred in borrow check"),
338+
};
339+
340+
Some(RegionName {
341+
name: region_name,
342+
source: RegionNameSource::SynthesizedFreeEnvRegion(
343+
args_span,
344+
note.to_string(),
345+
),
346+
})
351347
}
352348

353349
ty::BoundRegionKind::BrAnon(_) => None,
@@ -765,48 +761,45 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
765761
fn get_future_inner_return_ty(&self, hir_ty: &'tcx hir::Ty<'tcx>) -> &'tcx hir::Ty<'tcx> {
766762
let hir = self.infcx.tcx.hir();
767763

768-
if let hir::TyKind::OpaqueDef(id, _) = hir_ty.kind {
769-
let opaque_ty = hir.item(id);
770-
if let hir::ItemKind::OpaqueTy(hir::OpaqueTy {
771-
bounds:
772-
[
773-
hir::GenericBound::LangItemTrait(
774-
hir::LangItem::Future,
775-
_,
776-
_,
777-
hir::GenericArgs {
778-
bindings:
779-
[
780-
hir::TypeBinding {
781-
ident: Ident { name: sym::Output, .. },
782-
kind:
783-
hir::TypeBindingKind::Equality {
784-
term: hir::Term::Ty(ty),
785-
},
786-
..
787-
},
788-
],
789-
..
790-
},
791-
),
792-
],
793-
..
794-
}) = opaque_ty.kind
795-
{
796-
ty
797-
} else {
798-
span_bug!(
799-
hir_ty.span,
800-
"bounds from lowered return type of async fn did not match expected format: {:?}",
801-
opaque_ty
802-
);
803-
}
804-
} else {
764+
let hir::TyKind::OpaqueDef(id, _) = hir_ty.kind else {
805765
span_bug!(
806766
hir_ty.span,
807767
"lowered return type of async fn is not OpaqueDef: {:?}",
808768
hir_ty
809769
);
770+
};
771+
let opaque_ty = hir.item(id);
772+
if let hir::ItemKind::OpaqueTy(hir::OpaqueTy {
773+
bounds:
774+
[
775+
hir::GenericBound::LangItemTrait(
776+
hir::LangItem::Future,
777+
_,
778+
_,
779+
hir::GenericArgs {
780+
bindings:
781+
[
782+
hir::TypeBinding {
783+
ident: Ident { name: sym::Output, .. },
784+
kind:
785+
hir::TypeBindingKind::Equality { term: hir::Term::Ty(ty) },
786+
..
787+
},
788+
],
789+
..
790+
},
791+
),
792+
],
793+
..
794+
}) = opaque_ty.kind
795+
{
796+
ty
797+
} else {
798+
span_bug!(
799+
hir_ty.span,
800+
"bounds from lowered return type of async fn did not match expected format: {:?}",
801+
opaque_ty
802+
);
810803
}
811804
}
812805

compiler/rustc_borrowck/src/lib.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1427,9 +1427,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
14271427
bug!("temporary should be initialized exactly once")
14281428
};
14291429

1430-
let loc = match init.location {
1431-
InitLocation::Statement(stmt) => stmt,
1432-
_ => bug!("temporary initialized in arguments"),
1430+
let InitLocation::Statement(loc) = init.location else {
1431+
bug!("temporary initialized in arguments")
14331432
};
14341433

14351434
let body = self.body;

0 commit comments

Comments
 (0)