Skip to content

Commit 124e1e1

Browse files
committed
Improve comments and address nits.
1 parent 5f43899 commit 124e1e1

File tree

5 files changed

+54
-38
lines changed

5 files changed

+54
-38
lines changed

src/librustc/middle/traits/fulfill.rs

+25-23
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,15 @@ impl<'tcx> FulfillmentContext<'tcx> {
250250
self.predicates.retain(|predicate| {
251251
// Hack: Retain does not pass in the index, but we want
252252
// to avoid processing the first `start_count` entries.
253-
if skip == 0 {
254-
retain_predicate(selcx, predicate,
255-
&mut selections, &mut errors, region_obligations)
256-
} else {
257-
skip -= 1;
258-
true
259-
}
253+
let processed =
254+
if skip == 0 {
255+
process_predicate(selcx, predicate,
256+
&mut selections, &mut errors, region_obligations)
257+
} else {
258+
skip -= 1;
259+
false
260+
};
261+
!processed
260262
});
261263
}
262264

@@ -286,17 +288,17 @@ impl<'tcx> FulfillmentContext<'tcx> {
286288
}
287289
}
288290

289-
fn retain_predicate<'a,'tcx>(selcx: &mut SelectionContext<'a,'tcx>,
290-
predicate: &PredicateObligation<'tcx>,
291-
selections: &mut Vec<Selection<'tcx>>,
292-
errors: &mut Vec<FulfillmentError<'tcx>>,
293-
region_obligations: &mut NodeMap<Vec<RegionObligation<'tcx>>>)
294-
-> bool
291+
fn process_predicate<'a,'tcx>(selcx: &mut SelectionContext<'a,'tcx>,
292+
predicate: &PredicateObligation<'tcx>,
293+
selections: &mut Vec<Selection<'tcx>>,
294+
errors: &mut Vec<FulfillmentError<'tcx>>,
295+
region_obligations: &mut NodeMap<Vec<RegionObligation<'tcx>>>)
296+
-> bool
295297
{
296298
/*!
297-
* Evaluates a predicate obligation and modifies the appropriate
298-
* output array. Returns `true` if the predicate must be retained
299-
* because it could not be fully evaluated yet due to insufficient
299+
* Processes a predicate obligation and modifies the appropriate
300+
* output array with the successful/error result. Returns `false`
301+
* if the predicate could not be processed due to insufficient
300302
* type inference.
301303
*/
302304

@@ -308,11 +310,11 @@ fn retain_predicate<'a,'tcx>(selcx: &mut SelectionContext<'a,'tcx>,
308310
trait_ref: trait_ref.clone() };
309311
match selcx.select(&trait_obligation) {
310312
Ok(None) => {
311-
true
313+
false
312314
}
313315
Ok(Some(s)) => {
314316
selections.push(s);
315-
false
317+
true
316318
}
317319
Err(selection_err) => {
318320
debug!("predicate: {} error: {}",
@@ -322,7 +324,7 @@ fn retain_predicate<'a,'tcx>(selcx: &mut SelectionContext<'a,'tcx>,
322324
FulfillmentError::new(
323325
predicate.clone(),
324326
CodeSelectionError(selection_err)));
325-
false
327+
true
326328
}
327329
}
328330
}
@@ -331,27 +333,27 @@ fn retain_predicate<'a,'tcx>(selcx: &mut SelectionContext<'a,'tcx>,
331333
let origin = infer::EquatePredicate(predicate.cause.span);
332334
match infer::mk_eqty(selcx.infcx(), false, origin, a, b) {
333335
Ok(()) => {
334-
false
336+
true
335337
}
336338
Err(_) => {
337339
errors.push(
338340
FulfillmentError::new(
339341
predicate.clone(),
340342
CodeSelectionError(Unimplemented)));
341-
false
343+
true
342344
}
343345
}
344346
}
345347

346348
ty::Predicate::RegionOutlives(r_a, r_b) => {
347349
let origin = infer::RelateRegionParamBound(predicate.cause.span);
348350
let () = infer::mk_subr(selcx.infcx(), origin, r_b, r_a); // `b : a` ==> `a <= b`
349-
false
351+
true
350352
}
351353

352354
ty::Predicate::TypeOutlives(t_a, r_b) => {
353355
register_region_obligation(tcx, t_a, r_b, predicate.cause, region_obligations);
354-
false
356+
true
355357
}
356358
}
357359
}

src/librustc/middle/traits/mod.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,12 @@ pub type TraitObligation<'tcx> = Obligation<'tcx, Rc<ty::TraitRef<'tcx>>>;
6161
pub struct ObligationCause<'tcx> {
6262
pub span: Span,
6363

64-
// the id of XXX
64+
// The id of the fn body that triggered this obligation. This is
65+
// used for region obligations to determine the precise
66+
// environment in which the region obligation should be evaluated
67+
// (in particular, closures can add new assumptions). See the
68+
// field `region_obligations` of the `FulfillmentContext` for more
69+
// information.
6570
pub body_id: ast::NodeId,
6671

6772
pub code: ObligationCauseCode<'tcx>

src/librustc/middle/traits/util.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,16 @@ use super::{Obligation, ObligationCause, PredicateObligation,
2424
VtableImpl, VtableParam, VtableParamData, VtableImplData};
2525

2626
///////////////////////////////////////////////////////////////////////////
27-
// Elaboration iterator
27+
// `Elaboration` iterator
28+
///////////////////////////////////////////////////////////////////////////
2829

30+
/// "Elaboration" is the process of identifying all the predicates that
31+
/// are implied by a source predicate. Currently this basically means
32+
/// walking the "supertraits" and other similar assumptions. For
33+
/// example, if we know that `T : Ord`, the elaborator would deduce
34+
/// that `T : PartialOrd` holds as well. Similarly, if we have `trait
35+
/// Foo : 'static`, and we know that `T : Foo`, then we know that `T :
36+
/// 'static`.
2937
pub struct Elaborator<'cx, 'tcx:'cx> {
3038
tcx: &'cx ty::ctxt<'tcx>,
3139
stack: Vec<StackEntry<'tcx>>,
@@ -157,7 +165,10 @@ impl<'cx, 'tcx> Iterator<ty::Predicate<'tcx>> for Elaborator<'cx, 'tcx> {
157165

158166
///////////////////////////////////////////////////////////////////////////
159167
// Supertrait iterator
168+
///////////////////////////////////////////////////////////////////////////
160169

170+
/// A filter around the `Elaborator` that just yields up supertrait references,
171+
/// not other kinds of predicates.
161172
pub struct Supertraits<'cx, 'tcx:'cx> {
162173
elaborator: Elaborator<'cx, 'tcx>,
163174
}
@@ -197,6 +208,8 @@ impl<'cx, 'tcx> Iterator<Rc<ty::TraitRef<'tcx>>> for Supertraits<'cx, 'tcx> {
197208
}
198209
}
199210

