]> git.lizzy.rs Git - rust.git/commitdiff
Introduce constraint category for yields.
authorDavid Wood <david@davidtw.co>
Mon, 3 Dec 2018 13:11:53 +0000 (14:11 +0100)
committerDavid Wood <david@davidtw.co>
Fri, 7 Dec 2018 13:05:58 +0000 (14:05 +0100)
This commit adds a new `ConstraintCategory` for yield points - this
allows for differentiation between a normal return and a yield in the
diagnostics.

src/librustc/ich/impls_mir.rs
src/librustc/mir/mod.rs
src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs
src/librustc_mir/borrow_check/nll/type_check/mod.rs

index c72887124aa0b4ab7b11619d032fa9b5507841a9..a46e12be1aeace57d5b28a503e8f90111c98e075 100644 (file)
@@ -471,6 +471,7 @@ fn hash_stable<W: StableHasherResult>(&self,
 
 impl_stable_hash_for!(enum mir::ConstraintCategory {
     Return,
+    Yield,
     UseAsConst,
     UseAsStatic,
     TypeAnnotation,
index 7259bbfb780bfe47b0368db6dabc235147565e37..6ff60b39bd341298097050ca2a0cbe50d77808a9 100644 (file)
@@ -2905,6 +2905,7 @@ pub struct ClosureOutlivesRequirement<'tcx> {
 #[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]
 pub enum ConstraintCategory {
     Return,
+    Yield,
     UseAsConst,
     UseAsStatic,
     TypeAnnotation,
index 3358e5851f939d10c7da2d079c8ee0fc92839f47..940f9d6040cf522b825df6f67e682e6d4ac96afc 100644 (file)
@@ -38,6 +38,7 @@ fn description(&self) -> &'static str {
         match self {
             ConstraintCategory::Assignment => "assignment ",
             ConstraintCategory::Return => "returning this value ",
+            ConstraintCategory::Yield => "yielding this value ",
             ConstraintCategory::UseAsConst => "using this value as a constant ",
             ConstraintCategory::UseAsStatic => "using this value as a static ",
             ConstraintCategory::Cast => "cast ",
@@ -133,11 +134,10 @@ fn best_blame_constraint(
             let constraint_sup_scc = self.constraint_sccs.scc(constraint.sup);
 
             match categorized_path[i].0 {
-                ConstraintCategory::OpaqueType
-                | ConstraintCategory::Boring
-                | ConstraintCategory::BoringNoLocation
-                | ConstraintCategory::Internal => false,
-                ConstraintCategory::TypeAnnotation | ConstraintCategory::Return => true,
+                ConstraintCategory::OpaqueType | ConstraintCategory::Boring |
+                ConstraintCategory::BoringNoLocation | ConstraintCategory::Internal => false,
+                ConstraintCategory::TypeAnnotation | ConstraintCategory::Return |
+                ConstraintCategory::Yield => true,
                 _ => constraint_sup_scc != target_scc,
             }
         });
index 5f64dfd931c8989a6f2c31f0bf1cc2c6fa742124..33346a584e5a47e6f659e93b370ccfa3b3644840 100644 (file)
@@ -1467,7 +1467,7 @@ fn check_terminator(
                             value_ty,
                             ty,
                             term_location.to_locations(),
-                            ConstraintCategory::Return,
+                            ConstraintCategory::Yield,
                         ) {
                             span_mirbug!(
                                 self,