Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 607243b

Browse files
committedOct 9, 2018
Auto merge of #54798 - matthewjasper:free-region-closure-errors, r=nikomatsakis
[NLL] Improve closure region bound errors Previously, we would report free region errors that originate from closure with the span of the closure and a "closure body requires ..." message. This is now updated to use a reason and span from inside the closure.
2 parents b1a137d + 8258107 commit 607243b

26 files changed

+300
-210
lines changed
 

‎src/librustc/ich/impls_mir.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,23 @@ impl_stable_hash_for!(struct mir::ClosureRegionRequirements<'tcx> {
551551
impl_stable_hash_for!(struct mir::ClosureOutlivesRequirement<'tcx> {
552552
subject,
553553
outlived_free_region,
554-
blame_span
554+
blame_span,
555+
category
556+
});
557+
558+
impl_stable_hash_for!(enum mir::ConstraintCategory {
559+
Return,
560+
TypeAnnotation,
561+
Cast,
562+
ClosureBounds,
563+
CallArgument,
564+
CopyBound,
565+
SizedBound,
566+
Assignment,
567+
OpaqueType,
568+
Boring,
569+
BoringNoLocation,
570+
Internal,
555571
});
556572

557573
impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for mir::ClosureOutlivesSubject<'gcx> {

‎src/librustc/mir/mod.rs

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2676,11 +2676,51 @@ pub struct ClosureOutlivesRequirement<'tcx> {
26762676
// This region or type ...
26772677
pub subject: ClosureOutlivesSubject<'tcx>,
26782678

2679-
// .. must outlive this one.
2679+
// ... must outlive this one.
26802680
pub outlived_free_region: ty::RegionVid,
26812681

2682-
// If not, report an error here.
2682+
// If not, report an error here ...
26832683
pub blame_span: Span,
2684+
2685+
// ... due to this reason.
2686+
pub category: ConstraintCategory,
2687+
}
2688+
2689+
/// Outlives constraints can be categorized to determine whether and why they
2690+
/// are interesting (for error reporting). Order of variants indicates sort
2691+
/// order of the category, thereby influencing diagnostic output.
2692+
///
2693+
/// See also [rustc_mir::borrow_check::nll::constraints]
2694+
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]
2695+
pub enum ConstraintCategory {
2696+
Return,
2697+
TypeAnnotation,
2698+
Cast,
2699+
2700+
/// A constraint that came from checking the body of a closure.
2701+
///
2702+
/// We try to get the category that the closure used when reporting this.
2703+
ClosureBounds,
2704+
CallArgument,
2705+
CopyBound,
2706+
SizedBound,
2707+
Assignment,
2708+
OpaqueType,
2709+
2710+
/// A "boring" constraint (caused by the given location) is one that
2711+
/// the user probably doesn't want to see described in diagnostics,
2712+
/// because it is kind of an artifact of the type system setup.
2713+
/// Example: `x = Foo { field: y }` technically creates
2714+
/// intermediate regions representing the "type of `Foo { field: y
2715+
/// }`", and data flows from `y` into those variables, but they
2716+
/// are not very interesting. The assignment into `x` on the other
2717+
/// hand might be.
2718+
Boring,
2719+
// Boring and applicable everywhere.
2720+
BoringNoLocation,
2721+
2722+
/// A constraint that doesn't correspond to anything the user sees.
2723+
Internal,
26842724
}
26852725

26862726
/// The subject of a ClosureOutlivesRequirement -- that is, the thing

‎src/librustc_mir/borrow_check/nll/constraints/graph.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
// except according to those terms.
1010

1111
use borrow_check::nll::type_check::Locations;
12-
use borrow_check::nll::constraints::{ConstraintCategory, ConstraintIndex};
12+
use borrow_check::nll::constraints::ConstraintIndex;
1313
use borrow_check::nll::constraints::{ConstraintSet, OutlivesConstraint};
14+
use rustc::mir::ConstraintCategory;
1415
use rustc::ty::RegionVid;
1516
use rustc_data_structures::graph;
1617
use rustc_data_structures::indexed_vec::IndexVec;

‎src/librustc_mir/borrow_check/nll/constraints/mod.rs

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
use rustc::mir::ConstraintCategory;
1112
use rustc::ty::RegionVid;
1213
use rustc_data_structures::graph::scc::Sccs;
1314
use rustc_data_structures::indexed_vec::{Idx, IndexVec};
@@ -23,42 +24,6 @@ crate struct ConstraintSet {
2324
constraints: IndexVec<ConstraintIndex, OutlivesConstraint>,
2425
}
2526

