@@ -2,11 +2,11 @@ use crate::infer::InferCtxtExt as _;
22use crate :: traits:: { self , ObligationCause , PredicateObligation } ;
33use rustc_data_structures:: fx:: FxHashMap ;
44use rustc_data_structures:: sync:: Lrc ;
5- use rustc_data_structures:: vec_map:: VecMap ;
65use rustc_hir as hir;
76use rustc_hir:: def_id:: { DefId , LocalDefId } ;
87use rustc_infer:: infer:: error_reporting:: unexpected_hidden_region_diagnostic;
98use rustc_infer:: infer:: free_regions:: FreeRegionRelations ;
9+ use rustc_infer:: infer:: opaque_types:: { OpaqueTypeDecl , OpaqueTypeMap } ;
1010use rustc_infer:: infer:: type_variable:: { TypeVariableOrigin , TypeVariableOriginKind } ;
1111use rustc_infer:: infer:: { self , InferCtxt , InferOk } ;
1212use rustc_middle:: ty:: fold:: { BottomUpFolder , TypeFoldable , TypeFolder , TypeVisitor } ;
@@ -16,72 +16,6 @@ use rustc_span::Span;
1616
1717use std:: ops:: ControlFlow ;
1818
19- pub type OpaqueTypeMap < ' tcx > = VecMap < OpaqueTypeKey < ' tcx > , OpaqueTypeDecl < ' tcx > > ;
20-
21- /// Information about the opaque types whose values we
22- /// are inferring in this function (these are the `impl Trait` that
23- /// appear in the return type).
24- #[ derive( Copy , Clone , Debug ) ]
25- pub struct OpaqueTypeDecl < ' tcx > {
26- /// The opaque type (`ty::Opaque`) for this declaration.
27- pub opaque_type : Ty < ' tcx > ,
28-
29- /// The span of this particular definition of the opaque type. So
30- /// for example:
31- ///
32- /// ```ignore (incomplete snippet)
33- /// type Foo = impl Baz;
34- /// fn bar() -> Foo {
35- /// // ^^^ This is the span we are looking for!
36- /// }
37- /// ```
38- ///
39- /// In cases where the fn returns `(impl Trait, impl Trait)` or
40- /// other such combinations, the result is currently
41- /// over-approximated, but better than nothing.
42- pub definition_span : Span ,
43-
44- /// The type variable that represents the value of the opaque type
45- /// that we require. In other words, after we compile this function,
46- /// we will be created a constraint like:
47- ///
48- /// Foo<'a, T> = ?C
49- ///
50- /// where `?C` is the value of this type variable. =) It may
51- /// naturally refer to the type and lifetime parameters in scope
52- /// in this function, though ultimately it should only reference
53- /// those that are arguments to `Foo` in the constraint above. (In
54- /// other words, `?C` should not include `'b`, even though it's a
55- /// lifetime parameter on `foo`.)
56- pub concrete_ty : Ty < ' tcx > ,
57-
58- /// Returns `true` if the `impl Trait` bounds include region bounds.
59- /// For example, this would be true for:
60- ///
61- /// fn foo<'a, 'b, 'c>() -> impl Trait<'c> + 'a + 'b
62- ///
63- /// but false for:
64- ///
65- /// fn foo<'c>() -> impl Trait<'c>
66- ///
67- /// unless `Trait` was declared like:
68- ///
69- /// trait Trait<'c>: 'c
70- ///
71- /// in which case it would be true.
72- ///
73- /// This is used during regionck to decide whether we need to
74- /// impose any additional constraints to ensure that region
75- /// variables in `concrete_ty` wind up being constrained to
76- /// something from `substs` (or, at minimum, things that outlive
77- /// the fn body). (Ultimately, writeback is responsible for this
78- /// check.)
79- pub has_required_region_bounds : bool ,
80-
81- /// The origin of the opaque type.
82- pub origin : hir:: OpaqueTyOrigin ,
83- }
84-
8519/// Whether member constraints should be generated for all opaque types
8620#[ derive( Debug ) ]
8721pub enum GenerateMemberConstraints {
@@ -105,11 +39,7 @@ pub trait InferCtxtExt<'tcx> {
10539 value_span : Span ,
10640 ) -> InferOk < ' tcx , ( T , OpaqueTypeMap < ' tcx > ) > ;
10741
108- fn constrain_opaque_types < FRR : FreeRegionRelations < ' tcx > > (
109- & self ,
110- opaque_types : & OpaqueTypeMap < ' tcx > ,
111- free_region_relations : & FRR ,
112- ) ;
42+ fn constrain_opaque_types < FRR : FreeRegionRelations < ' tcx > > ( & self , free_region_relations : & FRR ) ;
11343
11444 fn constrain_opaque_type < FRR : FreeRegionRelations < ' tcx > > (
11545 & self ,
@@ -350,12 +280,9 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
350280 /// - `opaque_types` -- the map produced by `instantiate_opaque_types`
351281 /// - `free_region_relations` -- something that can be used to relate
352282 /// the free regions (`'a`) that appear in the impl trait.
353- fn constrain_opaque_types < FRR : FreeRegionRelations < ' tcx > > (
354- & self ,
355- opaque_types : & OpaqueTypeMap < ' tcx > ,
356- free_region_relations : & FRR ,
357- ) {
358- for & ( opaque_type_key, opaque_defn) in opaque_types {
283+ fn constrain_opaque_types < FRR : FreeRegionRelations < ' tcx > > ( & self , free_region_relations : & FRR ) {
284+ let opaque_types = self . inner . borrow ( ) . opaque_types . clone ( ) ;
285+ for ( opaque_type_key, opaque_defn) in opaque_types {
359286 self . constrain_opaque_type (
360287 opaque_type_key,
361288 & opaque_defn,
0 commit comments