Skip to content

Commit 9b28901

Browse files
committed
Remove vestigial diverging !-coercion
Such conversions are no longer permitted.
1 parent a997525 commit 9b28901

File tree

3 files changed

+16
-42
lines changed

3 files changed

+16
-42
lines changed

src/librustc_typeck/check/_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
690690
arm_span: arm.body.span,
691691
source: match_src
692692
});
693-
coercion.coerce(self, &cause, &arm.body, arm_ty, self.diverges.get());
693+
coercion.coerce(self, &cause, &arm.body, arm_ty);
694694
}
695695
}
696696

src/librustc_typeck/check/coercion.rs

+5-19
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
//! sort of a minor point so I've opted to leave it for later---after all
6161
//! we may want to adjust precisely when coercions occur.
6262
63-
use check::{Diverges, FnCtxt, Needs};
63+
use check::{FnCtxt, Needs};
6464

6565
use rustc::hir;
6666
use rustc::hir::def_id::DefId;
@@ -798,22 +798,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
798798
exprs: &[E],
799799
prev_ty: Ty<'tcx>,
800800
new: &hir::Expr,
801-
new_ty: Ty<'tcx>,
802-
new_diverges: Diverges)
801+
new_ty: Ty<'tcx>)
803802
-> RelateResult<'tcx, Ty<'tcx>>
804803
where E: AsCoercionSite
805804
{
806805
let prev_ty = self.resolve_type_vars_with_obligations(prev_ty);
807806
let new_ty = self.resolve_type_vars_with_obligations(new_ty);
808807
debug!("coercion::try_find_coercion_lub({:?}, {:?})", prev_ty, new_ty);
809808

810-
// Special-ish case: we can coerce any type `T` into the `!`
811-
// type, but only if the source expression diverges.
812-
if prev_ty.is_never() && new_diverges.always() {
813-
debug!("permit coercion to `!` because expr diverges");
814-
return Ok(prev_ty);
815-
}
816-
817809
// Special-case that coercion alone cannot handle:
818810
// Two function item types of differing IDs or Substs.
819811
if let (&ty::TyFnDef(..), &ty::TyFnDef(..)) = (&prev_ty.sty, &new_ty.sty) {
@@ -1052,14 +1044,12 @@ impl<'gcx, 'tcx, 'exprs, E> CoerceMany<'gcx, 'tcx, 'exprs, E>
10521044
fcx: &FnCtxt<'a, 'gcx, 'tcx>,
10531045
cause: &ObligationCause<'tcx>,
10541046
expression: &'gcx hir::Expr,
1055-
expression_ty: Ty<'tcx>,
1056-
expression_diverges: Diverges)
1047+
expression_ty: Ty<'tcx>)
10571048
{
10581049
self.coerce_inner(fcx,
10591050
cause,
10601051
Some(expression),
10611052
expression_ty,
1062-
expression_diverges,
10631053
None, false)
10641054
}
10651055

@@ -1085,7 +1075,6 @@ impl<'gcx, 'tcx, 'exprs, E> CoerceMany<'gcx, 'tcx, 'exprs, E>
10851075
cause,
10861076
None,
10871077
fcx.tcx.mk_nil(),
1088-
Diverges::Maybe,
10891078
Some(augment_error),
10901079
label_unit_as_expected)
10911080
}
@@ -1098,7 +1087,6 @@ impl<'gcx, 'tcx, 'exprs, E> CoerceMany<'gcx, 'tcx, 'exprs, E>
10981087
cause: &ObligationCause<'tcx>,
10991088
expression: Option<&'gcx hir::Expr>,
11001089
mut expression_ty: Ty<'tcx>,
1101-
expression_diverges: Diverges,
11021090
augment_error: Option<&mut FnMut(&mut DiagnosticBuilder)>,
11031091
label_expression_as_expected: bool)
11041092
{
@@ -1132,15 +1120,13 @@ impl<'gcx, 'tcx, 'exprs, E> CoerceMany<'gcx, 'tcx, 'exprs, E>
11321120
exprs,
11331121
self.merged_ty(),
11341122
expression,
1135-
expression_ty,
1136-
expression_diverges),
1123+
expression_ty),
11371124
Expressions::UpFront(ref coercion_sites) =>
11381125
fcx.try_find_coercion_lub(cause,
11391126
&coercion_sites[0..self.pushed],
11401127
self.merged_ty(),
11411128
expression,
1142-
expression_ty,
1143-
expression_diverges),
1129+
expression_ty),
11441130
}
11451131
}
11461132
} else {

src/librustc_typeck/check/mod.rs

+10-22
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ pub struct FnCtxt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
542542
/// you get indicates whether any subexpression that was
543543
/// evaluating up to and including `X` diverged.
544544
///
545-
/// We use this flag for two purposes:
545+
/// We currently use this flag only for diagnostic purposes:
546546
///
547547
/// - To warn about unreachable code: if, after processing a
548548
/// sub-expression but before we have applied the effects of the
@@ -556,16 +556,8 @@ pub struct FnCtxt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
556556
/// foo();}` or `{return; 22}`, where we would warn on the
557557
/// `foo()` or `22`.
558558
///
559-
/// - To permit assignment into a local variable or other place
560-
/// (including the "return slot") of type `!`. This is allowed
561-
/// if **either** the type of value being assigned is `!`, which
562-
/// means the current code is dead, **or** the expression's
563-
/// diverging flag is true, which means that a diverging value was
564-
/// wrapped (e.g., `let x: ! = foo(return)`).
565-
///
566-
/// To repeat the last point: an expression represents dead-code
567-
/// if, after checking it, **either** its type is `!` OR the
568-
/// diverges flag is set to something other than `Maybe`.
559+
/// An expression represents dead-code if, after checking it,
560+
/// the diverges flag is set to something other than `Maybe`.
569561
diverges: Cell<Diverges>,
570562

571563
/// Whether any child nodes have any type errors.
@@ -2999,8 +2991,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
29992991
&self.cause(return_expr.span,
30002992
ObligationCauseCode::ReturnType(return_expr.id)),
30012993
return_expr,
3002-
return_expr_ty,
3003-
self.diverges.get());
2994+
return_expr_ty);
30042995
}
30052996