26-
/// Constraints can be categorized to determine whether and why they are
27-
/// interesting. Order of variants indicates sort order of the category,
28-
/// thereby influencing diagnostic output.
29-
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
30-
pub enum ConstraintCategory {
31-
Return,
32-
TypeAnnotation,
33-
Cast,
34-
CallArgument,
35-
36-
/// A constraint that came from checking the body of a closure.
37-
///
38-
/// Ideally we would give an explanation that points to the relevant part
39-
/// of the closure's body.
40-
ClosureBounds,
41-
CopyBound,
42-
SizedBound,
43-
Assignment,
44-
OpaqueType,
45-
46-
/// A "boring" constraint (caused by the given location) is one that
47-
/// the user probably doesn't want to see described in diagnostics,
48-
/// because it is kind of an artifact of the type system setup.
49-
/// Example: `x = Foo { field: y }` technically creates
50-
/// intermediate regions representing the "type of `Foo { field: y
51-
/// }`", and data flows from `y` into those variables, but they
52-
/// are not very interesting. The assignment into `x` on the other
53-
/// hand might be.
54-
Boring,
55-
// Boring and applicable everywhere.
56-
BoringNoLocation,
57-
58-
/// A constraint that doesn't correspond to anything the user sees.
59-
Internal,
60-
}
61-
6227
impl ConstraintSet {
6328
crate fn push(&mut self, constraint: OutlivesConstraint) {
6429
debug!(

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ pub(in borrow_check) fn compute_regions<'cx, 'gcx, 'tcx>(
138138
let MirTypeckRegionConstraints {
139139
mut liveness_constraints,
140140
outlives_constraints,
141+
closure_bounds_mapping,
141142
type_tests,
142143
} = constraints;
143144

@@ -157,6 +158,7 @@ pub(in borrow_check) fn compute_regions<'cx, 'gcx, 'tcx>(
157158
universal_region_relations,
158159
mir,
159160
outlives_constraints,
161+
closure_bounds_mapping,
160162
type_tests,
161163
liveness_constraints,
162164
elements,

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

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use borrow_check::nll::constraints::{OutlivesConstraint, ConstraintCategory};
11+
use borrow_check::nll::constraints::{OutlivesConstraint};
1212
use borrow_check::nll::region_infer::RegionInferenceContext;
13+
use borrow_check::nll::type_check::Locations;
1314
use rustc::hir::def_id::DefId;
1415
use rustc::infer::error_reporting::nice_region_error::NiceRegionError;
1516
use rustc::infer::InferCtxt;
16-
use rustc::mir::{Location, Mir};
17+
use rustc::mir::{ConstraintCategory, Location, Mir};
1718
use rustc::ty::{self, RegionVid};
1819
use rustc_data_structures::indexed_vec::IndexVec;
1920
use rustc_errors::{Diagnostic, DiagnosticBuilder};
2021
use std::collections::VecDeque;
21-
use std::fmt;
2222
use syntax::symbol::keywords;
2323
use syntax_pos::Span;
2424
use syntax::errors::Applicability;
@@ -28,22 +28,26 @@ mod var_name;
2828

2929
use self::region_name::RegionName;
3030

31-
impl fmt::Display for ConstraintCategory {
32-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
31+
trait ConstraintDescription {
32+
fn description(&self) -> &'static str;
33+
}
34+
35+
impl ConstraintDescription for ConstraintCategory {
36+
fn description(&self) -> &'static str {
3337
// Must end with a space. Allows for empty names to be provided.
3438
match self {
35-
ConstraintCategory::Assignment => write!(f, "assignment "),
36-
ConstraintCategory::Return => write!(f, "returning this value "),
37-
ConstraintCategory::Cast => write!(f, "cast "),
38-
ConstraintCategory::CallArgument => write!(f, "argument "),
39-
ConstraintCategory::TypeAnnotation => write!(f, "type annotation "),
40-
ConstraintCategory::ClosureBounds => write!(f, "closure body "),
41-
ConstraintCategory::SizedBound => write!(f, "proving this value is `Sized` "),
42-
ConstraintCategory::CopyBound => write!(f, "copying this value "),
43-
ConstraintCategory::OpaqueType => write!(f, "opaque type "),
39+
ConstraintCategory::Assignment => "assignment ",
40+
ConstraintCategory::Return => "returning this value ",
41+
ConstraintCategory::Cast => "cast ",
42+
ConstraintCategory::CallArgument => "argument ",
43+
ConstraintCategory::TypeAnnotation => "type annotation ",
44+
ConstraintCategory::ClosureBounds => "closure body ",
45+
ConstraintCategory::SizedBound => "proving this value is `Sized` ",
46+
ConstraintCategory::CopyBound => "copying this value ",
47+
ConstraintCategory::OpaqueType => "opaque type ",
4448
ConstraintCategory::Boring
4549
| ConstraintCategory::BoringNoLocation
46-
| ConstraintCategory::Internal => write!(f, ""),
50+
| ConstraintCategory::Internal => "",
4751
}
4852
}
4953
}
@@ -89,7 +93,13 @@ impl<'tcx> RegionInferenceContext<'tcx> {
8993
// Classify each of the constraints along the path.
9094
let mut categorized_path: Vec<(ConstraintCategory, Span)> = path
9195
.iter()
92-
.map(|constraint| (constraint.category, constraint.locations.span(mir)))
96+
.map(|constraint| {
97+
if constraint.category == ConstraintCategory::ClosureBounds {
98+
self.retrieve_closure_constraint_info(mir, &constraint)
99+
} else {
100+
(constraint.category, constraint.locations.span(mir))
101+
}
102+
})
93103
.collect();
94104
debug!(
95105
"best_blame_constraint: categorized_path={:#?}",
@@ -358,7 +368,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
358368
_ => {
359369
diag.span_label(span, format!(
360370
"{}requires that `{}` must outlive `{}`",
361-
category, fr_name, outlived_fr_name,
371+
category.description(), fr_name, outlived_fr_name,
362372
));
363373
},
364374
}
@@ -470,8 +480,24 @@ impl<'tcx> RegionInferenceContext<'tcx> {
470480
mir: &Mir<'tcx>,
471481
fr1: RegionVid,
472482
fr2: RegionVid,
473-
) -> Span {
474-
let (_, span, _) = self.best_blame_constraint(mir, fr1, |r| r == fr2);
475-
span
483+
) -> (ConstraintCategory, Span) {
484+
let (category, span, _) = self.best_blame_constraint(mir, fr1, |r| r == fr2);
485+
(category, span)
486+
}
487+
488+
fn retrieve_closure_constraint_info(
489+
&self,
490+
mir: &Mir<'tcx>,
491+
constraint: &OutlivesConstraint
492+
) -> (ConstraintCategory, Span) {
493+
let loc = match constraint.locations {
494+
Locations::All(span) => return (constraint.category, span),
495+
Locations::Single(loc) => loc,
496+
};
497+
498+
let opt_span_category = self
499+
.closure_bounds_mapping[&loc]
500+
.get(&(constraint.sup, constraint.sub));
501+
*opt_span_category.unwrap_or(&(constraint.category, mir.source_info(loc).span))
476502
}
477503
}

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

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,17 @@ use rustc::infer::canonical::QueryRegionConstraint;
1919
use rustc::infer::region_constraints::{GenericKind, VarInfos, VerifyBound};
2020
use rustc::infer::{InferCtxt, NLLRegionVariableOrigin, RegionVariableOrigin};
2121
use rustc::mir::{
22-
ClosureOutlivesRequirement, ClosureOutlivesSubject, ClosureRegionRequirements, Local, Location,
23-
Mir,
22+
ClosureOutlivesRequirement, ClosureOutlivesSubject, ClosureRegionRequirements,
23+
ConstraintCategory, Local, Location, Mir,
2424
};
2525
use rustc::ty::{self, RegionVid, Ty, TyCtxt, TypeFoldable};
2626
use rustc::util::common;
2727
use rustc_data_structures::bit_set::BitSet;
28+
use rustc_data_structures::fx::FxHashMap;
2829
use rustc_data_structures::graph::scc::Sccs;
2930
use rustc_data_structures::indexed_vec::IndexVec;
3031
use rustc_errors::{Diagnostic, DiagnosticBuilder};
32+
use syntax_pos::Span;
3133

3234
use std::rc::Rc;
3335

@@ -60,10 +62,16 @@ pub struct RegionInferenceContext<'tcx> {
6062
/// the SCC (see `constraint_sccs`) and for error reporting.
6163
constraint_graph: Rc<NormalConstraintGraph>,
6264

63-
/// The SCC computed from `constraints` and the constraint graph. Used to compute the values
64-
/// of each region.
65+
/// The SCC computed from `constraints` and the constraint graph. Used to
66+
/// compute the values of each region.
6567
constraint_sccs: Rc<Sccs<RegionVid, ConstraintSccIndex>>,
6668

69+
/// Map closure bounds to a `Span` that should be used for error reporting.
70+
closure_bounds_mapping: FxHashMap<
71+
Location,
72+
FxHashMap<(RegionVid, RegionVid), (ConstraintCategory, Span)>,
73+
>,
74+
6775
/// Contains the minimum universe of any variable within the same
6876
/// SCC. We will ensure that no SCC contains values that are not
6977
/// visible from this index.
@@ -187,6 +195,10 @@ impl<'tcx> RegionInferenceContext<'tcx> {
187195
universal_region_relations: Rc<UniversalRegionRelations<'tcx>>,
188196
_mir: &Mir<'tcx>,
189197
outlives_constraints: ConstraintSet,
198+
closure_bounds_mapping: FxHashMap<
199+
Location,
200+
FxHashMap<(RegionVid, RegionVid), (ConstraintCategory, Span)>,
201+
>,
190202
type_tests: Vec<TypeTest<'tcx>>,
191203
liveness_constraints: LivenessValues<RegionVid>,
192204
elements: &Rc<RegionValueElements>,
@@ -220,6 +232,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
220232
constraints,
221233
constraint_graph,
222234
constraint_sccs,
235+
closure_bounds_mapping,
223236
scc_universes,
224237
scc_representatives,
225238
scc_values,
@@ -727,6 +740,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
727740
subject,
728741
outlived_free_region: non_local_ub,
729742
blame_span: locations.span(mir),
743+
category: ConstraintCategory::Boring,
730744
};
731745
debug!("try_promote_type_test: pushing {:#?}", requirement);
732746
propagated_outlives_requirements.push(requirement);
@@ -1125,7 +1139,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
11251139
longer_fr, shorter_fr,
11261140
);
11271141

1128-
let blame_span = self.find_outlives_blame_span(mir, longer_fr, shorter_fr);
1142+
let blame_span_category = self.find_outlives_blame_span(mir, longer_fr, shorter_fr);
11291143

11301144
if let Some(propagated_outlives_requirements) = propagated_outlives_requirements {
11311145
// Shrink `fr` until we find a non-local region (if we do).
@@ -1150,7 +1164,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
11501164
propagated_outlives_requirements.push(ClosureOutlivesRequirement {
11511165
subject: ClosureOutlivesSubject::Region(fr_minus),
11521166
outlived_free_region: shorter_fr_plus,
1153-
blame_span: blame_span,
1167+
blame_span: blame_span_category.1,
1168+
category: blame_span_category.0,
11541169
});
11551170
return;
11561171
}
@@ -1213,7 +1228,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
12131228
};
12141229

12151230
// Find the code to blame for the fact that `longer_fr` outlives `error_fr`.
1216-
let span = self.find_outlives_blame_span(mir, longer_fr, error_region);
1231+
let (_, span) = self.find_outlives_blame_span(mir, longer_fr, error_region);
12171232

12181233
// Obviously, this error message is far from satisfactory.
12191234
// At present, though, it only appears in unit tests --

‎src/librustc_mir/borrow_check/nll/type_check/constraint_conversion.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use borrow_check::nll::constraints::{ConstraintCategory, ConstraintSet, OutlivesConstraint};
11+
use borrow_check::nll::constraints::{ConstraintSet, OutlivesConstraint};
1212
use borrow_check::nll::region_infer::TypeTest;
1313
use borrow_check::nll::type_check::Locations;
1414
use borrow_check::nll::universal_regions::UniversalRegions;
@@ -17,6 +17,7 @@ use rustc::infer::outlives::env::RegionBoundPairs;
1717
use rustc::infer::outlives::obligations::{TypeOutlives, TypeOutlivesDelegate};
1818
use rustc::infer::region_constraints::{GenericKind, VerifyBound};
1919
use rustc::infer::{self, SubregionOrigin};
20+
use rustc::mir::ConstraintCategory;
2021
use rustc::ty::subst::UnpackedKind;
2122
use rustc::ty::{self, TyCtxt};
2223
use syntax_pos::DUMMY_SP;

‎src/librustc_mir/borrow_check/nll/type_check/free_region_relations.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ use borrow_check::nll::type_check::constraint_conversion;
1212
use borrow_check::nll::type_check::{Locations, MirTypeckRegionConstraints};
1313
use borrow_check::nll::universal_regions::UniversalRegions;
1414
use borrow_check::nll::ToRegionVid;
15-
use borrow_check::nll::constraints::ConstraintCategory;
1615
use rustc::infer::canonical::QueryRegionConstraint;
1716
use rustc::infer::outlives::free_region_map::FreeRegionRelations;
1817
use rustc::infer::region_constraints::GenericKind;
1918
use rustc::infer::InferCtxt;
19+
use rustc::mir::ConstraintCategory;
2020
use rustc::traits::query::outlives_bounds::{self, OutlivesBound};
2121
use rustc::traits::query::type_op::{self, TypeOp};
2222
use rustc::ty::{self, RegionVid, Ty};

‎src/librustc_mir/borrow_check/nll/type_check/input_output.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use rustc::ty::Ty;
2424
use rustc_data_structures::indexed_vec::Idx;
2525
use syntax_pos::Span;
2626

27-
use super::{ConstraintCategory, Locations, TypeChecker};
27+
use super::{Locations, TypeChecker};
2828

2929
impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
3030
pub(super) fn equate_inputs_and_outputs(

‎src/librustc_mir/borrow_check/nll/type_check/liveness/trace.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111
use borrow_check::location::LocationTable;
12-
use borrow_check::nll::constraints::ConstraintCategory;
1312
use borrow_check::nll::region_infer::values::{self, PointIndex, RegionValueElements};
1413
use borrow_check::nll::type_check::liveness::liveness_map::{LiveVar, NllLivenessMap};
1514
use borrow_check::nll::type_check::liveness::local_use_map::LocalUseMap;
@@ -19,7 +18,7 @@ use dataflow::move_paths::indexes::MovePathIndex;
1918
use dataflow::move_paths::MoveData;
2019
use dataflow::{FlowAtLocation, FlowsAtLocation, MaybeInitializedPlaces};
2120
use rustc::infer::canonical::QueryRegionConstraint;
22-
use rustc::mir::{BasicBlock, Local, Location, Mir};
21+
use rustc::mir::{BasicBlock, ConstraintCategory, Local, Location, Mir};
2322
use rustc::traits::query::dropck_outlives::DropckOutlivesResult;
2423
use rustc::traits::query::type_op::outlives::DropckOutlives;
2524
use rustc::traits::query::type_op::TypeOp;

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

Lines changed: 90 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use borrow_check::borrow_set::BorrowSet;
1515
use borrow_check::location::LocationTable;
16-
use borrow_check::nll::constraints::{ConstraintCategory, ConstraintSet, OutlivesConstraint};
16+
use borrow_check::nll::constraints::{ConstraintSet, OutlivesConstraint};
1717
use borrow_check::nll::facts::AllFacts;
1818
use borrow_check::nll::region_infer::values::LivenessValues;
1919
use borrow_check::nll::region_infer::values::PlaceholderIndices;
@@ -42,15 +42,15 @@ use rustc::traits::query::type_op::custom::CustomTypeOp;
4242
use rustc::traits::query::{Fallible, NoSolution};
4343
use rustc::traits::{ObligationCause, PredicateObligations};
4444
use rustc::ty::fold::TypeFoldable;
45-
use rustc::ty::subst::Subst;
45+
use rustc::ty::subst::{Subst, UnpackedKind};
4646
use rustc::ty::{self, CanonicalTy, RegionVid, ToPolyTraitRef, Ty, TyCtxt, TyKind};
4747
use std::rc::Rc;
4848
use std::{fmt, iter};
4949
use syntax_pos::{Span, DUMMY_SP};
5050
use transform::{MirPass, MirSource};
5151

5252
use either::Either;
53-
use rustc_data_structures::fx::FxHashSet;
53+
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
5454

5555
macro_rules! span_mirbug {
5656
($context:expr, $elem:expr, $($message:tt)*) => ({
@@ -128,6 +128,7 @@ pub(crate) fn type_check<'gcx, 'tcx>(
128128
let mut constraints = MirTypeckRegionConstraints {
129129
liveness_constraints: LivenessValues::new(elements),
130130
outlives_constraints: ConstraintSet::default(),
131+
closure_bounds_mapping: FxHashMap(),
131132
type_tests: Vec::default(),
132133
};
133134
let mut placeholder_indices = PlaceholderIndices::default();
@@ -752,6 +753,11 @@ crate struct MirTypeckRegionConstraints<'tcx> {
752753

753754
crate outlives_constraints: ConstraintSet,
754755

756+
crate closure_bounds_mapping: FxHashMap<
757+
Location,
758+
FxHashMap<(RegionVid, RegionVid), (ConstraintCategory, Span)>,
759+
>,
760+
755761
crate type_tests: Vec<TypeTest<'tcx>>,
756762
}
757763

@@ -860,7 +866,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
860866
&mut self,
861867
locations: Locations,
862868
category: ConstraintCategory,
863-
op: impl type_op::TypeOp<'gcx, 'tcx, Output = R>,
869+
op: impl type_op::TypeOp<'gcx, 'tcx, Output=R>,
864870
) -> Fallible<R> {
865871
let (r, opt_data) = op.fully_perform(self.infcx)?;
866872

@@ -1103,17 +1109,17 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
11031109
let place_ty = place.ty(mir, tcx).to_ty(tcx);
11041110
let rv_ty = rv.ty(mir, tcx);
11051111
if let Err(terr) =
1106-
self.sub_types_or_anon(rv_ty, place_ty, location.to_locations(), category)
1107-
{
1108-
span_mirbug!(
1112+
self.sub_types_or_anon(rv_ty, place_ty, location.to_locations(), category)
1113+
{
1114+
span_mirbug!(
11091115
self,
11101116
stmt,
11111117
"bad assignment ({:?} = {:?}): {:?}",
11121118
place_ty,
11131119
rv_ty,
11141120
terr
11151121
);
1116-
}
1122+
}
11171123

11181124
if let Some(user_ty) = self.rvalue_user_ty(rv) {
11191125
if let Err(terr) = self.relate_type_and_user_type(
@@ -1233,17 +1239,17 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
12331239

12341240
let locations = term_location.to_locations();
12351241
if let Err(terr) =
1236-
self.sub_types(rv_ty, place_ty, locations, ConstraintCategory::Assignment)
1237-
{
1238-
span_mirbug!(
1242+
self.sub_types(rv_ty, place_ty, locations, ConstraintCategory::Assignment)
1243+
{
1244+
span_mirbug!(
12391245
self,
12401246
term,
12411247
"bad DropAndReplace ({:?} = {:?}): {:?}",
12421248
place_ty,
12431249
rv_ty,
12441250
terr
12451251
);
1246-
}
1252+
}
12471253
}
12481254
TerminatorKind::SwitchInt {
12491255
ref discr,
@@ -1387,17 +1393,17 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
13871393
let locations = term_location.to_locations();
13881394

13891395
if let Err(terr) =
1390-
self.sub_types_or_anon(sig.output(), dest_ty, locations, category)
1391-
{
1392-
span_mirbug!(
1396+
self.sub_types_or_anon(sig.output(), dest_ty, locations, category)
1397+
{
1398+
span_mirbug!(
13931399
self,
13941400
term,
13951401
"call dest mismatch ({:?} <- {:?}): {:?}",
13961402
dest_ty,
13971403
sig.output(),
13981404
terr
13991405
);
1400-
}
1406+
}
14011407

14021408
// When `#![feature(unsized_locals)]` is not enabled,
14031409
// this check is done at `check_local`.
@@ -2038,7 +2044,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
20382044
aggregate_kind, location
20392045
);
20402046

2041-
let instantiated_predicates = match aggregate_kind {
2047+
let instantiated_predicates = match aggregate_kind {
20422048
AggregateKind::Adt(def, _, substs, _, _) => {
20432049
tcx.predicates_of(def.did).instantiate(tcx, substs)
20442050
}
@@ -2064,24 +2070,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
20642070
// these extra requirements are basically like where
20652071
// clauses on the struct.
20662072
AggregateKind::Closure(def_id, substs) => {
2067-
if let Some(closure_region_requirements) =
2068-
tcx.mir_borrowck(*def_id).closure_requirements
2069-
{
2070-
let closure_constraints = closure_region_requirements.apply_requirements(
2071-
self.infcx.tcx,
2072-
location,
2073-
*def_id,
2074-
*substs,
2075-
);
2076-
2077-
self.push_region_constraints(
2078-
location.to_locations(),
2079-
ConstraintCategory::ClosureBounds,
2080-
&closure_constraints,
2081-
);
2082-
}
2083-
2084-
tcx.predicates_of(*def_id).instantiate(tcx, substs.substs)
2073+
self.prove_closure_bounds(tcx, *def_id, *substs, location)
20852074
}
20862075

20872076
AggregateKind::Generator(def_id, substs, _) => {
@@ -2097,6 +2086,72 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
20972086
);
20982087
}
20992088

2089+
fn prove_closure_bounds(
2090+
&mut self,
2091+
tcx: TyCtxt<'a, 'gcx, 'tcx>,
2092+
def_id: DefId,
2093+
substs: ty::ClosureSubsts<'tcx>,
2094+
location: Location,
2095+
) -> ty::InstantiatedPredicates<'tcx> {
2096+
if let Some(closure_region_requirements) =
2097+
tcx.mir_borrowck(def_id).closure_requirements
2098+
{
2099+
let closure_constraints = closure_region_requirements.apply_requirements(
2100+
tcx,
2101+
location,
2102+
def_id,
2103+
substs,
2104+
);
2105+
2106+
if let Some(ref mut borrowck_context) = self.borrowck_context {
2107+
let bounds_mapping = closure_constraints
2108+
.iter()
2109+
.enumerate()
2110+
.filter_map(|(idx, constraint)| {
2111+
let ty::OutlivesPredicate(k1, r2) =
2112+
constraint.no_late_bound_regions().unwrap_or_else(|| {
2113+
bug!(
2114+
"query_constraint {:?} contained bound regions",
2115+
constraint,
2116+
);
2117+
});
2118+
2119+
match k1.unpack() {
2120+
UnpackedKind::Lifetime(r1) => {
2121+
// constraint is r1: r2
2122+
let r1_vid = borrowck_context.universal_regions.to_region_vid(r1);
2123+
let r2_vid = borrowck_context.universal_regions.to_region_vid(r2);
2124+
let outlives_requirements = &closure_region_requirements
2125+
.outlives_requirements[idx];
2126+
Some((
2127+
(r1_vid, r2_vid),
2128+
(
2129+
outlives_requirements.category,
2130+
outlives_requirements.blame_span,
2131+
),
2132+
))
2133+
}
2134+
UnpackedKind::Type(_) => None,
2135+
}
2136+
})
2137+
.collect();
2138+
2139+
let existing = borrowck_context.constraints
2140+
.closure_bounds_mapping
2141+
.insert(location, bounds_mapping);
2142+
assert!(existing.is_none(), "Multiple closures at the same location.");
2143+
}
2144+
2145+
self.push_region_constraints(
2146+
location.to_locations(),
2147+
ConstraintCategory::ClosureBounds,
2148+
&closure_constraints,
2149+
);
2150+
}
2151+
2152+
tcx.predicates_of(def_id).instantiate(tcx, substs.substs)
2153+
}
2154+
21002155
fn prove_trait_ref(
21012156
&mut self,
21022157
trait_ref: ty::TraitRef<'tcx>,

‎src/librustc_mir/borrow_check/nll/type_check/relate_tys.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use borrow_check::nll::constraints::{ConstraintCategory, OutlivesConstraint};
11+
use borrow_check::nll::constraints::OutlivesConstraint;
1212
use borrow_check::nll::type_check::{BorrowCheckContext, Locations};
1313
use rustc::infer::canonical::{Canonical, CanonicalVarInfos};
1414
use rustc::infer::{InferCtxt, NLLRegionVariableOrigin};
15+
use rustc::mir::ConstraintCategory;
1516
use rustc::traits::query::Fallible;
1617
use rustc::ty::fold::{TypeFoldable, TypeVisitor};
1718
use rustc::ty::relate::{self, Relate, RelateResult, TypeRelation};
Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
error: unsatisfied lifetime constraints
2-
--> $DIR/issue-10291.rs:12:65
2+
--> $DIR/issue-10291.rs:13:9
33
|
4-
LL | fn test<'x>(x: &'x isize) {
5-
| -- lifetime `'x` defined here
6-
LL | drop::<Box<for<'z> FnMut(&'z isize) -> &'z isize>>(Box::new(|z| {
7-
| _________________________________________________________________^
8-
LL | | x //~ ERROR E0312
9-
LL | | }));
10-
| |_____^ closure body requires that `'x` must outlive `'static`
4+
LL | fn test<'x>(x: &'x isize) {
5+
| -- lifetime `'x` defined here
6+
LL | drop::<Box<for<'z> FnMut(&'z isize) -> &'z isize>>(Box::new(|z| {
7+
LL | x //~ ERROR E0312
8+
| ^ returning this value requires that `'x` must outlive `'static`
119

1210
error: aborting due to previous error
1311

‎src/test/ui/nll/closure-requirements/propagate-approximated-ref.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ fn demand_y<'x, 'y>(_cell_x: &Cell<&'x u32>, _cell_y: &Cell<&'y u32>, _y: &'y u3
5151
#[rustc_regions]
5252
fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
5353
establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
54-
//~^ ERROR unsatisfied lifetime constraints
5554

5655
// Only works if 'x: 'y:
5756
demand_y(x, y, x.get())
57+
//~^ ERROR unsatisfied lifetime constraints
5858
});
5959
}
6060

‎src/test/ui/nll/closure-requirements/propagate-approximated-ref.stderr

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ note: External requirements
33
|
44
LL | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
55
| _______________________________________________^
6-
LL | | //~^ ERROR unsatisfied lifetime constraints
76
LL | |
87
LL | | // Only works if 'x: 'y:
98
LL | | demand_y(x, y, x.get())
9+
LL | | //~^ ERROR unsatisfied lifetime constraints
1010
LL | | });
1111
| |_____^
1212
|
@@ -24,8 +24,8 @@ note: No external requirements
2424
|
2525
LL | / fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
2626
LL | | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
27-
LL | | //~^ ERROR unsatisfied lifetime constraints
2827
LL | |
28+
LL | | // Only works if 'x: 'y:
2929
... |
3030
LL | | });
3131
LL | | }
@@ -34,20 +34,15 @@ LL | | }
3434
= note: defining type: DefId(0/0:6 ~ propagate_approximated_ref[317d]::supply[0]) with substs []
3535

