Skip to content

Commit 85a5d3f

Browse files
committed
Auto merge of #44784 - frewsxcv:rollup, r=frewsxcv
Rollup of 14 pull requests - Successful merges: #44554, #44648, #44658, #44712, #44717, #44726, #44745, #44746, #44749, #44759, #44770, #44773, #44776, #44778 - Failed merges:
2 parents 9ad67e9 + 2aa42ef commit 85a5d3f

File tree

19 files changed

+309
-58
lines changed

19 files changed

+309
-58
lines changed

CONTRIBUTING.md

+2
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ For people new to Rust, and just starting to contribute, or even for
461461
more seasoned developers, some useful places to look for information
462462
are:
463463

464+
* [Rust Forge][rustforge] contains additional documentation, including write-ups of how to achieve common tasks
464465
* The [Rust Internals forum][rif], a place to ask questions and
465466
discuss Rust's internals
466467
* The [generated documentation for rust's compiler][gdfrustc]
@@ -476,6 +477,7 @@ are:
476477
[gsearchdocs]: https://www.google.com/search?q=site:doc.rust-lang.org+your+query+here
477478
[rif]: http://internals.rust-lang.org
478479
[rr]: https://doc.rust-lang.org/book/README.html
480+
[rustforge]: https://forge.rust-lang.org/
479481
[tlgba]: http://tomlee.co/2014/04/a-more-detailed-tour-of-the-rust-compiler/
480482
[ro]: http://www.rustaceans.org/
481483
[rctd]: ./src/test/COMPILER_TESTS.md

src/liballoc/arc.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ const MAX_REFCOUNT: usize = (isize::MAX) as usize;
7272
/// first: after all, isn't the point of `Arc<T>` thread safety? The key is
7373
/// this: `Arc<T>` makes it thread safe to have multiple ownership of the same
7474
/// data, but it doesn't add thread safety to its data. Consider
75-
/// `Arc<RefCell<T>>`. `RefCell<T>` isn't [`Sync`], and if `Arc<T>` was always
76-
/// [`Send`], `Arc<RefCell<T>>` would be as well. But then we'd have a problem:
77-
/// `RefCell<T>` is not thread safe; it keeps track of the borrowing count using
75+
/// `Arc<`[`RefCell<T>`]`>`. [`RefCell<T>`] isn't [`Sync`], and if `Arc<T>` was always
76+
/// [`Send`], `Arc<`[`RefCell<T>`]`>` would be as well. But then we'd have a problem:
77+
/// [`RefCell<T>`] is not thread safe; it keeps track of the borrowing count using
7878
/// non-atomic operations.
7979
///
8080
/// In the end, this means that you may need to pair `Arc<T>` with some sort of
81-
/// `std::sync` type, usually `Mutex<T>`.
81+
/// [`std::sync`] type, usually [`Mutex<T>`][mutex].
8282
///
8383
/// ## Breaking cycles with `Weak`
8484
///
@@ -106,7 +106,7 @@ const MAX_REFCOUNT: usize = (isize::MAX) as usize;
106106
/// // a and b both point to the same memory location as foo.
107107
/// ```
108108
///
109-
/// The `Arc::clone(&from)` syntax is the most idiomatic because it conveys more explicitly
109+
/// The [`Arc::clone(&from)`] syntax is the most idiomatic because it conveys more explicitly
110110
/// the meaning of the code. In the example above, this syntax makes it easier to see that
111111
/// this code is creating a new reference rather than copying the whole content of foo.
112112
///
@@ -141,6 +141,9 @@ const MAX_REFCOUNT: usize = (isize::MAX) as usize;
141141
/// [upgrade]: struct.Weak.html#method.upgrade
142142
/// [`None`]: ../../std/option/enum.Option.html#variant.None
143143
/// [assoc]: ../../book/first-edition/method-syntax.html#associated-functions
144+
/// [`RefCell<T>`]: ../../std/cell/struct.RefCell.html
145+
/// [`std::sync`]: ../../std/sync/index.html
146+
/// [`Arc::clone(&from)`]: #method.clone
144147
///
145148
/// # Examples
146149
///

src/libcore/fmt/mod.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -1700,8 +1700,18 @@ impl<T: ?Sized + Debug> Debug for RefCell<T> {
17001700
.finish()
17011701
}
17021702
Err(_) => {
1703+
// The RefCell is mutably borrowed so we can't look at its value
1704+
// here. Show a placeholder instead.
1705+
struct BorrowedPlaceholder;
1706+
1707+
impl Debug for BorrowedPlaceholder {
1708+
fn fmt(&self, f: &mut Formatter) -> Result {
1709+
f.write_str("<borrowed>")
1710+
}
1711+
}
1712+
17031713
f.debug_struct("RefCell")
1704-
.field("value", &"<borrowed>")
1714+
.field("value", &BorrowedPlaceholder)
17051715
.finish()
17061716
}
17071717
}

