Skip to content

Commit 4efaddf

Browse files
committed
Start restructuring to support generalized where clauses etc.
1 parent ffc1118 commit 4efaddf

File tree

11 files changed

+112
-113
lines changed

11 files changed

+112
-113
lines changed

src/librustc/metadata/csearch.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use middle::def;
2121
use middle::lang_items;
2222
use middle::resolve;
2323
use middle::ty;
24-
use middle::subst::VecPerParamSpace;
2524

2625
use rbml;
2726
use rbml::reader;
@@ -250,9 +249,8 @@ pub fn get_field_type<'tcx>(tcx: &ty::ctxt<'tcx>, class_id: ast::DefId,
250249
});
251250
let ty = decoder::item_type(def, the_field, tcx, &*cdata);
252251
ty::Polytype {
253-
generics: ty::Generics {types: VecPerParamSpace::empty(),
254-
regions: VecPerParamSpace::empty()},
255-
ty: ty
252+
generics: ty::Generics::empty(),
253+
ty: ty,
256254
}
257255
}
258256

src/librustc/middle/astencode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1553,7 +1553,7 @@ impl<'a, 'tcx> rbml_decoder_decoder_helpers<'tcx> for reader::Decoder<'a> {
15531553
this.read_struct_field("regions", 1, |this| {
15541554
Ok(this.read_vec_per_param_space(
15551555
|this| Decodable::decode(this).unwrap()))
1556-
}).unwrap()
1556+
}).unwrap(),
15571557
})
15581558
})
15591559
}).unwrap(),

src/librustc/middle/traits/fulfill.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use std::rc::Rc;
1616
use util::ppaux::Repr;
1717

1818
use super::CodeAmbiguity;
19-
use super::Obligation;
19+
use super::TraitObligation;
2020
use super::FulfillmentError;
2121
use super::CodeSelectionError;
2222
use super::select::SelectionContext;
@@ -41,7 +41,7 @@ pub struct FulfillmentContext<'tcx> {
4141

4242
// A list of all obligations that have been registered with this
4343
// fulfillment context.
44-
trait_obligations: Vec<Obligation<'tcx>>,
44+
trait_obligations: Vec<TraitObligation<'tcx>>,
4545

4646
// Remembers the count of trait obligations that we have already
4747
// attempted to select. This is used to avoid repeating work
@@ -60,7 +60,7 @@ impl<'tcx> FulfillmentContext<'tcx> {
6060

6161
pub fn register_obligation(&mut self,
6262
tcx: &ty::ctxt<'tcx>,
63-
obligation: Obligation<'tcx>)
63+
obligation: TraitObligation<'tcx>)
6464
{
6565
if self.duplicate_set.insert(obligation.trait_ref.clone()) {
6666
debug!("register_obligation({})", obligation.repr(tcx));
@@ -117,7 +117,7 @@ impl<'tcx> FulfillmentContext<'tcx> {
117117
self.select(&mut selcx, false)
118118
}
119119

120-
pub fn pending_trait_obligations(&self) -> &[Obligation<'tcx>] {
120+
pub fn pending_trait_obligations(&self) -> &[TraitObligation<'tcx>] {
121121
self.trait_obligations[]
122122
}
123123

src/librustc/middle/traits/mod.rs

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,22 @@ mod util;
4747
/// provides the required vtable, or else finding a bound that is in
4848
/// scope. The eventual result is usually a `Selection` (defined below).
4949
#[deriving(Clone)]
50-
pub struct Obligation<'tcx> {
50+
pub struct Obligation<'tcx, T> {
5151
pub cause: ObligationCause<'tcx>,
5252
pub recursion_depth: uint,
53-
pub trait_ref: Rc<ty::TraitRef<'tcx>>,
53+
pub trait_ref: T,
5454
}
5555

56+
pub type TraitObligation<'tcx> = Obligation<'tcx, Rc<ty::TraitRef<'tcx>>>;
57+
5658
/// Why did we incur this obligation? Used for error reporting.
57-
#[deriving(Clone)]
59+
#[deriving(Copy, Clone)]
5860
pub struct ObligationCause<'tcx> {
5961
pub span: Span,
6062
pub code: ObligationCauseCode<'tcx>
6163
}
6264

63-
impl<'tcx> Copy for ObligationCause<'tcx> {}
64-
65-
#[deriving(Clone)]
65+
#[deriving(Copy, Clone)]
6666
pub enum ObligationCauseCode<'tcx> {
6767
/// Not well classified or should be obvious from span.
6868
MiscObligation,
@@ -95,11 +95,11 @@ pub enum ObligationCauseCode<'tcx> {
9595
ObjectSized,
9696
}
9797

98-
pub type Obligations<'tcx> = subst::VecPerParamSpace<Obligation<'tcx>>;
98+
pub type Obligations<'tcx, O> = subst::VecPerParamSpace<Obligation<'tcx, O>>;
9999

100-
impl<'tcx> Copy for ObligationCauseCode<'tcx> {}
100+
pub type TraitObligations<'tcx> = subst::VecPerParamSpace<TraitObligation<'tcx>>;
101101

102-
pub type Selection<'tcx> = Vtable<'tcx, Obligation<'tcx>>;
102+
pub type Selection<'tcx> = Vtable<'tcx, TraitObligation<'tcx>>;
103103

104104
#[deriving(Clone,Show)]
105105
pub enum SelectionError<'tcx> {
@@ -109,7 +109,7 @@ pub enum SelectionError<'tcx> {
109109
}
110110

111111
pub struct FulfillmentError<'tcx> {
112-
pub obligation: Obligation<'tcx>,
112+
pub obligation: TraitObligation<'tcx>,
113113
pub code: FulfillmentErrorCode<'tcx>
114114
}
115115