3636
error: unsatisfied lifetime constraints
37-
--> $DIR/propagate-approximated-ref.rs:53:47
37+
--> $DIR/propagate-approximated-ref.rs:56:9
3838
|
39-
LL | fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
40-
| -- -- lifetime `'b` defined here
41-
| |
42-
| lifetime `'a` defined here
43-
LL | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
44-
| _______________________________________________^
45-
LL | | //~^ ERROR unsatisfied lifetime constraints
46-
LL | |
47-
LL | | // Only works if 'x: 'y:
48-
LL | | demand_y(x, y, x.get())
49-
LL | | });
50-
| |_____^ closure body requires that `'a` must outlive `'b`
39+
LL | fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
40+
| -- -- lifetime `'b` defined here
41+
| |
42+
| lifetime `'a` defined here
43+
...
44+
LL | demand_y(x, y, x.get())
45+
| ^^^^^^^^^^^^^^^^^^^^^^^ argument requires that `'a` must outlive `'b`
5146

5247
error: aborting due to previous error
5348

‎src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ fn demand_y<'x, 'y>(_cell_x: &Cell<&'x u32>, _cell_y: &Cell<&'y u32>, _y: &'y u3
4444
fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
4545
establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
4646
//~^ ERROR borrowed data escapes outside of function
47-
//~| ERROR unsatisfied lifetime constraints
4847

4948
// Only works if 'x: 'y:
5049
demand_y(x, y, x.get())
50+
//~^ ERROR unsatisfied lifetime constraints
5151
});
5252
}
5353

