Skip to content

Commit 01fb206

Browse files
committed
do more stuff
1 parent 0b728a0 commit 01fb206

File tree

5 files changed

+74
-14
lines changed

5 files changed

+74
-14
lines changed

chalk-integration/src/lowering.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1241,7 +1241,7 @@ impl LowerTrait for TraitDefn {
12411241
binders: binders,
12421242
flags: self.flags.lower(),
12431243
associated_ty_ids,
1244-
well_known: self.well_known.as_ref().map(|t| t.lower()),
1244+
well_known: self.well_known.map(|t| t.lower()),
12451245
})
12461246
}
12471247
}

chalk-parse/src/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub struct TraitDefn {
5151
pub well_known: Option<WellKnownTrait>,
5252
}
5353

54-
#[derive(Clone, PartialEq, Eq, Debug)]
54+
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
5555
pub enum WellKnownTrait {
5656
SizedTrait,
5757
}

chalk-rust-ir/src/lib.rs

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,35 @@ pub struct StructFlags {
8787
}
8888

8989
#[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:
9192
///
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
94114
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
95119
pub id: TraitId<I>,
96120

97121
pub binders: Binders<TraitDatumBound<I>>,
@@ -101,15 +125,18 @@ pub struct TraitDatum<I: Interner> {
101125
/// chalk we add annotations like `#[auto]`.
102126
pub flags: TraitFlags,
103127

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
105132
pub associated_ty_ids: Vec<AssocTypeId<I>>,
106133

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.
109136
pub well_known: Option<WellKnownTrait>,
110137
}
111138

112-
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
139+
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
113140
pub enum WellKnownTrait {
114141
SizedTrait,
115142
}
@@ -141,18 +168,34 @@ pub struct TraitDatumBound<I: Interner> {
141168

142169
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
143170
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`.
144175
pub auto: bool,
176+
145177
pub marker: bool,
178+
146179
/// Indicate that a trait is defined upstream (in a dependency), used during
147180
/// coherence checking.
148181
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.
151190
pub fundamental: bool,
191+
152192
/// 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.
155197
pub non_enumerable: bool,
198+
156199
pub coinductive: bool,
157200
}
158201

chalk-solve/src/clauses.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,9 @@ fn program_clauses_that_could_match<I: Interner>(
237237
}
238238
}
239239

240-
// TODO sized, unsize_trait, builtin impls?
240+
if let Some(well_known) = trait_datum.well_known {
241+
builtin_traits::add_builtin_program_clauses(well_known, trait_ref, builder);
242+
}
241243
}
242244
DomainGoal::Holds(WhereClause::AliasEq(alias_predicate)) => {
243245
db.associated_ty_data(alias_predicate.alias.associated_ty_id)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,16 @@
1+
use crate::{TraitRef, WellKnownTrait};
2+
use crate::Interner;
3+
use super::builder::ClauseBuilder;
4+
5+
pub fn add_builtin_program_clauses<I: Interner>(
6+
well_known: WellKnownTrait,
7+
_trait_ref: &TraitRef<I>,
8+
_builder: &mut ClauseBuilder<I>,
9+
) {
10+
match well_known {
11+
WellKnownTrait::SizedTrait => {
12+
/* TODO */
13+
}
14+
}
15+
}
116

0 commit comments

Comments
 (0)