30062997

@@ -3031,13 +3022,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
30313022
let mut coerce: DynamicCoerceMany = CoerceMany::new(coerce_to_ty);
30323023

30333024
let if_cause = self.cause(sp, ObligationCauseCode::IfExpression);
3034-
coerce.coerce(self, &if_cause, then_expr, then_ty, then_diverges);
3025+
coerce.coerce(self, &if_cause, then_expr, then_ty);
30353026

30363027
if let Some(else_expr) = opt_else_expr {
30373028
let else_ty = self.check_expr_with_expectation(else_expr, expected);
30383029
let else_diverges = self.diverges.get();
30393030

3040-
coerce.coerce(self, &if_cause, else_expr, else_ty, else_diverges);
3031+
coerce.coerce(self, &if_cause, else_expr, else_ty);
30413032

30423033
// We won't diverge unless both branches do (or the condition does).
30433034
self.diverges.set(cond_diverges | then_diverges & else_diverges);
@@ -3722,7 +3713,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
37223713
}
37233714
hir::ExprBreak(destination, ref expr_opt) => {
37243715
if let Some(target_id) = destination.target_id.opt_id() {
3725-
let (e_ty, e_diverges, cause);
3716+
let (e_ty, cause);
37263717
if let Some(ref e) = *expr_opt {
37273718
// If this is a break with a value, we need to type-check
37283719
// the expression. Get an expected type from the loop context.
@@ -3741,13 +3732,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
37413732

37423733
// Recurse without `enclosing_breakables` borrowed.
37433734
e_ty = self.check_expr_with_hint(e, coerce_to);
3744-
e_diverges = self.diverges.get();
37453735
cause = self.misc(e.span);
37463736
} else {
37473737
// Otherwise, this is a break *without* a value. That's
37483738
// always legal, and is equivalent to `break ()`.
37493739
e_ty = tcx.mk_nil();
3750-
e_diverges = Diverges::Maybe;
37513740
cause = self.misc(expr.span);
37523741
}
37533742

@@ -3758,7 +3747,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
37583747
let ctxt = enclosing_breakables.find_breakable(target_id);
37593748
if let Some(ref mut coerce) = ctxt.coerce {
37603749
if let Some(ref e) = *expr_opt {
3761-
coerce.coerce(self, &cause, e, e_ty, e_diverges);
3750+
coerce.coerce(self, &cause, e, e_ty);
37623751
} else {
37633752
assert!(e_ty.is_nil());
37643753
coerce.coerce_forced_unit(self, &cause, &mut |_| (), true);
@@ -3964,7 +3953,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
39643953
for e in args {
39653954
let e_ty = self.check_expr_with_hint(e, coerce_to);
39663955
let cause = self.misc(e.span);
3967-
coerce.coerce(self, &cause, e, e_ty, self.diverges.get());
3956+
coerce.coerce(self, &cause, e, e_ty);
39683957
}
39693958
coerce.complete(self)
39703959
} else {
@@ -4375,8 +4364,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
43754364
coerce.coerce(self,
43764365
&cause,
43774366
tail_expr,
4378-
tail_expr_ty,
4379-
self.diverges.get());
4367+
tail_expr_ty);
43804368
} else {
43814369
// Subtle: if there is no explicit tail expression,
43824370
// that is typically equivalent to a tail expression

0 commit comments

Comments
 (0)