src/libcore/mem.rs

+46-2
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,59 @@ pub fn forget<T>(t: T) {
177177

178178
/// Returns the size of a type in bytes.
179179
///
180-
/// More specifically, this is the offset in bytes between successive
181-
/// items of the same type, including alignment padding.
180+
/// More specifically, this is the offset in bytes between successive elements
181+
/// in an array with that item type including alignment padding. Thus, for any
182+
/// type `T` and length `n`, `[T; n]` has a size of `n * size_of::<T>()`.
183+
///
184+
/// In general, the size of a type is not stable across compilations, but
185+
/// specific types such as primitives are.
186+
///
187+
/// The following table gives the size for primitives.
188+
///
189+
/// Type | size_of::\<Type>()
190+
/// ---- | ---------------
191+
/// () | 0
192+
/// u8 | 1
193+
/// u16 | 2
194+
/// u32 | 4
195+
/// u64 | 8
196+
/// i8 | 1
197+
/// i16 | 2
198+
/// i32 | 4
199+
/// i64 | 8
200+
/// f32 | 4
201+
/// f64 | 8
202+
/// char | 4
203+
///
204+
/// Furthermore, `usize` and `isize` have the same size.
205+
///
206+
/// The types `*const T`, `&T`, `Box<T>`, `Option<&T>`, and `Option<Box<T>>` all have
207+
/// the same size. If `T` is Sized, all of those types have the same size as `usize`.
208+
///
209+
/// The mutability of a pointer does not change its size. As such, `&T` and `&mut T`
210+
/// have the same size. Likewise for `*const T` and `*mut T`.
182211
///
183212
/// # Examples
184213
///
185214
/// ```
186215
/// use std::mem;
187216
///
217+
/// // Some primitives
188218
/// assert_eq!(4, mem::size_of::<i32>());
219+
/// assert_eq!(8, mem::size_of::<f64>());
220+
/// assert_eq!(0, mem::size_of::<()>());
221+
///
222+
/// // Some arrays
223+
/// assert_eq!(8, mem::size_of::<[i32; 2]>());
224+
/// assert_eq!(12, mem::size_of::<[i32; 3]>());
225+
/// assert_eq!(0, mem::size_of::<[i32; 0]>());
226+
///
227+
///
228+
/// // Pointer size equality
229+
/// assert_eq!(mem::size_of::<&i32>(), mem::size_of::<*const i32>());
230+
/// assert_eq!(mem::size_of::<&i32>(), mem::size_of::<Box<i32>>());
231+
/// assert_eq!(mem::size_of::<&i32>(), mem::size_of::<Option<&i32>>());
232+
/// assert_eq!(mem::size_of::<Box<i32>>(), mem::size_of::<Option<Box<i32>>>());
189233
/// ```
190234
#[inline]
191235
#[stable(feature = "rust1", since = "1.0.0")]

src/libcore/str/mod.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1399,9 +1399,6 @@ Section: Comparing strings
13991399
*/
14001400

14011401
/// Bytewise slice equality
1402-
/// NOTE: This function is (ab)used in rustc::middle::trans::_match
1403-
/// to compare &[u8] byte slices that are not necessarily valid UTF-8.
1404-
#[lang = "str_eq"]
14051402
#[inline]
14061403
fn eq_slice(a: &str, b: &str) -> bool {
14071404
a.as_bytes() == b.as_bytes()

src/librustc/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ incremental improves that may change.)
3737

3838
The dependency structure of these crates is roughly a diamond:
3939

40-
````
40+
```
4141
rustc_driver
4242
/ | \
4343
/ | \

src/librustc/hir/lowering.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ use syntax::codemap::{self, respan, Spanned, CompilerDesugaringKind};
6565
use syntax::std_inject;
6666
use syntax::symbol::{Symbol, keywords};
6767
use syntax::tokenstream::{TokenStream, TokenTree, Delimited};
68-
use syntax::parse::token::{Token, DelimToken};
68+
use syntax::parse::token::Token;
6969
use syntax::util::small_vector::SmallVector;
7070
use syntax::visit::{self, Visitor};
7171
use syntax_pos::Span;
@@ -606,10 +606,12 @@ impl<'a> LoweringContext<'a> {
606606
}
607607

608608
fn lower_token_stream(&mut self, tokens: TokenStream) -> TokenStream {
609-
tokens.into_trees().map(|tree| self.lower_token_tree(tree)).collect()
609+
tokens.into_trees()
610+
.flat_map(|tree| self.lower_token_tree(tree).into_trees())
611+
.collect()
610612
}
611613

612-
fn lower_token_tree(&mut self, tree: TokenTree) -> TokenTree {
614+
fn lower_token_tree(&mut self, tree: TokenTree) -> TokenStream {
613615
match tree {
614616
TokenTree::Token(span, token) => {
615617
self.lower_token(token, span)
@@ -618,23 +620,19 @@ impl<'a> LoweringContext<'a> {
618620
TokenTree::Delimited(span, Delimited {
619621
delim: delimited.delim,
620622
tts: self.lower_token_stream(delimited.tts.into()).into(),
621-
})
623+
}).into()
622624
}
623625
}
624626
}
625627

626-
fn lower_token(&mut self, token: Token, span: Span) -> TokenTree {
628+
fn lower_token(&mut self, token: Token, span: Span) -> TokenStream {
627629
match token {
628630
Token::Interpolated(_) => {}
629-
other => return TokenTree::Token(span, other),
631+
other => return TokenTree::Token(span, other).into(),
630632
}
631633

632634
let tts = token.interpolated_to_tokenstream(&self.sess.parse_sess, span);
633-
let tts = self.lower_token_stream(tts);
634-
TokenTree::Delimited(span, Delimited {
635-
delim: DelimToken::NoDelim,
636-
tts: tts.into(),
637-
})
635+
self.lower_token_stream(tts)
638636
}
639637

640638
fn lower_arm(&mut self, arm: &Arm) -> hir::Arm {

src/librustc/middle/lang_items.rs

-2
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,6 @@ language_item_table! {
280280
EqTraitLangItem, "eq", eq_trait;
281281
OrdTraitLangItem, "ord", ord_trait;
282282

283-
StrEqFnLangItem, "str_eq", str_eq_fn;
284-
285283
// A number of panic-related lang items. The `panic` item corresponds to
286284
// divide-by-zero and various panic cases with `match`. The
287285
// `panic_bounds_check` item is for indexing arrays.

src/librustc/session/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,8 @@ impl Session {
411411
}
412412
pub fn emit_end_regions(&self) -> bool {
413413
self.opts.debugging_opts.emit_end_regions ||
414-
(self.opts.debugging_opts.mir_emit_validate > 0)
414+
(self.opts.debugging_opts.mir_emit_validate > 0) ||
415+
self.opts.debugging_opts.borrowck_mir
415416
}
416417
pub fn lto(&self) -> bool {
417418
self.opts.cg.lto

src/librustc_mir/borrow_check.rs

+19-6
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
419419
self.each_borrow_involving_path(
420420
context, lvalue_span.0, flow_state, |this, _idx, borrow| {
421421
if !borrow.compatible_with(BorrowKind::Shared) {
422-
this.report_use_while_mutably_borrowed(context, lvalue_span);
422+
this.report_use_while_mutably_borrowed(context, lvalue_span, borrow);
423423
Control::Break
424424
} else {
425425
Control::Continue
@@ -914,11 +914,17 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
914914

915915
fn report_use_while_mutably_borrowed(&mut self,
916916
_context: Context,
917-
(lvalue, span): (&Lvalue, Span)) {
917+
(lvalue, span): (&Lvalue, Span),
918+
borrow : &BorrowData) {
919+
let described_lvalue = self.describe_lvalue(lvalue);
920+
let borrow_span = self.retrieve_borrow_span(borrow);
921+
918922
let mut err = self.tcx.cannot_use_when_mutably_borrowed(
919-
span, &self.describe_lvalue(lvalue), Origin::Mir);
920-
// FIXME 1: add span_label for "borrow of `()` occurs here"
921-
// FIXME 2: add span_label for "use of `{}` occurs here"
923+
span, &described_lvalue, Origin::Mir);
924+
925+
err.span_label(borrow_span, format!("borrow of `{}` occurs here", described_lvalue));
926+
err.span_label(span, format!("use of borrowed `{}`", described_lvalue));
927+
922928
err.emit();
923929
}
924930

@@ -998,7 +1004,7 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
9981004
ProjectionElem::Downcast(..) =>
9991005
("", format!(""), None), // (dont emit downcast info)
10001006
ProjectionElem::Field(field, _ty) =>
1001-
("", format!(".{}", field.index()), None),
1007+
("", format!(".{}", field.index()), None), // FIXME: report name of field
10021008
ProjectionElem::Index(index) =>
10031009
("", format!(""), Some(index)),
10041010
ProjectionElem::ConstantIndex { offset, min_length, from_end: true } =>
@@ -1024,6 +1030,13 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
10241030
}
10251031
}
10261032
}
1033+
1034+
// Retrieve span of given borrow from the current MIR representation
1035+
fn retrieve_borrow_span(&self, borrow: &BorrowData) -> Span {
1036+
self.mir.basic_blocks()[borrow.location.block]
1037+
.statements[borrow.location.statement_index]
1038+
.source_info.span
1039+
}
10271040
}
10281041

10291042
impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx> {

src/librustdoc/html/render.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -2621,7 +2621,8 @@ fn render_assoc_item(w: &mut fmt::Formatter,
26212621
href(did).map(|p| format!("{}#{}.{}", p.0, ty, name)).unwrap_or(anchor)
26222622
}
26232623
};
2624-
let mut head_len = format!("{}{}{:#}fn {}{:#}",
2624+
let mut head_len = format!("{}{}{}{:#}fn {}{:#}",
2625+
VisSpace(&meth.visibility),
26252626
ConstnessSpace(constness),
26262627
UnsafetySpace(unsafety),
26272628
AbiSpace(abi),
@@ -2633,8 +2634,9 @@ fn render_assoc_item(w: &mut fmt::Formatter,
26332634
} else {
26342635
(0, true)
26352636
};
2636-
write!(w, "{}{}{}fn <a href='{href}' class='fnname'>{name}</a>\
2637+
write!(w, "{}{}{}{}fn <a href='{href}' class='fnname'>{name}</a>\
26372638
{generics}{decl}{where_clause}",
2639+
VisSpace(&meth.visibility),
26382640
ConstnessSpace(constness),
26392641
UnsafetySpace(unsafety),
26402642
AbiSpace(abi),

src/libstd/fs.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1595,9 +1595,9 @@ pub fn create_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
15951595
///
15961596
/// Notable exception is made for situations where any of the directories
15971597
/// specified in the `path` could not be created as it was being created concurrently.
1598-
/// Such cases are considered success. In other words: calling `create_dir_all`
1599-
/// concurrently from multiple threads or processes is guaranteed to not fail
1600-
/// due to race itself.
1598+
/// Such cases are considered to be successful. That is, calling `create_dir_all`
1599+
/// concurrently from multiple threads or processes is guaranteed not to fail
1600+
/// due to a race condition with itself.
16011601
///
16021602
/// # Examples
16031603
///

src/libstd/io/util.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ use mem;
4040
///
4141
/// io::copy(&mut reader, &mut writer)?;
4242
///
43-
/// assert_eq!(reader, &writer[..]);
43+
/// assert_eq!(&b"hello"[..], &writer[..]);
4444
/// # Ok(())
4545
/// # }
46+
/// # foo().unwrap();
4647
/// ```
4748
#[stable(feature = "rust1", since = "1.0.0")]
4849
pub fn copy<R: ?Sized, W: ?Sized>(reader: &mut R, writer: &mut W) -> io::Result<u64>

src/libstd/primitive_docs.rs

+8
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,10 @@ mod prim_u128 { }
710710
//
711711
/// The pointer-sized signed integer type.
712712
///
713+
/// The size of this primitive is how many bytes it takes to reference any
714+
/// location in memory. For example, on a 32 bit target, this is 4 bytes
715+
/// and on a 64 bit target, this is 8 bytes.
716+
///
713717
/// *[See also the `std::isize` module](isize/index.html).*
714718
///
715719
/// However, please note that examples are shared between primitive integer
@@ -722,6 +726,10 @@ mod prim_isize { }
722726
//
723727
/// The pointer-sized unsigned integer type.
724728
///
729+
/// The size of this primitive is how many bytes it takes to reference any
730+
/// location in memory. For example, on a 32 bit target, this is 4 bytes
731+
/// and on a 64 bit target, this is 8 bytes.
732+
///
725733
/// *[See also the `std::usize` module](usize/index.html).*
726734
///
727735
/// However, please note that examples are shared between primitive integer

0 commit comments

Comments
 (0)