Skip to content

Commit ba51fc6

Browse files
committed
Change branch to assert
1 parent ee44706 commit ba51fc6

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

compiler/rustc_hir_typeck/src/coercion.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,29 +1290,29 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12901290
let mut coerce = Coerce::new(self, cause.clone(), AllowTwoPhase::No, true);
12911291
coerce.use_lub = true;
12921292

1293-
// First try to coerce the new expression to the type of the previous ones,
1294-
// but only if the new expression has no coercion already applied to it.
1295-
let mut first_error = None;
1296-
if !self.typeck_results.borrow().adjustments().contains_key(new.hir_id) {
1297-
let result = self.commit_if_ok(|_| coerce.coerce(new_ty, prev_ty));
1298-
match result {
1299-
Ok(ok) => {
1300-
let (adjustments, target) = self.register_infer_ok_obligations(ok);
1301-
self.apply_adjustments(new, adjustments);
1302-
debug!(
1303-
"coercion::try_find_coercion_lub: was able to coerce from new type {:?} to previous type {:?} ({:?})",
1304-
new_ty, prev_ty, target
1305-
);
1306-
return Ok(target);
1307-
}
1308-
Err(e) => first_error = Some(e),
1293+
// This might be okay, but we previously branched on this without any
1294+
// test, so I'm just keeping the assert to avoid surprising behavior.
1295+
assert!(!self.typeck_results.borrow().adjustments().contains_key(new.hir_id));
1296+
1297+
// First try to coerce the new expression to the type of the previous ones.
1298+
let result = self.commit_if_ok(|_| coerce.coerce(new_ty, prev_ty));
1299+
let first_error = match result {
1300+
Ok(ok) => {
1301+
let (adjustments, target) = self.register_infer_ok_obligations(ok);
1302+
self.apply_adjustments(new, adjustments);
1303+
debug!(
1304+
"coercion::try_find_coercion_lub: was able to coerce from new type {:?} to previous type {:?} ({:?})",
1305+
new_ty, prev_ty, target
1306+
);
1307+
return Ok(target);
13091308
}
1310-
}
1309+
Err(e) => e,
1310+
};
13111311

13121312
let ok = self
13131313
.commit_if_ok(|_| coerce.coerce(prev_ty, new_ty))
13141314
// Avoid giving strange errors on failed attempts.
1315-
.map_err(|e| first_error.unwrap_or(e))?;
1315+
.map_err(|_| first_error)?;
13161316

13171317
let (adjustments, target) = self.register_infer_ok_obligations(ok);
13181318
for expr in exprs {

0 commit comments

Comments
 (0)