‎src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ note: External requirements
44
LL | establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
55
| _______________________________________________^
66
LL | | //~^ ERROR borrowed data escapes outside of function
7-
LL | | //~| ERROR unsatisfied lifetime constraints
87
LL | |
98
LL | | // Only works if 'x: 'y:
109
LL | | demand_y(x, y, x.get())
10+
LL | | //~^ ERROR unsatisfied lifetime constraints
1111
LL | | });
1212
| |_____^
1313
|
@@ -26,7 +26,7 @@ note: No external requirements
2626
LL | / fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
2727
LL | | establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
2828
LL | | //~^ ERROR borrowed data escapes outside of function
29-
LL | | //~| ERROR unsatisfied lifetime constraints
29+
LL | |
3030
... |
3131
LL | | });
3232
LL | | }
@@ -41,29 +41,23 @@ LL | fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
4141
| ------ `cell_a` is a reference that is only valid in the function body
4242
LL | / establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
4343
LL | | //~^ ERROR borrowed data escapes outside of function
44-
LL | | //~| ERROR unsatisfied lifetime constraints
4544
LL | |
4645
LL | | // Only works if 'x: 'y:
4746
LL | | demand_y(x, y, x.get())
47+
LL | | //~^ ERROR unsatisfied lifetime constraints
4848
LL | | });
4949
| |______^ `cell_a` escapes the function body here
5050

