Skip to content

Commit a8a1bf9

Browse files
committed
Introduce constraint category for yields.
This commit adds a new `ConstraintCategory` for yield points - this allows for differentiation between a normal return and a yield in the diagnostics.
1 parent d48ab69 commit a8a1bf9

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

src/librustc/ich/impls_mir.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ impl_stable_hash_for!(struct mir::ClosureOutlivesRequirement<'tcx> {
503503

504504
impl_stable_hash_for!(enum mir::ConstraintCategory {
505505
Return,
506+
Yield,
506507
UseAsConst,
507508
UseAsStatic,
508509
TypeAnnotation,

src/librustc/mir/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2894,6 +2894,7 @@ pub struct ClosureOutlivesRequirement<'tcx> {
28942894
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]
28952895
pub enum ConstraintCategory {
28962896
Return,
2897+
Yield,
28972898
UseAsConst,
28982899
UseAsStatic,
28992900
TypeAnnotation,

src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ impl ConstraintDescription for ConstraintCategory {
3838
match self {
3939
ConstraintCategory::Assignment => "assignment ",
4040
ConstraintCategory::Return => "returning this value ",
41+
ConstraintCategory::Yield => "yielding this value ",
4142
ConstraintCategory::UseAsConst => "using this value as a constant ",
4243
ConstraintCategory::UseAsStatic => "using this value as a static ",
4344
ConstraintCategory::Cast => "cast ",
@@ -133,11 +134,10 @@ impl<'tcx> RegionInferenceContext<'tcx> {
133134
let constraint_sup_scc = self.constraint_sccs.scc(constraint.sup);
134135

135136
match categorized_path[i].0 {
136-
ConstraintCategory::OpaqueType
137-
| ConstraintCategory::Boring
138-
| ConstraintCategory::BoringNoLocation
139-
| ConstraintCategory::Internal => false,
140-
ConstraintCategory::TypeAnnotation | ConstraintCategory::Return => true,
137+
ConstraintCategory::OpaqueType | ConstraintCategory::Boring |
138+
ConstraintCategory::BoringNoLocation | ConstraintCategory::Internal => false,
139+
ConstraintCategory::TypeAnnotation | ConstraintCategory::Return |
140+
ConstraintCategory::Yield => true,
141141
_ => constraint_sup_scc != target_scc,
142142
}
143143
});

src/librustc_mir/borrow_check/nll/type_check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1467,7 +1467,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
14671467
value_ty,
14681468
ty,
14691469
term_location.to_locations(),
1470-
ConstraintCategory::Return,
1470+
ConstraintCategory::Yield,
14711471
) {
14721472
span_mirbug!(
14731473
self,

0 commit comments

Comments
 (0)