mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-01 11:13:43 +00:00
More let_else adoptions
This commit is contained in:
parent
d5f9c40e6a
commit
670f5c6ef3
@ -471,9 +471,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||||||
// two imports.
|
// two imports.
|
||||||
for new_node_id in [id1, id2] {
|
for new_node_id in [id1, id2] {
|
||||||
let new_id = self.resolver.local_def_id(new_node_id);
|
let new_id = self.resolver.local_def_id(new_node_id);
|
||||||
let res = if let Some(res) = resolutions.next() {
|
let Some(res) = resolutions.next() else {
|
||||||
res
|
|
||||||
} else {
|
|
||||||
// Associate an HirId to both ids even if there is no resolution.
|
// Associate an HirId to both ids even if there is no resolution.
|
||||||
let _old = self
|
let _old = self
|
||||||
.node_id_to_hir_id
|
.node_id_to_hir_id
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
|
|
||||||
#![feature(crate_visibility_modifier)]
|
#![feature(crate_visibility_modifier)]
|
||||||
#![feature(box_patterns)]
|
#![feature(box_patterns)]
|
||||||
|
#![feature(let_else)]
|
||||||
#![feature(never_type)]
|
#![feature(never_type)]
|
||||||
#![recursion_limit = "256"]
|
#![recursion_limit = "256"]
|
||||||
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
|
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
|
||||||
|
@ -217,7 +217,14 @@ where
|
|||||||
let mut issue_num = None;
|
let mut issue_num = None;
|
||||||
let mut is_soft = false;
|
let mut is_soft = false;
|
||||||
for meta in metas {
|
for meta in metas {
|
||||||
if let Some(mi) = meta.meta_item() {
|
let Some(mi) = meta.meta_item() else {
|
||||||
|
handle_errors(
|
||||||
|
&sess.parse_sess,
|
||||||
|
meta.span(),
|
||||||
|
AttrError::UnsupportedLiteral("unsupported literal", false),
|
||||||
|
);
|
||||||
|
continue 'outer;
|
||||||
|
};
|
||||||
match mi.name_or_empty() {
|
match mi.name_or_empty() {
|
||||||
sym::feature => {
|
sym::feature => {
|
||||||
if !get(mi, &mut feature) {
|
if !get(mi, &mut feature) {
|
||||||
@ -247,10 +254,7 @@ where
|
|||||||
"`issue` must be a non-zero numeric string \
|
"`issue` must be a non-zero numeric string \
|
||||||
or \"none\"",
|
or \"none\"",
|
||||||
)
|
)
|
||||||
.span_label(
|
.span_label(mi.name_value_literal_span().unwrap(), msg)
|
||||||
mi.name_value_literal_span().unwrap(),
|
|
||||||
msg,
|
|
||||||
)
|
|
||||||
.emit();
|
.emit();
|
||||||
};
|
};
|
||||||
match issue.parse() {
|
match issue.parse() {
|
||||||
@ -289,14 +293,6 @@ where
|
|||||||
continue 'outer;
|
continue 'outer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
handle_errors(
|
|
||||||
&sess.parse_sess,
|
|
||||||
meta.span(),
|
|
||||||
AttrError::UnsupportedLiteral("unsupported literal", false),
|
|
||||||
);
|
|
||||||
continue 'outer;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
match (feature, reason, issue) {
|
match (feature, reason, issue) {
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
//! The goal is to move the definition of `MetaItem` and things that don't need to be in `syntax`
|
//! The goal is to move the definition of `MetaItem` and things that don't need to be in `syntax`
|
||||||
//! to this crate.
|
//! to this crate.
|
||||||
|
|
||||||
|
#![feature(let_else)]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate rustc_macros;
|
extern crate rustc_macros;
|
||||||
|
|
||||||
|
@ -311,12 +311,12 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
|
|||||||
ty::BoundRegionKind::BrEnv => {
|
ty::BoundRegionKind::BrEnv => {
|
||||||
let def_ty = self.regioncx.universal_regions().defining_ty;
|
let def_ty = self.regioncx.universal_regions().defining_ty;
|
||||||
|
|
||||||
if let DefiningTy::Closure(_, substs) = def_ty {
|
let DefiningTy::Closure(_, substs) = def_ty else {
|
||||||
let args_span = if let hir::ExprKind::Closure(_, _, _, span, _) =
|
// Can't have BrEnv in functions, constants or generators.
|
||||||
tcx.hir().expect_expr(self.mir_hir_id()).kind
|
bug!("BrEnv outside of closure.");
|
||||||
{
|
};
|
||||||
span
|
let hir::ExprKind::Closure(_, _, _, args_span, _) =
|
||||||
} else {
|
tcx.hir().expect_expr(self.mir_hir_id()).kind else {
|
||||||
bug!("Closure is not defined by a closure expr");
|
bug!("Closure is not defined by a closure expr");
|
||||||
};
|
};
|
||||||
let region_name = self.synthesize_region_name();
|
let region_name = self.synthesize_region_name();
|
||||||
@ -344,10 +344,6 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
|
|||||||
note.to_string(),
|
note.to_string(),
|
||||||
),
|
),
|
||||||
})
|
})
|
||||||
} else {
|
|
||||||
// Can't have BrEnv in functions, constants or generators.
|
|
||||||
bug!("BrEnv outside of closure.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ty::BoundRegionKind::BrAnon(_) => None,
|
ty::BoundRegionKind::BrAnon(_) => None,
|
||||||
@ -765,7 +761,13 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
|
|||||||
fn get_future_inner_return_ty(&self, hir_ty: &'tcx hir::Ty<'tcx>) -> &'tcx hir::Ty<'tcx> {
|
fn get_future_inner_return_ty(&self, hir_ty: &'tcx hir::Ty<'tcx>) -> &'tcx hir::Ty<'tcx> {
|
||||||
let hir = self.infcx.tcx.hir();
|
let hir = self.infcx.tcx.hir();
|
||||||
|
|
||||||
if let hir::TyKind::OpaqueDef(id, _) = hir_ty.kind {
|
let hir::TyKind::OpaqueDef(id, _) = hir_ty.kind else {
|
||||||
|
span_bug!(
|
||||||
|
hir_ty.span,
|
||||||
|
"lowered return type of async fn is not OpaqueDef: {:?}",
|
||||||
|
hir_ty
|
||||||
|
);
|
||||||
|
};
|
||||||
let opaque_ty = hir.item(id);
|
let opaque_ty = hir.item(id);
|
||||||
if let hir::ItemKind::OpaqueTy(hir::OpaqueTy {
|
if let hir::ItemKind::OpaqueTy(hir::OpaqueTy {
|
||||||
bounds:
|
bounds:
|
||||||
@ -780,9 +782,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
|
|||||||
hir::TypeBinding {
|
hir::TypeBinding {
|
||||||
ident: Ident { name: sym::Output, .. },
|
ident: Ident { name: sym::Output, .. },
|
||||||
kind:
|
kind:
|
||||||
hir::TypeBindingKind::Equality {
|
hir::TypeBindingKind::Equality { term: hir::Term::Ty(ty) },
|
||||||
term: hir::Term::Ty(ty),
|
|
||||||
},
|
|
||||||
..
|
..
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -801,13 +801,6 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
|
|||||||
opaque_ty
|
opaque_ty
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
span_bug!(
|
|
||||||
hir_ty.span,
|
|
||||||
"lowered return type of async fn is not OpaqueDef: {:?}",
|
|
||||||
hir_ty
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn give_name_if_anonymous_region_appears_in_yield_ty(
|
fn give_name_if_anonymous_region_appears_in_yield_ty(
|
||||||
|
@ -1427,9 +1427,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||||||
bug!("temporary should be initialized exactly once")
|
bug!("temporary should be initialized exactly once")
|
||||||
};
|
};
|
||||||
|
|
||||||
let loc = match init.location {
|
let InitLocation::Statement(loc) = init.location else {
|
||||||
InitLocation::Statement(stmt) => stmt,
|
bug!("temporary initialized in arguments")
|
||||||
_ => bug!("temporary initialized in arguments"),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let body = self.body;
|
let body = self.body;
|
||||||
|
@ -602,10 +602,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||||||
for binding in &candidate_ref.bindings {
|
for binding in &candidate_ref.bindings {
|
||||||
let local = self.var_local_id(binding.var_id, OutsideGuard);
|
let local = self.var_local_id(binding.var_id, OutsideGuard);
|
||||||
|
|
||||||
if let Some(box LocalInfo::User(ClearCrossCrate::Set(BindingForm::Var(
|
let Some(box LocalInfo::User(ClearCrossCrate::Set(BindingForm::Var(
|
||||||
VarBindingForm { opt_match_place: Some((ref mut match_place, _)), .. },
|
VarBindingForm { opt_match_place: Some((ref mut match_place, _)), .. },
|
||||||
)))) = self.local_decls[local].local_info
|
)))) = self.local_decls[local].local_info else {
|
||||||
{
|
bug!("Let binding to non-user variable.")
|
||||||
|
};
|
||||||
// `try_upvars_resolved` may fail if it is unable to resolve the given
|
// `try_upvars_resolved` may fail if it is unable to resolve the given
|
||||||
// `PlaceBuilder` inside a closure. In this case, we don't want to include
|
// `PlaceBuilder` inside a closure. In this case, we don't want to include
|
||||||
// a scrutinee place. `scrutinee_place_builder` will fail for destructured
|
// a scrutinee place. `scrutinee_place_builder` will fail for destructured
|
||||||
@ -623,13 +624,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||||||
if let Ok(match_pair_resolved) =
|
if let Ok(match_pair_resolved) =
|
||||||
initializer.clone().try_upvars_resolved(self.tcx, self.typeck_results)
|
initializer.clone().try_upvars_resolved(self.tcx, self.typeck_results)
|
||||||
{
|
{
|
||||||
let place =
|
let place = match_pair_resolved.into_place(self.tcx, self.typeck_results);
|
||||||
match_pair_resolved.into_place(self.tcx, self.typeck_results);
|
|
||||||
*match_place = Some(place);
|
*match_place = Some(place);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
bug!("Let binding to non-user variable.")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// All of the subcandidates should bind the same locals, so we
|
// All of the subcandidates should bind the same locals, so we
|
||||||
// only visit the first one.
|
// only visit the first one.
|
||||||
|
@ -227,16 +227,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||||||
let target_blocks = make_target_blocks(self);
|
let target_blocks = make_target_blocks(self);
|
||||||
let terminator = if *switch_ty.kind() == ty::Bool {
|
let terminator = if *switch_ty.kind() == ty::Bool {
|
||||||
assert!(!options.is_empty() && options.len() <= 2);
|
assert!(!options.is_empty() && options.len() <= 2);
|
||||||
if let [first_bb, second_bb] = *target_blocks {
|
let [first_bb, second_bb] = *target_blocks else {
|
||||||
|
bug!("`TestKind::SwitchInt` on `bool` should have two targets")
|
||||||
|
};
|
||||||
let (true_bb, false_bb) = match options[0] {
|
let (true_bb, false_bb) = match options[0] {
|
||||||
1 => (first_bb, second_bb),
|
1 => (first_bb, second_bb),
|
||||||
0 => (second_bb, first_bb),
|
0 => (second_bb, first_bb),
|
||||||
v => span_bug!(test.span, "expected boolean value but got {:?}", v),
|
v => span_bug!(test.span, "expected boolean value but got {:?}", v),
|
||||||
};
|
};
|
||||||
TerminatorKind::if_(self.tcx, Operand::Copy(place), true_bb, false_bb)
|
TerminatorKind::if_(self.tcx, Operand::Copy(place), true_bb, false_bb)
|
||||||
} else {
|
|
||||||
bug!("`TestKind::SwitchInt` on `bool` should have two targets")
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// The switch may be inexhaustive so we have a catch all block
|
// The switch may be inexhaustive so we have a catch all block
|
||||||
debug_assert_eq!(options.len() + 1, target_blocks.len());
|
debug_assert_eq!(options.len() + 1, target_blocks.len());
|
||||||
@ -285,7 +284,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||||||
let hi = self.literal_operand(test.span, hi);
|
let hi = self.literal_operand(test.span, hi);
|
||||||
let val = Operand::Copy(place);
|
let val = Operand::Copy(place);
|
||||||
|
|
||||||
if let [success, fail] = *target_blocks {
|
let [success, fail] = *target_blocks else {
|
||||||
|
bug!("`TestKind::Range` should have two target blocks");
|
||||||
|
};
|
||||||
self.compare(
|
self.compare(
|
||||||
block,
|
block,
|
||||||
lower_bound_success,
|
lower_bound_success,
|
||||||
@ -300,9 +301,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||||||
RangeEnd::Excluded => BinOp::Lt,
|
RangeEnd::Excluded => BinOp::Lt,
|
||||||
};
|
};
|
||||||
self.compare(lower_bound_success, success, fail, source_info, op, val, hi);
|
self.compare(lower_bound_success, success, fail, source_info, op, val, hi);
|
||||||
} else {
|
|
||||||
bug!("`TestKind::Range` should have two target blocks");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TestKind::Len { len, op } => {
|
TestKind::Len { len, op } => {
|
||||||
@ -317,7 +315,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||||||
// expected = <N>
|
// expected = <N>
|
||||||
let expected = self.push_usize(block, source_info, len);
|
let expected = self.push_usize(block, source_info, len);
|
||||||
|
|
||||||
if let [true_bb, false_bb] = *target_blocks {
|
let [true_bb, false_bb] = *target_blocks else {
|
||||||
|
bug!("`TestKind::Len` should have two target blocks");
|
||||||
|
};
|
||||||
// result = actual == expected OR result = actual < expected
|
// result = actual == expected OR result = actual < expected
|
||||||
// branch based on result
|
// branch based on result
|
||||||
self.compare(
|
self.compare(
|
||||||
@ -329,9 +329,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||||||
Operand::Move(actual),
|
Operand::Move(actual),
|
||||||
Operand::Move(expected),
|
Operand::Move(expected),
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
bug!("`TestKind::Len` should have two target blocks");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -459,16 +456,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||||||
);
|
);
|
||||||
self.diverge_from(block);
|
self.diverge_from(block);
|
||||||
|
|
||||||
if let [success_block, fail_block] = *make_target_blocks(self) {
|
let [success_block, fail_block] = *make_target_blocks(self) else {
|
||||||
|
bug!("`TestKind::Eq` should have two target blocks")
|
||||||
|
};
|
||||||
// check the result
|
// check the result
|
||||||
self.cfg.terminate(
|
self.cfg.terminate(
|
||||||
eq_block,
|
eq_block,
|
||||||
source_info,
|
source_info,
|
||||||
TerminatorKind::if_(self.tcx, Operand::Move(eq_result), success_block, fail_block),
|
TerminatorKind::if_(self.tcx, Operand::Move(eq_result), success_block, fail_block),
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
bug!("`TestKind::Eq` should have two target blocks")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Given that we are performing `test` against `test_place`, this job
|
/// Given that we are performing `test` against `test_place`, this job
|
||||||
|
@ -47,11 +47,10 @@ use rls_data::{
|
|||||||
|
|
||||||
use tracing::{debug, error};
|
use tracing::{debug, error};
|
||||||
|
|
||||||
|
#[rustfmt::skip] // https://github.com/rust-lang/rustfmt/issues/5213
|
||||||
macro_rules! down_cast_data {
|
macro_rules! down_cast_data {
|
||||||
($id:ident, $kind:ident, $sp:expr) => {
|
($id:ident, $kind:ident, $sp:expr) => {
|
||||||
let $id = if let super::Data::$kind(data) = $id {
|
let super::Data::$kind($id) = $id else {
|
||||||
data
|
|
||||||
} else {
|
|
||||||
span_bug!($sp, "unexpected data kind: {:?}", $id);
|
span_bug!($sp, "unexpected data kind: {:?}", $id);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
|
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
|
||||||
#![feature(if_let_guard)]
|
#![feature(if_let_guard)]
|
||||||
#![feature(nll)]
|
#![feature(nll)]
|
||||||
|
#![feature(let_else)]
|
||||||
#![recursion_limit = "256"]
|
#![recursion_limit = "256"]
|
||||||
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
|
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user