Thread a id to Obligation

This commit is contained in:
Niko Matsakis 2014-12-05 01:59:17 -05:00
parent 4efaddf7c9
commit 9bdd7f0040
12 changed files with 48 additions and 26 deletions

View File

@ -36,7 +36,7 @@ use util::nodemap::NodeSet;
use syntax::ast;
use syntax::print::pprust;
use syntax::visit::Visitor;
use syntax::codemap::{DUMMY_SP, Span};
use syntax::codemap::Span;
use syntax::visit;
#[deriving(Eq, PartialEq)]
@ -119,7 +119,7 @@ impl<'a, 'tcx> CheckStaticVisitor<'a, 'tcx> {
let ty = ty::node_id_to_type(self.tcx, e.id);
let infcx = infer::new_infer_ctxt(self.tcx);
let mut fulfill_cx = traits::FulfillmentContext::new();
let cause = traits::ObligationCause::misc(DUMMY_SP);
let cause = traits::ObligationCause::dummy();
let obligation = traits::obligation_for_builtin_bound(self.tcx, cause, ty,
ty::BoundSync);
fulfill_cx.register_obligation(self.tcx, obligation.unwrap());

View File

@ -11,7 +11,7 @@
//! See `doc.rs` for high-level documentation
use super::SelectionContext;
use super::Obligation;
use super::{Obligation, ObligationCause};
use super::util;
use middle::subst;
@ -48,7 +48,7 @@ pub fn impl_can_satisfy(infcx: &InferCtxt,
// same types.
let param_env = ty::empty_parameter_environment();
let mut selcx = SelectionContext::intercrate(infcx, &param_env, infcx.tcx);
let obligation = Obligation::misc(DUMMY_SP, impl1_trait_ref);
let obligation = Obligation::new(ObligationCause::dummy(), impl1_trait_ref);
debug!("impl_can_satisfy(obligation={})", obligation.repr(infcx.tcx));
selcx.evaluate_impl(impl2_def_id, &obligation)
}

View File

@ -59,6 +59,10 @@ pub type TraitObligation<'tcx> = Obligation<'tcx, Rc<ty::TraitRef<'tcx>>>;
#[deriving(Copy, Clone)]
pub struct ObligationCause<'tcx> {
pub span: Span,
// the id of XXX
pub scope_id: ast::NodeId,
pub code: ObligationCauseCode<'tcx>
}
@ -303,8 +307,8 @@ impl<'tcx,O> Obligation<'tcx,O> {
trait_ref: trait_ref }
}
pub fn misc(span: Span, trait_ref: O) -> Obligation<'tcx, O> {
Obligation::new(ObligationCause::misc(span), trait_ref)
pub fn misc(span: Span, scope_id: ast::NodeId, trait_ref: O) -> Obligation<'tcx, O> {
Obligation::new(ObligationCause::misc(span, scope_id), trait_ref)
}
}
@ -315,17 +319,19 @@ impl<'tcx> Obligation<'tcx,Rc<ty::TraitRef<'tcx>>> {
}
impl<'tcx> ObligationCause<'tcx> {
pub fn new(span: Span, code: ObligationCauseCode<'tcx>)
pub fn new(span: Span,
scope_id: ast::NodeId,
code: ObligationCauseCode<'tcx>)
-> ObligationCause<'tcx> {
ObligationCause { span: span, code: code }
ObligationCause { span: span, scope_id: scope_id, code: code }
}
pub fn misc(span: Span) -> ObligationCause<'tcx> {
ObligationCause { span: span, code: MiscObligation }
pub fn misc(span: Span, scope_id: ast::NodeId) -> ObligationCause<'tcx> {
ObligationCause { span: span, scope_id: scope_id, code: MiscObligation }
}
pub fn dummy() -> ObligationCause<'tcx> {
ObligationCause { span: DUMMY_SP, code: MiscObligation }
ObligationCause { span: DUMMY_SP, scope_id: 0, code: MiscObligation }
}
}

View File