5151
error: unsatisfied lifetime constraints
52-
--> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:45:47
52+
--> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:49:9
5353
|
54-
LL | fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
55-
| -- -- lifetime `'b` defined here
56-
| |
57-
| lifetime `'a` defined here
58-
LL | establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
59-
| _______________________________________________^
60-
LL | | //~^ ERROR borrowed data escapes outside of function
61-
LL | | //~| ERROR unsatisfied lifetime constraints
62-
LL | |
63-
LL | | // Only works if 'x: 'y:
64-
LL | | demand_y(x, y, x.get())
65-
LL | | });
66-
| |_____^ closure body requires that `'a` must outlive `'b`
54+
LL | fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
55+
| -- -- lifetime `'b` defined here
56+
| |
57+
| lifetime `'a` defined here
58+
...
59+
LL | demand_y(x, y, x.get())
60+
| ^^^^^^^^^^^^^^^^^^^^^^^ argument requires that `'a` must outlive `'b`
6761

6862
error: aborting due to 2 previous errors
6963

‎src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ fn demand_y<'x, 'y>(_cell_x: &Cell<&'x u32>, _cell_y: &Cell<&'y u32>, _y: &'y u3
4747
fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
4848
establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
4949
//~^ ERROR borrowed data escapes outside of function
50-
//~| ERROR unsatisfied lifetime constraints
5150
// Only works if 'x: 'y:
5251
demand_y(x, y, x.get())
52+
//~^ ERROR unsatisfied lifetime constraints
5353
});
5454
}
5555

