Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
resolve: collect trait aliases along with traits
  • Loading branch information
seanmonstar authored and Alexander Regueiro committed Mar 23, 2019
commit a2b6734ea40dcd53e1bdad6d8dc3e31c0fec929a
15 changes: 13 additions & 2 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,13 @@ impl<'a> ModuleData<'a> {
}
}

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 }
}
Expand Down Expand Up @@ -4369,8 +4376,10 @@ impl<'a> Resolver<'a> {
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());
Expand Down Expand Up @@ -4834,6 +4843,7 @@ impl<'a> Resolver<'a> {
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",
};
Expand Down Expand Up @@ -4862,6 +4872,7 @@ impl<'a> Resolver<'a> {
(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",
};

Expand Down
23 changes: 23 additions & 0 deletions src/test/run-pass/traits/trait-alias-import.rs
Original file line number Diff line number Diff line change
@@ -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();
}