Skip to content

Commit 9bdd7f0

Browse files
committed
Thread a id to Obligation
1 parent 4efaddf commit 9bdd7f0

File tree

12 files changed

+48
-26
lines changed

12 files changed

+48
-26
lines changed

src/librustc/middle/check_static.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use util::nodemap::NodeSet;
3636
use syntax::ast;
3737
use syntax::print::pprust;
3838
use syntax::visit::Visitor;
39-
use syntax::codemap::{DUMMY_SP, Span};
39+
use syntax::codemap::Span;
4040
use syntax::visit;
4141

4242
#[deriving(Eq, PartialEq)]
@@ -119,7 +119,7 @@ impl<'a, 'tcx> CheckStaticVisitor<'a, 'tcx> {
119119
let ty = ty::node_id_to_type(self.tcx, e.id);
120120
let infcx = infer::new_infer_ctxt(self.tcx);
121121
let mut fulfill_cx = traits::FulfillmentContext::new();
122-
let cause = traits::ObligationCause::misc(DUMMY_SP);
122+
let cause = traits::ObligationCause::dummy();
123123
let obligation = traits::obligation_for_builtin_bound(self.tcx, cause, ty,
124124
ty::BoundSync);
125125
fulfill_cx.register_obligation(self.tcx, obligation.unwrap());

src/librustc/middle/traits/coherence.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//! See `doc.rs` for high-level documentation
1212
1313
use super::SelectionContext;
14-
use super::Obligation;
14+
use super::{Obligation, ObligationCause};
1515
use super::util;
1616

1717
use middle::subst;
@@ -48,7 +48,7 @@ pub fn impl_can_satisfy(infcx: &InferCtxt,
4848
// same types.
4949
let param_env = ty::empty_parameter_environment();
5050
let mut selcx = SelectionContext::intercrate(infcx, &param_env, infcx.tcx);
51-
let obligation = Obligation::misc(DUMMY_SP, impl1_trait_ref);
51+
let obligation = Obligation::new(ObligationCause::dummy(), impl1_trait_ref);
5252
debug!("impl_can_satisfy(obligation={})", obligation.repr(infcx.tcx));
5353
selcx.evaluate_impl(impl2_def_id, &obligation)
5454
}

src/librustc/middle/traits/mod.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ pub type TraitObligation<'tcx> = Obligation<'tcx, Rc<ty::TraitRef<'tcx>>>;
5959
#[deriving(Copy, Clone)]
6060
pub struct ObligationCause<'tcx> {
6161
pub span: Span,
62+
63+
// the id of XXX
64+
pub scope_id: ast::NodeId,
65+
6266
pub code: ObligationCauseCode<'tcx>
6367
}
6468

@@ -303,8 +307,8 @@ impl<'tcx,O> Obligation<'tcx,O> {
303307
trait_ref: trait_ref }
304308
}
305309

306-
pub fn misc(span: Span, trait_ref: O) -> Obligation<'tcx, O> {
307-
Obligation::new(ObligationCause::misc(span), trait_ref)
310+
pub fn misc(span: Span, scope_id: ast::NodeId, trait_ref: O) -> Obligation<'tcx, O> {
311+
Obligation::new(ObligationCause::misc(span, scope_id), trait_ref)
308312
}
309313
}
310314

@@ -315,17 +319,19 @@ impl<'tcx> Obligation<'tcx,Rc<ty::TraitRef<'tcx>>> {
315319
}
316320

