resolve: collect trait aliases along with traits

This commit is contained in:
Sean McArthur 2019-03-13 14:24:42 -07:00 committed by Alexander Regueiro
parent 9f91bee03f
commit a2b6734ea4
2 changed files with 36 additions and 2 deletions

View 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",
};

View File

@ -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();
}