Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 17 pull requests #49190

Merged
merged 58 commits into from
Mar 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
cba5f6b
Rewrite Borrow's trait documentation.
partim Dec 5, 2017
c4ea700
Remove trailing white space.
partim Dec 5, 2017
85e8a9b
Include feedback and try to make examples build on all channels.
partim Dec 7, 2017
fc6c638
Fix documentation links.
partim Dec 13, 2017
7ae7e53
New introduction and revised hash map explanation.
partim Feb 8, 2018
44be054
Further refinement of Borrow documentation.
partim Feb 27, 2018
5766e71
Cache the specialization_graph query
wesleywiser Mar 14, 2018
0b111e6
change &self to self and fix lifetime annotations
csmoe Mar 8, 2018
c62d9eb
fix formatting
csmoe Mar 11, 2018
50f2884
Replace many of the last references to readmes
mark-i-m Mar 16, 2018
b910d6b
Use associated consts for GenericRadix base and prefix
glandium Mar 17, 2018
5bef034
Bring back the phrase 'borrowing as' for what Borrow does.
partim Mar 17, 2018
d664b89
Rewrite the documentation for BorrowMut.
partim Mar 17, 2018
9f5a356
improve attribute trailing semicolon error
csmoe Mar 17, 2018
fab7020
Add span_suggestion while removing TyRefs based on the snippet String.
ysiraichi Feb 9, 2018
1e73c1d
rustbuild: Ship libsynchronization
NovemberZulu Mar 18, 2018
13d94d6
Fix formatting.
partim Mar 18, 2018
5511624
remove unneeded where clause
csmoe Mar 15, 2018
5581aa8
Fix events handling in rustdoc
GuillaumeGomez Mar 18, 2018
16da5d4
Add BufReader::buffer
sfackler Mar 18, 2018
4dd4506
Refactored with high-order functions.
ysiraichi Mar 11, 2018
e0fb013
Test added.
ysiraichi Mar 13, 2018
f44b945
New test added.
ysiraichi Mar 13, 2018
97b66d2
Review fixes.
ysiraichi Mar 13, 2018
f41dc77
Keeping code formatting.
ysiraichi Mar 14, 2018
52cd07a
Created multiple line test.
ysiraichi Mar 14, 2018
f6bffd1
Rebased with master.
ysiraichi Mar 14, 2018
c1ba5ac
Reporting with `span_suggestion_short`.
ysiraichi Mar 16, 2018
74a4928
Review fixes.
ysiraichi Mar 17, 2018
0b36b20
CodeMap functions refactored.
ysiraichi Mar 18, 2018
736ba43
Cleaned comments and extras s.
ysiraichi Mar 18, 2018
612c4a9
Impl Integer methods for Wrapping
Phlosioneer Mar 7, 2018
5258af3
Make Wrapping::pow use wrapping_pow, add example
Phlosioneer Mar 8, 2018
bf101a5
Fix trailing whitespace
Phlosioneer Mar 8, 2018
741d7a5
Docs: fix incorrect copy-paste for new `X?` in formatting strings
SimonSapin Mar 19, 2018
3799866
#49133 - Reworded the Error message: "`pub` not needed here" message
dileepbapat Mar 19, 2018
a8f59aa
#49133 - Reworded the Error message: "`pub` not needed here" message
dileepbapat Mar 19, 2018
253ade5
Update rustfmt to 0.4.1
alanhdu Mar 19, 2018
7dd9438
config.toml.example: thinlto bootstrap was removed in ff227c4a2d8a2fa…
matthiaskrgr Mar 19, 2018
1b8f1fc
Do not suggest `.into()` in `const`s
estebank Mar 19, 2018
57c74c3
Update beta to version with fixed FreeBSD support from #49023.
bdrewery Mar 19, 2018
f32f810
Rollup merge of #46518 - partim:asref-borrow-doc, r=dtolnay
kennytm Mar 19, 2018
5d5f5a0
Rollup merge of #48810 - Phlosioneer:32463-impl-integer-for-wrapping,…
kennytm Mar 19, 2018
49b584c
Rollup merge of #48834 - ysiraichi:suggest-remove-ref, r=estebank
kennytm Mar 19, 2018
7aa6651
Rollup merge of #48902 - csmoe:refactor_BorrowckErrors_fn_self, r=nik…
kennytm Mar 19, 2018
28eced1
Rollup merge of #49004 - wesleywiser:incr_specialization_graph_query,…
kennytm Mar 19, 2018
7bc9fe3
Rollup merge of #49092 - mark-i-m:deptrack_readme, r=nikomatsakis
kennytm Mar 19, 2018
23e2e3a
Rollup merge of #49096 - alanhdu:master, r=alexcrichton
kennytm Mar 19, 2018
63ab361
Rollup merge of #49099 - glandium:master, r=sfackler
kennytm Mar 19, 2018
73846dc
Rollup merge of #49104 - csmoe:semicolon_error, r=petrochenkov
kennytm Mar 19, 2018
baea60b
Rollup merge of #49125 - NovemberZulu:master, r=alexcrichton
kennytm Mar 19, 2018
1f5d31f
Rollup merge of #49139 - sfackler:bufreader-buffer, r=SimonSapin
kennytm Mar 19, 2018
45de057
Rollup merge of #49152 - GuillaumeGomez:rustdoc-event-handling, r=Qui…
kennytm Mar 19, 2018
cfb5317
Rollup merge of #49157 - estebank:const-into, r=oli-obk
kennytm Mar 19, 2018
7fc81fa
Rollup merge of #49161 - rust-lang:SimonSapin-patch-1, r=KodrAus
kennytm Mar 19, 2018
c152e98
Rollup merge of #49166 - dileepbapat:pr-49133, r=nikomatsakis
kennytm Mar 19, 2018
d5244e4
Rollup merge of #49176 - matthiaskrgr:config_example_rm_thinlto, r=al…
kennytm Mar 19, 2018
57b8211
Rollup merge of #49184 - bdrewery:update-beta-freebsd, r=alexcrichton
kennytm Mar 19, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,6 @@
# compiler.
#codegen-units = 1

