Skip to content

Commit 9acb574

Browse files
committed
Move ty::{BoundConst, CReaderCacheKey, ClosureSizeProfileData, CrateInherentImpls, CrateVariancesMap, Destructor, DestructuredConst, ImplHeader, ImplOverlapKind, ImplSubject, InferVarInfo, OpaqueTypeKey, VariantDiscr, VariantFlags} to their own little modules (cute)
1 parent a1e3cb4 commit 9acb574

15 files changed

+215
-173
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use crate::ty::{BoundVar, Ty};
2+
3+
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, HashStable)]
4+
#[derive(TyEncodable, TyDecodable, PartialOrd, Ord)]
5+
pub struct BoundConst<'tcx> {
6+
pub var: BoundVar,
7+
pub ty: Ty<'tcx>,
8+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use rustc_hir::def_id::CrateNum;
2+
3+
/// Contains information needed to resolve types and (in the future) look up
4+
/// the types of AST nodes.
5+
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
6+
pub struct CReaderCacheKey {
7+
pub cnum: Option<CrateNum>,
8+
pub pos: usize,
9+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use crate::ty::Ty;
2+
3+
#[derive(Clone, Debug, PartialEq, Eq, Copy, Hash, TyEncodable, TyDecodable, HashStable)]
4+
#[derive(TypeFoldable, TypeVisitable)]
5+
pub struct ClosureSizeProfileData<'tcx> {
6+
/// Tuple containing the types of closure captures before the feature `capture_disjoint_fields`
7+
pub before_feature_tys: Ty<'tcx>,
8+
/// Tuple containing the types of closure captures after the feature `capture_disjoint_fields`
9+
pub after_feature_tys: Ty<'tcx>,
10+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use rustc_data_structures::fx::FxHashMap;
2+
use rustc_hir::def_id::{DefId, LocalDefId, LocalDefIdMap};
3+
4+
use crate::ty::SimplifiedType;
5+
6+
/// A map for the local crate mapping each type to a vector of its
7+
/// inherent impls. This is not meant to be used outside of coherence;
8+
/// rather, you should request the vector for a specific type via
9+
/// `tcx.inherent_impls(def_id)` so as to minimize your dependencies
10+
/// (constructing this map requires touching the entire crate).
11+
#[derive(Clone, Debug, Default, HashStable)]
12+
pub struct CrateInherentImpls {
13+
pub inherent_impls: LocalDefIdMap<Vec<DefId>>,
14+
pub incoherent_impls: FxHashMap<SimplifiedType, Vec<LocalDefId>>,
15+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use rustc_hir::def_id::DefIdMap;
2+
3+
use crate::ty;
4+
5+
/// The crate variances map is computed during typeck and contains the
6+
/// variance of every item in the local crate. You should not use it
7+
/// directly, because to do so will make your pass dependent on the
8+
/// HIR of every item in the local crate. Instead, use
9+
/// `tcx.variances_of()` to get the variance for a *particular*
10+
/// item.
11+
#[derive(HashStable, Debug)]
12+
pub struct CrateVariancesMap<'tcx> {
13+
/// For each item with generics, maps to a vector of the variance
14+
/// of its generics. If an item has no generics, it will have no
15+
/// entry.
16+
pub variances: DefIdMap<&'tcx [ty::Variance]>,
17+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use rustc_hir as hir;
2+
use rustc_hir::def_id::DefId;
3+
4+
#[derive(Copy, Clone, Debug, HashStable, Encodable, Decodable)]
5+
pub struct Destructor {
6+
/// The `DefId` of the destructor method
7+
pub did: DefId,
8+
/// The constness of the destructor method
9+
pub constness: hir::Constness,
10+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use crate::ty::{self, VariantIdx};
2+
3+
/// The constituent parts of a type level constant of kind ADT or array.
4+
#[derive(Copy, Clone, Debug, HashStable)]
5+
pub struct DestructuredConst<'tcx> {
6+
pub variant: Option<VariantIdx>,
7+
pub fields: &'tcx [ty::Const<'tcx>],
8+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use rustc_hir::def_id::DefId;
2+
3+
use crate::ty::{Predicate, TraitRef, Ty};
4+
5+
/// The "header" of an impl is everything outside the body: a Self type, a trait
6+
/// ref (in the case of a trait impl), and a set of predicates (from the
7+
/// bounds / where-clauses).
8+
#[derive(Clone, Debug, TypeFoldable, TypeVisitable)]
9+
pub struct ImplHeader<'tcx> {
10+
pub impl_def_id: DefId,
11+
pub self_ty: Ty<'tcx>,
12+
pub trait_ref: Option<TraitRef<'tcx>>,
13+
pub predicates: Vec<Predicate<'tcx>>,
14+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#[derive(Debug, PartialEq, Eq)]
2+
pub enum ImplOverlapKind {
3+
/// These impls are always allowed to overlap.
4+
Permitted {
5+
/// Whether or not the impl is permitted due to the trait being a `#[marker]` trait
6+
marker: bool,
7+
},
8+
/// These impls are allowed to overlap, but that raises
9+
/// an issue #33140 future-compatibility warning.
10+
///
11+
/// Some background: in Rust 1.0, the trait-object types `Send + Sync` (today's
12+
/// `dyn Send + Sync`) and `Sync + Send` (now `dyn Sync + Send`) were different.
13+
///
14+
/// The widely-used version 0.1.0 of the crate `traitobject` had accidentally relied
15+
/// that difference, making what reduces to the following set of impls:
16+
///
17+
/// ```compile_fail,(E0119)
18+
/// trait Trait {}
19+
/// impl Trait for dyn Send + Sync {}
20+
/// impl Trait for dyn Sync + Send {}
21+
/// ```
22+
///
23+
/// Obviously, once we made these types be identical, that code causes a coherence
24+
/// error and a fairly big headache for us. However, luckily for us, the trait
25+
/// `Trait` used in this case is basically a marker trait, and therefore having
26+
/// overlapping impls for it is sound.
27+
///
28+
/// To handle this, we basically regard the trait as a marker trait, with an additional
29+
/// future-compatibility warning. To avoid accidentally "stabilizing" this feature,
30+
/// it has the following restrictions:
31+
///
32+
/// 1. The trait must indeed be a marker-like trait (i.e., no items), and must be
33+
/// positive impls.
34+
/// 2. The trait-ref of both impls must be equal.
35+
/// 3. The trait-ref of both impls must be a trait object type consisting only of
36+
/// marker traits.
37+
/// 4. Neither of the impls can have any where-clauses.
38+
///
39+
/// Once `traitobject` 0.1.0 is no longer an active concern, this hack can be removed.
40+
Issue33140,
41+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
use crate::ty::{TraitRef, Ty};
2+
3+
#[derive(Copy, Clone, PartialEq, Eq, Debug, TypeFoldable, TypeVisitable)]
4+
pub enum ImplSubject<'tcx> {
5+
Trait(TraitRef<'tcx>),
6+
Inherent(Ty<'tcx>),
7+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#[derive(Debug, Default, Copy, Clone)]
2+
pub struct InferVarInfo {
3+
/// This is true if we identified that this Ty (`?T`) is found in a `?T: Foo`
4+
/// obligation, where:
5+
///
6+
/// * `Foo` is not `Sized`
7+
/// * `(): Foo` may be satisfied
8+
pub self_in_trait: bool,
9+
/// This is true if we identified that this Ty (`?T`) is found in a `<_ as
10+
/// _>::AssocType = ?T`
11+
pub output: bool,
12+
}

0 commit comments

Comments
 (0)