Skip to content

Commit

Permalink
Auto merge of #53335 - eddyb:issue-53333, r=petrochenkov
Browse files Browse the repository at this point in the history
rustc_resolve: crates only exist in the type namespace.

Fixes #53333 by resolving `::crate_name` in `TypeNS` alone, which was overlooked in #52923 and didn't break tests, since having `use crate_name;` and a `crate_name` value in the same scope is rare.
  • Loading branch information
bors committed Aug 14, 2018
2 parents 5bb9239 + 262392c commit d67ba90
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/librustc_resolve/resolve_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,21 +194,22 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> {
}

// Fall back to resolving to an external crate.
if !self.extern_prelude.contains(&ident.name) {
if !(ns == TypeNS && self.extern_prelude.contains(&ident.name)) {
// ... unless the crate name is not in the `extern_prelude`.
return binding;
}
}

let crate_root = if
ns == TypeNS &&
root != keywords::Extern.name() &&
(
ident.name == keywords::Crate.name() ||
ident.name == keywords::DollarCrate.name()
)
{
self.resolve_crate_root(ident)
} else if !ident.is_path_segment_keyword() {
} else if ns == TypeNS && !ident.is_path_segment_keyword() {
let crate_id =
self.crate_loader.process_path_extern(ident.name, ident.span);
self.get_module(DefId { krate: crate_id, index: CRATE_DEF_INDEX })
Expand Down
17 changes: 17 additions & 0 deletions src/test/run-pass/issue-53333.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// edition:2018

fn main() {
use std;
let std = "std";
println!("{}", std);
}

0 comments on commit d67ba90

Please sign in to comment.