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 10 pull requests #73115

Merged
merged 28 commits into from
Jun 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
e9c78db
Update annotate-snippets-rs to 0.8.0
zzau13 May 8, 2020
f16060f
Add UI test where `annotated_files` count is > 1 #64205
zzau13 May 9, 2020
8fc6202
Fix make sure out primary file comes first
zzau13 May 16, 2020
91f52a5
impl AsRef<[T]> for vec::IntoIter<T>
CAD97 May 25, 2020
2b26b8b
Fix documentation example for gcov profiling
jschwe May 26, 2020
d1e3898
Added the documentation for the 'use' keyword
poliorcetics May 29, 2020
b0e524d
Apply suggestions from code review
poliorcetics May 30, 2020
4bae9e5
Remove the fn main() in code example
poliorcetics May 30, 2020
7944998
Rearrange impl blocks with Deref as first
pickfire May 31, 2020
7140463
Merge raw_vec into_box with previous impl<T, Global>
pickfire May 31, 2020
7bf026e
Doc: unstable book - profile.md: improve wording
jschwe Jun 3, 2020
00a7b56
Added the documentation about length to CString::from_raw
poliorcetics Jun 3, 2020
87abe17
Added a warning to CString::into_raw too
poliorcetics Jun 3, 2020
b541d3d
Add `-Z span-debug` to allow for easier debugging of proc macros
Aaron1011 May 31, 2020
ff327c8
Add comments to `Resolve::get_module`
jyn514 Jun 6, 2020
8f4dfa8
Free `default()` forwarding to `Default::default()`
ilya-bobyr Jun 4, 2020
ebb8722
unstable book: default_free_fn
ilya-bobyr Jun 5, 2020
af68249
Clean up E0646
GuillaumeGomez Jun 7, 2020
8484b99
Rollup merge of #72026 - botika:master, r=estebank
RalfJung Jun 8, 2020
b0559be
Rollup merge of #72583 - CAD97:vec-iter-asref-slice, r=dtolnay
RalfJung Jun 8, 2020
e8bb4c7
Rollup merge of #72615 - jschwe:fix-Zprofile-documentation, r=stevekl…
RalfJung Jun 8, 2020
89d8979
Rollup merge of #72761 - poliorcetics:use-keyword-doc, r=Dylan-DPC
RalfJung Jun 8, 2020
e135087
Rollup merge of #72799 - Aaron1011:feature/span-debug, r=petrochenkov
RalfJung Jun 8, 2020
13815e4
Rollup merge of #72811 - pickfire:liballoc-impl, r=Amanieu
RalfJung Jun 8, 2020
824ea6b
Rollup merge of #72963 - poliorcetics:cstring-from-raw, r=dtolnay
RalfJung Jun 8, 2020
244465d
Rollup merge of #73001 - ilya-bobyr:master, r=dtolnay
RalfJung Jun 8, 2020
13f2838
Rollup merge of #73075 - jyn514:comment-module, r=Dylan-DPC
RalfJung Jun 8, 2020
7983e56
Rollup merge of #73092 - GuillaumeGomez:cleanup-e0646, r=Dylan-DPC
RalfJung Jun 8, 2020
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
12 changes: 9 additions & 3 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ dependencies = [
"ansi_term",
]

[[package]]
name = "annotate-snippets"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d78ea013094e5ea606b1c05fe35f1dd7ea1eb1ea259908d040b25bd5ec677ee5"