‎src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ note: External requirements
44
LL | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
55
| _______________________________________________^
66
LL | | //~^ ERROR borrowed data escapes outside of function
7-
LL | | //~| ERROR unsatisfied lifetime constraints
87
LL | | // Only works if 'x: 'y:
98
LL | | demand_y(x, y, x.get())
9+
LL | | //~^ ERROR unsatisfied lifetime constraints
1010
LL | | });
1111
| |_____^
1212
|
@@ -25,7 +25,7 @@ note: No external requirements
2525
LL | / fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
2626
LL | | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
2727
LL | | //~^ ERROR borrowed data escapes outside of function
28-
LL | | //~| ERROR unsatisfied lifetime constraints
28+
LL | | // Only works if 'x: 'y:
2929
... |
3030
LL | | });
3131
LL | | }
@@ -40,27 +40,22 @@ LL | fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
4040
| ------ `cell_a` is a reference that is only valid in the function body
4141
LL | / establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
4242
LL | | //~^ ERROR borrowed data escapes outside of function
43-
LL | | //~| ERROR unsatisfied lifetime constraints
4443
LL | | // Only works if 'x: 'y:
4544
LL | | demand_y(x, y, x.get())
45+
LL | | //~^ ERROR unsatisfied lifetime constraints
4646
LL | | });
4747
| |______^ `cell_a` escapes the function body here
4848

