Skip to content

Commit 25808b1

Browse files
committed
simplify AnonTypeDecl in the impl trait code
We don't need to know the vector of region bounds; we only care if there were any region bounds at all.
1 parent 5c50d6c commit 25808b1

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

src/librustc_typeck/check/mod.rs

+23-4
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,28 @@ struct AnonTypeDecl<'tcx> {
258258
/// lifetime parameter on `foo`.)
259259
concrete_ty: Ty<'tcx>,
260260

261-
/// A list of all required region bounds on the impl Trait type,
262-
/// e.g. `'a` and `'b` in `fn foo<'a, 'b, 'c>() -> impl Trait<'c> + 'a + 'b`.
263-
required_region_bounds: Vec<ty::Region<'tcx>>,
261+
/// True if the `impl Trait` bounds include region bounds.
262+
/// For example, this would be true for:
263+
///
264+
/// fn foo<'a, 'b, 'c>() -> impl Trait<'c> + 'a + 'b
265+
///
266+
/// but false for:
267+
///
268+
/// fn foo<'c>() -> impl Trait<'c>
269+
///
270+
/// unless `Trait` was declared like:
271+
///
272+
/// trait Trait<'c>: 'c
273+
///
274+
/// in which case it would be true.
275+
///
276+
/// This is used during regionck to decide whether we need to
277+
/// impose any additional constraints to ensure that region
278+
/// variables in `concrete_ty` wind up being constrained to
279+
/// something from `substs` (or, at minimum, things that outlive
280+
/// the fn body). (Ultimately, writeback is responsible for this
281+
/// check.)
282+
has_required_region_bounds: bool,
264283
}
265284

266285
impl<'a, 'gcx, 'tcx> Deref for Inherited<'a, 'gcx, 'tcx> {
@@ -1941,7 +1960,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
19411960
self.anon_types.borrow_mut().insert(def_id, AnonTypeDecl {
19421961
substs,
19431962
concrete_ty: ty_var,
1944-
required_region_bounds,
1963+
has_required_region_bounds: !required_region_bounds.is_empty(),
19451964
});
19461965
debug!("instantiate_anon_types: ty_var={:?}", ty_var);
19471966

src/librustc_typeck/check/regionck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> {
451451
// If there are required region bounds, we can just skip
452452
// ahead. There will already be a registered region
453453
// obligation related `concrete_ty` to those regions.
454-
if anon_defn.required_region_bounds.len() != 0 {
454+
if anon_defn.has_required_region_bounds {
455455
continue;
456456
}
457457

0 commit comments

Comments
 (0)