Skip to content

Commit 306096a

Browse files
committed
third part
1 parent bd70847 commit 306096a

File tree

28 files changed

+417
-450
lines changed

28 files changed

+417
-450
lines changed

compiler/rustc_mir_transform/src/promote_consts.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -997,12 +997,11 @@ fn promote_candidates<'tcx>(
997997
for candidate in candidates.into_iter().rev() {
998998
let Location { block, statement_index } = candidate.location;
999999
if let StatementKind::Assign(box (place, _)) = &body[block].statements[statement_index].kind
1000+
&& let Some(local) = place.as_local()
10001001
{
1001-
if let Some(local) = place.as_local() {
1002-
if temps[local] == TempState::PromotedOut {
1003-
// Already promoted.
1004-
continue;
1005-
}
1002+
if temps[local] == TempState::PromotedOut {
1003+
// Already promoted.
1004+
continue;
10061005
}
10071006
}
10081007

@@ -1066,11 +1065,11 @@ fn promote_candidates<'tcx>(
10661065
_ => true,
10671066
});
10681067
let terminator = block.terminator_mut();
1069-
if let TerminatorKind::Drop { place, target, .. } = &terminator.kind {
1070-
if let Some(index) = place.as_local() {
1071-
if promoted(index) {
1072-
terminator.kind = TerminatorKind::Goto { target: *target };
1073-
}
1068+
if let TerminatorKind::Drop { place, target, .. } = &terminator.kind
1069+
&& let Some(index) = place.as_local()
1070+
{
1071+
if promoted(index) {
1072+
terminator.kind = TerminatorKind::Goto { target: *target };
10741073
}
10751074
}
10761075
}

compiler/rustc_mir_transform/src/remove_noop_landing_pads.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,13 @@ impl<'tcx> crate::MirPass<'tcx> for RemoveNoopLandingPads {
4848
let postorder: Vec<_> = traversal::postorder(body).map(|(bb, _)| bb).collect();
4949
for bb in postorder {
5050
debug!(" processing {:?}", bb);
51-
if let Some(unwind) = body[bb].terminator_mut().unwind_mut() {
52-
if let UnwindAction::Cleanup(unwind_bb) = *unwind {
53-
if nop_landing_pads.contains(unwind_bb) {
54-
debug!(" removing noop landing pad");
55-
landing_pads_removed += 1;
56-
*unwind = UnwindAction::Continue;
57-
}
58-
}
51+
if let Some(unwind) = body[bb].terminator_mut().unwind_mut()
52+
&& let UnwindAction::Cleanup(unwind_bb) = *unwind
53+
&& nop_landing_pads.contains(unwind_bb)
54+
{
55+
debug!(" removing noop landing pad");
56+
landing_pads_removed += 1;
57+
*unwind = UnwindAction::Continue;
5958
}
6059

6160
body[bb].terminator_mut().successors_mut(|target| {

compiler/rustc_mir_transform/src/validate.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,14 @@ impl<'tcx> crate::MirPass<'tcx> for Validator {
8080
cfg_checker.fail(location, msg);
8181
}
8282

83-
if let MirPhase::Runtime(_) = body.phase {
84-
if let ty::InstanceKind::Item(_) = body.source.instance {
85-
if body.has_free_regions() {
86-
cfg_checker.fail(
87-
Location::START,
88-
format!("Free regions in optimized {} MIR", body.phase.name()),
89-
);
90-
}
91-
}
83+
if let MirPhase::Runtime(_) = body.phase
84+
&& let ty::InstanceKind::Item(_) = body.source.instance
85+
&& body.has_free_regions()
86+
{
87+
cfg_checker.fail(
88+
Location::START,
89+
format!("Free regions in optimized {} MIR", body.phase.name()),
90+
);
9291
}
9392
}
9493

compiler/rustc_monomorphize/src/partitioning.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,12 +1178,11 @@ fn collect_and_partition_mono_items(tcx: TyCtxt<'_>, (): ()) -> MonoItemPartitio
11781178
let autodiff_items = tcx.arena.alloc_from_iter(autodiff_items);
11791179

11801180
// Output monomorphization stats per def_id
1181-
if let SwitchWithOptPath::Enabled(ref path) = tcx.sess.opts.unstable_opts.dump_mono_stats {
1182-
if let Err(err) =
1181+
if let SwitchWithOptPath::Enabled(ref path) = tcx.sess.opts.unstable_opts.dump_mono_stats
1182+
&& let Err(err) =
11831183
dump_mono_items_stats(tcx, codegen_units, path, tcx.crate_name(LOCAL_CRATE))
1184-
{
1185-
tcx.dcx().emit_fatal(CouldntDumpMonoStats { error: err.to_string() });
1186-
}
1184+
{
1185+
tcx.dcx().emit_fatal(CouldntDumpMonoStats { error: err.to_string() });
11871186
}
11881187

11891188
if tcx.sess.opts.unstable_opts.print_mono_items {

compiler/rustc_parse/src/parser/item.rs

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1973,21 +1973,21 @@ impl<'a> Parser<'a> {
19731973
format!("expected `,`, or `}}`, found {}", super::token_descr(&self.token));
19741974

19751975
// Try to recover extra trailing angle brackets
1976-
if let TyKind::Path(_, Path { segments, .. }) = &a_var.ty.kind {
1977-
if let Some(last_segment) = segments.last() {
1978-
let guar = self.check_trailing_angle_brackets(
1979-
last_segment,
1980-
&[exp!(Comma), exp!(CloseBrace)],
1981-
);
1982-
if let Some(_guar) = guar {
1983-
// Handle a case like `Vec<u8>>,` where we can continue parsing fields
1984-
// after the comma
1985-
let _ = self.eat(exp!(Comma));
1986-
1987-
// `check_trailing_angle_brackets` already emitted a nicer error, as
1988-
// proven by the presence of `_guar`. We can continue parsing.
1989-
return Ok(a_var);
1990-
}
1976+
if let TyKind::Path(_, Path { segments, .. }) = &a_var.ty.kind
1977+
&& let Some(last_segment) = segments.last()
1978+
{
1979+
let guar = self.check_trailing_angle_brackets(
1980+
last_segment,
1981+
&[exp!(Comma), exp!(CloseBrace)],
1982+
);
1983+
if let Some(_guar) = guar {
1984+
// Handle a case like `Vec<u8>>,` where we can continue parsing fields
1985+
// after the comma
1986+
let _ = self.eat(exp!(Comma));
1987+
1988+
// `check_trailing_angle_brackets` already emitted a nicer error, as
1989+
// proven by the presence of `_guar`. We can continue parsing.
1990+
return Ok(a_var);
19911991
}
19921992
}
19931993

@@ -3034,18 +3034,16 @@ impl<'a> Parser<'a> {
30343034

30353035
if let Ok(t) = &ty {
30363036
// Check for trailing angle brackets
3037-
if let TyKind::Path(_, Path { segments, .. }) = &t.kind {
3038-
if let Some(segment) = segments.last() {
3039-
if let Some(guar) =
3040-
this.check_trailing_angle_brackets(segment, &[exp!(CloseParen)])
3041-
{
3042-
return Ok((
3043-
dummy_arg(segment.ident, guar),
3044-
Trailing::No,
3045-
UsePreAttrPos::No,
3046-
));
3047-
}
3048-
}
3037+
if let TyKind::Path(_, Path { segments, .. }) = &t.kind
3038+
&& let Some(segment) = segments.last()
3039+
&& let Some(guar) =
3040+
this.check_trailing_angle_brackets(segment, &[exp!(CloseParen)])
3041+
{
3042+
return Ok((
3043+
dummy_arg(segment.ident, guar),
3044+
Trailing::No,
3045+
UsePreAttrPos::No,
3046+
));
30493047
}
30503048

30513049
if this.token != token::Comma && this.token != token::CloseParen {

compiler/rustc_passes/src/reachable.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,10 @@ impl<'tcx> Visitor<'tcx> for ReachableContext<'tcx> {
104104

105105
fn visit_inline_asm(&mut self, asm: &'tcx hir::InlineAsm<'tcx>, id: hir::HirId) {
106106
for (op, _) in asm.operands {
107-
if let hir::InlineAsmOperand::SymStatic { def_id, .. } = op {
108-
if let Some(def_id) = def_id.as_local() {
109-
self.reachable_symbols.insert(def_id);
110-
}
107+
if let hir::InlineAsmOperand::SymStatic { def_id, .. } = op
108+
&& let Some(def_id) = def_id.as_local()
109+
{
110+
self.reachable_symbols.insert(def_id);
111111
}
112112
}
113113
intravisit::walk_inline_asm(self, asm, id);

compiler/rustc_passes/src/stability.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -929,10 +929,10 @@ struct CheckTraitImplStable<'tcx> {
929929

930930
impl<'tcx> Visitor<'tcx> for CheckTraitImplStable<'tcx> {
931931
fn visit_path(&mut self, path: &hir::Path<'tcx>, _id: hir::HirId) {
932-
if let Some(def_id) = path.res.opt_def_id() {
933-
if let Some(stab) = self.tcx.lookup_stability(def_id) {
934-
self.fully_stable &= stab.level.is_stable();
935-
}
932+
if let Some(def_id) = path.res.opt_def_id()
933+
&& let Some(stab) = self.tcx.lookup_stability(def_id)
934+
{
935+
self.fully_stable &= stab.level.is_stable();
936936
}
937937
intravisit::walk_path(self, path)
938938
}
@@ -1055,10 +1055,10 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
10551055
// implications from this crate.
10561056
remaining_implications.remove(&feature);
10571057

1058-
if let FeatureStability::Unstable { old_name: Some(alias) } = stability {
1059-
if let Some(span) = remaining_lib_features.swap_remove(&alias) {
1060-
tcx.dcx().emit_err(errors::RenamedFeature { span, feature, alias });
1061-
}
1058+
if let FeatureStability::Unstable { old_name: Some(alias) } = stability
1059+
&& let Some(span) = remaining_lib_features.swap_remove(&alias)
1060+
{
1061+
tcx.dcx().emit_err(errors::RenamedFeature { span, feature, alias });
10621062
}
10631063

10641064
if remaining_lib_features.is_empty() && remaining_implications.is_empty() {

compiler/rustc_passes/src/upvars.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,19 +75,19 @@ impl<'tcx> Visitor<'tcx> for CaptureCollector<'_, 'tcx> {
7575
}
7676

7777
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) {
78-
if let hir::ExprKind::Closure(closure) = expr.kind {
79-
if let Some(upvars) = self.tcx.upvars_mentioned(closure.def_id) {
80-
// Every capture of a closure expression is a local in scope,
81-
// that is moved/copied/borrowed into the closure value, and
82-
// for this analysis they are like any other access to a local.
83-
//
84-
// E.g. in `|b| |c| (a, b, c)`, the upvars of the inner closure
85-
// are `a` and `b`, and while `a` is not directly used in the
86-
// outer closure, it needs to be an upvar there too, so that
87-
// the inner closure can take it (from the outer closure's env).
88-
for (&var_id, upvar) in upvars {
89-
self.visit_local_use(var_id, upvar.span);
90-
}
78+
if let hir::ExprKind::Closure(closure) = expr.kind
79+
&& let Some(upvars) = self.tcx.upvars_mentioned(closure.def_id)
80+
{
81+
// Every capture of a closure expression is a local in scope,
82+
// that is moved/copied/borrowed into the closure value, and
83+
// for this analysis they are like any other access to a local.
84+
//
85+
// E.g. in `|b| |c| (a, b, c)`, the upvars of the inner closure
86+
// are `a` and `b`, and while `a` is not directly used in the
87+
// outer closure, it needs to be an upvar there too, so that
88+
// the inner closure can take it (from the outer closure's env).
89+
for (&var_id, upvar) in upvars {
90+
self.visit_local_use(var_id, upvar.span);
9191
}
9292
}
9393

compiler/rustc_privacy/src/lib.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,10 @@ where
204204
// Something like `fn() {my_method}` type of the method
205205
// `impl Pub<Priv> { pub fn my_method() {} }` is considered a private type,
206206
// so we need to visit the self type additionally.
207-
if let Some(assoc_item) = tcx.opt_associated_item(def_id) {
208-
if let Some(impl_def_id) = assoc_item.impl_container(tcx) {
209-
try_visit!(
210-
tcx.type_of(impl_def_id).instantiate_identity().visit_with(self)
211-
);
212-
}
207+
if let Some(assoc_item) = tcx.opt_associated_item(def_id)
208+
&& let Some(impl_def_id) = assoc_item.impl_container(tcx)
209+
{
210+
try_visit!(tcx.type_of(impl_def_id).instantiate_identity().visit_with(self));
213211
}
214212
}
215213
ty::Alias(kind @ (ty::Inherent | ty::Free | ty::Projection), data) => {
@@ -734,6 +732,7 @@ impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> {
734732
if let Some(ctor_def_id) = variant.data.ctor_def_id() {
735733
self.update(ctor_def_id, variant_ev, Level::Reachable);
736734
}
735+
737736
for field in variant.data.fields() {
738737
self.update(field.def_id, variant_ev, Level::Reachable);
739738
self.reach(field.def_id, variant_ev).ty();

compiler/rustc_query_system/src/dep_graph/graph.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -498,12 +498,12 @@ impl<D: Deps> DepGraph<D> {
498498

499499
#[cfg(debug_assertions)]
500500
{
501-
if let Some(target) = task_deps.node {
502-
if let Some(ref forbidden_edge) = data.current.forbidden_edge {
503-
let src = forbidden_edge.index_to_node.lock()[&dep_node_index];
504-
if forbidden_edge.test(&src, &target) {
505-
panic!("forbidden edge {:?} -> {:?} created", src, target)
506-
}
501+
if let Some(target) = task_deps.node
502+
&& let Some(ref forbidden_edge) = data.current.forbidden_edge
503+
{
504+
let src = forbidden_edge.index_to_node.lock()[&dep_node_index];
505+
if forbidden_edge.test(&src, &target) {
506+
panic!("forbidden edge {:?} -> {:?} created", src, target)
507507
}
508508
}
509509
}

0 commit comments

Comments
 (0)