4949
error: unsatisfied lifetime constraints
50-
--> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:48:47
50+
--> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:51:9
5151
|
52-
LL | fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
53-
| -- -- lifetime `'b` defined here
54-
| |
55-
| lifetime `'a` defined here
56-
LL | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
57-
| _______________________________________________^
58-
LL | | //~^ ERROR borrowed data escapes outside of function
59-
LL | | //~| ERROR unsatisfied lifetime constraints
60-
LL | | // Only works if 'x: 'y:
61-
LL | | demand_y(x, y, x.get())
62-
LL | | });
63-
| |_____^ closure body requires that `'a` must outlive `'b`
52+
LL | fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
53+
| -- -- lifetime `'b` defined here
54+
| |
55+
| lifetime `'a` defined here
56+
...
57+
LL | demand_y(x, y, x.get())
58+
| ^^^^^^^^^^^^^^^^^^^^^^^ argument requires that `'a` must outlive `'b`
6459

6560
error: aborting due to 2 previous errors
6661

‎src/test/ui/nll/closure-requirements/propagate-approximated-val.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ fn demand_y<'x, 'y>(_outlives1: Cell<&&'x u32>, _outlives2: Cell<&'y &u32>, _y:
4444
#[rustc_regions]
4545
fn test<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
4646
establish_relationships(cell_a, cell_b, |outlives1, outlives2, x, y| {
47-
//~^ ERROR unsatisfied lifetime constraints
4847

4948
// Only works if 'x: 'y:
5049
demand_y(outlives1, outlives2, x.get())
50+
//~^ ERROR unsatisfied lifetime constraints
5151
});
5252
}
5353

‎src/test/ui/nll/closure-requirements/propagate-approximated-val.stderr

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ note: External requirements
33
|
44
LL | establish_relationships(cell_a, cell_b, |outlives1, outlives2, x, y| {
55
| _____________________________________________^
6-
LL | | //~^ ERROR unsatisfied lifetime constraints
76
LL | |
87
LL | | // Only works if 'x: 'y:
98
LL | | demand_y(outlives1, outlives2, x.get())
9+
LL | | //~^ ERROR unsatisfied lifetime constraints
1010
LL | | });
1111
| |_____^
1212
|
@@ -24,8 +24,8 @@ note: No external requirements
2424
|
2525
LL | / fn test<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
2626
LL | | establish_relationships(cell_a, cell_b, |outlives1, outlives2, x, y| {
27-
LL | | //~^ ERROR unsatisfied lifetime constraints
2827
LL | |
28+
LL | | // Only works if 'x: 'y:
2929
... |
3030
LL | | });
3131
LL | | }
@@ -34,20 +34,15 @@ LL | | }
3434
= note: defining type: DefId(0/0:6 ~ propagate_approximated_val[317d]::test[0]) with substs []
3535

3636
error: unsatisfied lifetime constraints
37-
--> $DIR/propagate-approximated-val.rs:46:45
37+
--> $DIR/propagate-approximated-val.rs:49:9
3838
|
39-
LL | fn test<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
40-
| -- -- lifetime `'b` defined here
41-
| |
42-
| lifetime `'a` defined here
43-
LL | establish_relationships(cell_a, cell_b, |outlives1, outlives2, x, y| {
44-
| _____________________________________________^
45-
LL | | //~^ ERROR unsatisfied lifetime constraints
46-
LL | |
47-
LL | | // Only works if 'x: 'y:
48-
LL | | demand_y(outlives1, outlives2, x.get())
49-
LL | | });
50-
| |_____^ closure body requires that `'a` must outlive `'b`
39+
LL | fn test<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
40+
| -- -- lifetime `'b` defined here
41+
| |
42+
| lifetime `'a` defined here
43+
...
44+
LL | demand_y(outlives1, outlives2, x.get())
45+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ argument requires that `'a` must outlive `'b`
5146

5247
error: aborting due to previous error
5348

‎src/test/ui/nll/ty-outlives/projection-one-region-closure.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ LL | with_signature(cell, t, |cell, t| require(cell, t));
4141
= help: consider adding an explicit lifetime bound `T: ReFree(DefId(0/0:8 ~ projection_one_region_closure[317d]::no_relationships_late[0]), BrNamed(crate0:DefIndex(1:16), 'a))`...
4242

