Skip to content

Commit e1fa8de

Browse files
committed
Auto merge of #42522 - frewsxcv:rollup, r=frewsxcv
Rollup of 5 pull requests - Successful merges: #42470, #42490, #42497, #42510, #42512 - Failed merges:
2 parents d8d5592 + 13ae42f commit e1fa8de

File tree

12 files changed

+119
-32
lines changed

12 files changed

+119
-32
lines changed

src/Cargo.lock

+16-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/libcore/iter/iterator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ pub trait Iterator {
262262
/// Creates an iterator starting at the same point, but stepping by
263263
/// the given amount at each iteration.
264264
///
265-
/// Note that it will always return the first element of the range,
265+
/// Note that it will always return the first element of the iterator,
266266
/// regardless of the step given.
267267
///
268268
/// # Panics

src/librustc_mir/diagnostics.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,8 @@ use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT};
309309
310310
const A: AtomicUsize = ATOMIC_USIZE_INIT;
311311
static B: &'static AtomicUsize = &A;
312-
// error: cannot borrow a constant which contains interior mutability, create a
313-
// static instead
312+
// error: cannot borrow a constant which may contain interior mutability,
313+
// create a static instead
314314
```
315315
316316
A `const` represents a constant value that should never change. If one takes
@@ -338,8 +338,8 @@ use std::cell::Cell;
338338
339339
const A: Cell<usize> = Cell::new(1);
340340
const B: &'static Cell<usize> = &A;
341-
// error: cannot borrow a constant which contains interior mutability, create
342-
// a static instead
341+
// error: cannot borrow a constant which may contain interior mutability,
342+
// create a static instead
343343
344344
// or:
345345
struct C { a: Cell<usize> }

src/librustc_mir/transform/qualify_consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
663663
self.add(Qualif::NOT_CONST);
664664
if self.mode != Mode::Fn {
665665
span_err!(self.tcx.sess, self.span, E0492,
666-
"cannot borrow a constant which contains \
666+
"cannot borrow a constant which may contain \
667667
interior mutability, create a static instead");
668668
}
669669
}

src/librustc_resolve/macros.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,7 @@ impl<'a> base::Resolver for Resolver<'a> {
285285
-> Result<Option<Rc<SyntaxExtension>>, Determinacy> {
286286
let def = match invoc.kind {
287287
InvocationKind::Attr { attr: None, .. } => return Ok(None),
288-
_ => match self.resolve_invoc_to_def(invoc, scope, force) {
289-
Ok(def) => def,
290-
Err(determinacy) => return Err(determinacy),
291-
},
288+
_ => self.resolve_invoc_to_def(invoc, scope, force)?,
292289
};
293290

294291
self.macro_defs.insert(invoc.expansion_data.mark, def.def_id());

src/libstd/ffi/c_str.rs

+60
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,26 @@ impl CString {
288288
/// Failure to call [`from_raw`] will lead to a memory leak.
289289
///
290290
/// [`from_raw`]: #method.from_raw
291+
///
292+
/// # Examples
293+
///
294+
/// ```
295+
/// use std::ffi::CString;
296+
///
297+
/// let c_string = CString::new("foo").unwrap();
298+
///
299+
/// let ptr = c_string.into_raw();
300+
///
301+
/// unsafe {
302+
/// assert_eq!(b'f', *ptr as u8);
303+
/// assert_eq!(b'o', *ptr.offset(1) as u8);
304+
/// assert_eq!(b'o', *ptr.offset(2) as u8);
305+
/// assert_eq!(b'\0', *ptr.offset(3) as u8);
306+
///
307+
/// // retake pointer to free memory
308+
/// let _ = CString::from_raw(ptr);
309+
/// }
310+
/// ```
291311
#[stable(feature = "cstr_memory", since = "1.4.0")]
292312
pub fn into_raw(self) -> *mut c_char {
293313
Box::into_raw(self.into_inner()) as *mut c_char
@@ -311,6 +331,16 @@ impl CString {
311331
///
312332
/// The returned buffer does **not** contain the trailing nul separator and
313333
/// it is guaranteed to not have any interior nul bytes.
334+
///
335+
/// # Examples
336+
///
337+
/// ```
338+
/// use std::ffi::CString;
339+
///
340+
/// let c_string = CString::new("foo").unwrap();
341+
/// let bytes = c_string.into_bytes();
342+
/// assert_eq!(bytes, vec![b'f', b'o', b'o']);
343+
/// ```
314344
#[stable(feature = "cstring_into", since = "1.7.0")]
315345
pub fn into_bytes(self) -> Vec<u8> {
316346
let mut vec = self.into_inner().into_vec();
@@ -323,6 +353,16 @@ impl CString {
323353
/// includes the trailing nul byte.
324354
///
325355
/// [`into_bytes`]: #method.into_bytes
356+
///
357+
/// # Examples
358+
///
359+
/// ```
360+
/// use std::ffi::CString;
361+
///
362+
/// let c_string = CString::new("foo").unwrap();
363+
/// let bytes = c_string.into_bytes_with_nul();
364+
/// assert_eq!(bytes, vec![b'f', b'o', b'o', b'\0']);
365+
/// ```
326366
#[stable(feature = "cstring_into", since = "1.7.0")]
327367
pub fn into_bytes_with_nul(self) -> Vec<u8> {
328368
self.into_inner().into_vec()
@@ -332,6 +372,16 @@ impl CString {
332372
///
333373
/// The returned slice does **not** contain the trailing nul separator and
334374
/// it is guaranteed to not have any interior nul bytes.
375+
///
376+
/// # Examples
377+
///
378+
/// ```
379+
/// use std::ffi::CString;
380+
///
381+
/// let c_string = CString::new("foo").unwrap();
382+
/// let bytes = c_string.as_bytes();
383+
/// assert_eq!(bytes, &[b'f', b'o', b'o']);
384+
/// ```
335385
#[stable(feature = "rust1", since = "1.0.0")]
336386
pub fn as_bytes(&self) -> &[u8] {
337387
&self.inner[..self.inner.len() - 1]
@@ -341,6 +391,16 @@ impl CString {
341391
/// includes the trailing nul byte.
342392
///
343393
/// [`as_bytes`]: #method.as_bytes
394+
///
395+
/// # Examples
396+
///
397+
/// ```
398+
/// use std::ffi::CString;
399+
///
400+
/// let c_string = CString::new("foo").unwrap();
401+
/// let bytes = c_string.as_bytes_with_nul();
402+
/// assert_eq!(bytes, &[b'f', b'o', b'o', b'\0']);
403+
/// ```
344404
#[stable(feature = "rust1", since = "1.0.0")]
345405
pub fn as_bytes_with_nul(&self) -> &[u8] {
346406
&self.inner

src/libstd/panic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ pub trait UnwindSafe {}
112112
/// This is a "helper marker trait" used to provide impl blocks for the
113113
/// `UnwindSafe` trait, for more information see that documentation.
114114
#[stable(feature = "catch_unwind", since = "1.9.0")]
115-
#[rustc_on_unimplemented = "the type {Self} contains interior mutability \
115+
#[rustc_on_unimplemented = "the type {Self} may contain interior mutability \
116116
and a reference may not be safely transferrable \
117117
across a catch_unwind boundary"]
118118
pub trait RefUnwindSafe {}

src/libsyntax/parse/parser.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1249,10 +1249,7 @@ impl<'a> Parser<'a> {
12491249
let mac = respan(lo.to(self.prev_span), Mac_ { path: pth, tts: tts });
12501250
(keywords::Invalid.ident(), ast::TraitItemKind::Macro(mac))
12511251
} else {
1252-
let (constness, unsafety, abi) = match self.parse_fn_front_matter() {
1253-
Ok(cua) => cua,
1254-
Err(e) => return Err(e),
1255-
};
1252+
let (constness, unsafety, abi) = self.parse_fn_front_matter()?;
12561253

12571254
let ident = self.parse_ident()?;
12581255
let mut generics = self.parse_generics()?;

src/libsyntax/ptr.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,7 @@ impl<T: Encodable> Encodable for P<[T]> {
211211

212212
impl<T: Decodable> Decodable for P<[T]> {
213213
fn decode<D: Decoder>(d: &mut D) -> Result<P<[T]>, D::Error> {
214-
Ok(P::from_vec(match Decodable::decode(d) {
215-
Ok(t) => t,
216-
Err(e) => return Err(e)
217-
}))
214+
Ok(P::from_vec(Decodable::decode(d)?))
218215
}
219216
}
220217

src/test/compile-fail/issue-17718-const-borrow.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ use std::cell::UnsafeCell;
1414

1515
const A: UnsafeCell<usize> = UnsafeCell::new(1);
1616
const B: &'static UnsafeCell<usize> = &A;
17-
//~^ ERROR: cannot borrow a constant which contains interior mutability
17+
//~^ ERROR: cannot borrow a constant which may contain interior mutability
1818

1919
struct C { a: UnsafeCell<usize> }
2020
const D: C = C { a: UnsafeCell::new(1) };
2121
const E: &'static UnsafeCell<usize> = &D.a;
22-
//~^ ERROR: cannot borrow a constant which contains interior mutability
22+
//~^ ERROR: cannot borrow a constant which may contain interior mutability
2323
const F: &'static C = &D;
24-
//~^ ERROR: cannot borrow a constant which contains interior mutability
24+
//~^ ERROR: cannot borrow a constant which may contain interior mutability
2525

2626
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2016 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+
use std::cell::Cell;
12+
use std::panic::catch_unwind;
13+
fn main() {
14+
let mut x = Cell::new(22);
15+
catch_unwind(|| { x.set(23); });
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0277]: the trait bound `std::cell::UnsafeCell<i32>: std::panic::RefUnwindSafe` is not satisfied in `std::cell::Cell<i32>`
2+
--> $DIR/interior-mutability.rs:15:5
3+
|
4+
15 | catch_unwind(|| { x.set(23); });
5+
| ^^^^^^^^^^^^ the type std::cell::UnsafeCell<i32> may contain interior mutability and a reference may not be safely transferrable across a catch_unwind boundary
6+
|
7+
= help: within `std::cell::Cell<i32>`, the trait `std::panic::RefUnwindSafe` is not implemented for `std::cell::UnsafeCell<i32>`
8+
= note: required because it appears within the type `std::cell::Cell<i32>`
9+
= note: required because of the requirements on the impl of `std::panic::UnwindSafe` for `&std::cell::Cell<i32>`
10+
= note: required because it appears within the type `[closure@$DIR/interior-mutability.rs:15:18: 15:35 x:&std::cell::Cell<i32>]`
11+
= note: required by `std::panic::catch_unwind`
12+
13+
error: aborting due to previous error(s)
14+

0 commit comments

Comments
 (0)