[[package]]
name = "ansi_term"
version = "0.11.0"
Expand Down Expand Up @@ -3316,7 +3322,7 @@ version = "659.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c374e89b3c9714869ef86076942155383804ba6778c26be2169d324563c31f9"
dependencies = [
"annotate-snippets",
"annotate-snippets 0.6.1",
"atty",
"log",
"rustc-ap-rustc_data_structures",
Expand Down Expand Up @@ -3810,7 +3816,7 @@ version = "0.0.0"
name = "rustc_errors"
version = "0.0.0"
dependencies = [
"annotate-snippets",
"annotate-snippets 0.8.0",
"atty",
"log",
"rustc_data_structures",
Expand Down Expand Up @@ -4477,7 +4483,7 @@ dependencies = [
name = "rustfmt-nightly"
version = "1.4.15"
dependencies = [
"annotate-snippets",
"annotate-snippets 0.6.1",
"bytecount",
"cargo_metadata 0.8.0",
"derive-new",
Expand Down
8 changes: 7 additions & 1 deletion src/doc/unstable-book/src/compiler-flags/profile.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@ For example:
```Bash
cargo new testgcov --bin
cd testgcov
export RUSTFLAGS="-Zprofile"
export RUSTFLAGS="-Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort"
export CARGO_INCREMENTAL=0
cargo build
cargo run
```

Once you've built and run your program, files with the `gcno` (after build) and `gcda` (after execution) extensions will be created.
You can parse them with [llvm-cov gcov](https://llvm.org/docs/CommandGuide/llvm-cov.html#llvm-cov-gcov) or [grcov](https://github.com/mozilla/grcov).

Please note that `RUSTFLAGS` by default applies to everything that cargo builds and runs during a build!
When the `--target` flag is explicitly passed to cargo, the `RUSTFLAGS` no longer apply to build scripts and procedural macros.
For more fine-grained control consider passing a `RUSTC_WRAPPER` program to cargo that only adds the profiling flags to
rustc for the specific crates you want to profile.
45 changes: 45 additions & 0 deletions src/doc/unstable-book/src/library-features/default-free-fn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# `default_free_fn`

The tracking issue for this feature is: [#73014]

[#73014]: https://github.com/rust-lang/rust/issues/73014

------------------------

Adds a free `default()` function to the `std::default` module. This function
just forwards to [`Default::default()`], but may remove repetition of the word
"default" from the call site.

Here is an example:

```rust
#![feature(default_free_fn)]
use std::default::default;

#[derive(Default)]
struct AppConfig {
foo: FooConfig,
bar: BarConfig,
}

#[derive(Default)]
struct FooConfig {
foo: i32,
}

#[derive(Default)]
struct BarConfig {
bar: f32,
baz: u8,
}

fn main() {
let options = AppConfig {
foo: default(),
bar: BarConfig {
bar: 10.1,
..default()
},
};
}
```
50 changes: 24 additions & 26 deletions src/liballoc/raw_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,30 @@ impl<T> RawVec<T, Global> {
RawVec::from_raw_parts(slice.as_mut_ptr(), slice.len())
}
}

/// Converts the entire buffer into `Box<[MaybeUninit<T>]>` with the specified `len`.
///
/// Note that this will correctly reconstitute any `cap` changes
/// that may have been performed. (See description of type for details.)
///
/// # Safety
///
/// * `len` must be greater than or equal to the most recently requested capacity, and
/// * `len` must be less than or equal to `self.capacity()`.
///
/// Note, that the requested capacity and `self.capacity()` could differ, as
/// an allocator could overallocate and return a greater memory block than requested.
pub unsafe fn into_box(self, len: usize) -> Box<[MaybeUninit<T>]> {
// Sanity-check one half of the safety requirement (we cannot check the other half).
debug_assert!(
len <= self.capacity(),
"`len` must be smaller than or equal to `self.capacity()`"
);

let me = ManuallyDrop::new(self);
let slice = slice::from_raw_parts_mut(me.ptr() as *mut MaybeUninit<T>, len);
Box::from_raw(slice)
}
}

impl<T, A: AllocRef> RawVec<T, A> {
Expand Down Expand Up @@ -520,32 +544,6 @@ where
Ok(memory)
}

impl<T> RawVec<T, Global> {
/// Converts the entire buffer into `Box<[MaybeUninit<T>]>` with the specified `len`.
///
/// Note that this will correctly reconstitute any `cap` changes
/// that may have been performed. (See description of type for details.)
///
/// # Safety
///
/// * `len` must be greater than or equal to the most recently requested capacity, and
/// * `len` must be less than or equal to `self.capacity()`.
///
/// Note, that the requested capacity and `self.capacity()` could differ, as
/// an allocator could overallocate and return a greater memory block than requested.
pub unsafe fn into_box(self, len: usize) -> Box<[MaybeUninit<T>]> {
// Sanity-check one half of the safety requirement (we cannot check the other half).
debug_assert!(
len <= self.capacity(),
"`len` must be smaller than or equal to `self.capacity()`"
);

let me = ManuallyDrop::new(self);
let slice = slice::from_raw_parts_mut(me.ptr() as *mut MaybeUninit<T>, len);
Box::from_raw(slice)
}
}

unsafe impl<#[may_dangle] T, A: AllocRef> Drop for RawVec<T, A> {
/// Frees the memory owned by the `RawVec` *without* trying to drop its contents.
fn drop(&mut self) {
Expand Down
39 changes: 23 additions & 16 deletions src/liballoc/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1905,6 +1905,22 @@ unsafe impl<T: ?Sized> IsZero for Option<Box<T>> {
// Common trait implementations for Vec
////////////////////////////////////////////////////////////////////////////////

#[stable(feature = "rust1", since = "1.0.0")]
impl<T> ops::Deref for Vec<T> {
type Target = [T];

fn deref(&self) -> &[T] {
unsafe { slice::from_raw_parts(self.as_ptr(), self.len) }
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T> ops::DerefMut for Vec<T> {
fn deref_mut(&mut self) -> &mut [T] {
unsafe { slice::from_raw_parts_mut(self.as_mut_ptr(), self.len) }
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Clone> Clone for Vec<T> {
#[cfg(not(test))]
Expand Down Expand Up @@ -1960,22 +1976,6 @@ impl<T, I: SliceIndex<[T]>> IndexMut<I> for Vec<T> {
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T> ops::Deref for Vec<T> {
type Target = [T];

fn deref(&self) -> &[T] {
unsafe { slice::from_raw_parts(self.as_ptr(), self.len) }
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T> ops::DerefMut for Vec<T> {
fn deref_mut(&mut self) -> &mut [T] {
unsafe { slice::from_raw_parts_mut(self.as_mut_ptr(), self.len) }
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T> FromIterator<T> for Vec<T> {
#[inline]
Expand Down Expand Up @@ -2628,6 +2628,13 @@ impl<T> IntoIter<T> {
}
}

#[stable(feature = "vec_intoiter_as_ref", since = "1.46.0")]
impl<T> AsRef<[T]> for IntoIter<T> {
fn as_ref(&self) -> &[T] {
self.as_slice()
}
}

#[stable(feature = "rust1", since = "1.0.0")]
unsafe impl<T: Send> Send for IntoIter<T> {}
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
44 changes: 44 additions & 0 deletions src/libcore/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,50 @@ pub trait Default: Sized {
fn default() -> Self;
}

/// Return the default value of a type according to the `Default` trait.
///
/// The type to return is inferred from context; this is equivalent to
/// `Default::default()` but shorter to type.
///
/// For example:
/// ```
/// #![feature(default_free_fn)]
///
/// use std::default::default;
///
/// #[derive(Default)]
/// struct AppConfig {
/// foo: FooConfig,
/// bar: BarConfig,
/// }
///
/// #[derive(Default)]
/// struct FooConfig {
/// foo: i32,
/// }
///
/// #[derive(Default)]
/// struct BarConfig {
/// bar: f32,
/// baz: u8,
/// }
///
/// fn main() {
/// let options = AppConfig {
/// foo: default(),
/// bar: BarConfig {
/// bar: 10.1,
/// ..default()
/// },
/// };
/// }
/// ```
#[unstable(feature = "default_free_fn", issue = "73014")]
#[inline]
pub fn default<T: Default>() -> T {
Default::default()
}

/// Derive macro generating an impl of the trait `Default`.
#[rustc_builtin_macro]
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
Expand Down
1 change: 1 addition & 0 deletions src/librustc_error_codes/error_codes/E0646.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
It is not possible to define `main` with a where clause.

Erroneous code example:

```compile_fail,E0646
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_errors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ rustc_data_structures = { path = "../librustc_data_structures" }
unicode-width = "0.1.4"
atty = "0.2"
termcolor = "1.0"
annotate-snippets = "0.6.1"
annotate-snippets = "0.8.0"
termize = "0.1.1"

[target.'cfg(windows)'.dependencies]
Expand Down
Loading