Skip to content

Commit f87177b

Browse files
committed
Replace bool with new FallbackMode enum
1 parent 61c75bd commit f87177b

File tree

2 files changed

+18
-8
lines changed
  • src
    • librustc/infer/opaque_types
    • librustc_typeck/check

2 files changed

+18
-8
lines changed

Diff for: src/librustc/infer/opaque_types/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub type OpaqueTypeMap<'tcx> = DefIdMap<OpaqueTypeDecl<'tcx>>;
2525
#[derive(Copy, Clone, Debug)]
2626
pub struct OpaqueTypeDecl<'tcx> {
2727

28-
/// The opaque type (`ty::Opaque`) for this declaration
28+
/// The opaque type (`ty::Opaque`) for this declaration.
2929
pub opaque_type: Ty<'tcx>,
3030

3131
/// The substitutions that we apply to the opaque type that this

Diff for: src/librustc_typeck/check/mod.rs

+17-7
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ pub struct Inherited<'a, 'tcx> {
232232
opaque_types: RefCell<DefIdMap<OpaqueTypeDecl<'tcx>>>,
233233

234234
/// A map from inference variables created from opaque
235-
/// type instantiations (ty::Infer) to the actual opaque
235+
/// type instantiations (`ty::Infer`) to the actual opaque
236236
/// type (`ty::Opaque`). Used during fallback to map unconstrained
237237
/// opaque type inference variables to their corresponding
238238
/// opaque type.
@@ -950,7 +950,7 @@ fn typeck_tables_of(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::TypeckTables<'_> {
950950
// better error messages.
951951
// The first time, we do *not* replace opaque types.
952952
for ty in &fcx.unsolved_variables() {
953-
fallback_has_occurred |= fcx.fallback_if_possible(ty, false /* opaque_fallback */);
953+
fallback_has_occurred |= fcx.fallback_if_possible(ty, FallbackMode::NoOpaque);
954954
}
955955
// We now see if we can make progress. This might
956956
// cause us to unify inference variables for opaque types,
@@ -968,7 +968,7 @@ fn typeck_tables_of(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::TypeckTables<'_> {
968968
// ```
969969
//
970970
// we want to unify the opaque inference variable in `bad_produce`
971-
// with the diverging fallback for `panic!` (e.g. `()` or `!`),
971+
// with the diverging fallback for `panic!` (e.g. `()` or `!`).
972972
// This will produce a nice error message about conflicting concrete
973973
// types for `MyType`.
974974
//
@@ -981,10 +981,10 @@ fn typeck_tables_of(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::TypeckTables<'_> {
981981
// unconstrained opaque type variables, in addition to performing
982982
// other kinds of fallback.
983983
for ty in &fcx.unsolved_variables() {
984-
fallback_has_occurred |= fcx.fallback_if_possible(ty, true /* opaque_fallback */);
984+
fallback_has_occurred |= fcx.fallback_if_possible(ty, FallbackMode::All);
985985
}
986986

987-
// See if we can make any more progress
987+
// See if we can make any more progress.
988988
fcx.select_obligations_where_possible(fallback_has_occurred, |_| {});
989989

990990
// Even though coercion casts provide type hints, we check casts after fallback for
@@ -2544,6 +2544,16 @@ enum TupleArgumentsFlag {
25442544
TupleArguments,
25452545
}
25462546

2547+
/// Controls how we perform fallback for unconstrained
2548+
/// type variables.
2549+
enum FallbackMode {
2550+
/// Do not fallback type variables to opaque types.
2551+
NoOpaque,
2552+
/// Perform all possible kinds of fallback, including
2553+
/// turning type variables to opaque types.
2554+
All,
2555+
}
2556+
25472557
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
25482558
pub fn new(
25492559
inh: &'a Inherited<'a, 'tcx>,
@@ -3125,7 +3135,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
31253135
// Fallback becomes very dubious if we have encountered type-checking errors.
31263136
// In that case, fallback to Error.
31273137
// The return value indicates whether fallback has occurred.
3128-
fn fallback_if_possible(&self, ty: Ty<'tcx>, opaque_fallback: bool) -> bool {
3138+
fn fallback_if_possible(&self, ty: Ty<'tcx>, mode: FallbackMode) -> bool {
31293139
use rustc::ty::error::UnconstrainedNumeric::Neither;
31303140
use rustc::ty::error::UnconstrainedNumeric::{UnconstrainedInt, UnconstrainedFloat};
31313141

@@ -3170,7 +3180,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
31703180
// instantiating `Option<Foo>` will be completely unconstrained.
31713181
// We treat this as a non-defining use by making the inference
31723182
// variable fall back to the opaque type itself.
3173-
if opaque_fallback {
3183+
if let FallbackMode::All = mode {
31743184
if let Some(opaque_ty) = self.opaque_types_vars.borrow().get(ty) {
31753185
debug!("fallback_if_possible: falling back opaque type var {:?} to {:?}",
31763186
ty, opaque_ty);

0 commit comments

Comments
 (0)