about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAaron Hill <aa1ronham@gmail.com>2019-11-15 16:24:51 -0500
committerAaron Hill <aa1ronham@gmail.com>2019-11-18 14:01:37 -0500
commitf87177b1c5df80d98e8f9c4645ecfc68edbae931 (patch)
treeea9f35134d1f8b0fb9efad29c360560c8753ad24
parent61c75bdb11e782ee50ff1e4de6d29fd5ff4f0e31 (diff)
downloadrust-f87177b1c5df80d98e8f9c4645ecfc68edbae931.tar.gz
rust-f87177b1c5df80d98e8f9c4645ecfc68edbae931.zip
Replace bool with new `FallbackMode` enum
-rw-r--r--src/librustc/infer/opaque_types/mod.rs2
-rw-r--r--src/librustc_typeck/check/mod.rs24
2 files changed, 18 insertions, 8 deletions
diff --git a/src/librustc/infer/opaque_types/mod.rs b/src/librustc/infer/opaque_types/mod.rs
index 500122ce8c4..9b197c1ecb1 100644
--- a/src/librustc/infer/opaque_types/mod.rs
+++ b/src/librustc/infer/opaque_types/mod.rs
@@ -25,7 +25,7 @@ pub type OpaqueTypeMap<'tcx> = DefIdMap<OpaqueTypeDecl<'tcx>>;
 #[derive(Copy, Clone, Debug)]
 pub struct OpaqueTypeDecl<'tcx> {
 
-    /// The opaque type (`ty::Opaque`) for this declaration
+    /// The opaque type (`ty::Opaque`) for this declaration.
     pub opaque_type: Ty<'tcx>,
 
     /// The substitutions that we apply to the opaque type that this
diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs
index 6c2f6e4fb3e..50c1a74fe91 100644
--- a/src/librustc_typeck/check/mod.rs
+++ b/src/librustc_typeck/check/mod.rs
@@ -232,7 +232,7 @@ pub struct Inherited<'a, 'tcx> {
     opaque_types: RefCell<DefIdMap<OpaqueTypeDecl<'tcx>>>,
 
     /// A map from inference variables created from opaque
-    /// type instantiations (ty::Infer) to the actual opaque
+    /// type instantiations (`ty::Infer`) to the actual opaque
     /// type (`ty::Opaque`). Used during fallback to map unconstrained
     /// opaque type inference variables to their corresponding
     /// opaque type.
@@ -950,7 +950,7 @@ fn typeck_tables_of(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::TypeckTables<'_> {
         // better error messages.
         // The first time, we do *not* replace opaque types.
         for ty in &fcx.unsolved_variables() {
-            fallback_has_occurred |= fcx.fallback_if_possible(ty, false /* opaque_fallback */);
+            fallback_has_occurred |= fcx.fallback_if_possible(ty, FallbackMode::NoOpaque);
         }
         // We now see if we can make progress. This might
         // cause us to unify inference variables for opaque types,
@@ -968,7 +968,7 @@ fn typeck_tables_of(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::TypeckTables<'_> {
         // ```
         //
         // we want to unify the opaque inference variable in `bad_produce`
-        // with the diverging fallback for `panic!` (e.g. `()` or `!`),
+        // with the diverging fallback for `panic!` (e.g. `()` or `!`).
         // This will produce a nice error message about conflicting concrete
         // types for `MyType`.
         //
@@ -981,10 +981,10 @@ fn typeck_tables_of(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::TypeckTables<'_> {
         // unconstrained opaque type variables, in addition to performing
         // other kinds of fallback.
         for ty in &fcx.unsolved_variables() {
-            fallback_has_occurred |= fcx.fallback_if_possible(ty, true /* opaque_fallback */);
+            fallback_has_occurred |= fcx.fallback_if_possible(ty, FallbackMode::All);
         }
 
-        // See if we can make any more progress
+        // See if we can make any more progress.
         fcx.select_obligations_where_possible(fallback_has_occurred, |_| {});
 
         // Even though coercion casts provide type hints, we check casts after fallback for
@@ -2544,6 +2544,16 @@ enum TupleArgumentsFlag {
     TupleArguments,
 }
 
+/// Controls how we perform fallback for unconstrained
+/// type variables.
+enum FallbackMode {
+    /// Do not fallback type variables to opaque types.
+    NoOpaque,
+    /// Perform all possible kinds of fallback, including
+    /// turning type variables to opaque types.
+    All,
+}
+
 impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
     pub fn new(
         inh: &'a Inherited<'a, 'tcx>,
@@ -3125,7 +3135,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
     // Fallback becomes very dubious if we have encountered type-checking errors.
     // In that case, fallback to Error.
     // The return value indicates whether fallback has occurred.
-    fn fallback_if_possible(&self, ty: Ty<'tcx>, opaque_fallback: bool) -> bool {
+    fn fallback_if_possible(&self, ty: Ty<'tcx>, mode: FallbackMode) -> bool {
         use rustc::ty::error::UnconstrainedNumeric::Neither;
         use rustc::ty::error::UnconstrainedNumeric::{UnconstrainedInt, UnconstrainedFloat};
 
@@ -3170,7 +3180,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                 // instantiating `Option<Foo>` will be completely unconstrained.
                 // We treat this as a non-defining use by making the inference
                 // variable fall back to the opaque type itself.
-                if opaque_fallback {
+                if let FallbackMode::All = mode {
                     if let Some(opaque_ty) = self.opaque_types_vars.borrow().get(ty) {
                         debug!("fallback_if_possible: falling back opaque type var {:?} to {:?}",
                                ty, opaque_ty);