resolve: collect trait aliases along with traits
This commit is contained in:
parent
9f91bee03f
commit
a2b6734ea4
@ -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> {
|
fn nearest_item_scope(&'a self) -> Module<'a> {
|
||||||
if self.is_trait() { self.parent.unwrap() } else { self }
|
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();
|
let mut collected_traits = Vec::new();
|
||||||
module.for_each_child(|name, ns, binding| {
|
module.for_each_child(|name, ns, binding| {
|
||||||
if ns != TypeNS { return }
|
if ns != TypeNS { return }
|
||||||
if let Def::Trait(_) = binding.def() {
|
match binding.def() {
|
||||||
collected_traits.push((name, binding));
|
Def::Trait(_) |
|
||||||
|
Def::TraitAlias(_) => collected_traits.push((name, binding)),
|
||||||
|
_ => (),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
*traits = Some(collected_traits.into_boxed_slice());
|
*traits = Some(collected_traits.into_boxed_slice());
|
||||||
@ -4834,6 +4843,7 @@ fn report_conflict<'b>(&mut self,
|
|||||||
let container = match parent.kind {
|
let container = match parent.kind {
|
||||||
ModuleKind::Def(Def::Mod(_), _) => "module",
|
ModuleKind::Def(Def::Mod(_), _) => "module",
|
||||||
ModuleKind::Def(Def::Trait(_), _) => "trait",
|
ModuleKind::Def(Def::Trait(_), _) => "trait",
|
||||||
|
ModuleKind::Def(Def::TraitAlias(_), _) => "trait alias",
|
||||||
ModuleKind::Block(..) => "block",
|
ModuleKind::Block(..) => "block",
|
||||||
_ => "enum",
|
_ => "enum",
|
||||||
};
|
};
|
||||||
@ -4862,6 +4872,7 @@ fn report_conflict<'b>(&mut self,
|
|||||||
(TypeNS, _) if old_binding.is_extern_crate() => "extern crate",
|
(TypeNS, _) if old_binding.is_extern_crate() => "extern crate",
|
||||||
(TypeNS, Some(module)) if module.is_normal() => "module",
|
(TypeNS, Some(module)) if module.is_normal() => "module",
|
||||||
(TypeNS, Some(module)) if module.is_trait() => "trait",
|
(TypeNS, Some(module)) if module.is_trait() => "trait",
|
||||||
|
(TypeNS, Some(module)) if module.is_trait_alias() => "trait alias",
|
||||||
(TypeNS, _) => "type",
|
(TypeNS, _) => "type",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
23
src/test/run-pass/traits/trait-alias-import.rs
Normal file
23
src/test/run-pass/traits/trait-alias-import.rs
Normal 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();
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user