about summary refs log tree commit diff
path: root/compiler/rustc_infer/src/infer/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_infer/src/infer/mod.rs')
-rw-r--r--compiler/rustc_infer/src/infer/mod.rs73
1 files changed, 36 insertions, 37 deletions
diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs
index 5a99b976b0d..cc3ad921489 100644
--- a/compiler/rustc_infer/src/infer/mod.rs
+++ b/compiler/rustc_infer/src/infer/mod.rs
@@ -1,9 +1,6 @@
 use std::cell::{Cell, RefCell};
 use std::fmt;
 
-pub use BoundRegionConversionTime::*;
-pub use RegionVariableOrigin::*;
-pub use SubregionOrigin::*;
 pub use at::DefineOpaqueTypes;
 use free_regions::RegionRelations;
 pub use freshen::TypeFreshener;
@@ -35,7 +32,7 @@ use rustc_middle::ty::{
     PseudoCanonicalInput, Term, TermKind, Ty, TyCtxt, TyVid, TypeFoldable, TypeFolder,
     TypeSuperFoldable, TypeVisitable, TypeVisitableExt, TypingEnv, TypingMode, fold_regions,
 };
-use rustc_span::{Span, Symbol};
+use rustc_span::{DUMMY_SP, Span, Symbol};
 use snapshot::undo_log::InferCtxtUndoLogs;
 use tracing::{debug, instrument};
 use type_variable::TypeVariableOrigin;
@@ -403,7 +400,7 @@ pub enum RegionVariableOrigin {
     /// Region variables created for ill-categorized reasons.
     ///
     /// They mostly indicate places in need of refactoring.
-    MiscVariable(Span),
+    Misc(Span),
 
     /// Regions created by a `&P` or `[...]` pattern.
     PatternRegion(Span),
@@ -467,21 +464,19 @@ pub struct FixupError {
 
 impl fmt::Display for FixupError {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        use TyOrConstInferVar::*;
-
         match self.unresolved {
-            TyInt(_) => write!(
+            TyOrConstInferVar::TyInt(_) => write!(
                 f,
                 "cannot determine the type of this integer; \
                  add a suffix to specify the type explicitly"
             ),
-            TyFloat(_) => write!(
+            TyOrConstInferVar::TyFloat(_) => write!(
                 f,
                 "cannot determine the type of this number; \
                  add a suffix to specify the type explicitly"
             ),
-            Ty(_) => write!(f, "unconstrained type"),
-            Const(_) => write!(f, "unconstrained const value"),
+            TyOrConstInferVar::Ty(_) => write!(f, "unconstrained type"),
+            TyOrConstInferVar::Const(_) => write!(f, "unconstrained const value"),
         }
     }
 }
@@ -865,7 +860,10 @@ impl<'tcx> InferCtxt<'tcx> {
             GenericParamDefKind::Lifetime => {
                 // Create a region inference variable for the given
                 // region parameter definition.
-                self.next_region_var(RegionParameterDefinition(span, param.name)).into()
+                self.next_region_var(RegionVariableOrigin::RegionParameterDefinition(
+                    span, param.name,
+                ))
+                .into()
             }
             GenericParamDefKind::Type { .. } => {
                 // Create a type inference variable for the given
@@ -1179,7 +1177,7 @@ impl<'tcx> InferCtxt<'tcx> {
             let arg: ty::GenericArg<'_> = match bound_var_kind {
                 ty::BoundVariableKind::Ty(_) => self.next_ty_var(span).into(),
                 ty::BoundVariableKind::Region(br) => {
-                    self.next_region_var(BoundRegion(span, br, lbrct)).into()
+                    self.next_region_var(RegionVariableOrigin::BoundRegion(span, br, lbrct)).into()
                 }
                 ty::BoundVariableKind::Const => self.next_const_var(span).into(),
             };
@@ -1479,15 +1477,15 @@ impl<'tcx> TypeTrace<'tcx> {
 impl<'tcx> SubregionOrigin<'tcx> {
     pub fn span(&self) -> Span {
         match *self {
-            Subtype(ref a) => a.span(),
-            RelateObjectBound(a) => a,
-            RelateParamBound(a, ..) => a,
-            RelateRegionParamBound(a, _) => a,
-            Reborrow(a) => a,
-            ReferenceOutlivesReferent(_, a) => a,
-            CompareImplItemObligation { span, .. } => span,
-            AscribeUserTypeProvePredicate(span) => span,
-            CheckAssociatedTypeBounds { ref parent, .. } => parent.span(),
+            SubregionOrigin::Subtype(ref a) => a.span(),
+            SubregionOrigin::RelateObjectBound(a) => a,
+            SubregionOrigin::RelateParamBound(a, ..) => a,
+            SubregionOrigin::RelateRegionParamBound(a, _) => a,
+            SubregionOrigin::Reborrow(a) => a,
+            SubregionOrigin::ReferenceOutlivesReferent(_, a) => a,
+            SubregionOrigin::CompareImplItemObligation { span, .. } => span,
+            SubregionOrigin::AscribeUserTypeProvePredicate(span) => span,
+            SubregionOrigin::CheckAssociatedTypeBounds { ref parent, .. } => parent.span(),
         }
     }
 
@@ -1535,15 +1533,15 @@ impl<'tcx> SubregionOrigin<'tcx> {
 impl RegionVariableOrigin {
     pub fn span(&self) -> Span {
         match *self {
-            MiscVariable(a)
-            | PatternRegion(a)
-            | BorrowRegion(a)
-            | Autoref(a)
-            | Coercion(a)
-            | RegionParameterDefinition(a, ..)
-            | BoundRegion(a, ..)
-            | UpvarRegion(_, a) => a,
-            Nll(..) => bug!("NLL variable used with `span`"),
+            RegionVariableOrigin::Misc(a)
+            | RegionVariableOrigin::PatternRegion(a)
+            | RegionVariableOrigin::BorrowRegion(a)
+            | RegionVariableOrigin::Autoref(a)
+            | RegionVariableOrigin::Coercion(a)
+            | RegionVariableOrigin::RegionParameterDefinition(a, ..)
+            | RegionVariableOrigin::BoundRegion(a, ..)
+            | RegionVariableOrigin::UpvarRegion(_, a) => a,
+            RegionVariableOrigin::Nll(..) => bug!("NLL variable used with `span`"),
         }
     }
 }
@@ -1564,15 +1562,16 @@ impl<'tcx> InferCtxt<'tcx> {
         }
     }
 
-    /// Given a [`hir::HirId`] for a block, get the span of its last expression
-    /// or statement, peeling off any inner blocks.
+    /// Given a [`hir::HirId`] for a block (or an expr of a block), get the span
+    /// of its last expression or statement, peeling off any inner blocks.
     pub fn find_block_span_from_hir_id(&self, hir_id: hir::HirId) -> Span {
         match self.tcx.hir_node(hir_id) {
-            hir::Node::Block(blk) => self.find_block_span(blk),
-            // The parser was in a weird state if either of these happen, but
-            // it's better not to panic.
+            hir::Node::Block(blk)
+            | hir::Node::Expr(&hir::Expr { kind: hir::ExprKind::Block(blk, _), .. }) => {
+                self.find_block_span(blk)
+            }
             hir::Node::Expr(e) => e.span,
-            _ => rustc_span::DUMMY_SP,
+            _ => DUMMY_SP,
         }
     }
 }