Skip to content

Commit e500fc3

Browse files
authored
Merge branch 'master' into redox_builder
2 parents 34c9f8c + 7858dc2 commit e500fc3

File tree

207 files changed

+4795
-3227
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

207 files changed

+4795
-3227
lines changed

Cargo.lock

Lines changed: 1895 additions & 1896 deletions
Large diffs are not rendered by default.

src/doc/rustc-ux-guidelines.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ for details on how to format and write long error codes.
7070
[librustc_privacy](https://github.com/rust-lang/rust/blob/master/src/librustc_privacy/error_codes.rs),
7171
[librustc_resolve](https://github.com/rust-lang/rust/blob/master/src/librustc_resolve/error_codes.rs),
7272
[librustc_codegen_llvm](https://github.com/rust-lang/rust/blob/master/src/librustc_codegen_llvm/error_codes.rs),
73-
[librustc_plugin](https://github.com/rust-lang/rust/blob/master/src/librustc_plugin/error_codes.rs),
73+
[librustc_plugin_impl](https://github.com/rust-lang/rust/blob/master/src/librustc_plugin/error_codes.rs),
7474
[librustc_typeck](https://github.com/rust-lang/rust/blob/master/src/librustc_typeck/error_codes.rs).
7575
* Explanations have full markdown support. Use it, especially to highlight
7676
code with backticks.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# `or_patterns`
2+
3+
The tracking issue for this feature is: [#54883]
4+
5+
[#54883]: https://github.com/rust-lang/rust/issues/54883
6+
7+
------------------------
8+
9+
The `or_pattern` language feature allows `|` to be arbitrarily nested within
10+
a pattern, for example, `Some(A(0) | B(1 | 2))` becomes a valid pattern.
11+
12+
## Examples
13+
14+
```rust,ignore
15+
#![feature(or_patterns)]
16+
17+
pub enum Foo {
18+
Bar,
19+
Baz,
20+
Quux,
21+
}
22+
23+
pub fn example(maybe_foo: Option<Foo>) {
24+
match maybe_foo {
25+
Some(Foo::Bar | Foo::Baz) => {
26+
println!("The value contained `Bar` or `Baz`");
27+
}
28+
Some(_) => {
29+
println!("The value did not contain `Bar` or `Baz`");
30+
}
31+
None => {
32+
println!("The value was `None`");
33+
}
34+
}
35+
}
36+
```

src/doc/unstable-book/src/language-features/plugin.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ extend the compiler's behavior with new syntax extensions, lint checks, etc.
1818
A plugin is a dynamic library crate with a designated *registrar* function that
1919
registers extensions with `rustc`. Other crates can load these extensions using
2020
the crate attribute `#![plugin(...)]`. See the
21-
`rustc_plugin` documentation for more about the
21+
`rustc_driver::plugin` documentation for more about the
2222
mechanics of defining and loading a plugin.
2323

2424
If present, arguments passed as `#![plugin(foo(... args ...))]` are not
@@ -54,13 +54,13 @@ that implements Roman numeral integer literals.
5454
extern crate syntax;
5555
extern crate syntax_pos;
5656
extern crate rustc;
57-
extern crate rustc_plugin;
57+
extern crate rustc_driver;
5858
5959
use syntax::parse::token::{self, Token};
6060
use syntax::tokenstream::TokenTree;
6161
use syntax::ext::base::{ExtCtxt, MacResult, DummyResult, MacEager};
6262
use syntax_pos::Span;
63-
use rustc_plugin::Registry;
63+
use rustc_driver::plugin::Registry;
6464
6565
fn expand_rn(cx: &mut ExtCtxt, sp: Span, args: &[TokenTree])
6666
-> Box<dyn MacResult + 'static> {
@@ -180,11 +180,11 @@ extern crate syntax;
180180
// Load rustc as a plugin to get macros
181181
#[macro_use]
182182
extern crate rustc;
183-
extern crate rustc_plugin;
183+
extern crate rustc_driver;
184184
185185
use rustc::lint::{EarlyContext, LintContext, LintPass, EarlyLintPass,
186186
EarlyLintPassObject, LintArray};
187-
use rustc_plugin::Registry;
187+
use rustc_driver::plugin::Registry;
188188
use syntax::ast;
189189
190190
declare_lint!(TEST_LINT, Warn, "Warn about items named 'lintme'");

src/liballoc/boxed.rs

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,10 @@ use core::ops::{
9191
CoerceUnsized, DispatchFromDyn, Deref, DerefMut, Receiver, Generator, GeneratorState
9292
};
9393
use core::ptr::{self, NonNull, Unique};
94+
use core::slice;
9495
use core::task::{Context, Poll};
9596

97+
use crate::alloc::{self, Global, Alloc};
9698
use crate::vec::Vec;
9799
use crate::raw_vec::RawVec;
98100
use crate::str::from_boxed_utf8_unchecked;
@@ -121,6 +123,34 @@ impl<T> Box<T> {
121123
box x
122124
}
123125

126+
/// Constructs a new box with uninitialized contents.
127+
///
128+
/// # Examples
129+
///
130+
/// ```
131+
/// #![feature(new_uninit)]
132+
///
133+
/// let mut five = Box::<u32>::new_uninit();
134+
///
135+
/// let five = unsafe {
136+
/// // Deferred initialization:
137+
/// five.as_mut_ptr().write(5);
138+
///
139+
/// five.assume_init()
140+
/// };
141+
///
142+
/// assert_eq!(*five, 5)
143+
/// ```
144+
#[unstable(feature = "new_uninit", issue = "63291")]
145+
pub fn new_uninit() -> Box<mem::MaybeUninit<T>> {
146+
let layout = alloc::Layout::new::<mem::MaybeUninit<T>>();
147+
let ptr = unsafe {
148+
Global.alloc(layout)
149+
.unwrap_or_else(|_| alloc::handle_alloc_error(layout))
150+
};
151+
Box(ptr.cast().into())
152+
}
153+
124154
/// Constructs a new `Pin<Box<T>>`. If `T` does not implement `Unpin`, then
125155
/// `x` will be pinned in memory and unable to be moved.
126156
#[stable(feature = "pin", since = "1.33.0")]
@@ -130,6 +160,111 @@ impl<T> Box<T> {
130160
}
131161
}
132162

163+
impl<T> Box<[T]> {
164+
/// Constructs a new boxed slice with uninitialized contents.
165+
///
166+
/// # Examples
167+
///
168+
/// ```
169+
/// #![feature(new_uninit)]
170+
///
171+
/// let mut values = Box::<[u32]>::new_uninit_slice(3);
172+
///
173+
/// let values = unsafe {
174+
/// // Deferred initialization:
175+
/// values[0].as_mut_ptr().write(1);
176+
/// values[1].as_mut_ptr().write(2);
177+
/// values[2].as_mut_ptr().write(3);
178+
///
179+
/// values.assume_init()
180+
/// };
181+
///
182+
/// assert_eq!(*values, [1, 2, 3])
183+
/// ```
184+
#[unstable(feature = "new_uninit", issue = "63291")]
185+
pub fn new_uninit_slice(len: usize) -> Box<[mem::MaybeUninit<T>]> {
186+
let layout = alloc::Layout::array::<mem::MaybeUninit<T>>(len).unwrap();
187+
let ptr = unsafe { alloc::alloc(layout) };
188+
let unique = Unique::new(ptr).unwrap_or_else(|| alloc::handle_alloc_error(layout));
189+
let slice = unsafe { slice::from_raw_parts_mut(unique.cast().as_ptr(), len) };
190+
Box(Unique::from(slice))
191+
}
192+
}
193+
194+
impl<T> Box<mem::MaybeUninit<T>> {
195+
/// Converts to `Box<T>`.
196+
///
197+
/// # Safety
198+
///
199+
/// As with [`MaybeUninit::assume_init`],
200+
/// it is up to the caller to guarantee that the value
201+
/// really is in an initialized state.
202+
/// Calling this when the content is not yet fully initialized
203+
/// causes immediate undefined behavior.
204+
///
205+
/// [`MaybeUninit::assume_init`]: ../../std/mem/union.MaybeUninit.html#method.assume_init
206+
///
207+
/// # Examples
208+
///
209+
/// ```
210+
/// #![feature(new_uninit)]
211+
///
212+
/// let mut five = Box::<u32>::new_uninit();
213+
///
214+
/// let five: Box<u32> = unsafe {
215+
/// // Deferred initialization:
216+
/// five.as_mut_ptr().write(5);
217+
///
218+
/// five.assume_init()
219+
/// };
220+
///
221+
/// assert_eq!(*five, 5)
222+
/// ```
223+
#[unstable(feature = "new_uninit", issue = "63291")]
224+
#[inline]
225+
pub unsafe fn assume_init(self) -> Box<T> {
226+
Box(Box::into_unique(self).cast())
227+
}
228+
}
229+
230+
impl<T> Box<[mem::MaybeUninit<T>]> {
231+
/// Converts to `Box<[T]>`.
232+
///
233+
/// # Safety
234+
///
235+
/// As with [`MaybeUninit::assume_init`],
236+
/// it is up to the caller to guarantee that the values
237+
/// really are in an initialized state.
238+
/// Calling this when the content is not yet fully initialized
239+
/// causes immediate undefined behavior.
240+
///
241+
/// [`MaybeUninit::assume_init`]: ../../std/mem/union.MaybeUninit.html#method.assume_init
242+
///
243+
/// # Examples
244+
///
245+
/// ```
246+
/// #![feature(new_uninit)]
247+
///
248+
/// let mut values = Box::<[u32]>::new_uninit_slice(3);
249+
///
250+
/// let values = unsafe {
251+
/// // Deferred initialization:
252+
/// values[0].as_mut_ptr().write(1);
253+
/// values[1].as_mut_ptr().write(2);
254+
/// values[2].as_mut_ptr().write(3);
255+
///
256+
/// values.assume_init()
257+
/// };
258+
///
259+
/// assert_eq!(*values, [1, 2, 3])
260+
/// ```
261+
#[unstable(feature = "new_uninit", issue = "63291")]
262+
#[inline]
263+
pub unsafe fn assume_init(self) -> Box<[T]> {
264+
Box(Unique::new_unchecked(Box::into_raw(self) as _))
265+
}
266+
}
267+
133268
impl<T: ?Sized> Box<T> {
134269
/// Constructs a box from a raw pointer.
135270
///

src/liballoc/collections/vec_deque.rs

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,6 +1199,31 @@ impl<T> VecDeque<T> {
11991199
}
12001200
}
12011201

1202+
/// Removes the last element from the `VecDeque` and returns it, or `None` if
1203+
/// it is empty.
1204+
///
1205+
/// # Examples
1206+
///
1207+
/// ```
1208+
/// use std::collections::VecDeque;
1209+
///
1210+
/// let mut buf = VecDeque::new();
1211+
/// assert_eq!(buf.pop_back(), None);
1212+
/// buf.push_back(1);
1213+
/// buf.push_back(3);
1214+
/// assert_eq!(buf.pop_back(), Some(3));
1215+
/// ```
1216+
#[stable(feature = "rust1", since = "1.0.0")]
1217+
pub fn pop_back(&mut self) -> Option<T> {
1218+
if self.is_empty() {
1219+
None
1220+
} else {
1221+
self.head = self.wrap_sub(self.head, 1);
1222+
let head = self.head;
1223+
unsafe { Some(self.buffer_read(head)) }
1224+
}
1225+
}
1226+
12021227
/// Prepends an element to the `VecDeque`.
12031228
///
12041229
/// # Examples
@@ -1243,38 +1268,13 @@ impl<T> VecDeque<T> {
12431268
unsafe { self.buffer_write(head, value) }
12441269
}
12451270

1246-
/// Removes the last element from the `VecDeque` and returns it, or `None` if
1247-
/// it is empty.
1248-
///
1249-
/// # Examples
1250-
///
1251-
/// ```
1252-
/// use std::collections::VecDeque;
1253-
///
1254-
/// let mut buf = VecDeque::new();
1255-
/// assert_eq!(buf.pop_back(), None);
1256-
/// buf.push_back(1);
1257-
/// buf.push_back(3);
1258-
/// assert_eq!(buf.pop_back(), Some(3));
1259-
/// ```
1260-
#[stable(feature = "rust1", since = "1.0.0")]
1261-
pub fn pop_back(&mut self) -> Option<T> {
1262-
if self.is_empty() {
1263-
None
1264-
} else {
1265-
self.head = self.wrap_sub(self.head, 1);
1266-
let head = self.head;
1267-
unsafe { Some(self.buffer_read(head)) }
1268-
}
1269-
}
1270-
12711271
#[inline]
12721272
fn is_contiguous(&self) -> bool {
12731273
self.tail <= self.head
12741274
}
12751275

1276-
/// Removes an element from anywhere in the `VecDeque` and returns it, replacing it with the
1277-
/// last element.
1276+
/// Removes an element from anywhere in the `VecDeque` and returns it,
1277+
/// replacing it with the first element.
12781278
///
12791279
/// This does not preserve ordering, but is O(1).
12801280
///
@@ -1288,28 +1288,28 @@ impl<T> VecDeque<T> {
12881288
/// use std::collections::VecDeque;
12891289
///
12901290
/// let mut buf = VecDeque::new();
1291-
/// assert_eq!(buf.swap_remove_back(0), None);
1291+
/// assert_eq!(buf.swap_remove_front(0), None);
12921292
/// buf.push_back(1);
12931293
/// buf.push_back(2);
12941294
/// buf.push_back(3);
12951295
/// assert_eq!(buf, [1, 2, 3]);
12961296
///
1297-
/// assert_eq!(buf.swap_remove_back(0), Some(1));
1298-
/// assert_eq!(buf, [3, 2]);
1297+
/// assert_eq!(buf.swap_remove_front(2), Some(3));
1298+
/// assert_eq!(buf, [2, 1]);
12991299
/// ```
13001300
#[stable(feature = "deque_extras_15", since = "1.5.0")]
1301-
pub fn swap_remove_back(&mut self, index: usize) -> Option<T> {
1301+
pub fn swap_remove_front(&mut self, index: usize) -> Option<T> {
13021302
let length = self.len();
1303-
if length > 0 && index < length - 1 {
1304-
self.swap(index, length - 1);
1303+
if length > 0 && index < length && index != 0 {
1304+
self.swap(index, 0);
13051305
} else if index >= length {
13061306
return None;
13071307
}
1308-
self.pop_back()
1308+
self.pop_front()
13091309
}
13101310

1311-
/// Removes an element from anywhere in the `VecDeque` and returns it,
1312-
/// replacing it with the first element.
1311+
/// Removes an element from anywhere in the `VecDeque` and returns it, replacing it with the
1312+
/// last element.
13131313
///
13141314
/// This does not preserve ordering, but is O(1).
13151315
///
@@ -1323,24 +1323,24 @@ impl<T> VecDeque<T> {
13231323
/// use std::collections::VecDeque;
13241324
///
13251325
/// let mut buf = VecDeque::new();
1326-
/// assert_eq!(buf.swap_remove_front(0), None);
1326+
/// assert_eq!(buf.swap_remove_back(0), None);
13271327
/// buf.push_back(1);
13281328
/// buf.push_back(2);
13291329
/// buf.push_back(3);
13301330
/// assert_eq!(buf, [1, 2, 3]);
13311331
///
1332-
/// assert_eq!(buf.swap_remove_front(2), Some(3));
1333-
/// assert_eq!(buf, [2, 1]);
1332+
/// assert_eq!(buf.swap_remove_back(0), Some(1));
1333+
/// assert_eq!(buf, [3, 2]);
13341334
/// ```
13351335
#[stable(feature = "deque_extras_15", since = "1.5.0")]
1336-
pub fn swap_remove_front(&mut self, index: usize) -> Option<T> {
1336+
pub fn swap_remove_back(&mut self, index: usize) -> Option<T> {
13371337
let length = self.len();
1338-
if length > 0 && index < length && index != 0 {
1339-
self.swap(index, 0);
1338+
if length > 0 && index < length - 1 {
1339+
self.swap(index, length - 1);
13401340
} else if index >= length {
13411341
return None;
13421342
}
1343-
self.pop_front()
1343+
self.pop_back()
13441344
}
13451345

13461346
/// Inserts an element at `index` within the `VecDeque`, shifting all elements with indices

0 commit comments

Comments
 (0)