Skip to content

Commit 4418664

Browse files
committed
auto merge of #15733 : sanxiyn/rust/use-from-type, r=alexcrichton
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.
2 parents d9f1d6b + 99bd926 commit 4418664

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

src/librustc/middle/resolve.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1622,6 +1622,12 @@ impl<'a> Resolver<'a> {
16221622
if is_exported {
16231623
self.external_exports.insert(def.def_id());
16241624
}
1625+
1626+
let kind = match def {
1627+
DefStruct(..) | DefTy(..) => ImplModuleKind,
1628+
_ => NormalModuleKind
1629+
};
1630+
16251631
match def {
16261632
DefMod(def_id) | DefForeignMod(def_id) | DefStruct(def_id) |
16271633
DefTy(def_id) => {
@@ -1640,7 +1646,7 @@ impl<'a> Resolver<'a> {
16401646

16411647
child_name_bindings.define_module(parent_link,
16421648
Some(def_id),
1643-
NormalModuleKind,
1649+
kind,
16441650
true,
16451651
is_public,
16461652
DUMMY_SP);

src/test/auxiliary/use_from_trait_xc.rs

+10
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
pub use self::sub::Bar;
12+
1113
pub trait Trait {
1214
fn foo();
1315
}
@@ -17,3 +19,11 @@ struct Foo;
1719
impl Foo {
1820
pub fn new() {}
1921
}
22+
23+
mod sub {
24+
pub struct Bar;
25+
26+
impl Bar {
27+
pub fn new() {}
28+
}
29+
}

src/test/compile-fail/use-from-trait-xc.rs

+3
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,7 @@ use use_from_trait_xc::Trait::foo;
1818
use use_from_trait_xc::Foo::new;
1919
//~^ ERROR unresolved import `use_from_trait_xc::Foo::new`. Cannot import from a trait or type imple
2020

21+
use use_from_trait_xc::Bar::new;
22+
//~^ ERROR unresolved import `use_from_trait_xc::Bar::new`. Cannot import from a trait or type
23+
2124
fn main() {}

0 commit comments

Comments
 (0)