Skip to content

Commit

Permalink
auto merge of #15733 : sanxiyn/rust/use-from-type, r=alexcrichton
Browse files Browse the repository at this point in the history
Importing from types was disallowed in #6462. Flag was set for paths whether it is a module or a type. Type flag was set when impl was seen. The problem is, for cross-crate situations, when reexport is involved, it is possible that impl is seen too late because metadata is loaded lazily.

Fix #15664.
  • Loading branch information
bors committed Jul 18, 2014
2 parents d9f1d6b + 99bd926 commit 4418664
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/librustc/middle/resolve.rs
Expand Up @@ -1622,6 +1622,12 @@ impl<'a> Resolver<'a> {
if is_exported {
self.external_exports.insert(def.def_id());
}

let kind = match def {
DefStruct(..) | DefTy(..) => ImplModuleKind,
_ => NormalModuleKind
};

match def {
DefMod(def_id) | DefForeignMod(def_id) | DefStruct(def_id) |
DefTy(def_id) => {
Expand All @@ -1640,7 +1646,7 @@ impl<'a> Resolver<'a> {

child_name_bindings.define_module(parent_link,
Some(def_id),
NormalModuleKind,
kind,
true,
is_public,
DUMMY_SP);
Expand Down
10 changes: 10 additions & 0 deletions src/test/auxiliary/use_from_trait_xc.rs
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

pub use self::sub::Bar;

pub trait Trait {
fn foo();
}
Expand All @@ -17,3 +19,11 @@ struct Foo;
impl Foo {
pub fn new() {}
}

mod sub {
pub struct Bar;

impl Bar {
pub fn new() {}
}
}
3 changes: 3 additions & 0 deletions src/test/compile-fail/use-from-trait-xc.rs
Expand Up @@ -18,4 +18,7 @@ use use_from_trait_xc::Trait::foo;
use use_from_trait_xc::Foo::new;
//~^ ERROR unresolved import `use_from_trait_xc::Foo::new`. Cannot import from a trait or type imple

use use_from_trait_xc::Bar::new;
//~^ ERROR unresolved import `use_from_trait_xc::Bar::new`. Cannot import from a trait or type

fn main() {}

0 comments on commit 4418664

Please sign in to comment.