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)]
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());
//! See `doc.rs` for high-level documentation
use super::SelectionContext;
-use super::Obligation;
+use super::{Obligation, ObligationCause};
use super::util;
use middle::subst;
// same types.
let param_env = ty::empty_parameter_environment();
let mut selcx = SelectionContext::intercrate(infcx, ¶m_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)
}
#[deriving(Copy, Clone)]
pub struct ObligationCause<'tcx> {
pub span: Span,
+
+ // the id of XXX
+ pub scope_id: ast::NodeId,
+
pub code: ObligationCauseCode<'tcx>
}
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)
}
}
}
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 }
}
}
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};
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);
/// 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>
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);
// 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, ¶m_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) => {
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);
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(),
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);
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()));
self.add_obligations_for_parameters(
traits::ObligationCause::new(
span,
+ self.body_id,
traits::ItemObligation(def_id)),
&substs,
&bounds);
{
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 {
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);
// 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 {
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 {
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);
let obligation = obligation_for_builtin_bound(
fcx.tcx(),
ObligationCause::new(span,
+ fcx.body_id,
traits::ObjectCastObligation(object_trait_ty)),
referent_ty,
builtin_bound);
// 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,
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`.
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);
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));
// 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));
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,