Skip to content

Commit d67ba90

Browse files
committed
Auto merge of #53335 - eddyb:issue-53333, r=petrochenkov
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.
2 parents 5bb9239 + 262392c commit d67ba90

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/librustc_resolve/resolve_imports.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -194,21 +194,22 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> {
194194
}
195195

196196
// Fall back to resolving to an external crate.
197-
if !self.extern_prelude.contains(&ident.name) {
197+
if !(ns == TypeNS && self.extern_prelude.contains(&ident.name)) {
198198
// ... unless the crate name is not in the `extern_prelude`.
199199
return binding;
200200
}
201201
}
202202

203203
let crate_root = if
204+
ns == TypeNS &&
204205
root != keywords::Extern.name() &&
205206
(
206207
ident.name == keywords::Crate.name() ||
207208
ident.name == keywords::DollarCrate.name()
208209
)
209210
{
210211
self.resolve_crate_root(ident)
211-
} else if !ident.is_path_segment_keyword() {
212+
} else if ns == TypeNS && !ident.is_path_segment_keyword() {
212213
let crate_id =
213214
self.crate_loader.process_path_extern(ident.name, ident.span);
214215
self.get_module(DefId { krate: crate_id, index: CRATE_DEF_INDEX })

src/test/run-pass/issue-53333.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// edition:2018
12+
13+
fn main() {
14+
use std;
15+
let std = "std";
16+
println!("{}", std);
17+
}

0 commit comments

Comments
 (0)