@@ -17,7 +17,7 @@ pub use self::AssocItemContainer::*;
17
17
pub use self :: BorrowKind :: * ;
18
18
pub use self :: IntVarValue :: * ;
19
19
pub use self :: Variance :: * ;
20
- use crate :: error:: { OpaqueHiddenTypeMismatch , TypeMismatchReason } ;
20
+ use crate :: error:: TypeMismatchReason ;
21
21
use crate :: metadata:: ModChild ;
22
22
use crate :: middle:: privacy:: EffectiveVisibilities ;
23
23
use crate :: mir:: { Body , GeneratorLayout } ;
@@ -34,7 +34,6 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
34
34
use rustc_data_structures:: intern:: Interned ;
35
35
use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
36
36
use rustc_data_structures:: steal:: Steal ;
37
- use rustc_errors:: ErrorGuaranteed ;
38
37
use rustc_hir as hir;
39
38
use rustc_hir:: def:: { CtorKind , CtorOf , DefKind , DocLinkResMap , LifetimeRes , Res } ;
40
39
use rustc_hir:: def_id:: { CrateNum , DefId , DefIdMap , LocalDefId , LocalDefIdMap } ;
@@ -144,6 +143,7 @@ mod typeck_results;
144
143
mod alias_relation_direction;
145
144
mod bound_constness;
146
145
mod impl_polarity;
146
+ mod opaque_hidden_type;
147
147
mod param_env;
148
148
mod predicate;
149
149
mod term;
@@ -153,6 +153,7 @@ mod visibility;
153
153
pub use alias_relation_direction:: AliasRelationDirection ;
154
154
pub use bound_constness:: BoundConstness ;
155
155
pub use impl_polarity:: ImplPolarity ;
156
+ pub use opaque_hidden_type:: OpaqueHiddenType ;
156
157
pub use param_env:: { ParamEnv , ParamEnvAnd } ;
157
158
pub use predicate:: {
158
159
CoercePredicate , InstantiatedPredicates , OutlivesPredicate , PolyCoercePredicate ,
@@ -412,86 +413,6 @@ pub struct OpaqueTypeKey<'tcx> {
412
413
pub substs : SubstsRef < ' tcx > ,
413
414
}
414
415
415
- #[ derive( Copy , Clone , Debug , TypeFoldable , TypeVisitable , HashStable , TyEncodable , TyDecodable ) ]
416
- pub struct OpaqueHiddenType < ' tcx > {
417
- /// The span of this particular definition of the opaque type. So
418
- /// for example:
419
- ///
420
- /// ```ignore (incomplete snippet)
421
- /// type Foo = impl Baz;
422
- /// fn bar() -> Foo {
423
- /// // ^^^ This is the span we are looking for!
424
- /// }
425
- /// ```
426
- ///
427
- /// In cases where the fn returns `(impl Trait, impl Trait)` or
428
- /// other such combinations, the result is currently
429
- /// over-approximated, but better than nothing.
430
- pub span : Span ,
431
-
432
- /// The type variable that represents the value of the opaque type
433
- /// that we require. In other words, after we compile this function,
434
- /// we will be created a constraint like:
435
- /// ```ignore (pseudo-rust)
436
- /// Foo<'a, T> = ?C
437
- /// ```
438
- /// where `?C` is the value of this type variable. =) It may
439
- /// naturally refer to the type and lifetime parameters in scope
440
- /// in this function, though ultimately it should only reference
441
- /// those that are arguments to `Foo` in the constraint above. (In
442
- /// other words, `?C` should not include `'b`, even though it's a
443
- /// lifetime parameter on `foo`.)
444
- pub ty : Ty < ' tcx > ,
445
- }
446
-
447
- impl < ' tcx > OpaqueHiddenType < ' tcx > {
448
- pub fn report_mismatch ( & self , other : & Self , tcx : TyCtxt < ' tcx > ) -> ErrorGuaranteed {
449
- // Found different concrete types for the opaque type.
450
- let sub_diag = if self . span == other. span {
451
- TypeMismatchReason :: ConflictType { span : self . span }
452
- } else {
453
- TypeMismatchReason :: PreviousUse { span : self . span }
454
- } ;
455
- tcx. sess . emit_err ( OpaqueHiddenTypeMismatch {
456
- self_ty : self . ty ,
457
- other_ty : other. ty ,
458
- other_span : other. span ,
459
- sub : sub_diag,
460
- } )
461
- }
462
-
463
- #[ instrument( level = "debug" , skip( tcx) , ret) ]
464
- pub fn remap_generic_params_to_declaration_params (
465
- self ,
466
- opaque_type_key : OpaqueTypeKey < ' tcx > ,
467
- tcx : TyCtxt < ' tcx > ,
468
- // typeck errors have subpar spans for opaque types, so delay error reporting until borrowck.
469
- ignore_errors : bool ,
470
- ) -> Self {
471
- let OpaqueTypeKey { def_id, substs } = opaque_type_key;
472
-
473
- // Use substs to build up a reverse map from regions to their
474
- // identity mappings. This is necessary because of `impl
475
- // Trait` lifetimes are computed by replacing existing
476
- // lifetimes with 'static and remapping only those used in the
477
- // `impl Trait` return type, resulting in the parameters
478
- // shifting.
479
- let id_substs = InternalSubsts :: identity_for_item ( tcx, def_id) ;
480
- debug ! ( ?id_substs) ;
481
-
482
- // This zip may have several times the same lifetime in `substs` paired with a different
483
- // lifetime from `id_substs`. Simply `collect`ing the iterator is the correct behaviour:
484
- // it will pick the last one, which is the one we introduced in the impl-trait desugaring.
485
- let map = substs. iter ( ) . zip ( id_substs) . collect ( ) ;
486
- debug ! ( "map = {:#?}" , map) ;
487
-
488
- // Convert the type from the function into a type valid outside
489
- // the function, by replacing invalid regions with 'static,
490
- // after producing an error for each of them.
491
- self . fold_with ( & mut opaque_types:: ReverseMapper :: new ( tcx, map, self . span , ignore_errors) )
492
- }
493
- }
494
-
495
416
/// The "placeholder index" fully defines a placeholder region, type, or const. Placeholders are
496
417
/// identified by both a universe, as well as a name residing within that universe. Distinct bound
497
418
/// regions/types/consts within the same universe simply have an unknown relationship to one
0 commit comments