Skip to content

Commit 577a5b2

Browse files
committed
Auto merge of #51181 - mbrubeck:prelude, r=petrochenkov
Add std/core to prelude if extern_prelude enabled Fixes #50605
2 parents 4412902 + 72ab4b4 commit 577a5b2

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

src/librustc_resolve/lib.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -1610,6 +1610,16 @@ impl<'a> Resolver<'a> {
16101610
DefCollector::new(&mut definitions, Mark::root())
16111611
.collect_root(crate_name, session.local_crate_disambiguator());
16121612

1613+
let mut extern_prelude: FxHashSet<Name> =
1614+
session.opts.externs.iter().map(|kv| Symbol::intern(kv.0)).collect();
1615+
if !attr::contains_name(&krate.attrs, "no_core") {
1616+
if !attr::contains_name(&krate.attrs, "no_std") {
1617+
extern_prelude.insert(Symbol::intern("std"));
1618+
} else {
1619+
extern_prelude.insert(Symbol::intern("core"));
1620+
}
1621+
}
1622+
16131623
let mut invocations = FxHashMap();
16141624
invocations.insert(Mark::root(),
16151625
arenas.alloc_invocation_data(InvocationData::root(graph_root)));
@@ -1630,7 +1640,7 @@ impl<'a> Resolver<'a> {
16301640
// AST.
16311641
graph_root,
16321642
prelude: None,
1633-
extern_prelude: session.opts.externs.iter().map(|kv| Symbol::intern(kv.0)).collect(),
1643+
extern_prelude,
16341644

16351645
has_self: FxHashSet(),
16361646
field_names: FxHashMap(),
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
#![feature(extern_prelude, lang_items, start, alloc)]
12+
#![no_std]
13+
14+
extern crate std as other;
15+
16+
mod foo {
17+
pub fn test() {
18+
let x = core::cmp::min(2, 3);
19+
assert_eq!(x, 2);
20+
}
21+
}
22+
23+
#[start]
24+
fn start(_argc: isize, _argv: *const *const u8) -> isize {
25+
foo::test();
26+
0
27+
}
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
#![feature(extern_prelude)]
12+
13+
mod foo {
14+
pub fn test() {
15+
let x = std::cmp::min(2, 3);
16+
assert_eq!(x, 2);
17+
}
18+
}
19+
20+
fn main() {
21+
foo::test();
22+
}

0 commit comments

Comments
 (0)