@ -78,7 +78,7 @@ use std::rc::Rc;
use std::collections::hash_map::{HashMap, Occupied, Vacant};
use arena::TypedArena;
use syntax::abi;
use syntax::ast::{CrateNum, DefId, FnStyle, Ident, ItemTrait, LOCAL_CRATE};
use syntax::ast::{CrateNum, DefId, DUMMY_NODE_ID, FnStyle, Ident, ItemTrait, LOCAL_CRATE};
use syntax::ast::{MutImmutable, MutMutable, Name, NamedField, NodeId};
use syntax::ast::{Onceness, StmtExpr, StmtSemi, StructField, UnnamedField};
use syntax::ast::{Visibility};
@ -3158,9 +3158,15 @@ pub fn type_moves_by_default<'tcx>(cx: &ctxt<'tcx>,
let infcx = infer::new_infer_ctxt(cx);
let mut fulfill_cx = traits::FulfillmentContext::new();
// we can use dummy values here because we won't report any errors
// that result nor will we pay any mind to region obligations that arise
// (there shouldn't really be any anyhow)
let cause = ObligationCause::misc(DUMMY_SP, DUMMY_NODE_ID);
let obligation = traits::obligation_for_builtin_bound(
cx,
ObligationCause::misc(DUMMY_SP),
cause,
ty,
ty::BoundCopy).unwrap();
fulfill_cx.register_obligation(cx, obligation);
@ -5846,7 +5852,7 @@ pub fn empty_parameter_environment<'tcx>() -> ParameterEnvironment<'tcx> {
/// See `ParameterEnvironment` struct def'n for details
pub fn construct_parameter_environment<'tcx>(
tcx: &ctxt<'tcx>,
span: Span,
_span: Span,
generics: &ty::Generics<'tcx>,
free_id: ast::NodeId)
-> ParameterEnvironment<'tcx>
@ -5884,7 +5890,7 @@ pub fn construct_parameter_environment<'tcx>(
let bounds = generics.to_bounds(tcx, &free_substs);
let bounds = liberate_late_bound_regions(tcx, free_id_scope, &bind(bounds)).value;
let obligations = traits::obligations_for_generics(tcx,
traits::ObligationCause::misc(span),
traits::ObligationCause::dummy(),
&bounds,
&free_substs.types);
let type_bounds = bounds.types.subst(tcx, &free_substs);

View File