# Whether to enable ThinLTO (and increase the codegen units to either a default
# or the configured value). On by default. If we want the fastest possible
# compiler, we should disable this.
#thinlto = true

# Whether or not debug assertions are enabled for the compiler and standard
# library. Also enables compilation of debug! and trace! logging macros.
#debug-assertions = false
Expand Down
139 changes: 47 additions & 92 deletions src/Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/bootstrap/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ fn make_win_dist(
"libsecur32.a",
"libsetupapi.a",
"libshell32.a",
"libsynchronization.a",
"libuser32.a",
"libuserenv.a",
"libuuid.a",
Expand Down
2 changes: 1 addition & 1 deletion src/liballoc/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
//! * *nothing* ⇒ [`Display`]
//! * `?` ⇒ [`Debug`]
//! * `x?` ⇒ [`Debug`] with lower-case hexadecimal integers
//! * `X?` ⇒ [`Debug`] with lower-case hexadecimal integers
//! * `X?` ⇒ [`Debug`] with upper-case hexadecimal integers
//! * `o` ⇒ [`Octal`](trait.Octal.html)
//! * `x` ⇒ [`LowerHex`](trait.LowerHex.html)
//! * `X` ⇒ [`UpperHex`](trait.UpperHex.html)
Expand Down
164 changes: 149 additions & 15 deletions src/libcore/borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,154 @@

/// A trait for borrowing data.
///
/// In general, there may be several ways to "borrow" a piece of data. The
/// typical ways of borrowing a type `T` are `&T` (a shared borrow) and `&mut T`
/// (a mutable borrow). But types like `Vec<T>` provide additional kinds of
/// borrows: the borrowed slices `&[T]` and `&mut [T]`.
/// In Rust, it is common to provide different representations of a type for
/// different use cases. For instance, storage location and management for a
/// value can be specifically chosen as appropriate for a particular use via
/// pointer types such as [`Box<T>`] or [`Rc<T>`]. Beyond these generic
/// wrappers that can be used with any type, some types provide optional
/// facets providing potentially costly functionality. An example for such a
/// type is [`String`] which adds the ability to extend a string to the basic
/// [`str`]. This requires keeping additional information unnecessary for a
/// simple, immutable string.
///
/// When writing generic code, it is often desirable to abstract over all ways
/// of borrowing data from a given type. That is the role of the `Borrow`
/// trait: if `T: Borrow<U>`, then `&U` can be borrowed from `&T`. A given
/// type can be borrowed as multiple different types. In particular, `Vec<T>:
/// Borrow<Vec<T>>` and `Vec<T>: Borrow<[T]>`.
/// These types provide access to the underlying data through references
/// to the type of that data. They are said to be ‘borrowed as’ that type.
/// For instance, a [`Box<T>`] can be borrowed as `T` while a [`String`]
/// can be borrowed as `str`.
///
/// If you are implementing `Borrow` and both `Self` and `Borrowed` implement
/// `Hash`, `Eq`, and/or `Ord`, they must produce the same result.
/// Types express that they can be borrowed as some type `T` by implementing
/// `Borrow<T>`, providing a reference to a `T` in the trait’s
/// [`borrow`] method. A type is free to borrow as several different types.
/// If it wishes to mutably borrow as the type – allowing the underlying data
/// to be modified, it can additionally implement [`BorrowMut<T>`].
///
/// `Borrow` is very similar to, but different than, `AsRef`. See
/// [the book][book] for more.
/// Further, when providing implementations for additional traits, it needs
/// to be considered whether they should behave identical to those of the
/// underlying type as a consequence of acting as a representation of that
/// underlying type. Generic code typically uses `Borrow<T>` when it relies
/// on the identical behavior of these additional trait implementations.
/// These traits will likely appear as additional trait bounds.
///
/// [book]: ../../book/first-edition/borrow-and-asref.html
/// If generic code merely needs to work for all types that can
/// provide a reference to related type `T`, it is often better to use
/// [`AsRef<T>`] as more types can safely implement it.
///
/// [`AsRef<T>`]: ../../std/convert/trait.AsRef.html
/// [`BorrowMut<T>`]: trait.BorrowMut.html
/// [`Box<T>`]: ../../std/boxed/struct.Box.html
/// [`Mutex<T>`]: ../../std/sync/struct.Mutex.html
/// [`Rc<T>`]: ../../std/rc/struct.Rc.html
/// [`str`]: ../../std/primitive.str.html
/// [`String`]: ../../std/string/struct.String.html
/// [`borrow`]: #tymethod.borrow
///
/// # Examples
///
/// As a data collection, [`HashMap<K, V>`] owns both keys and values. If
/// the key’s actual data is wrapped in a managing type of some kind, it
/// should, however, still be possible to search for a value using a
/// reference to the key’s data. For instance, if the key is a string, then
/// it is likely stored with the hash map as a [`String`], while it should
/// be possible to search using a [`&str`][`str`]. Thus, `insert` needs to
/// operate on a `String` while `get` needs to be able to use a `&str`.
///
/// Slightly simplified, the relevant parts of `HashMap<K, V>` look like
/// this:
///
/// ```
/// use std::borrow::Borrow;
/// use std::hash::Hash;
///
/// pub struct HashMap<K, V> {
/// # marker: ::std::marker::PhantomData<(K, V)>,
/// // fields omitted
/// }
///
/// impl<K, V> HashMap<K, V> {
/// pub fn insert(&self, key: K, value: V) -> Option<V>
/// where K: Hash + Eq
/// {
/// # unimplemented!()
/// // ...
/// }
///
/// pub fn get<Q>(&self, k: &Q) -> Option<&V>
/// where
/// K: Borrow<Q>,
/// Q: Hash + Eq + ?Sized
/// {
/// # unimplemented!()
/// // ...
/// }
/// }
/// ```
///
/// The entire hash map is generic over a key type `K`. Because these keys
/// are stored with the hash map, this type has to own the key’s data.
/// When inserting a key-value pair, the map is given such a `K` and needs
/// to find the correct hash bucket and check if the key is already present
/// based on that `K`. It therefore requires `K: Hash + Eq`.
///
/// When searching for a value in the map, however, having to provide a
/// reference to a `K` as the key to search for would require to always
/// create such an owned value. For string keys, this would mean a `String`
/// value needs to be created just for the search for cases where only a
/// `str` is available.
///
/// Instead, the `get` method is generic over the type of the underlying key
/// data, called `Q` in the method signature above. It states that `K`
/// borrows as a `Q` by requiring that `K: Borrow<Q>`. By additionally
/// requiring `Q: Hash + Eq`, it signals the requirement that `K` and `Q`
/// have implementations of the `Hash` and `Eq` traits that produce identical
/// results.
///
/// The implementation of `get` relies in particular on identical
/// implementations of `Hash` by determining the key’s hash bucket by calling
/// `Hash::hash` on the `Q` value even though it inserted the key based on
/// the hash value calculated from the `K` value.
///
/// As a consequence, the hash map breaks if a `K` wrapping a `Q` value
/// produces a different hash than `Q`. For instance, imagine you have a
/// type that wraps a string but compares ASCII letters ignoring their case:
///
/// ```
/// pub struct CaseInsensitiveString(String);
///
/// impl PartialEq for CaseInsensitiveString {
/// fn eq(&self, other: &Self) -> bool {
/// self.0.eq_ignore_ascii_case(&other.0)
/// }
/// }
///
/// impl Eq for CaseInsensitiveString { }
/// ```
///
/// Because two equal values need to produce the same hash value, the
/// implementation of `Hash` needs to ignore ASCII case, too:
///
/// ```
/// # use std::hash::{Hash, Hasher};
/// # pub struct CaseInsensitiveString(String);
/// impl Hash for CaseInsensitiveString {
/// fn hash<H: Hasher>(&self, state: &mut H) {
/// for c in self.0.as_bytes() {
/// c.to_ascii_lowercase().hash(state)
/// }
/// }
/// }
/// ```
///
/// Can `CaseInsensitiveString` implement `Borrow<str>`? It certainly can
/// provide a reference to a string slice via its contained owned string.
/// But because its `Hash` implementation differs, it behaves differently
/// from `str` and therefore must not, in fact, implement `Borrow<str>`.
/// If it wants to allow others access to the underlying `str`, it can do
/// that via `AsRef<str>` which doesn’t carry any extra requirements.
///
/// [`Hash`]: ../../std/hash/trait.Hash.html
/// [`HashMap<K, V>`]: ../../std/collections/struct.HashMap.html
/// [`String`]: ../../std/string/struct.String.html
/// [`str`]: ../../std/primitive.str.html
#[stable(feature = "rust1", since = "1.0.0")]
pub trait Borrow<Borrowed: ?Sized> {
/// Immutably borrows from an owned value.
Expand Down Expand Up @@ -59,7 +189,11 @@ pub trait Borrow<Borrowed: ?Sized> {

/// A trait for mutably borrowing data.
///
/// Similar to `Borrow`, but for mutable borrows.
/// As a companion to [`Borrow<T>`] this trait allows a type to borrow as
/// an underlying type by providing a mutable reference. See [`Borrow<T>`]
/// for more information on borrowing as another type.
///
/// [`Borrow<T>`]: trait.Borrow.html
#[stable(feature = "rust1", since = "1.0.0")]
pub trait BorrowMut<Borrowed: ?Sized> : Borrow<Borrowed> {
/// Mutably borrows from an owned value.
Expand Down
32 changes: 15 additions & 17 deletions src/libcore/fmt/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,13 @@ doit! { i8 i16 i32 i64 i128 isize u8 u16 u32 u64 u128 usize }
#[doc(hidden)]
trait GenericRadix {
/// The number of digits.
fn base(&self) -> u8;
const BASE: u8;

/// A radix-specific prefix string.
fn prefix(&self) -> &'static str {
""
}
const PREFIX: &'static str;

/// Converts an integer to corresponding radix digit.
fn digit(&self, x: u8) -> u8;
fn digit(x: u8) -> u8;

/// Format an integer using the radix using a formatter.
fn fmt_int<T: Int>(&self, mut x: T, f: &mut fmt::Formatter) -> fmt::Result {
Expand All @@ -67,14 +65,14 @@ trait GenericRadix {
let is_nonnegative = x >= zero;
let mut buf = [0; 128];
let mut curr = buf.len();
let base = T::from_u8(self.base());
let base = T::from_u8(Self::BASE);
if is_nonnegative {
// Accumulate each digit of the number from the least significant
// to the most significant figure.
for byte in buf.iter_mut().rev() {
let n = x % base; // Get the current place value.
x = x / base; // Deaccumulate the number.
*byte = self.digit(n.to_u8()); // Store the digit in the buffer.
let n = x % base; // Get the current place value.
x = x / base; // Deaccumulate the number.
*byte = Self::digit(n.to_u8()); // Store the digit in the buffer.
curr -= 1;
if x == zero {
// No more digits left to accumulate.
Expand All @@ -84,9 +82,9 @@ trait GenericRadix {
} else {
// Do the same as above, but accounting for two's complement.
for byte in buf.iter_mut().rev() {
let n = zero - (x % base); // Get the current place value.
x = x / base; // Deaccumulate the number.
*byte = self.digit(n.to_u8()); // Store the digit in the buffer.
let n = zero - (x % base); // Get the current place value.
x = x / base; // Deaccumulate the number.
*byte = Self::digit(n.to_u8()); // Store the digit in the buffer.
curr -= 1;
if x == zero {
// No more digits left to accumulate.
Expand All @@ -95,7 +93,7 @@ trait GenericRadix {
}
}
let buf = unsafe { str::from_utf8_unchecked(&buf[curr..]) };
f.pad_integral(is_nonnegative, self.prefix(), buf)
f.pad_integral(is_nonnegative, Self::PREFIX, buf)
}
}

Expand All @@ -122,12 +120,12 @@ struct UpperHex;
macro_rules! radix {
($T:ident, $base:expr, $prefix:expr, $($x:pat => $conv:expr),+) => {
impl GenericRadix for $T {
fn base(&self) -> u8 { $base }
fn prefix(&self) -> &'static str { $prefix }
fn digit(&self, x: u8) -> u8 {
const BASE: u8 = $base;
const PREFIX: &'static str = $prefix;
fn digit(x: u8) -> u8 {
match x {
$($x => $conv,)+
x => panic!("number not in the range 0..{}: {}", self.base() - 1, x),
x => panic!("number not in the range 0..{}: {}", Self::BASE - 1, x),
}
}
}
Expand Down
Loading