]> git.lizzy.rs Git - rust.git/commitdiff
Thread a id to `Obligation`
authorNiko Matsakis <niko@alum.mit.edu>
Fri, 5 Dec 2014 06:59:17 +0000 (01:59 -0500)
committerNiko Matsakis <niko@alum.mit.edu>
Sat, 13 Dec 2014 01:24:34 +0000 (20:24 -0500)
12 files changed:
src/librustc/middle/check_static.rs
src/librustc/middle/traits/coherence.rs
src/librustc/middle/traits/mod.rs
src/librustc/middle/ty.rs
src/librustc_trans/trans/common.rs
src/librustc_typeck/check/method/confirm.rs
src/librustc_typeck/check/method/mod.rs
src/librustc_typeck/check/method/probe.rs
src/librustc_typeck/check/mod.rs
src/librustc_typeck/check/regionck.rs
src/librustc_typeck/check/vtable.rs
src/librustc_typeck/check/wf.rs

index a495d1e049d17601ac8386d4983d27de20dbfe6d..9aa258c16aa16f7715dd40d70a9b63b5c5519ba6 100644 (file)
@@ -36,7 +36,7 @@
 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 @@ fn check_static_type(&self, e: &ast::Expr) {
         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());
index 1bce353cb0cfe986b9662f0de630a1ca41a8f6e8..822979c86017b22aa2fc81af6c0ffcda5d59d032 100644 (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)
 }
index 1505fe7561b609351ced435ae39ca0e7c465ab2a..2600640a17daf77a22ea064e27c83229092fe6e2 100644 (file)
@@ -59,6 +59,10 @@ pub struct Obligation<'tcx, T> {
 #[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 @@ pub fn new(cause: ObligationCause<'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)
     }
 }
 
@@ -315,17 +319,19 @@ pub fn self_ty(&self) -> Ty<'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 }
     }
 }
 
index 5f5709f87f7783e2487b021ef6f90ead10b4015a..ee13fc5e3460079393c80370c036b643547b563d 100644 (file)
@@ -78,7 +78,7 @@
 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);
index 77412b00299ba672ef2a38676498d68e09ca521f..da6aa84cfa118e32cb1422a3d7059b73f5cb21ac 100644 (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) => {
index b6a9e2cbc59eae956c6874d780a4832ea65c9022..7b43b97a4bb36f00fcc2464047561fc581df0b2f 100644 (file)
@@ -462,7 +462,7 @@ fn add_obligations(&mut self,
                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);
 
index 53bda93b28e0216607050d38b188a9b7c3b6c091..1ab76740962bde00d6c8a1b919f4560bf99009aa 100644 (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);
 
index 4d23161f6dee475d5e22d5602546e029c884731a..3d7590db748efc9010db77bdd8f03afd35ff65f7 100644 (file)
@@ -804,7 +804,7 @@ fn consider_probe(&self, self_ty: Ty<'tcx>, probe: &Candidate<'tcx>) -> bool {
                     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()));
index 7270e66ab5302d12d2fef6fa813b8676ea41ace4..265766029b50536a529bb884f1be0574daab5bc4 100644 (file)
@@ -1790,6 +1790,7 @@ pub fn instantiate_type(&self,
         self.add_obligations_for_parameters(
             traits::ObligationCause::new(
                 span,
+                self.body_id,
                 traits::ItemObligation(def_id)),
             &substs,
             &bounds);
@@ -1817,7 +1818,7 @@ pub fn require_type_meets(&self,
     {
         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);
 
index 80ee2cce4ce709e954df33a1c15ae33367e01e6c..c53ad34a6d22cfb82a43ad01caf536107d3abb48 100644 (file)
@@ -938,7 +938,7 @@ fn ensure_free_variable_types_outlive_closure_bound(
             // 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 {
index 1f0a486edd380b48c5b782cfa7d27ddc0e138322..17651b9bfb61c18a9fb3e07272a0e8c435ad5f78 100644 (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);
index a011982a1fc53b2613e412ed1c2636e5c66909aa..23db98b317583b81b196de4d5366102955d3847e 100644 (file)
@@ -122,7 +122,9 @@ fn check_type_defn(&mut self,
                 // 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 @@ fn check_impl(&mut self,
             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 @@ pub fn check_trait_ref(&mut self, trait_ref: &ty::TraitRef<'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 @@ fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'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 @@ fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'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,