Skip to content

Commit 235e7c1

Browse files
committed
Remove LoopIdResult
It's redundant as Result already implements Encodable as well as Decodable.
1 parent 3ef481a commit 235e7c1

File tree

8 files changed

+19
-64
lines changed

8 files changed

+19
-64
lines changed

src/librustc/cfg/construct.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
582582
scope_cf_kind: ScopeCfKind) -> (region::Scope, CFGIndex) {
583583

584584
match destination.target_id {
585-
hir::LoopIdResult::Ok(loop_id) => {
585+
Ok(loop_id) => {
586586
for b in &self.breakable_block_scopes {
587587
if b.block_expr_id == self.tcx.hir.node_to_hir_id(loop_id).local_id {
588588
let scope_id = self.tcx.hir.node_to_hir_id(loop_id).local_id;
@@ -603,7 +603,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
603603
}
604604
span_bug!(expr.span, "no scope for id {}", loop_id);
605605
}
606-
hir::LoopIdResult::Err(err) => span_bug!(expr.span, "scope error: {}", err),
606+
Err(err) => span_bug!(expr.span, "scope error: {}", err),
607607
}
608608
}
609609
}

src/librustc/hir/intravisit.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,9 +1039,8 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
10391039
if let Some(ref label) = destination.label {
10401040
visitor.visit_label(label);
10411041
match destination.target_id {
1042-
LoopIdResult::Ok(node_id) =>
1043-
visitor.visit_def_mention(Def::Label(node_id)),
1044-
LoopIdResult::Err(_) => {},
1042+
Ok(node_id) => visitor.visit_def_mention(Def::Label(node_id)),
1043+
Err(_) => {},
10451044
};
10461045
}
10471046
walk_list!(visitor, visit_expr, opt_expr);
@@ -1050,9 +1049,8 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
10501049
if let Some(ref label) = destination.label {
10511050
visitor.visit_label(label);
10521051
match destination.target_id {
1053-
LoopIdResult::Ok(node_id) =>
1054-
visitor.visit_def_mention(Def::Label(node_id)),
1055-
LoopIdResult::Err(_) => {},
1052+
Ok(node_id) => visitor.visit_def_mention(Def::Label(node_id)),
1053+
Err(_) => {},
10561054
};
10571055
}
10581056
}

