Skip to content

Commit bc10b68

Browse files
committed
Auto merge of #73115 - RalfJung:rollup-jecowhz, r=RalfJung
Rollup of 10 pull requests Successful merges: - #72026 (Update annotate-snippets-rs to 0.8.0) - #72583 (impl AsRef<[T]> for vec::IntoIter<T>) - #72615 (Fix documentation example for gcov profiling) - #72761 (Added the documentation for the 'use' keyword) - #72799 (Add `-Z span-debug` to allow for easier debugging of proc macros) - #72811 (Liballoc impl) - #72963 (Cstring `from_raw` and `into_raw` safety precisions) - #73001 (Free `default()` forwarding to `Default::default()`) - #73075 (Add comments to `Resolve::get_module`) - #73092 (Clean up E0646) Failed merges: r? @ghost
2 parents 7355816 + 7983e56 commit bc10b68

File tree

24 files changed

+655
-175
lines changed

24 files changed

+655
-175
lines changed

Cargo.lock

+9-3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ dependencies = [
4848
"ansi_term",
4949
]
5050

51+
[[package]]
52+
name = "annotate-snippets"
53+
version = "0.8.0"
54+
source = "registry+https://github.com/rust-lang/crates.io-index"
55+
checksum = "d78ea013094e5ea606b1c05fe35f1dd7ea1eb1ea259908d040b25bd5ec677ee5"
56+
5157
[[package]]
5258
name = "ansi_term"
5359
version = "0.11.0"
@@ -3316,7 +3322,7 @@ version = "659.0.0"
33163322
source = "registry+https://github.com/rust-lang/crates.io-index"
33173323
checksum = "0c374e89b3c9714869ef86076942155383804ba6778c26be2169d324563c31f9"
33183324
dependencies = [
3319-
"annotate-snippets",
3325+
"annotate-snippets 0.6.1",
33203326
"atty",
33213327
"log",
33223328
"rustc-ap-rustc_data_structures",
@@ -3810,7 +3816,7 @@ version = "0.0.0"
38103816
name = "rustc_errors"
38113817
version = "0.0.0"
38123818
dependencies = [
3813-
"annotate-snippets",
3819+
"annotate-snippets 0.8.0",
38143820
"atty",
38153821
"log",
38163822
"rustc_data_structures",
@@ -4477,7 +4483,7 @@ dependencies = [
44774483
name = "rustfmt-nightly"
44784484
version = "1.4.15"
44794485
dependencies = [
4480-
"annotate-snippets",
4486+
"annotate-snippets 0.6.1",
44814487
"bytecount",
44824488
"cargo_metadata 0.8.0",
44834489
"derive-new",

src/doc/unstable-book/src/compiler-flags/profile.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,16 @@ For example:
1212
```Bash
1313
cargo new testgcov --bin
1414
cd testgcov
15-
export RUSTFLAGS="-Zprofile"
15+
export RUSTFLAGS="-Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort"
16+
export CARGO_INCREMENTAL=0
1617
cargo build
1718
cargo run
1819
```
1920

2021
Once you've built and run your program, files with the `gcno` (after build) and `gcda` (after execution) extensions will be created.
2122
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).
23+
24+
Please note that `RUSTFLAGS` by default applies to everything that cargo builds and runs during a build!
25+
When the `--target` flag is explicitly passed to cargo, the `RUSTFLAGS` no longer apply to build scripts and procedural macros.
26+
For more fine-grained control consider passing a `RUSTC_WRAPPER` program to cargo that only adds the profiling flags to
27+
rustc for the specific crates you want to profile.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# `default_free_fn`
2+
3+
The tracking issue for this feature is: [#73014]
4+
5+
[#73014]: https://github.com/rust-lang/rust/issues/73014
6+
7+
------------------------
8+
9+
Adds a free `default()` function to the `std::default` module. This function
10+
just forwards to [`Default::default()`], but may remove repetition of the word
11+
"default" from the call site.
12+
13+
Here is an example:
14+
15+
```rust
16+
#![feature(default_free_fn)]
17+
use std::default::default;
18+
19+
#[derive(Default)]
20+
struct AppConfig {
21+
foo: FooConfig,
22+
bar: BarConfig,
23+
}
24+
25+
#[derive(Default)]
26+
struct FooConfig {
27+
foo: i32,
28+
}
29+
30+
#[derive(Default)]
31+
struct BarConfig {
32+
bar: f32,
33+
baz: u8,
34+
}
35+
36+
fn main() {
37+
let options = AppConfig {
38+
foo: default(),
39+
bar: BarConfig {
40+
bar: 10.1,
41+
..default()
42+
},
43+
};
44+
}
45+
```

src/liballoc/raw_vec.rs

+24-26
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,30 @@ impl<T> RawVec<T, Global> {
118118
RawVec::from_raw_parts(slice.as_mut_ptr(), slice.len())
119119
}
120120
}
121+
122+
/// Converts the entire buffer into `Box<[MaybeUninit<T>]>` with the specified `len`.
123+
///
124+
/// Note that this will correctly reconstitute any `cap` changes
125+
/// that may have been performed. (See description of type for details.)
126+
///
127+
/// # Safety
128+
///
129+
/// * `len` must be greater than or equal to the most recently requested capacity, and
130+
/// * `len` must be less than or equal to `self.capacity()`.
131+
///
132+
/// Note, that the requested capacity and `self.capacity()` could differ, as
133+
/// an allocator could overallocate and return a greater memory block than requested.
134+
pub unsafe fn into_box(self, len: usize) -> Box<[MaybeUninit<T>]> {
135+
// Sanity-check one half of the safety requirement (we cannot check the other half).
136+
debug_assert!(
137+
len <= self.capacity(),
138+
"`len` must be smaller than or equal to `self.capacity()`"
139+
);
140+
141+
let me = ManuallyDrop::new(self);
142+
let slice = slice::from_raw_parts_mut(me.ptr() as *mut MaybeUninit<T>, len);
143+
Box::from_raw(slice)
144+
}
121145
}
122146

123147
impl<T, A: AllocRef> RawVec<T, A> {
@@ -520,32 +544,6 @@ where
520544
Ok(memory)
521545
}
522546

523-
impl<T> RawVec<T, Global> {
524-
/// Converts the entire buffer into `Box<[MaybeUninit<T>]>` with the specified `len`.
525-
///
526-
/// Note that this will correctly reconstitute any `cap` changes
527-
/// that may have been performed. (See description of type for details.)
528-
///
529-
/// # Safety
530-
///
531-
/// * `len` must be greater than or equal to the most recently requested capacity, and
532-
/// * `len` must be less than or equal to `self.capacity()`.
533-
///
534-
/// Note, that the requested capacity and `self.capacity()` could differ, as
535-
/// an allocator could overallocate and return a greater memory block than requested.
536-
pub unsafe fn into_box(self, len: usize) -> Box<[MaybeUninit<T>]> {
537-
// Sanity-check one half of the safety requirement (we cannot check the other half).
538-
debug_assert!(
539-
len <= self.capacity(),
540-
"`len` must be smaller than or equal to `self.capacity()`"
541-
);
542-
543-
let me = ManuallyDrop::new(self);
544-
let slice = slice::from_raw_parts_mut(me.ptr() as *mut MaybeUninit<T>, len);
545-
Box::from_raw(slice)
546-
}
547-
}
548-
549547
unsafe impl<#[may_dangle] T, A: AllocRef> Drop for RawVec<T, A> {
550548
/// Frees the memory owned by the `RawVec` *without* trying to drop its contents.
551549
fn drop(&mut self) {

src/liballoc/vec.rs

+23-16
Original file line numberDiff line numberDiff line change
@@ -1905,6 +1905,22 @@ unsafe impl<T: ?Sized> IsZero for Option<Box<T>> {
19051905
// Common trait implementations for Vec
19061906
////////////////////////////////////////////////////////////////////////////////
19071907

1908+
#[stable(feature = "rust1", since = "1.0.0")]
1909+
impl<T> ops::Deref for Vec<T> {
1910+
type Target = [T];
1911+
1912+
fn deref(&self) -> &[T] {
1913+
unsafe { slice::from_raw_parts(self.as_ptr(), self.len) }
1914+
}
1915+
}
1916+
1917+
#[stable(feature = "rust1", since = "1.0.0")]
1918+
impl<T> ops::DerefMut for Vec<T> {
1919+
fn deref_mut(&mut self) -> &mut [T] {
1920+
unsafe { slice::from_raw_parts_mut(self.as_mut_ptr(), self.len) }
1921+
}
1922+
}
1923+
19081924
#[stable(feature = "rust1", since = "1.0.0")]
19091925
impl<T: Clone> Clone for Vec<T> {
19101926
#[cfg(not(test))]
@@ -1960,22 +1976,6 @@ impl<T, I: SliceIndex<[T]>> IndexMut<I> for Vec<T> {
19601976
}
19611977
}
19621978

1963-
#[stable(feature = "rust1", since = "1.0.0")]
1964-
impl<T> ops::Deref for Vec<T> {
1965-
type Target = [T];
1966-
1967-
fn deref(&self) -> &[T] {
1968-
unsafe { slice::from_raw_parts(self.as_ptr(), self.len) }
1969-
}
1970-
}
1971-
1972-
#[stable(feature = "rust1", since = "1.0.0")]
1973-
impl<T> ops::DerefMut for Vec<T> {
1974-
fn deref_mut(&mut self) -> &mut [T] {
1975-
unsafe { slice::from_raw_parts_mut(self.as_mut_ptr(), self.len) }
1976-
}
1977-
}
1978-
19791979
#[stable(feature = "rust1", since = "1.0.0")]
19801980
impl<T> FromIterator<T> for Vec<T> {
19811981
#[inline]
@@ -2628,6 +2628,13 @@ impl<T> IntoIter<T> {
26282628
}
26292629
}
26302630

2631+
#[stable(feature = "vec_intoiter_as_ref", since = "1.46.0")]
2632+
impl<T> AsRef<[T]> for IntoIter<T> {
2633+
fn as_ref(&self) -> &[T] {
2634+
self.as_slice()
2635+
}
2636+
}
2637+
26312638
#[stable(feature = "rust1", since = "1.0.0")]
26322639
unsafe impl<T: Send> Send for IntoIter<T> {}
26332640
#[stable(feature = "rust1", since = "1.0.0")]

src/libcore/default.rs

+44
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,50 @@ pub trait Default: Sized {
115115
fn default() -> Self;
116116
}
117117

118+
/// Return the default value of a type according to the `Default` trait.
119+
///
120+
/// The type to return is inferred from context; this is equivalent to
121+
/// `Default::default()` but shorter to type.
122+
///
123+
/// For example:
124+
/// ```
125+
/// #![feature(default_free_fn)]
126+
///
127+
/// use std::default::default;
128+
///
129+
/// #[derive(Default)]
130+
/// struct AppConfig {
131+
/// foo: FooConfig,
132+
/// bar: BarConfig,
133+
/// }
134+
///
135+
/// #[derive(Default)]
136+
/// struct FooConfig {
137+
/// foo: i32,
138+
/// }
139+
///
140+
/// #[derive(Default)]
141+
/// struct BarConfig {
142+
/// bar: f32,
143+
/// baz: u8,
144+
/// }
145+
///
146+
/// fn main() {
147+
/// let options = AppConfig {
148+
/// foo: default(),
149+
/// bar: BarConfig {
150+
/// bar: 10.1,
151+
/// ..default()
152+
/// },
153+
/// };
154+
/// }
155+
/// ```
156+
#[unstable(feature = "default_free_fn", issue = "73014")]
157+
#[inline]
158+
pub fn default<T: Default>() -> T {
159+
Default::default()
160+
}
161+
118162
/// Derive macro generating an impl of the trait `Default`.
119163
#[rustc_builtin_macro]
120164
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]

src/librustc_error_codes/error_codes/E0646.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
It is not possible to define `main` with a where clause.
2+
23
Erroneous code example:
34

45
```compile_fail,E0646

src/librustc_errors/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ rustc_data_structures = { path = "../librustc_data_structures" }
1717
unicode-width = "0.1.4"
1818
atty = "0.2"
1919
termcolor = "1.0"
20-
annotate-snippets = "0.6.1"
20+
annotate-snippets = "0.8.0"
2121
termize = "0.1.1"
2222

2323
[target.'cfg(windows)'.dependencies]

0 commit comments

Comments
 (0)