Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolve: Account for new importable entities #59047

Merged
merged 1 commit into from
Mar 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions src/librustc_resolve/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,24 +636,24 @@ impl<'a> Resolver<'a> {
// but metadata cannot encode gensyms currently, so we create it here.
// This is only a guess, two equivalent idents may incorrectly get different gensyms here.
let ident = ident.gensym_if_underscore();
let def_id = def.def_id();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this part of the diff, I presume isn't meaningful -- that is, we're now getting the def_id as part of the match, but in each case, it's the same def_id it was before?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the def-ids are the same.

let expansion = Mark::root(); // FIXME(jseyfried) intercrate hygiene
match def {
Def::Mod(..) | Def::Enum(..) => {
Def::Mod(def_id) | Def::Enum(def_id) => {
let module = self.new_module(parent,
ModuleKind::Def(def, ident.name),
def_id,
expansion,
span);
self.define(parent, ident, TypeNS, (module, vis, DUMMY_SP, expansion));
}
Def::Variant(..) | Def::TyAlias(..) | Def::ForeignTy(..) => {
Def::Variant(..) | Def::TyAlias(..) | Def::ForeignTy(..) | Def::Existential(..) |
Def::TraitAlias(..) | Def::PrimTy(..) | Def::ToolMod => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I understand but to make sure, could you educate me as to why ToolMod uses the TypeNS as opposed to MacroNS (the documentation on hir::def::Def barely exists...)?

Otherwise the PR looks good; r=me with green travis :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ToolMod is very similar to Mod living in type namespace, it's a container for other items.
The difference is that contained items are limited to tool attributes and nested tool modules + the number of contained items is infinite (i.e. no name checks are performed).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah; that makes sense, thanks!

self.define(parent, ident, TypeNS, (def, vis, DUMMY_SP, expansion));
}
Def::Fn(..) | Def::Static(..) | Def::Const(..) | Def::VariantCtor(..) => {
self.define(parent, ident, ValueNS, (def, vis, DUMMY_SP, expansion));
}
Def::StructCtor(..) => {
Def::StructCtor(def_id, ..) => {
self.define(parent, ident, ValueNS, (def, vis, DUMMY_SP, expansion));

if let Some(struct_def_id) =
Expand All @@ -662,7 +662,7 @@ impl<'a> Resolver<'a> {
self.struct_constructors.insert(struct_def_id, (def, vis));
}
}
Def::Trait(..) => {
Def::Trait(def_id) => {
let module_kind = ModuleKind::Def(def, ident.name);
let module = self.new_module(parent,
module_kind,
Expand All @@ -683,18 +683,14 @@ impl<'a> Resolver<'a> {
}
module.populated.set(true);
}
Def::Existential(..) |
Def::TraitAlias(..) => {
self.define(parent, ident, TypeNS, (def, vis, DUMMY_SP, expansion));
}
Def::Struct(..) | Def::Union(..) => {
Def::Struct(def_id) | Def::Union(def_id) => {
self.define(parent, ident, TypeNS, (def, vis, DUMMY_SP, expansion));

// Record field names for error reporting.
let field_names = self.cstore.struct_field_names_untracked(def_id);
self.insert_field_names(def_id, field_names);
}
Def::Macro(..) => {
Def::Macro(..) | Def::NonMacroAttr(..) => {
self.define(parent, ident, MacroNS, (def, vis, DUMMY_SP, expansion));
}
_ => bug!("unexpected definition: {:?}", def)
Expand Down
5 changes: 5 additions & 0 deletions src/test/ui/rust-2018/uniform-paths/auxiliary/cross-crate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// edition:2018

pub use ignore as built_in_attr;
pub use u8 as built_in_type;
pub use rustfmt as tool_mod;
11 changes: 11 additions & 0 deletions src/test/ui/rust-2018/uniform-paths/cross-crate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// edition:2018
// aux-build:cross-crate.rs

extern crate cross_crate;
use cross_crate::*;

#[built_in_attr] //~ ERROR cannot use a built-in attribute through an import
#[tool_mod::skip] //~ ERROR cannot use a tool module through an import
fn main() {
let _: built_in_type; // OK
}
26 changes: 26 additions & 0 deletions src/test/ui/rust-2018/uniform-paths/cross-crate.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
error: cannot use a built-in attribute through an import
--> $DIR/cross-crate.rs:7:3
|
LL | #[built_in_attr]
| ^^^^^^^^^^^^^
|
note: the built-in attribute imported here
--> $DIR/cross-crate.rs:5:5
|
LL | use cross_crate::*;
| ^^^^^^^^^^^^^^

error: cannot use a tool module through an import
--> $DIR/cross-crate.rs:8:3
|
LL | #[tool_mod::skip]
| ^^^^^^^^
|
note: the tool module imported here
--> $DIR/cross-crate.rs:5:5
|
LL | use cross_crate::*;
| ^^^^^^^^^^^^^^

error: aborting due to 2 previous errors