317321
impl<'tcx> ObligationCause<'tcx> {
318-
pub fn new(span: Span, code: ObligationCauseCode<'tcx>)
322+
pub fn new(span: Span,
323+
scope_id: ast::NodeId,
324+
code: ObligationCauseCode<'tcx>)
319325
-> ObligationCause<'tcx> {
320-
ObligationCause { span: span, code: code }
326+
ObligationCause { span: span, scope_id: scope_id, code: code }
321327
}
322328

323-
pub fn misc(span: Span) -> ObligationCause<'tcx> {
324-
ObligationCause { span: span, code: MiscObligation }
329+
pub fn misc(span: Span, scope_id: ast::NodeId) -> ObligationCause<'tcx> {
330+
ObligationCause { span: span, scope_id: scope_id, code: MiscObligation }
325331
}
326332

327333
pub fn dummy() -> ObligationCause<'tcx> {
328-
ObligationCause { span: DUMMY_SP, code: MiscObligation }
334+
ObligationCause { span: DUMMY_SP, scope_id: 0, code: MiscObligation }
329335
}
330336
}
331337

src/librustc/middle/ty.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ use std::rc::Rc;
7878
use std::collections::hash_map::{HashMap, Occupied, Vacant};
7979
use arena::TypedArena;
8080
use syntax::abi;
81-
use syntax::ast::{CrateNum, DefId, FnStyle, Ident, ItemTrait, LOCAL_CRATE};
81+
use syntax::ast::{CrateNum, DefId, DUMMY_NODE_ID, FnStyle, Ident, ItemTrait, LOCAL_CRATE};
8282
use syntax::ast::{MutImmutable, MutMutable, Name, NamedField, NodeId};
8383
use syntax::ast::{Onceness, StmtExpr, StmtSemi, StructField, UnnamedField};
8484
use syntax::ast::{Visibility};
@@ -3158,9 +3158,15 @@ pub fn type_moves_by_default<'tcx>(cx: &ctxt<'tcx>,
31583158

31593159
let infcx = infer::new_infer_ctxt(cx);
31603160
let mut fulfill_cx = traits::FulfillmentContext::new();
3161+
3162+
// we can use dummy values here because we won't report any errors
3163+
// that result nor will we pay any mind to region obligations that arise
3164+
// (there shouldn't really be any anyhow)
3165+
let cause = ObligationCause::misc(DUMMY_SP, DUMMY_NODE_ID);
3166+
31613167
let obligation = traits::obligation_for_builtin_bound(
31623168
cx,
3163-
ObligationCause::misc(DUMMY_SP),
3169+
cause,
31643170
ty,
31653171
ty::BoundCopy).unwrap();
31663172
fulfill_cx.register_obligation(cx, obligation);
@@ -5846,7 +5852,7 @@ pub fn empty_parameter_environment<'tcx>() -> ParameterEnvironment<'tcx> {
58465852
/// See `ParameterEnvironment` struct def'n for details
58475853
pub fn construct_parameter_environment<'tcx>(
58485854
tcx: &ctxt<'tcx>,
5849-
span: Span,
5855+
_span: Span,
58505856
generics: &ty::Generics<'tcx>,
58515857
free_id: ast::NodeId)
58525858
-> ParameterEnvironment<'tcx>
@@ -5884,7 +5890,7 @@ pub fn construct_parameter_environment<'tcx>(
58845890
let bounds = generics.to_bounds(tcx, &free_substs);
58855891
let bounds = liberate_late_bound_regions(tcx, free_id_scope, &bind(bounds)).value;
58865892
let obligations = traits::obligations_for_generics(tcx,
5887-
traits::ObligationCause::misc(span),
5893+
traits::ObligationCause::dummy(),
58885894
&bounds,
58895895
&free_substs.types);
58905896
let type_bounds = bounds.types.subst(tcx, &free_substs);

