Skip to content

Commit c6807bb

Browse files
committed
Auto merge of #52159 - SimonSapin:alloc-prelude, r=alexcrichton
Add the `alloc::prelude` module It contains the re-exports that are in `std::prelude::v1` but not in `core::prelude::v1`. Calling it prelude is somewhat of a misnomer since (unlike those modules in `std` or `core`) its contents are never implicitly imported in modules. Rather it is intended to be used with an explicit glob import like `use alloc::prelude::*;`. However there is precedent for the same misnomer with `std::io::prelude`, for example. This new module is unstable with the same feature name as the `alloc` care. They are proposed for stabilization together in RFC rust-lang/rfcs#2480.
2 parents c30acc7 + 5b795cf commit c6807bb

File tree

3 files changed

+72
-17
lines changed

3 files changed

+72
-17
lines changed

Diff for: src/liballoc/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ pub mod collections;
169169
pub mod sync;
170170
pub mod rc;
171171
pub mod raw_vec;
172-
172+
pub mod prelude;
173173
pub mod borrow;
174174
pub mod fmt;
175175
pub mod slice;

Diff for: src/liballoc/prelude.rs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
//! The alloc Prelude
12+
//!
13+
//! The purpose of this module is to alleviate imports of commonly-used
14+
//! items of the `alloc` crate by adding a glob import to the top of modules:
15+
//!
16+
//! ```
17+
//! # #![allow(unused_imports)]
18+
//! # #![feature(alloc)]
19+
//! extern crate alloc;
20+
//! use alloc::prelude::*;
21+
//! ```
22+
23+
#![unstable(feature = "alloc", issue = "27783")]
24+
25+
#[unstable(feature = "alloc", issue = "27783")] pub use borrow::ToOwned;
26+
#[unstable(feature = "alloc", issue = "27783")] pub use boxed::Box;
27+
#[unstable(feature = "alloc", issue = "27783")] pub use slice::SliceConcatExt;
28+
#[unstable(feature = "alloc", issue = "27783")] pub use string::{String, ToString};
29+
#[unstable(feature = "alloc", issue = "27783")] pub use vec::Vec;

Diff for: src/libstd/prelude/v1.rs

+42-16
Original file line numberDiff line numberDiff line change
@@ -12,42 +12,68 @@
1212
//!
1313
//! See the [module-level documentation](../index.html) for more.
1414
15+
16+
1517
#![stable(feature = "rust1", since = "1.0.0")]
1618

1719
// Re-exported core operators
1820
#[stable(feature = "rust1", since = "1.0.0")]
19-
#[doc(no_inline)] pub use marker::{Copy, Send, Sized, Sync};
21+
#[doc(no_inline)]
22+
pub use marker::{Copy, Send, Sized, Sync};
2023
#[stable(feature = "rust1", since = "1.0.0")]
21-
#[doc(no_inline)] pub use ops::{Drop, Fn, FnMut, FnOnce};
24+
#[doc(no_inline)]
25+
pub use ops::{Drop, Fn, FnMut, FnOnce};
2226

2327
// Re-exported functions
2428
#[stable(feature = "rust1", since = "1.0.0")]
25-
#[doc(no_inline)] pub use mem::drop;
29+
#[doc(no_inline)]
30+
pub use mem::drop;
2631

2732
// Re-exported types and traits
2833
#[stable(feature = "rust1", since = "1.0.0")]
29-
#[doc(no_inline)] pub use boxed::Box;
34+
#[doc(no_inline)]
35+
pub use clone::Clone;
3036
#[stable(feature = "rust1", since = "1.0.0")]
31-
#[doc(no_inline)] pub use borrow::ToOwned;
37+
#[doc(no_inline)]
38+
pub use cmp::{PartialEq, PartialOrd, Eq, Ord};
3239
#[stable(feature = "rust1", since = "1.0.0")]
33-
#[doc(no_inline)] pub use clone::Clone;
40+
#[doc(no_inline)]
41+
pub use convert::{AsRef, AsMut, Into, From};
3442
#[stable(feature = "rust1", since = "1.0.0")]
35-
#[doc(no_inline)] pub use cmp::{PartialEq, PartialOrd, Eq, Ord};
43+
#[doc(no_inline)]
44+
pub use default::Default;
3645
#[stable(feature = "rust1", since = "1.0.0")]
37-
#[doc(no_inline)] pub use convert::{AsRef, AsMut, Into, From};
46+
#[doc(no_inline)]
47+
pub use iter::{Iterator, Extend, IntoIterator};
3848
#[stable(feature = "rust1", since = "1.0.0")]
39-
#[doc(no_inline)] pub use default::Default;
49+
#[doc(no_inline)]
50+
pub use iter::{DoubleEndedIterator, ExactSizeIterator};
4051
#[stable(feature = "rust1", since = "1.0.0")]
41-
#[doc(no_inline)] pub use iter::{Iterator, Extend, IntoIterator};
52+
#[doc(no_inline)]
53+
pub use option::Option::{self, Some, None};
4254
#[stable(feature = "rust1", since = "1.0.0")]
43-
#[doc(no_inline)] pub use iter::{DoubleEndedIterator, ExactSizeIterator};
55+
#[doc(no_inline)]
56+
pub use result::Result::{self, Ok, Err};
57+
58+
59+
// The file so far is equivalent to src/libcore/prelude/v1.rs,
60+
// and below to src/liballoc/prelude.rs.
61+
// Those files are duplicated rather than using glob imports
62+
// because we want docs to show these re-exports as pointing to within `std`.
63+
64+
4465
#[stable(feature = "rust1", since = "1.0.0")]
45-
#[doc(no_inline)] pub use option::Option::{self, Some, None};
66+
#[doc(no_inline)]
67+
pub use boxed::Box;
4668
#[stable(feature = "rust1", since = "1.0.0")]
47-
#[doc(no_inline)] pub use result::Result::{self, Ok, Err};
69+
#[doc(no_inline)]
70+
pub use borrow::ToOwned;
4871
#[stable(feature = "rust1", since = "1.0.0")]
49-
#[doc(no_inline)] pub use slice::SliceConcatExt;
72+
#[doc(no_inline)]
73+
pub use slice::SliceConcatExt;
5074
#[stable(feature = "rust1", since = "1.0.0")]
51-
#[doc(no_inline)] pub use string::{String, ToString};
75+
#[doc(no_inline)]
76+
pub use string::{String, ToString};
5277
#[stable(feature = "rust1", since = "1.0.0")]
53-
#[doc(no_inline)] pub use vec::Vec;
78+
#[doc(no_inline)]
79+
pub use vec::Vec;

0 commit comments

Comments
 (0)