Skip to content

hygiene: Implement transparent marks and use them for call-site hygiene in proc-macros #51762

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

Merged
merged 7 commits into from
Jun 30, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
resolve: Cleanup resolve_crate_root
  • Loading branch information
petrochenkov committed Jun 29, 2018
commit 1328bdeef8451779831d3ddc26e16ee64c3d65b5
2 changes: 1 addition & 1 deletion src/librustc_resolve/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ impl<'a> Resolver<'a> {

// Disallow `use $crate;`
if source.name == keywords::DollarCrate.name() && path.segments.len() == 1 {
let crate_root = self.resolve_crate_root(source.span.ctxt(), true);
let crate_root = self.resolve_crate_root(source);
let crate_name = match crate_root.kind {
ModuleKind::Def(_, name) => name,
ModuleKind::Block(..) => unreachable!(),
Expand Down
14 changes: 6 additions & 8 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1981,8 +1981,9 @@ impl<'a> Resolver<'a> {
result
}

fn resolve_crate_root(&mut self, mut ctxt: SyntaxContext, legacy: bool) -> Module<'a> {
let mark = if legacy {
fn resolve_crate_root(&mut self, ident: Ident) -> Module<'a> {
let mut ctxt = ident.span.ctxt();
let mark = if ident.name == keywords::DollarCrate.name() {
// When resolving `$crate` from a `macro_rules!` invoked in a `macro`,
// we don't want to pretend that the `macro_rules!` definition is in the `macro`
// as described in `SyntaxContext::apply_mark`, so we ignore prepended modern marks.
Expand Down Expand Up @@ -3345,14 +3346,11 @@ impl<'a> Resolver<'a> {
if ns == TypeNS {
if (i == 0 && name == keywords::CrateRoot.name()) ||
(i == 0 && name == keywords::Crate.name()) ||
(i == 0 && name == keywords::DollarCrate.name()) ||
(i == 1 && name == keywords::Crate.name() &&
path[0].name == keywords::CrateRoot.name()) {
// `::a::b` or `::crate::a::b`
module = Some(self.resolve_crate_root(ident.span.ctxt(), false));
continue
} else if i == 0 && name == keywords::DollarCrate.name() {
// `$crate::a::b`
module = Some(self.resolve_crate_root(ident.span.ctxt(), true));
// `::a::b`, `crate::a::b`, `::crate::a::b` or `$crate::a::b`
module = Some(self.resolve_crate_root(ident));
continue
} else if i == 1 && !ident.is_path_segment_keyword() {
let prev_name = path[0].name;
Expand Down
5 changes: 2 additions & 3 deletions src/librustc_resolve/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,9 @@ impl<'a> base::Resolver for Resolver<'a> {
}
});

let ident = path.segments[0].ident;
if ident.name == keywords::DollarCrate.name() {
if path.segments[0].ident.name == keywords::DollarCrate.name() {
let module = self.0.resolve_crate_root(path.segments[0].ident);
path.segments[0].ident.name = keywords::CrateRoot.name();
let module = self.0.resolve_crate_root(ident.span.ctxt(), true);
if !module.is_local() {
let span = path.segments[0].ident.span;
path.segments.insert(1, match module.kind {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_resolve/resolve_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
"crate root imports need to be explicitly named: \
`use crate as name;`".to_string()));
} else {
Some(self.resolve_crate_root(source.span.ctxt().modern(), false))
Some(self.resolve_crate_root(source))
}
} else if is_extern && !source.is_path_segment_keyword() {
let crate_id =
Expand Down