src/librustc_trans/trans/common.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,8 @@ pub fn fulfill_obligation<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
793793
// Do the initial selection for the obligation. This yields the
794794
// shallow result we are looking for -- that is, what specific impl.
795795
let mut selcx = traits::SelectionContext::new(&infcx, &param_env, tcx);
796-
let obligation = traits::Obligation::misc(span, trait_ref.clone());
796+
let obligation = traits::Obligation::new(traits::ObligationCause::dummy(),
797+
trait_ref.clone());
797798
let selection = match selcx.select(&obligation) {
798799
Ok(Some(selection)) => selection,
799800
Ok(None) => {

src/librustc_typeck/check/method/confirm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> {
462462
method_bounds.repr(self.tcx()));
463463

464464
self.fcx.add_obligations_for_parameters(
465-
traits::ObligationCause::misc(self.span),
465+
traits::ObligationCause::misc(self.span, self.fcx.body_id),
466466
method_bounds_substs,
467467
method_bounds);
468468

src/librustc_typeck/check/method/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ pub fn lookup_in_trait_adjusted<'a, 'tcx>(fcx: &'a FnCtxt<'a, 'tcx>,
169169
let trait_ref = Rc::new(ty::TraitRef::new(trait_def_id, substs));
170170

171171
// Construct an obligation
172-
let obligation = traits::Obligation::misc(span, trait_ref.clone());
172+
let obligation = traits::Obligation::misc(span, fcx.body_id, trait_ref.clone());
173173

174174
// Now we want to know if this can be matched
175175
let mut selcx = traits::SelectionContext::new(fcx.infcx(),
@@ -219,7 +219,7 @@ pub fn lookup_in_trait_adjusted<'a, 'tcx>(fcx: &'a FnCtxt<'a, 'tcx>,
219219
let method_bounds = method_ty.generics.to_bounds(fcx.tcx(), &trait_ref.substs);
220220
assert!(!method_bounds.has_escaping_regions());
221221
fcx.add_obligations_for_parameters(
222-
traits::ObligationCause::misc(span),
222+
traits::ObligationCause::misc(span, fcx.body_id),
223223
&trait_ref.substs,
224224
&method_bounds);
225225

src/librustc_typeck/check/method/probe.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
804804
let obligations =
805805
traits::obligations_for_generics(
806806
self.tcx(),
807-
traits::ObligationCause::misc(self.span),
807+
traits::ObligationCause::misc(self.span, self.fcx.body_id),
808808
&impl_bounds,
809809
&substs.types);
810810
debug!("impl_obligations={}", obligations.repr(self.tcx()));

src/librustc_typeck/check/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1790,6 +1790,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17901790
self.add_obligations_for_parameters(
17911791
traits::ObligationCause::new(
17921792
span,
1793+
self.body_id,
17931794
traits::ItemObligation(def_id)),
17941795
&substs,
17951796
&bounds);
@@ -1817,7 +1818,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18171818
{
18181819
let obligation = traits::obligation_for_builtin_bound(
18191820
self.tcx(),
1820-
traits::ObligationCause::new(span, code),
1821+
traits::ObligationCause::new(span, self.body_id, code),
18211822
ty,
18221823
bound);
18231824
if let Ok(ob) = obligation {
@@ -5197,7 +5198,7 @@ pub fn instantiate_path<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
51975198
debug!("after late-bounds have been replaced: bounds={}", bounds.repr(fcx.tcx()));
51985199

51995200
fcx.add_obligations_for_parameters(
5200-
traits::ObligationCause::new(span, traits::ItemObligation(def.def_id())),
5201+
traits::ObligationCause::new(span, fcx.body_id, traits::ItemObligation(def.def_id())),
52015202
&substs,
52025203
&bounds);
52035204

src/librustc_typeck/check/regionck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,7 @@ fn check_expr_fn_block(rcx: &mut Rcx,
938938
// Check that the type meets the criteria of the existential bounds:
939939
for builtin_bound in bounds.builtin_bounds.iter() {
940940
let code = traits::ClosureCapture(var_node_id, expr.span);
941-
let cause = traits::ObligationCause::new(freevar.span, code);
941+
let cause = traits::ObligationCause::new(freevar.span, rcx.fcx.body_id, code);
942942
let obligation = traits::obligation_for_builtin_bound(rcx.tcx(), cause,
943943
var_ty, builtin_bound);
944944
if let Ok(obligation) = obligation {

src/librustc_typeck/check/vtable.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ pub fn register_object_cast_obligations<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
252252
let sized_obligation =
253253
traits::obligation_for_builtin_bound(
254254
fcx.tcx(),
255-
traits::ObligationCause::new(span, traits::ObjectSized),
255+
traits::ObligationCause::new(span, fcx.body_id, traits::ObjectSized),
256256
referent_ty,
257257
ty::BoundSized);
258258
match sized_obligation {
@@ -287,6 +287,7 @@ pub fn register_object_cast_obligations<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
287287
let object_obligation =
288288
Obligation::new(
289289
ObligationCause::new(span,
290+
fcx.body_id,
290291
traits::ObjectCastObligation(object_trait_ty)),
291292
object_trait_ref.clone());
292293
fcx.register_obligation(object_obligation);
@@ -299,6 +300,7 @@ pub fn register_object_cast_obligations<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
299300
let obligation = obligation_for_builtin_bound(
300301
fcx.tcx(),
301302
ObligationCause::new(span,
303+
fcx.body_id,
302304
traits::ObjectCastObligation(object_trait_ty)),
303305
referent_ty,
304306
builtin_bound);

src/librustc_typeck/check/wf.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
122122
// For DST, all intermediate types must be sized.
123123
if variant.fields.len() > 0 {
124124
for field in variant.fields.init().iter() {
125-
let cause = traits::ObligationCause::new(field.span, traits::FieldSized);
125+
let cause = traits::ObligationCause::new(field.span,
126+
fcx.body_id,
127+
traits::FieldSized);
126128
let obligation = traits::obligation_for_builtin_bound(fcx.tcx(),
127129
cause,
128130
field.ty,
@@ -223,6 +225,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
223225
let cause =
224226
traits::ObligationCause::new(
225227
item.span,
228+
fcx.body_id,
226229
traits::ItemObligation(trait_ref.def_id));
227230

228231
// Find the supertrait bounds. This will add `int:Bar`.
@@ -291,6 +294,7 @@ impl<'cx,'tcx> BoundsChecker<'cx,'tcx> {
291294
self.fcx.add_obligations_for_parameters(
292295
traits::ObligationCause::new(
293296
self.span,
297+
self.fcx.body_id,
294298
traits::ItemObligation(trait_ref.def_id)),
295299
&trait_ref.substs,
296300
&bounds);
@@ -341,6 +345,7 @@ impl<'cx,'tcx> TypeFolder<'tcx> for BoundsChecker<'cx,'tcx> {
341345
if self.binding_count == 0 {
342346
self.fcx.add_obligations_for_parameters(
343347
traits::ObligationCause::new(self.span,
348+
self.fcx.body_id,
344349
traits::ItemObligation(type_id)),
345350
substs,
346351
&polytype.generics.to_bounds(self.tcx(), substs));
@@ -369,6 +374,7 @@ impl<'cx,'tcx> TypeFolder<'tcx> for BoundsChecker<'cx,'tcx> {
369374
// that will require an RFC. -nmatsakis)
370375
self.fcx.add_trait_obligations_for_generics(
371376
traits::ObligationCause::new(self.span,
377+
self.fcx.body_id,
372378
traits::ItemObligation(type_id)),
373379
substs,
374380
&polytype.generics.to_bounds(self.tcx(), substs));
@@ -469,7 +475,7 @@ fn check_struct_safe_for_destructor<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
469475
if !struct_tpt.generics.has_type_params(subst::TypeSpace)
470476
&& !struct_tpt.generics.has_region_params(subst::TypeSpace)
471477
{
472-
let cause = traits::ObligationCause::new(span, traits::DropTrait);
478+
let cause = traits::ObligationCause::new(span, fcx.body_id, traits::DropTrait);
473479
let obligation = traits::obligation_for_builtin_bound(fcx.tcx(),
474480
cause,
475481
self_ty,

0 commit comments

Comments
 (0)