4343
error: unsatisfied lifetime constraints
44-
--> $DIR/projection-one-region-closure.rs:55:29
44+
--> $DIR/projection-one-region-closure.rs:55:39
4545
|
4646
LL | fn no_relationships_late<'a, 'b, T>(cell: Cell<&'a ()>, t: T)
4747
| -- -- lifetime `'b` defined here
4848
| |
4949
| lifetime `'a` defined here
5050
...
5151
LL | with_signature(cell, t, |cell, t| require(cell, t));
52-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ closure body requires that `'b` must outlive `'a`
52+
| ^^^^^^^^^^^^^^^^ argument requires that `'b` must outlive `'a`
5353

5454
note: External requirements
5555
--> $DIR/projection-one-region-closure.rs:66:29
@@ -95,15 +95,15 @@ LL | with_signature(cell, t, |cell, t| require(cell, t));
9595
= help: consider adding an explicit lifetime bound `T: ReEarlyBound(0, 'a)`...
9696

9797
error: unsatisfied lifetime constraints
98-
--> $DIR/projection-one-region-closure.rs:66:29
98+
--> $DIR/projection-one-region-closure.rs:66:39
9999
|
100100
LL | fn no_relationships_early<'a, 'b, T>(cell: Cell<&'a ()>, t: T)
101101
| -- -- lifetime `'b` defined here
102102
| |
103103
| lifetime `'a` defined here
104104
...
105105
LL | with_signature(cell, t, |cell, t| require(cell, t));
106-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ closure body requires that `'b` must outlive `'a`
106+
| ^^^^^^^^^^^^^^^^ argument requires that `'b` must outlive `'a`
107107

108108
note: External requirements
109109
--> $DIR/projection-one-region-closure.rs:80:29

‎src/test/ui/nll/ty-outlives/projection-one-region-trait-bound-closure.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ LL | | }
3232
]
3333

3434
error: unsatisfied lifetime constraints
35-
--> $DIR/projection-one-region-trait-bound-closure.rs:47:29
35+
--> $DIR/projection-one-region-trait-bound-closure.rs:47:39
3636
|
3737
LL | fn no_relationships_late<'a, 'b, T>(cell: Cell<&'a ()>, t: T)
3838
| -- -- lifetime `'b` defined here
3939
| |
4040
| lifetime `'a` defined here
4141
...
4242
LL | with_signature(cell, t, |cell, t| require(cell, t));
43-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ closure body requires that `'b` must outlive `'a`
43+
| ^^^^^^^^^^^^^^^^ argument requires that `'b` must outlive `'a`
4444

4545
note: External requirements
4646
--> $DIR/projection-one-region-trait-bound-closure.rs:57:29
@@ -77,15 +77,15 @@ LL | | }
7777
]
7878

7979
error: unsatisfied lifetime constraints
80-
--> $DIR/projection-one-region-trait-bound-closure.rs:57:29
80+
--> $DIR/projection-one-region-trait-bound-closure.rs:57:39
8181
|
8282
LL | fn no_relationships_early<'a, 'b, T>(cell: Cell<&'a ()>, t: T)
8383
| -- -- lifetime `'b` defined here
8484
| |
8585
| lifetime `'a` defined here
8686
...
8787
LL | with_signature(cell, t, |cell, t| require(cell, t));
88-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ closure body requires that `'b` must outlive `'a`
88+
| ^^^^^^^^^^^^^^^^ argument requires that `'b` must outlive `'a`
8989

9090
note: External requirements
9191
--> $DIR/projection-one-region-trait-bound-closure.rs:70:29

‎src/test/ui/regions/regions-addr-of-upvar-self.nll.stderr

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,13 @@ LL | let p: &'static mut usize = &mut self.food; //~ ERROR cannot in
2121
= note: closure implements `FnMut`, so references to captured variables can't escape the closure
2222

2323
error: unsatisfied lifetime constraints
24-
--> $DIR/regions-addr-of-upvar-self.rs:19:18
24+
--> $DIR/regions-addr-of-upvar-self.rs:20:17
2525
|
26-
LL | pub fn chase_cat(&mut self) {
27-
| - let's call the lifetime of this reference `'1`
28-
LL | let _f = || {
29-
| __________________^
30-
LL | | let p: &'static mut usize = &mut self.food; //~ ERROR cannot infer
31-
LL | | *p = 3;
32-
LL | | };
33-
| |_________^ closure body requires that `'1` must outlive `'static`
26+
LL | pub fn chase_cat(&mut self) {
27+
| - let's call the lifetime of this reference `'1`
28+
LL | let _f = || {
29+
LL | let p: &'static mut usize = &mut self.food; //~ ERROR cannot infer
30+
| ^ type annotation requires that `'1` must outlive `'static`
3431

3532
error[E0597]: `self` does not live long enough
3633
--> $DIR/regions-addr-of-upvar-self.rs:20:46

‎src/test/ui/regions/regions-nested-fns.nll.stderr

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,13 @@ LL | }
3636
= note: borrowed value must be valid for the static lifetime...
3737

3838
error: unsatisfied lifetime constraints
39-
--> $DIR/regions-nested-fns.rs:23:68
39+
--> $DIR/regions-nested-fns.rs:24:27
4040
|
41-
LL | fn nested<'x>(x: &'x isize) {
42-
| -- lifetime `'x` defined here
41+
LL | fn nested<'x>(x: &'x isize) {
42+
| -- lifetime `'x` defined here
4343
...
44-
LL | ignore::< Box<for<'z> FnMut(&'z isize) -> &'z isize>>(Box::new(|z| {
45-
| ____________________________________________________________________^
46-
LL | | if false { return x; } //~ ERROR E0312
47-
LL | | if false { return ay; }
48-
LL | | return z;
49-
LL | | }));
50-
| |_____^ closure body requires that `'x` must outlive `'static`
44+
LL | if false { return x; } //~ ERROR E0312
45+
| ^ returning this value requires that `'x` must outlive `'static`
5146

5247
error: aborting due to 4 previous errors
5348

0 commit comments

Comments
 (0)
Please sign in to comment.