]> git.lizzy.rs Git - rust.git/commitdiff
Allow impls for traits as a concrete type
authorNick Cameron <ncameron@mozilla.com>
Tue, 21 Oct 2014 20:08:07 +0000 (09:08 +1300)
committerNick Cameron <ncameron@mozilla.com>
Mon, 3 Nov 2014 20:37:00 +0000 (09:37 +1300)
src/librustc/middle/resolve.rs
src/librustc/middle/traits/select.rs
src/librustc/middle/typeck/coherence/mod.rs
src/librustc/middle/typeck/coherence/orphan.rs

index c297bdc6ca2e70a131fe4dafc61cf9941b5c0f0f..03f1c33cce1208fe6930c6e5d0859b7673133b54 100644 (file)
@@ -627,7 +627,10 @@ fn define_module(&self,
                      sp: Span) {
         // Merges the module with the existing type def or creates a new one.
         let modifiers = if is_public { PUBLIC } else { DefModifiers::empty() } | IMPORTABLE;
-        let module_ = Rc::new(Module::new(parent_link, def_id, kind, external,
+        let module_ = Rc::new(Module::new(parent_link,
+                                          def_id,
+                                          kind,
+                                          external,
                                           is_public));
         let type_def = self.type_def.borrow().clone();
         match type_def {
@@ -1372,6 +1375,8 @@ fn build_reduced_graph_for_item(&mut self,
                 // Create the module and add all methods.
                 match ty.node {
                     TyPath(ref path, _, _) if path.segments.len() == 1 => {
+                        // FIXME(18446) we should distinguish between the name of
+                        // a trait and the name of an impl of that trait.
                         let mod_name = path.segments.last().unwrap().identifier.name;
 
                         let parent_opt = parent.module().children.borrow()
@@ -1380,8 +1385,8 @@ fn build_reduced_graph_for_item(&mut self,
                             // It already exists
                             Some(ref child) if child.get_module_if_available()
                                                 .is_some() &&
-                                           child.get_module().kind.get() ==
-                                                ImplModuleKind => {
+                                           (child.get_module().kind.get() == ImplModuleKind ||
+                                            child.get_module().kind.get() == TraitModuleKind) => {
                                 ModuleReducedGraphParent(child.get_module())
                             }
                             Some(ref child) if child.get_module_if_available()
index f8c1c37452b38c4e93b6ac35a75ee3cbc720b382..9ac47a234720956cab3a32389e18bb8c1f2e7d31 100644 (file)
@@ -514,7 +514,7 @@ pub fn evaluate_method_obligation(&mut self,
         // and `Rc<Baz>`. (Note that it is not a *coherence violation*
         // to have impls for both `Bar` and `Baz`, despite this
         // ambiguity).  In this case, we report an error, listing all
-        // the applicable impls.  The use can explicitly "up-coerce"
+        // the applicable impls.  The user can explicitly "up-coerce"
         // to the type they want.
         //
         // Note that this coercion step only considers actual impls
@@ -1931,7 +1931,7 @@ fn push_stack<'o,'s:'o>(&mut self,
 
     fn all_impls(&self, trait_def_id: ast::DefId) -> Vec<ast::DefId> {
         /*!
-         * Returns se tof all impls for a given trait.
+         * Returns seof all impls for a given trait.
          */
 
         ty::populate_implementations_for_trait_if_necessary(self.tcx(),
index a569053507cf88ff96d8ef7ef565e70e066177a2..ac18f53de046599cc8ac9651e4c5a6e6ef3812ca 100644 (file)
@@ -207,8 +207,8 @@ fn check_implementation(&self,
         let impl_items = self.create_impl_from_item(item);
 
         for associated_trait in associated_traits.iter() {
-            let trait_ref = ty::node_id_to_trait_ref(
-                self.crate_context.tcx, associated_trait.ref_id);
+            let trait_ref = ty::node_id_to_trait_ref(self.crate_context.tcx,
+                                                     associated_trait.ref_id);
             debug!("(checking implementation) adding impl for trait '{}', item '{}'",
                    trait_ref.repr(self.crate_context.tcx),
                    token::get_ident(item.ident));
index e7139e1229b23c69f162b00fc6a3f097363cad3e..3c4ad3473610cfd0509a956a6bba4b053ee7fa90 100644 (file)
@@ -41,7 +41,8 @@ fn visit_item(&mut self, item: &'v ast::Item) {
                 let self_ty = ty::lookup_item_type(self.tcx, def_id).ty;
                 match ty::get(self_ty).sty {
                     ty::ty_enum(def_id, _) |
-                    ty::ty_struct(def_id, _) => {
+                    ty::ty_struct(def_id, _) |
+                    ty::ty_trait(box ty::TyTrait{ def_id, ..}) => {
                         if def_id.krate != ast::LOCAL_CRATE {
                             span_err!(self.tcx.sess, item.span, E0116,
                                       "cannot associate methods with a type outside the \