Skip to content

Commit badf406

Browse files
authored
Auto merge of #36126 - GuillaumeGomez:rollup, r=GuillaumeGomez
Rollup of 16 pull requests - Successful merges: #35418, #35759, #35862, #35863, #35895, #35962, #35977, #35993, #35997, #36054, #36056, #36060, #36086, #36100, #36103, #36125 - Failed merges: #35771, #35810
2 parents addb753 + 2217fc5 commit badf406

File tree

30 files changed

+385
-136
lines changed

30 files changed

+385
-136
lines changed

src/doc/book/compiler-plugins.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ extern crate rustc;
4646
extern crate rustc_plugin;
4747
4848
use syntax::parse::token;
49-
use syntax::ast::TokenTree;
49+
use syntax::tokenstream::TokenTree;
5050
use syntax::ext::base::{ExtCtxt, MacResult, DummyResult, MacEager};
5151
use syntax::ext::build::AstBuilder; // trait for expr_usize
52-
use syntax_pos::Span;
52+
use syntax::ext::quote::rt::Span;
5353
use rustc_plugin::Registry;
5454
5555
fn expand_rn(cx: &mut ExtCtxt, sp: Span, args: &[TokenTree])
@@ -69,7 +69,7 @@ fn expand_rn(cx: &mut ExtCtxt, sp: Span, args: &[TokenTree])
6969
}
7070
7171
let text = match args[0] {
72-
TokenTree::Token(_, token::Ident(s, _)) => s.to_string(),
72+
TokenTree::Token(_, token::Ident(s)) => s.to_string(),
7373
_ => {
7474
cx.span_err(sp, "argument should be a single identifier");
7575
return DummyResult::any(sp);

src/liballoc/arc.rs

+6
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ const MAX_REFCOUNT: usize = (isize::MAX) as usize;
7171
/// does not use atomics, making it both thread-unsafe as well as significantly
7272
/// faster when updating the reference count.
7373
///
74+
/// Note: the inherent methods defined on `Arc<T>` are all associated functions,
75+
/// which means that you have to call them as e.g. `Arc::get_mut(&value)`
76+
/// instead of `value.get_mut()`. This is so that there are no conflicts with
77+
/// methods on the inner type `T`, which are what you want to call in the
78+
/// majority of cases.
79+
///
7480
/// # Examples
7581
///
7682
/// In this example, a large vector of data will be shared by several threads. First we

src/liballoc/boxed.rs

+4
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,10 @@ impl<T: ?Sized> Box<T> {
271271
/// proper way to do so is to convert the raw pointer back into a
272272
/// `Box` with the `Box::from_raw` function.
273273
///
274+
/// Note: this is an associated function, which means that you have
275+
/// to call it as `Box::into_raw(b)` instead of `b.into_raw()`. This
276+
/// is so that there is no conflict with a method on the inner type.
277+
///
274278
/// # Examples
275279
///
276280
/// ```

src/liballoc/rc.rs

+6
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,12 @@ struct RcBox<T: ?Sized> {
182182
/// A reference-counted pointer type over an immutable value.
183183
///
184184
/// See the [module level documentation](./index.html) for more details.
185+
///
186+
/// Note: the inherent methods defined on `Rc<T>` are all associated functions,
187+
/// which means that you have to call them as e.g. `Rc::get_mut(&value)` instead
188+
/// of `value.get_mut()`. This is so that there are no conflicts with methods
189+
/// on the inner type `T`, which are what you want to call in the majority of
190+
/// cases.
185191
#[cfg_attr(stage0, unsafe_no_drop_flag)]
186192
#[stable(feature = "rust1", since = "1.0.0")]
187193
pub struct Rc<T: ?Sized> {

src/libcollections/fmt.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,15 @@
165165
//! provides some helper methods.
166166
//!
167167
//! Additionally, the return value of this function is `fmt::Result` which is a
168-
//! typedef to `Result<(), std::io::Error>` (also known as `std::io::Result<()>`).
169-
//! Formatting implementations should ensure that they return errors from `write!`
170-
//! correctly (propagating errors upward).
168+
//! type alias of `Result<(), std::fmt::Error>`. Formatting implementations
169+
//! should ensure that they propagate errors from the `Formatter` (e.g., when
170+
//! calling `write!`) however, they should never return errors spuriously. That
171+
//! is, a formatting implementation must and may only return an error if the
172+
//! passed-in `Formatter` returns an error. This is because, contrary to what
173+
//! the function signature might suggest, string formatting is an infallible
174+
//! operation. This function only returns a result because writing to the
175+
//! underlying stream might fail and it must provide a way to propagate the fact
176+
//! that an error has occurred back up the stack.
171177
//!
172178
//! An example of implementing the formatting traits would look
173179
//! like:

src/libcore/cell.rs

+39-10
Original file line numberDiff line numberDiff line change
@@ -119,26 +119,55 @@
119119
//! `Cell<T>`.
120120
//!
121121
//! ```
122+
//! #![feature(core_intrinsics)]
123+
//! #![feature(shared)]
122124
//! use std::cell::Cell;
125+
//! use std::ptr::Shared;
126+
//! use std::intrinsics::abort;
127+
//! use std::intrinsics::assume;
123128
//!
124-
//! struct Rc<T> {
125-
//! ptr: *mut RcBox<T>
129+
//! struct Rc<T: ?Sized> {
130+
//! ptr: Shared<RcBox<T>>
126131
//! }
127132
//!
128-
//! struct RcBox<T> {
129-
//! # #[allow(dead_code)]
133+
//! struct RcBox<T: ?Sized> {
134+
//! strong: Cell<usize>,
135+
//! refcount: Cell<usize>,
130136
//! value: T,
131-
//! refcount: Cell<usize>
132137
//! }
133138
//!
134-
//! impl<T> Clone for Rc<T> {
139+
//! impl<T: ?Sized> Clone for Rc<T> {
135140
//! fn clone(&self) -> Rc<T> {
136-
//! unsafe {
137-
//! (*self.ptr).refcount.set((*self.ptr).refcount.get() + 1);
138-
//! Rc { ptr: self.ptr }
139-
//! }
141+
//! self.inc_strong();
142+
//! Rc { ptr: self.ptr }
143+
//! }
144+
//! }
145+
//!
146+
//! trait RcBoxPtr<T: ?Sized> {
147+
//!
148+
//! fn inner(&self) -> &RcBox<T>;
149+
//!
150+
//! fn strong(&self) -> usize {
151+
//! self.inner().strong.get()
152+
//! }
153+
//!
154+
//! fn inc_strong(&self) {
155+
//! self.inner()
156+
//! .strong
157+
//! .set(self.strong()
158+
//! .checked_add(1)
159+
//! .unwrap_or_else(|| unsafe { abort() }));
140160
//! }
141161
//! }
162+
//!
163+
//! impl<T: ?Sized> RcBoxPtr<T> for Rc<T> {
164+
//! fn inner(&self) -> &RcBox<T> {
165+
//! unsafe {
166+
//! assume(!(*(&self.ptr as *const _ as *const *const ())).is_null());
167+
//! &(**self.ptr)
168+
//! }
169+
//! }
170+
//! }
142171
//! ```
143172
//!
144173

0 commit comments

Comments
 (0)