diff options
| author | bors <bors@rust-lang.org> | 2018-06-01 10:48:14 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-06-01 10:48:14 +0000 |
| commit | 577a5b2703d97e5408664e409f35768944360fea (patch) | |
| tree | 350999654c44dc4d6b76eb71bc628d6958089269 | |
| parent | 441290291fc71dbfa16a372636a59da75649eece (diff) | |
| parent | 72ab4b4f0128cc94c5e0281ab48e68597d9c0d51 (diff) | |
| download | rust-577a5b2703d97e5408664e409f35768944360fea.tar.gz rust-577a5b2703d97e5408664e409f35768944360fea.zip | |
Auto merge of #51181 - mbrubeck:prelude, r=petrochenkov
Add std/core to prelude if extern_prelude enabled Fixes #50605
| -rw-r--r-- | src/librustc_resolve/lib.rs | 12 | ||||
| -rw-r--r-- | src/test/run-pass/extern-prelude-core.rs | 27 | ||||
| -rw-r--r-- | src/test/run-pass/extern-prelude-std.rs | 22 |
3 files changed, 60 insertions, 1 deletions
diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index e05c6bf59ed..453627f3c36 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -1610,6 +1610,16 @@ impl<'a> Resolver<'a> { DefCollector::new(&mut definitions, Mark::root()) .collect_root(crate_name, session.local_crate_disambiguator()); + let mut extern_prelude: FxHashSet<Name> = + session.opts.externs.iter().map(|kv| Symbol::intern(kv.0)).collect(); + if !attr::contains_name(&krate.attrs, "no_core") { + if !attr::contains_name(&krate.attrs, "no_std") { + extern_prelude.insert(Symbol::intern("std")); + } else { + extern_prelude.insert(Symbol::intern("core")); + } + } + let mut invocations = FxHashMap(); invocations.insert(Mark::root(), arenas.alloc_invocation_data(InvocationData::root(graph_root))); @@ -1630,7 +1640,7 @@ impl<'a> Resolver<'a> { // AST. graph_root, prelude: None, - extern_prelude: session.opts.externs.iter().map(|kv| Symbol::intern(kv.0)).collect(), + extern_prelude, has_self: FxHashSet(), field_names: FxHashMap(), diff --git a/src/test/run-pass/extern-prelude-core.rs b/src/test/run-pass/extern-prelude-core.rs new file mode 100644 index 00000000000..d0d01b34c6e --- /dev/null +++ b/src/test/run-pass/extern-prelude-core.rs @@ -0,0 +1,27 @@ +// 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. + +#![feature(extern_prelude, lang_items, start, alloc)] +#![no_std] + +extern crate std as other; + +mod foo { + pub fn test() { + let x = core::cmp::min(2, 3); + assert_eq!(x, 2); + } +} + +#[start] +fn start(_argc: isize, _argv: *const *const u8) -> isize { + foo::test(); + 0 +} diff --git a/src/test/run-pass/extern-prelude-std.rs b/src/test/run-pass/extern-prelude-std.rs new file mode 100644 index 00000000000..de73f1d2278 --- /dev/null +++ b/src/test/run-pass/extern-prelude-std.rs @@ -0,0 +1,22 @@ +// 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. + +#![feature(extern_prelude)] + +mod foo { + pub fn test() { + let x = std::cmp::min(2, 3); + assert_eq!(x, 2); + } +} + +fn main() { + foo::test(); +} |
