@@ -87,11 +87,35 @@ pub struct StructFlags {
87
87
}
88
88
89
89
#[ derive( Clone , Debug , PartialEq , Eq , Hash ) ]
90
- /// A rust intermediate representation (rust_ir) of a Trait Definition.
90
+ /// A rust intermediate representation (rust_ir) of a Trait Definition. For
91
+ /// example, given the following rust code:
91
92
///
92
- /// Not to be confused with a rust_ir for a Trait Implementation, which is
93
- /// represented with ??? JRL
93
+ /// ```compile_fail
94
+ /// use std::fmt::Debug;
95
+ ///
96
+ /// trait Foo<T>
97
+ /// where
98
+ /// T: Debug,
99
+ /// {
100
+ /// type Bar<U>;
101
+ /// }
102
+ /// ```
103
+ ///
104
+ /// This would represent the `trait Foo` declaration. Note that the details of
105
+ /// the trait members (e.g., the associated type declaration (`type Bar<U>`) are
106
+ /// not contained in this type, and are represented separately (e.g., in
107
+ /// [`AssociatedTyDatum`]).
108
+ ///
109
+ /// Not to be confused with the rust_ir for a Trait Implementation, which is
110
+ /// represented by [`ImplDatum`]
111
+ ///
112
+ /// [`ImplDatum`]: struct.ImplDatum.html
113
+ /// [`AssociatedTyDatum`]: struct.AssociatedTyDatum.html
94
114
pub struct TraitDatum < I : Interner > {
115
+ /// The id of this trait; could be used to load the trait datum by invoking
116
+ /// the [`trait_datum`] method.
117
+ ///
118
+ /// [`trait_datum`]: ../chalk_solve/trait.RustIrDatabase.html#tymethod.trait_datum
95
119
pub id : TraitId < I > ,
96
120
97
121
pub binders : Binders < TraitDatumBound < I > > ,
@@ -101,15 +125,18 @@ pub struct TraitDatum<I: Interner> {
101
125
/// chalk we add annotations like `#[auto]`.
102
126
pub flags : TraitFlags ,
103
127
104
- /// The id of each associated type defined in the trait.
128
+ /// The ids for the associated type members of the trait. The details of
129
+ /// each type can be found by invoking the [`associated_ty_data`] method.
130
+ ///
131
+ /// [`associated_ty_data`]: ../chalk_solve/trait.RustIrDatabase.html#tymethod.associated_ty_data
105
132
pub associated_ty_ids : Vec < AssocTypeId < I > > ,
106
133
107
- /// A marker indicating if this trait definition represents one of the
108
- /// various builtin traits (sized, copy, etc)
134
+ /// A list of the traits that are "well known" to chalk, which means that
135
+ /// the chalk-solve crate has special, hard-coded impls for them.
109
136
pub well_known : Option < WellKnownTrait > ,
110
137
}
111
138
112
- #[ derive( Clone , Debug , PartialEq , Eq , Hash ) ]
139
+ #[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash ) ]
113
140
pub enum WellKnownTrait {
114
141
SizedTrait ,
115
142
}
@@ -141,18 +168,34 @@ pub struct TraitDatumBound<I: Interner> {
141
168
142
169
#[ derive( Clone , Debug , PartialEq , Eq , Hash ) ]
143
170
pub struct TraitFlags {
171
+ /// An "auto trait" is one that is "automatically implemented" for every
172
+ /// struct, so long as no explicit impl is given.
173
+ ///
174
+ /// Examples are `Send` and `Sync`.
144
175
pub auto : bool ,
176
+
145
177
pub marker : bool ,
178
+
146
179
/// Indicate that a trait is defined upstream (in a dependency), used during
147
180
/// coherence checking.
148
181
pub upstream : bool ,
149
- /// The trait equivalent of a struct fundamental, currently (2020-03-25)
150
- /// there are no known fundamental traits.
182
+
183
+ /// A fundamental trait is a trait where adding an impl for an existing type
184
+ /// is considered a breaking change. Examples of fundamental traits are the
185
+ /// closure traits like `Fn` and `FnMut`.
186
+ ///
187
+ /// As of this writing (2020-03-27), fundamental traits are declared by the
188
+ /// unstable `#[fundamental]` attribute in rustc, and hence cannot appear
189
+ /// outside of the standard library.
151
190
pub fundamental : bool ,
191
+
152
192
/// Indicates that chalk cannot list all of the implementations of the given
153
- /// trait, likely because it is a publicly exported trait in a library JRL
154
- /// ???.
193
+ /// trait, likely because it is a publicly exported trait in a library.
194
+ ///
195
+ /// Currently (2020-03-27) rustc and rust-analyzer mark all traits as
196
+ /// non_enumerable, and in the future it may become the only option.
155
197
pub non_enumerable : bool ,
198
+
156
199
pub coinductive : bool ,
157
200
}
158
201
0 commit comments