@ -793,7 +793,8 @@ pub fn fulfill_obligation<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
// Do the initial selection for the obligation. This yields the
// shallow result we are looking for -- that is, what specific impl.
let mut selcx = traits::SelectionContext::new(&infcx, &param_env, tcx);
let obligation = traits::Obligation::misc(span, trait_ref.clone());
let obligation = traits::Obligation::new(traits::ObligationCause::dummy(),
trait_ref.clone());
let selection = match selcx.select(&obligation) {
Ok(Some(selection)) => selection,
Ok(None) => {

View File

@ -462,7 +462,7 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> {
method_bounds.repr(self.tcx()));
self.fcx.add_obligations_for_parameters(
traits::ObligationCause::misc(self.span),
traits::ObligationCause::misc(self.span, self.fcx.body_id),
method_bounds_substs,
method_bounds);

View File

@ -169,7 +169,7 @@ pub fn lookup_in_trait_adjusted<'a, 'tcx>(fcx: &'a FnCtxt<'a, 'tcx>,
let trait_ref = Rc::new(ty::TraitRef::new(trait_def_id, substs));
// Construct an obligation
let obligation = traits::Obligation::misc(span, trait_ref.clone());
let obligation = traits::Obligation::misc(span, fcx.body_id, trait_ref.clone());
// Now we want to know if this can be matched
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>,
let method_bounds = method_ty.generics.to_bounds(fcx.tcx(), &trait_ref.substs);
assert!(!method_bounds.has_escaping_regions());
fcx.add_obligations_for_parameters(
traits::ObligationCause::misc(span),
traits::ObligationCause::misc(span, fcx.body_id),
&trait_ref.substs,
&method_bounds);

View File

@ -804,7 +804,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
let obligations =
traits::obligations_for_generics(
self.tcx(),
traits::ObligationCause::misc(self.span),
traits::ObligationCause::misc(self.span, self.fcx.body_id),
&impl_bounds,
&substs.types);
debug!("impl_obligations={}", obligations.repr(self.tcx()));

View File

@ -1790,6 +1790,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.add_obligations_for_parameters(
traits::ObligationCause::new(
span,
self.body_id,
traits::ItemObligation(def_id)),
&substs,
&bounds);
@ -1817,7 +1818,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
{
let obligation = traits::obligation_for_builtin_bound(
self.tcx(),
traits::ObligationCause::new(span, code),
traits::ObligationCause::new(span, self.body_id, code),
ty,
bound);
if let Ok(ob) = obligation {
@ -5197,7 +5198,7 @@ pub fn instantiate_path<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
debug!("after late-bounds have been replaced: bounds={}", bounds.repr(fcx.tcx()));
fcx.add_obligations_for_parameters(
traits::ObligationCause::new(span, traits::ItemObligation(def.def_id())),
traits::ObligationCause::new(span, fcx.body_id, traits::ItemObligation(def.def_id())),
&substs,
&bounds);

View File

@ -938,7 +938,7 @@ fn check_expr_fn_block(rcx: &mut Rcx,
// Check that the type meets the criteria of the existential bounds:
for builtin_bound in bounds.builtin_bounds.iter() {
let code = traits::ClosureCapture(var_node_id, expr.span);
let cause = traits::ObligationCause::new(freevar.span, code);
let cause = traits::ObligationCause::new(freevar.span, rcx.fcx.body_id, code);
let obligation = traits::obligation_for_builtin_bound(rcx.tcx(), cause,
var_ty, builtin_bound);
if let Ok(obligation) = obligation {

View File

@ -252,7 +252,7 @@ pub fn register_object_cast_obligations<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
let sized_obligation =
traits::obligation_for_builtin_bound(
fcx.tcx(),
traits::ObligationCause::new(span, traits::ObjectSized),
traits::ObligationCause::new(span, fcx.body_id, traits::ObjectSized),
referent_ty,
ty::BoundSized);
match sized_obligation {
@ -287,6 +287,7 @@ pub fn register_object_cast_obligations<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
let object_obligation =
Obligation::new(
ObligationCause::new(span,
fcx.body_id,
traits::ObjectCastObligation(object_trait_ty)),
object_trait_ref.clone());
fcx.register_obligation(object_obligation);
@ -299,6 +300,7 @@ pub fn register_object_cast_obligations<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
let obligation = obligation_for_builtin_bound(
fcx.tcx(),
ObligationCause::new(span,
fcx.body_id,
traits::ObjectCastObligation(object_trait_ty)),
referent_ty,
builtin_bound);

View File

@ -122,7 +122,9 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
// For DST, all intermediate types must be sized.
if variant.fields.len() > 0 {
for field in variant.fields.init().iter() {
let cause = traits::ObligationCause::new(field.span, traits::FieldSized);
let cause = traits::ObligationCause::new(field.span,
fcx.body_id,
traits::FieldSized);
let obligation = traits::obligation_for_builtin_bound(fcx.tcx(),
cause,
field.ty,
@ -223,6 +225,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
let cause =
traits::ObligationCause::new(
item.span,
fcx.body_id,
traits::ItemObligation(trait_ref.def_id));
// Find the supertrait bounds. This will add `int:Bar`.
@ -291,6 +294,7 @@ impl<'cx,'tcx> BoundsChecker<'cx,'tcx> {
self.fcx.add_obligations_for_parameters(
traits::ObligationCause::new(
self.span,
self.fcx.body_id,
traits::ItemObligation(trait_ref.def_id)),
&trait_ref.substs,
&bounds);
@ -341,6 +345,7 @@ impl<'cx,'tcx> TypeFolder<'tcx> for BoundsChecker<'cx,'tcx> {
if self.binding_count == 0 {
self.fcx.add_obligations_for_parameters(
traits::ObligationCause::new(self.span,
self.fcx.body_id,
traits::ItemObligation(type_id)),
substs,
&polytype.generics.to_bounds(self.tcx(), substs));
@ -369,6 +374,7 @@ impl<'cx,'tcx> TypeFolder<'tcx> for BoundsChecker<'cx,'tcx> {
// that will require an RFC. -nmatsakis)
self.fcx.add_trait_obligations_for_generics(
traits::ObligationCause::new(self.span,
self.fcx.body_id,
traits::ItemObligation(type_id)),
substs,
&polytype.generics.to_bounds(self.tcx(), substs));
@ -469,7 +475,7 @@ fn check_struct_safe_for_destructor<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
if !struct_tpt.generics.has_type_params(subst::TypeSpace)
&& !struct_tpt.generics.has_region_params(subst::TypeSpace)
{
let cause = traits::ObligationCause::new(span, traits::DropTrait);
let cause = traits::ObligationCause::new(span, fcx.body_id, traits::DropTrait);
let obligation = traits::obligation_for_builtin_bound(fcx.tcx(),
cause,
self_ty,