]> git.lizzy.rs Git - rust.git/commitdiff
Resolve methods called as functions and...
authorNick Cameron <ncameron@mozilla.com>
Thu, 16 Oct 2014 04:40:01 +0000 (17:40 +1300)
committerNick Cameron <ncameron@mozilla.com>
Fri, 31 Oct 2014 22:03:50 +0000 (11:03 +1300)
...defined in another crate.

Fixes #18061

src/librustc/metadata/decoder.rs
src/librustc/metadata/encoder.rs
src/librustc/middle/resolve.rs

index 22ebaa40eb20b9ae7ef962a7911a6c8c710628a0..d72b370864a82a39b28469d4ec57e554ec62d6e0 100644 (file)
@@ -115,6 +115,8 @@ enum Family {
     CtorFn,                // o
     StaticMethod,          // F
     UnsafeStaticMethod,    // U
+    Method,                // h
+    UnsafeMethod,          // H
     Type,                  // y
     ForeignType,           // T
     Mod,                   // m
@@ -141,6 +143,8 @@ fn item_family(item: rbml::Doc) -> Family {
       'o' => CtorFn,
       'F' => StaticMethod,
       'U' => UnsafeStaticMethod,
+      'h' => Method,
+      'H' => UnsafeMethod,
       'y' => Type,
       'T' => ForeignType,
       'm' => Mod,
@@ -312,6 +316,8 @@ fn item_to_def_like(item: rbml::Doc, did: ast::DefId, cnum: ast::CrateNum)
         UnsafeFn  => DlDef(def::DefFn(did, ast::UnsafeFn, false)),
         Fn        => DlDef(def::DefFn(did, ast::NormalFn, false)),
         CtorFn    => DlDef(def::DefFn(did, ast::NormalFn, true)),
+        UnsafeMethod  => DlDef(def::DefMethod(did, ast::UnsafeFn, false)),
+        Method    => DlDef(def::DefMethod(did, ast::NormalFn, false)),
         StaticMethod | UnsafeStaticMethod => {
             let fn_style = if fam == UnsafeStaticMethod {
                 ast::UnsafeFn
index fd983075218a505e78b15feb6c165cd63a3af078..2769d713273701be2be5cbbaf443c4b57e0d75b5 100644 (file)
@@ -840,7 +840,7 @@ fn encode_method_ty_fields(ecx: &EncodeContext,
         ty::StaticExplicitSelfCategory => {
             encode_family(rbml_w, fn_style_static_method_family(fn_style));
         }
-        _ => encode_family(rbml_w, style_fn_family(fn_style))
+        _ => encode_family(rbml_w, fn_style_method_family(fn_style))
     }
     encode_provided_source(rbml_w, method_ty.provided_source);
 }
@@ -978,6 +978,13 @@ fn fn_style_static_method_family(s: FnStyle) -> char {
     }
 }
 
+fn fn_style_method_family(s: FnStyle) -> char {
+    match s {
+        UnsafeFn => 'h',
+        NormalFn => 'H',
+    }
+}
+
 
 fn should_inline(attrs: &[Attribute]) -> bool {
     use syntax::attr::*;
@@ -1407,7 +1414,7 @@ fn add_to_index(item: &Item, rbml_w: &Encoder,
                         }
                         _ => {
                             encode_family(rbml_w,
-                                          style_fn_family(
+                                          fn_style_method_family(
                                               method_ty.fty.fn_style));
                         }
                     }
@@ -1432,30 +1439,30 @@ fn add_to_index(item: &Item, rbml_w: &Encoder,
             encode_parent_sort(rbml_w, 't');
 
             let trait_item = &ms[i];
-            match &ms[i] {
-                &RequiredMethod(ref tm) => {
-                    encode_attributes(rbml_w, tm.attrs.as_slice());
+            let foo = |rbml_w: &mut Encoder| {
+                // If this is a static method, we've already
+                // encoded this.
+                if is_nonstatic_method {
+                    // FIXME: I feel like there is something funny
+                    // going on.
+                    let pty = ty::lookup_item_type(tcx, item_def_id.def_id());
+                    encode_bounds_and_type(rbml_w, ecx, &pty);
+                }
+            };
+            match trait_item {
+                &RequiredMethod(ref m) => {
+                    encode_attributes(rbml_w, m.attrs.as_slice());
+                    foo(rbml_w);
                     encode_item_sort(rbml_w, 'r');
-                    encode_method_argument_names(rbml_w, &*tm.decl);
+                    encode_method_argument_names(rbml_w, &*m.decl);
                 }
 
                 &ProvidedMethod(ref m) => {
                     encode_attributes(rbml_w, m.attrs.as_slice());
-                    // If this is a static method, we've already
-                    // encoded this.
-                    if is_nonstatic_method {
-                        // FIXME: I feel like there is something funny
-                        // going on.
-                        let pty = ty::lookup_item_type(tcx,
-                                                       item_def_id.def_id());
-                        encode_bounds_and_type(rbml_w, ecx, &pty);
-                    }
+                    foo(rbml_w);
                     encode_item_sort(rbml_w, 'p');
-                    encode_inlined_item(ecx,
-                                        rbml_w,
-                                        IITraitItemRef(def_id, trait_item));
-                    encode_method_argument_names(rbml_w,
-                                                 &*m.pe_fn_decl());
+                    encode_inlined_item(ecx, rbml_w, IITraitItemRef(def_id, trait_item));
+                    encode_method_argument_names(rbml_w, &*m.pe_fn_decl());
                 }
 
                 &TypeTraitItem(ref associated_type) => {
index 383a60e51da7b6ca29ccc0607e940caf02aa47a5..7b21b8666e2b876c61382c31a9627744f7de2485 100644 (file)
@@ -1837,7 +1837,7 @@ fn handle_external_def(&mut self,
                 csearch::get_tuple_struct_definition_if_ctor(&self.session.cstore, ctor_id)
                     .map_or(def, |_| DefStruct(ctor_id)), DUMMY_SP, is_public);
           }
-          DefFn(..) | DefStaticMethod(..) | DefStatic(..) | DefConst(..) => {
+          DefFn(..) | DefStaticMethod(..) | DefStatic(..) | DefConst(..) | DefMethod(..) => {
             debug!("(building reduced graph for external \
                     crate) building value (fn/static) {}", final_ident);
             child_name_bindings.define_value(def, DUMMY_SP, is_public);
@@ -1902,11 +1902,6 @@ fn handle_external_def(&mut self,
             // Record the def ID and fields of this struct.
             self.structs.insert(def_id, fields);
           }
-          DefMethod(..) => {
-              debug!("(building reduced graph for external crate) \
-                      ignoring {}", def);
-              // Ignored; handled elsewhere.
-          }
           DefLocal(..) | DefPrimTy(..) | DefTyParam(..) |
           DefUse(..) | DefUpvar(..) | DefRegion(..) |
           DefTyParamBinder(..) | DefLabel(..) | DefSelfTy(..) => {