]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_typeck/collect.rs
Auto merge of #30341 - pnkfelix:call-site-scope, r=nikomatsakis
[rust.git] / src / librustc_typeck / collect.rs
index efda06d8cf6190cf9857747141486f577cbea326..bfe4151da5c91c3c99cff4b6b722ed057b9a47a9 100644 (file)
@@ -889,11 +889,13 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) {
             for impl_item in impl_items {
                 if let hir::ImplItemKind::Method(ref sig, ref body) = impl_item.node {
                     let body_id = body.id;
+                    let body_scope = ccx.tcx.region_maps.call_site_extent(impl_item.id, body_id);
                     check_method_self_type(ccx,
                                            &BindingRscope::new(),
                                            ccx.method_ty(impl_item.id),
                                            selfty,
                                            &sig.explicit_self,
+                                           body_scope,
                                            body_id);
                 }
             }
@@ -988,8 +990,16 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) {
             // This must be done after `collect_trait_methods` so that
             // we have a method type stored for every method.
             for trait_item in trait_items {
-                let sig = match trait_item.node {
-                    hir::MethodTraitItem(ref sig, _) => sig,
+                let (sig, the_scope, the_id) = match trait_item.node {
+                    hir::MethodTraitItem(ref sig, Some(ref body)) => {
+                        let body_scope =
+                            ccx.tcx.region_maps.call_site_extent(trait_item.id, body.id);
+                        (sig, body_scope, body.id)
+                    }
+                    hir::MethodTraitItem(ref sig, None) => {
+                        let item_scope = ccx.tcx.region_maps.item_extent(trait_item.id);
+                        (sig, item_scope, it.id)
+                    }
                     _ => continue
                 };
                 check_method_self_type(ccx,
@@ -997,7 +1007,8 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) {
                                        ccx.method_ty(trait_item.id),
                                        tcx.mk_self_type(),
                                        &sig.explicit_self,
-                                       it.id)
+                                       the_scope,
+                                       the_id)
             }
         },
         hir::ItemStruct(ref struct_def, _) => {
@@ -1061,7 +1072,7 @@ fn convert_enum_variant_types<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
                                         def: ty::AdtDefMaster<'tcx>,
                                         scheme: ty::TypeScheme<'tcx>,
                                         predicates: ty::GenericPredicates<'tcx>,
-                                        variants: &[P<hir::Variant>]) {
+                                        variants: &[hir::Variant]) {
     // fill the field types
     for (variant, ty_variant) in variants.iter().zip(def.variants.iter()) {
         for (f, ty_f) in variant.node.data.fields().iter().zip(ty_variant.fields.iter()) {
@@ -1479,7 +1490,7 @@ fn predicates_for_associated_types<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
                                                  ast_generics: &hir::Generics,
                                                  trait_predicates: &ty::GenericPredicates<'tcx>,
                                                  self_trait_ref: ty::TraitRef<'tcx>,
-                                                 trait_items: &[P<hir::TraitItem>])
+                                                 trait_items: &[hir::TraitItem])
                                                  -> Vec<ty::Predicate<'tcx>>
     {
         trait_items.iter().flat_map(|trait_item| {
@@ -2282,6 +2293,7 @@ fn check_method_self_type<'a, 'tcx, RS:RegionScope>(
     method_type: Rc<ty::Method<'tcx>>,
     required_type: Ty<'tcx>,
     explicit_self: &hir::ExplicitSelf,
+    body_scope: region::CodeExtent,
     body_id: ast::NodeId)
 {
     let tcx = ccx.tcx;
@@ -2293,8 +2305,6 @@ fn check_method_self_type<'a, 'tcx, RS:RegionScope>(
             _ => typ,
         };
 
-        let body_scope = tcx.region_maps.item_extent(body_id);
-
         // "Required type" comes from the trait definition. It may
         // contain late-bound regions from the method, but not the
         // trait (since traits only have early-bound region
@@ -2387,9 +2397,9 @@ fn enforce_impl_params_are_constrained<'tcx>(tcx: &ty::ctxt<'tcx>,
     // reachable from there, to start (if this is an inherent impl,
     // then just examine the self type).
     let mut input_parameters: HashSet<_> =
-        ctp::parameters_for_type(impl_scheme.ty).into_iter().collect();
+        ctp::parameters_for_type(impl_scheme.ty, false).into_iter().collect();
     if let Some(ref trait_ref) = impl_trait_ref {
-        input_parameters.extend(ctp::parameters_for_trait_ref(trait_ref));
+        input_parameters.extend(ctp::parameters_for_trait_ref(trait_ref, false));
     }
 
     ctp::setup_constraining_predicates(tcx,
@@ -2410,7 +2420,7 @@ fn enforce_impl_params_are_constrained<'tcx>(tcx: &ty::ctxt<'tcx>,
 fn enforce_impl_lifetimes_are_constrained<'tcx>(tcx: &ty::ctxt<'tcx>,
                                                 ast_generics: &hir::Generics,
                                                 impl_def_id: DefId,
-                                                impl_items: &[P<hir::ImplItem>])
+                                                impl_items: &[hir::ImplItem])
 {
     // Every lifetime used in an associated type must be constrained.
     let impl_scheme = tcx.lookup_item_type(impl_def_id);
@@ -2418,9 +2428,9 @@ fn enforce_impl_lifetimes_are_constrained<'tcx>(tcx: &ty::ctxt<'tcx>,
     let impl_trait_ref = tcx.impl_trait_ref(impl_def_id);
 
     let mut input_parameters: HashSet<_> =
-        ctp::parameters_for_type(impl_scheme.ty).into_iter().collect();
+        ctp::parameters_for_type(impl_scheme.ty, false).into_iter().collect();
     if let Some(ref trait_ref) = impl_trait_ref {
-        input_parameters.extend(ctp::parameters_for_trait_ref(trait_ref));
+        input_parameters.extend(ctp::parameters_for_trait_ref(trait_ref, false));
     }
     ctp::identify_constrained_type_params(tcx,
         &impl_predicates.predicates.as_slice(), impl_trait_ref, &mut input_parameters);
@@ -2432,7 +2442,7 @@ fn enforce_impl_lifetimes_are_constrained<'tcx>(tcx: &ty::ctxt<'tcx>,
                       ty::TypeTraitItem(ref assoc_ty) => assoc_ty.ty,
                       ty::ConstTraitItem(..) | ty::MethodTraitItem(..) => None
                   })
-                  .flat_map(|ty| ctp::parameters_for_type(ty))
+                  .flat_map(|ty| ctp::parameters_for_type(ty, true))
                   .filter_map(|p| match p {
                       ctp::Parameter::Type(_) => None,
                       ctp::Parameter::Region(r) => Some(r),