@@ -230,7 +230,7 @@ pub fn select_inherent_impl<'a,'tcx>(infcx: &InferCtxt<'a,'tcx>,
230230
impl_def_id: ast::DefId,
231231
self_ty: Ty<'tcx>)
232232
-> SelectionResult<'tcx,
233-
VtableImplData<'tcx, Obligation<'tcx>>>
233+
VtableImplData<'tcx, TraitObligation<'tcx>>>
234234
{
235235
// This routine is only suitable for inherent impls. This is
236236
// because it does not attempt to unify the output type parameters
@@ -279,7 +279,7 @@ pub fn obligations_for_generics<'tcx>(tcx: &ty::ctxt<'tcx>,
279279
cause: ObligationCause<'tcx>,
280280
generic_bounds: &ty::GenericBounds<'tcx>,
281281
type_substs: &subst::VecPerParamSpace<Ty<'tcx>>)
282-
-> subst::VecPerParamSpace<Obligation<'tcx>>
282+
-> subst::VecPerParamSpace<TraitObligation<'tcx>>
283283
{
284284
util::obligations_for_generics(tcx, cause, 0, generic_bounds, type_substs)
285285
}
@@ -288,23 +288,27 @@ pub fn obligation_for_builtin_bound<'tcx>(tcx: &ty::ctxt<'tcx>,
288288
cause: ObligationCause<'tcx>,
289289
source_ty: Ty<'tcx>,
290290
builtin_bound: ty::BuiltinBound)
291-
-> Result<Obligation<'tcx>, ErrorReported>
291+
-> Result<TraitObligation<'tcx>, ErrorReported>
292292
{
293293
util::obligation_for_builtin_bound(tcx, cause, builtin_bound, 0, source_ty)
294294
}
295295

296-
impl<'tcx> Obligation<'tcx> {
297-
pub fn new(cause: ObligationCause<'tcx>, trait_ref: Rc<ty::TraitRef<'tcx>>)
298-
-> Obligation<'tcx> {
296+
impl<'tcx,O> Obligation<'tcx,O> {
297+
pub fn new(cause: ObligationCause<'tcx>,
298+
trait_ref: O)
299+
-> Obligation<'tcx, O>
300+
{
299301
Obligation { cause: cause,
300302
recursion_depth: 0,
301303
trait_ref: trait_ref }
302304
}
303305

304-
pub fn misc(span: Span, trait_ref: Rc<ty::TraitRef<'tcx>>) -> Obligation<'tcx> {
306+
pub fn misc(span: Span, trait_ref: O) -> Obligation<'tcx, O> {
305307
Obligation::new(ObligationCause::misc(span), trait_ref)
306308
}
309+
}
307310

311+
impl<'tcx> Obligation<'tcx,Rc<ty::TraitRef<'tcx>>> {
308312
pub fn self_ty(&self) -> Ty<'tcx> {
309313
self.trait_ref.self_ty()
310314
}
@@ -406,7 +410,8 @@ impl<N> VtableBuiltinData<N> {
406410
}
407411

408412
impl<'tcx> FulfillmentError<'tcx> {
409-
fn new(obligation: Obligation<'tcx>, code: FulfillmentErrorCode<'tcx>)
413+
fn new(obligation: TraitObligation<'tcx>,
414+
code: FulfillmentErrorCode<'tcx>)
410415
-> FulfillmentError<'tcx>
411416
{
412417
FulfillmentError { obligation: obligation, code: code }

0 commit comments

Comments
 (0)