]> git.lizzy.rs Git - rust.git/commitdiff
resolve: collect trait aliases along with traits
authorSean McArthur <sean@seanmonstar.com>
Wed, 13 Mar 2019 21:24:42 +0000 (14:24 -0700)
committerAlexander Regueiro <alexreg@me.com>
Sat, 23 Mar 2019 01:15:45 +0000 (01:15 +0000)
src/librustc_resolve/lib.rs
src/test/run-pass/traits/trait-alias-import.rs [new file with mode: 0644]

index ac149be4b2a8936929eae67f4d2b8f8865897714..e50cda602c2bf75b8de2506af5b9773c955c4abc 100644 (file)
@@ -1195,6 +1195,13 @@ fn is_trait(&self) -> bool {
         }
     }
 
+    fn is_trait_alias(&self) -> bool {
+        match self.kind {
+            ModuleKind::Def(Def::TraitAlias(_), _) => true,
+            _ => false,
+        }
+    }
+
     fn nearest_item_scope(&'a self) -> Module<'a> {
         if self.is_trait() { self.parent.unwrap() } else { self }
     }
@@ -4369,8 +4376,10 @@ fn get_traits_in_module_containing_item(&mut self,
             let mut collected_traits = Vec::new();
             module.for_each_child(|name, ns, binding| {
                 if ns != TypeNS { return }
-                if let Def::Trait(_) = binding.def() {
-                    collected_traits.push((name, binding));
+                match binding.def() {
+                    Def::Trait(_) |
+                    Def::TraitAlias(_) => collected_traits.push((name, binding)),
+                    _ => (),
                 }
             });
             *traits = Some(collected_traits.into_boxed_slice());
@@ -4834,6 +4843,7 @@ fn report_conflict<'b>(&mut self,
         let container = match parent.kind {
             ModuleKind::Def(Def::Mod(_), _) => "module",
             ModuleKind::Def(Def::Trait(_), _) => "trait",
+            ModuleKind::Def(Def::TraitAlias(_), _) => "trait alias",
             ModuleKind::Block(..) => "block",
             _ => "enum",
         };
@@ -4862,6 +4872,7 @@ fn report_conflict<'b>(&mut self,
             (TypeNS, _) if old_binding.is_extern_crate() => "extern crate",
             (TypeNS, Some(module)) if module.is_normal() => "module",
             (TypeNS, Some(module)) if module.is_trait() => "trait",
+            (TypeNS, Some(module)) if module.is_trait_alias() => "trait alias",
             (TypeNS, _) => "type",
         };
 
diff --git a/src/test/run-pass/traits/trait-alias-import.rs b/src/test/run-pass/traits/trait-alias-import.rs
new file mode 100644 (file)
index 0000000..9def1f0
--- /dev/null
@@ -0,0 +1,23 @@
+#![feature(trait_alias)]
+
+mod inner {
+    pub trait Foo {
+        fn foo(&self);
+    }
+
+    pub struct Qux;
+
+    impl Foo for Qux {
+        fn foo(&self) {}
+    }
+
+    pub trait Bar = Foo;
+}
+
+// Import only the alias, not the `Foo` trait.
+use inner::{Bar, Qux};
+
+fn main() {
+    let q = Qux;
+    q.foo();
+}