Skip to content

Commit 14021fe

Browse files
committed
Remove a field that is computed later anyway
1 parent d998059 commit 14021fe

File tree

2 files changed

+30
-45
lines changed

2 files changed

+30
-45
lines changed

compiler/rustc_infer/src/infer/opaque_types.rs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,29 +42,6 @@ pub struct OpaqueTypeDecl<'tcx> {
4242
/// lifetime parameter on `foo`.)
4343
pub concrete_ty: Ty<'tcx>,
4444

45-
/// Returns `true` if the `impl Trait` bounds include region bounds.
46-
/// For example, this would be true for:
47-
///
48-
/// fn foo<'a, 'b, 'c>() -> impl Trait<'c> + 'a + 'b
49-
///
50-
/// but false for:
51-
///
52-
/// fn foo<'c>() -> impl Trait<'c>
53-
///
54-
/// unless `Trait` was declared like:
55-
///
56-
/// trait Trait<'c>: 'c
57-
///
58-
/// in which case it would be true.
59-
///
60-
/// This is used during regionck to decide whether we need to
61-
/// impose any additional constraints to ensure that region
62-
/// variables in `concrete_ty` wind up being constrained to
63-
/// something from `substs` (or, at minimum, things that outlive
64-
/// the fn body). (Ultimately, writeback is responsible for this
65-
/// check.)
66-
pub has_required_region_bounds: bool,
67-
6845
/// The origin of the opaque type.
6946
pub origin: hir::OpaqueTyOrigin,
7047
}

compiler/rustc_trait_selection/src/opaque_types.rs

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -330,19 +330,36 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
330330

331331
let span = tcx.def_span(def_id);
332332

333-
// If there are required region bounds, we can use them.
334-
if opaque_defn.has_required_region_bounds {
335-
let bounds = tcx.explicit_item_bounds(def_id);
336-
debug!("{:#?}", bounds);
337-
let bounds: Vec<_> =
338-
bounds.iter().map(|(bound, _)| bound.subst(tcx, opaque_type_key.substs)).collect();
339-
debug!("{:#?}", bounds);
340-
let opaque_type = tcx.mk_opaque(def_id, opaque_type_key.substs);
341-
342-
let required_region_bounds =
343-
required_region_bounds(tcx, opaque_type, bounds.into_iter());
344-
debug_assert!(!required_region_bounds.is_empty());
333+
// Check if the `impl Trait` bounds include region bounds.
334+
// For example, this would be true for:
335+
//
336+
// fn foo<'a, 'b, 'c>() -> impl Trait<'c> + 'a + 'b
337+
//
338+
// but false for:
339+
//
340+
// fn foo<'c>() -> impl Trait<'c>
341+
//
342+
// unless `Trait` was declared like:
343+
//
344+
// trait Trait<'c>: 'c
345+
//
346+
// in which case it would be true.
347+
//
348+
// This is used during regionck to decide whether we need to
349+
// impose any additional constraints to ensure that region
350+
// variables in `concrete_ty` wind up being constrained to
351+
// something from `substs` (or, at minimum, things that outlive
352+
// the fn body). (Ultimately, writeback is responsible for this
353+
// check.)
354+
let bounds = tcx.explicit_item_bounds(def_id);
355+
debug!("{:#?}", bounds);
356+
let bounds: Vec<_> =
357+
bounds.iter().map(|(bound, _)| bound.subst(tcx, opaque_type_key.substs)).collect();
358+
debug!("{:#?}", bounds);
359+
let opaque_type = tcx.mk_opaque(def_id, opaque_type_key.substs);
345360

361+
let required_region_bounds = required_region_bounds(tcx, opaque_type, bounds.into_iter());
362+
if !required_region_bounds.is_empty() {
346363
for required_region in required_region_bounds {
347364
concrete_ty.visit_with(&mut ConstrainOpaqueTypeRegionVisitor {
348365
op: |r| self.sub_regions(infer::CallReturn(span), required_region, r),
@@ -979,9 +996,6 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
979996

980997
debug!("instantiate_opaque_types: bounds={:?}", bounds);
981998

982-
let required_region_bounds = required_region_bounds(tcx, ty, bounds.iter().copied());
983-
debug!("instantiate_opaque_types: required_region_bounds={:?}", required_region_bounds);
984-
985999
// Make sure that we are in fact defining the *entire* type
9861000
// (e.g., `type Foo<T: Bound> = impl Bar;` needs to be
9871001
// defined by a function like `fn foo<T: Bound>() -> Foo<T>`).
@@ -997,13 +1011,7 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
9971011

9981012
self.opaque_types.insert(
9991013
OpaqueTypeKey { def_id, substs },
1000-
OpaqueTypeDecl {
1001-
opaque_type: ty,
1002-
definition_span,
1003-
concrete_ty: ty_var,
1004-
has_required_region_bounds: !required_region_bounds.is_empty(),
1005-
origin,
1006-
},
1014+
OpaqueTypeDecl { opaque_type: ty, definition_span, concrete_ty: ty_var, origin },
10071015
);
10081016
debug!("instantiate_opaque_types: ty_var={:?}", ty_var);
10091017

0 commit comments

Comments
 (0)