Skip to content

Commit a2b6734

Browse files
seanmonstarAlexander Regueiro
authored and
Alexander Regueiro
committed
resolve: collect trait aliases along with traits
1 parent 9f91bee commit a2b6734

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

src/librustc_resolve/lib.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -1195,6 +1195,13 @@ impl<'a> ModuleData<'a> {
11951195
}
11961196
}
11971197

1198+
fn is_trait_alias(&self) -> bool {
1199+
match self.kind {
1200+
ModuleKind::Def(Def::TraitAlias(_), _) => true,
1201+
_ => false,
1202+
}
1203+
}
1204+
11981205
fn nearest_item_scope(&'a self) -> Module<'a> {
11991206
if self.is_trait() { self.parent.unwrap() } else { self }
12001207
}
@@ -4369,8 +4376,10 @@ impl<'a> Resolver<'a> {
43694376
let mut collected_traits = Vec::new();
43704377
module.for_each_child(|name, ns, binding| {
43714378
if ns != TypeNS { return }
4372-
if let Def::Trait(_) = binding.def() {
4373-
collected_traits.push((name, binding));
4379+
match binding.def() {
4380+
Def::Trait(_) |
4381+
Def::TraitAlias(_) => collected_traits.push((name, binding)),
4382+
_ => (),
43744383
}
43754384
});
43764385
*traits = Some(collected_traits.into_boxed_slice());
@@ -4834,6 +4843,7 @@ impl<'a> Resolver<'a> {
48344843
let container = match parent.kind {
48354844
ModuleKind::Def(Def::Mod(_), _) => "module",
48364845
ModuleKind::Def(Def::Trait(_), _) => "trait",
4846+
ModuleKind::Def(Def::TraitAlias(_), _) => "trait alias",
48374847
ModuleKind::Block(..) => "block",
48384848
_ => "enum",
48394849
};
@@ -4862,6 +4872,7 @@ impl<'a> Resolver<'a> {
48624872
(TypeNS, _) if old_binding.is_extern_crate() => "extern crate",
48634873
(TypeNS, Some(module)) if module.is_normal() => "module",
48644874
(TypeNS, Some(module)) if module.is_trait() => "trait",
4875+
(TypeNS, Some(module)) if module.is_trait_alias() => "trait alias",
48654876
(TypeNS, _) => "type",
48664877
};
48674878

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#![feature(trait_alias)]
2+
3+
mod inner {
4+
pub trait Foo {
5+
fn foo(&self);
6+
}
7+
8+
pub struct Qux;
9+
10+
impl Foo for Qux {
11+
fn foo(&self) {}
12+
}
13+
14+
pub trait Bar = Foo;
15+
}
16+
17+
// Import only the alias, not the `Foo` trait.
18+
use inner::{Bar, Qux};
19+
20+
fn main() {
21+
let q = Qux;
22+
q.foo();
23+
}

0 commit comments

Comments
 (0)