211+
///////////////////////////////////////////////////////////////////////////
212+
// Other
200213
///////////////////////////////////////////////////////////////////////////
201214

202215
// determine the `self` type, using fresh variables for all variables

src/librustc/middle/ty.rs

+9-12
Original file line numberDiff line numberDiff line change
@@ -1656,14 +1656,16 @@ impl<'tcx> Generics<'tcx> {
16561656

16571657
#[deriving(Clone, PartialEq, Eq, Hash, Show)]
16581658
pub enum Predicate<'tcx> {
1659-
/// where Foo : Bar
1659+
/// Corresponds to `where Foo : Bar<A,B,C>`. `Foo` here would be
1660+
/// the `Self` type of the trait reference and `A`, `B`, and `C`
1661+
/// would be the parameters in the `TypeSpace`.
16601662
Trait(Rc<TraitRef<'tcx>>),
16611663

1662-
/// where Foo == Bar
1663-
Equate(Ty<'tcx>, Ty<'tcx>),
1664+
/// where `T1 == T2`.
1665+
Equate(/* T1 */ Ty<'tcx>, /* T2 */ Ty<'tcx>),
16641666

16651667
/// where 'a : 'b
1666-
RegionOutlives(Region, Region),
1668+
RegionOutlives(/* 'a */ Region, /* 'b */ Region),
16671669

16681670
/// where T : 'a
16691671
TypeOutlives(Ty<'tcx>, Region),
@@ -1807,7 +1809,6 @@ impl<'tcx> ParameterEnvironment<'tcx> {
18071809
let method_generics = &method_ty.generics;
18081810
construct_parameter_environment(
18091811
cx,
1810-
method.span,
18111812
method_generics,
18121813
method.pe_body().id)
18131814
}
@@ -1842,7 +1843,6 @@ impl<'tcx> ParameterEnvironment<'tcx> {
18421843
let method_generics = &method_ty.generics;
18431844
construct_parameter_environment(
18441845
cx,
1845-
method.span,
18461846
method_generics,
18471847
method.pe_body().id)
18481848
}
@@ -1869,7 +1869,6 @@ impl<'tcx> ParameterEnvironment<'tcx> {
18691869
let fn_pty = ty::lookup_item_type(cx, fn_def_id);
18701870

18711871
construct_parameter_environment(cx,
1872-
item.span,
18731872
&fn_pty.generics,
18741873
body.id)
18751874
}
@@ -1880,8 +1879,7 @@ impl<'tcx> ParameterEnvironment<'tcx> {
18801879
ast::ItemStatic(..) => {
18811880
let def_id = ast_util::local_def(id);
18821881
let pty = ty::lookup_item_type(cx, def_id);
1883-
construct_parameter_environment(cx, item.span,
1884-
&pty.generics, id)
1882+
construct_parameter_environment(cx, &pty.generics, id)
18851883
}
18861884
_ => {
18871885
cx.sess.span_bug(item.span,
@@ -5031,8 +5029,8 @@ pub fn lookup_trait_def<'tcx>(cx: &ctxt<'tcx>, did: ast::DefId)
50315029
})
50325030
}
50335031

5034-
/// Given a reference to a trait, returns the bounds declared on the
5035-
/// trait, with appropriate substitutions applied.
5032+
/// Given a reference to a trait, returns the "superbounds" declared
5033+
/// on the trait, with appropriate substitutions applied.
50365034
pub fn predicates_for_trait_ref<'tcx>(tcx: &ctxt<'tcx>,
50375035
trait_ref: &TraitRef<'tcx>)
50385036
-> Vec<ty::Predicate<'tcx>>
@@ -5929,7 +5927,6 @@ pub fn empty_parameter_environment<'tcx>() -> ParameterEnvironment<'tcx> {
59295927
/// See `ParameterEnvironment` struct def'n for details
59305928
pub fn construct_parameter_environment<'tcx>(
59315929
tcx: &ctxt<'tcx>,
5932-
_span: Span,
59335930
generics: &ty::Generics<'tcx>,
59345931
free_id: ast::NodeId)
59355932
-> ParameterEnvironment<'tcx>

src/librustc_typeck/check/wf.rs

-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
9191
let polytype = ty::lookup_item_type(ccx.tcx, item_def_id);
9292
let param_env =
9393
ty::construct_parameter_environment(ccx.tcx,
94-
item.span,
9594
&polytype.generics,
9695
item.id);
9796
let inh = Inherited::new(ccx.tcx, param_env);

0 commit comments

Comments
 (0)