src/librustc/hir/lowering.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -929,9 +929,9 @@ impl<'a> LoweringContext<'a> {
929929
match destination {
930930
Some((id, label)) => {
931931
let target_id = if let Def::Label(loop_id) = self.expect_full_def(id) {
932-
hir::LoopIdResult::Ok(self.lower_node_id(loop_id).node_id)
932+
Ok(self.lower_node_id(loop_id).node_id)
933933
} else {
934-
hir::LoopIdResult::Err(hir::LoopIdError::UnresolvedLabel)
934+
Err(hir::LoopIdError::UnresolvedLabel)
935935
};
936936
hir::Destination {
937937
label: self.lower_label(Some(label)),
@@ -3598,7 +3598,7 @@ impl<'a> LoweringContext<'a> {
35983598
hir::ExprBreak(
35993599
hir::Destination {
36003600
label: None,
3601-
target_id: hir::LoopIdResult::Ok(catch_node),
3601+
target_id: Ok(catch_node),
36023602
},
36033603
Some(from_err_expr),
36043604
),

src/librustc/hir/mod.rs

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,47 +1502,14 @@ impl fmt::Display for LoopIdError {
15021502
}
15031503
}
15041504

1505-
// FIXME(cramertj) this should use `Result` once master compiles w/ a vesion of Rust where
1506-
// `Result` implements `Encodable`/`Decodable`
1507-
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
1508-
pub enum LoopIdResult {
1509-
Ok(NodeId),
1510-
Err(LoopIdError),
1511-
}
1512-
impl Into<Result<NodeId, LoopIdError>> for LoopIdResult {
1513-
fn into(self) -> Result<NodeId, LoopIdError> {
1514-
match self {
1515-
LoopIdResult::Ok(ok) => Ok(ok),
1516-
LoopIdResult::Err(err) => Err(err),
1517-
}
1518-
}
1519-
}
1520-
impl From<Result<NodeId, LoopIdError>> for LoopIdResult {
1521-
fn from(res: Result<NodeId, LoopIdError>) -> Self {
1522-
match res {
1523-
Ok(ok) => LoopIdResult::Ok(ok),
1524-
Err(err) => LoopIdResult::Err(err),
1525-
}
1526-
}
1527-
}
1528-
1529-
impl LoopIdResult {
1530-
pub fn ok(self) -> Option<NodeId> {
1531-
match self {
1532-
LoopIdResult::Ok(node_id) => Some(node_id),
1533-
LoopIdResult::Err(_) => None,
1534-
}
1535-
}
1536-
}
1537-
15381505
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
15391506
pub struct Destination {
15401507
// This is `Some(_)` iff there is an explicit user-specified `label
15411508
pub label: Option<Label>,
15421509

15431510
// These errors are caught and then reported during the diagnostics pass in
15441511
// librustc_passes/loops.rs
1545-
pub target_id: LoopIdResult,
1512+
pub target_id: Result<NodeId, LoopIdError>,
15461513
}
15471514

15481515
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]

src/librustc/ich/impls_hir.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -656,11 +656,6 @@ impl_stable_hash_for!(struct hir::Destination {
656656

657657
impl_stable_hash_for_spanned!(ast::Ident);
658658

659-
impl_stable_hash_for!(enum hir::LoopIdResult {
660-
Ok(node_id),
661-
Err(loop_id_error)
662-
});
663-
664659
impl_stable_hash_for!(enum hir::LoopIdError {
665660
OutsideLoopScope,
666661
UnlabeledCfInWhileCondition,

src/librustc/middle/liveness.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,9 +1051,8 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
10511051
hir::ExprBreak(label, ref opt_expr) => {
10521052
// Find which label this break jumps to
10531053
let target = match label.target_id {
1054-
hir::LoopIdResult::Ok(node_id) => self.break_ln.get(&node_id),
1055-
hir::LoopIdResult::Err(err) =>
1056-
span_bug!(expr.span, "loop scope error: {}", err),
1054+
Ok(node_id) => self.break_ln.get(&node_id),
1055+
Err(err) => span_bug!(expr.span, "loop scope error: {}", err),
10571056
}.map(|x| *x);
10581057

10591058
// Now that we know the label we're going to,
@@ -1068,9 +1067,8 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
10681067
hir::ExprAgain(label) => {
10691068
// Find which label this expr continues to
10701069
let sc = match label.target_id {
1071-
hir::LoopIdResult::Ok(node_id) => node_id,
1072-
hir::LoopIdResult::Err(err) =>
1073-
span_bug!(expr.span, "loop scope error: {}", err),
1070+
Ok(node_id) => node_id,
1071+
Err(err) => span_bug!(expr.span, "loop scope error: {}", err),
10741072
};
10751073

10761074
// Now that we know the label we're going to,

src/librustc_mir/hair/cx/expr.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -536,21 +536,19 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
536536
hir::ExprRet(ref v) => ExprKind::Return { value: v.to_ref() },
537537
hir::ExprBreak(dest, ref value) => {
538538
match dest.target_id {
539-
hir::LoopIdResult::Ok(target_id) => ExprKind::Break {
539+
Ok(target_id) => ExprKind::Break {
540540
label: region::Scope::Node(cx.tcx.hir.node_to_hir_id(target_id).local_id),
541541
value: value.to_ref(),
542542
},
543-
hir::LoopIdResult::Err(err) =>
544-
bug!("invalid loop id for break: {}", err)
543+
Err(err) => bug!("invalid loop id for break: {}", err)
545544
}
546545
}
547546
hir::ExprAgain(dest) => {
548547
match dest.target_id {
549-
hir::LoopIdResult::Ok(loop_id) => ExprKind::Continue {
548+
Ok(loop_id) => ExprKind::Continue {
550549
label: region::Scope::Node(cx.tcx.hir.node_to_hir_id(loop_id).local_id),
551550
},
552-
hir::LoopIdResult::Err(err) =>
553-
bug!("invalid loop id for continue: {}", err)
551+
Err(err) => bug!("invalid loop id for continue: {}", err)
554552
}
555553
}
556554
hir::ExprMatch(ref discr, ref arms, _) => {

src/librustc_passes/loops.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,7 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {
133133
self.require_loop("break", e.span);
134134
}
135135
hir::ExprAgain(label) => {
136-
if let hir::LoopIdResult::Err(
137-
hir::LoopIdError::UnlabeledCfInWhileCondition) = label.target_id {
136+
if let Err(hir::LoopIdError::UnlabeledCfInWhileCondition) = label.target_id {
138137
self.emit_unlabled_cf_in_while_condition(e.span, "continue");
139138
}
140139
self.require_loop("continue", e.span)

0 commit comments

Comments
 (0)