Skip to content

Commit 7bffede

Browse files
committed
Auto merge of #38958 - sanxiyn:rollup, r=sanxiyn
Rollup of 11 pull requests - Successful merges: #38606, #38607, #38623, #38664, #38799, #38816, #38836, #38839, #38841, #38849, #38874 - Failed merges: #38845
2 parents 78c892d + db74f11 commit 7bffede

File tree

30 files changed

+346
-49
lines changed

30 files changed

+346
-49
lines changed

src/bootstrap/step.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,6 @@ pub fn build_rules<'a>(build: &'a Build) -> Rules {
316316
"codegen-units");
317317
suite("check-incremental", "src/test/incremental", "incremental",
318318
"incremental");
319-
suite("check-ui", "src/test/ui", "ui", "ui");
320319
}
321320

322321
if build.config.build.contains("msvc") {
@@ -363,6 +362,7 @@ pub fn build_rules<'a>(build: &'a Build) -> Rules {
363362
});
364363
};
365364

365+
suite("check-ui", "src/test/ui", "ui", "ui");
366366
suite("check-rpass-full", "src/test/run-pass-fulldeps",
367367
"run-pass", "run-pass-fulldeps");
368368
suite("check-rfail-full", "src/test/run-fail-fulldeps",
@@ -1374,7 +1374,6 @@ mod tests {
13741374

13751375
assert!(plan.iter().any(|s| s.name.contains("-ui")));
13761376
assert!(plan.iter().any(|s| s.name.contains("cfail")));
1377-
assert!(plan.iter().any(|s| s.name.contains("cfail")));
13781377
assert!(plan.iter().any(|s| s.name.contains("cfail-full")));
13791378
assert!(plan.iter().any(|s| s.name.contains("codegen-units")));
13801379
assert!(plan.iter().any(|s| s.name.contains("debuginfo")));
@@ -1407,8 +1406,7 @@ mod tests {
14071406
assert!(plan.iter().all(|s| s.host == "A"));
14081407
assert!(plan.iter().all(|s| s.target == "C"));
14091408

1410-
assert!(plan.iter().any(|s| s.name.contains("-ui")));
1411-
assert!(plan.iter().any(|s| s.name.contains("cfail")));
1409+
assert!(!plan.iter().any(|s| s.name.contains("-ui")));
14121410
assert!(plan.iter().any(|s| s.name.contains("cfail")));
14131411
assert!(!plan.iter().any(|s| s.name.contains("cfail-full")));
14141412
assert!(plan.iter().any(|s| s.name.contains("codegen-units")));

src/doc/nomicon/coercions.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Coercion is allowed between the following types:
1717
* `&T` to `*const T`
1818
* `&mut T` to `*mut T`
1919
* Unsizing: `T` to `U` if `T` implements `CoerceUnsized<U>`
20+
* Deref coercion: Expression `&x` of type `&T` to `&*x` of type `&U` if `T` derefs to `U` (i.e. `T: Deref<Target=U>`)
2021

2122
`CoerceUnsized<Pointer<U>> for Pointer<T> where T: Unsize<U>` is implemented
2223
for all pointer types (including smart pointers like Box and Rc). Unsize is
@@ -27,8 +28,9 @@ only implemented automatically, and enables the following transformations:
2728
* `Foo<..., T, ...>` => `Foo<..., U, ...>` where:
2829
* `T: Unsize<U>`
2930
* `Foo` is a struct
30-
* Only the last field of `Foo` has type `T`
31+
* Only the last field of `Foo` has type involving `T`
3132
* `T` is not part of the type of any other fields
33+
* `Bar<T>: Unsize<Bar<U>>`, if the last field of `Foo` has type `Bar<T>`
3234

3335
Coercions occur at a *coercion site*. Any location that is explicitly typed
3436
will cause a coercion to its type. If inference is necessary, the coercion will

src/liballoc/arc.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ impl<T: ?Sized> Arc<T> {
708708
}
709709

710710
#[stable(feature = "rust1", since = "1.0.0")]
711-
impl<T: ?Sized> Drop for Arc<T> {
711+
unsafe impl<#[may_dangle] T: ?Sized> Drop for Arc<T> {
712712
/// Drops the `Arc`.
713713
///
714714
/// This will decrement the strong reference count. If the strong reference
@@ -736,7 +736,6 @@ impl<T: ?Sized> Drop for Arc<T> {
736736
/// drop(foo); // Doesn't print anything
737737
/// drop(foo2); // Prints "dropped!"
738738
/// ```
739-
#[unsafe_destructor_blind_to_params]
740739
#[inline]
741740
fn drop(&mut self) {
742741
// Because `fetch_sub` is already atomic, we do not need to synchronize

src/liballoc/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,10 @@
7979
#![feature(const_fn)]
8080
#![feature(core_intrinsics)]
8181
#![feature(custom_attribute)]
82-
#![feature(dropck_parametricity)]
82+
#![feature(dropck_eyepatch)]
8383
#![cfg_attr(not(test), feature(exact_size_is_empty))]
8484
#![feature(fundamental)]
85+
#![feature(generic_param_attrs)]
8586
#![feature(lang_items)]
8687
#![feature(needs_allocator)]
8788
#![feature(optin_builtin_traits)]

src/liballoc/raw_vec.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -539,8 +539,7 @@ impl<T> RawVec<T> {
539539
}
540540
}
541541

542-
impl<T> Drop for RawVec<T> {
543-
#[unsafe_destructor_blind_to_params]
542+
unsafe impl<#[may_dangle] T> Drop for RawVec<T> {
544543
/// Frees the memory owned by the RawVec *without* trying to Drop its contents.
545544
fn drop(&mut self) {
546545
let elem_size = mem::size_of::<T>();

src/liballoc/rc.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ impl<T: ?Sized> Deref for Rc<T> {
644644
}
645645

646646
#[stable(feature = "rust1", since = "1.0.0")]
647-
impl<T: ?Sized> Drop for Rc<T> {
647+
unsafe impl<#[may_dangle] T: ?Sized> Drop for Rc<T> {
648648
/// Drops the `Rc`.
649649
///
650650
/// This will decrement the strong reference count. If the strong reference
@@ -672,7 +672,6 @@ impl<T: ?Sized> Drop for Rc<T> {
672672
/// drop(foo); // Doesn't print anything
673673
/// drop(foo2); // Prints "dropped!"
674674
/// ```
675-
#[unsafe_destructor_blind_to_params]
676675
fn drop(&mut self) {
677676
unsafe {
678677
let ptr = *self.ptr;

src/libarena/lib.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@
3030

3131
#![feature(alloc)]
3232
#![feature(core_intrinsics)]
33+
#![feature(dropck_eyepatch)]
3334
#![feature(heap_api)]
34-
#![feature(heap_api)]
35+
#![feature(generic_param_attrs)]
3536
#![feature(staged_api)]
36-
#![feature(dropck_parametricity)]
3737
#![cfg_attr(test, feature(test))]
3838

3939
#![allow(deprecated)]
@@ -258,8 +258,7 @@ impl<T> TypedArena<T> {
258258
}
259259
}
260260

261-
impl<T> Drop for TypedArena<T> {
262-
#[unsafe_destructor_blind_to_params]
261+
unsafe impl<#[may_dangle] T> Drop for TypedArena<T> {
263262
fn drop(&mut self) {
264263
unsafe {
265264
// Determine how much was filled.

src/libcollections/btree/map.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,7 @@ pub struct BTreeMap<K, V> {
137137
}
138138

139139
#[stable(feature = "btree_drop", since = "1.7.0")]
140-
impl<K, V> Drop for BTreeMap<K, V> {
141-
#[unsafe_destructor_blind_to_params]
140+
unsafe impl<#[may_dangle] K, #[may_dangle] V> Drop for BTreeMap<K, V> {
142141
fn drop(&mut self) {
143142
unsafe {
144143
for _ in ptr::read(self).into_iter() {

src/libcollections/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@
3535
#![feature(box_syntax)]
3636
#![cfg_attr(not(test), feature(char_escape_debug))]
3737
#![feature(core_intrinsics)]
38-
#![feature(dropck_parametricity)]
38+
#![feature(dropck_eyepatch)]
3939
#![feature(exact_size_is_empty)]
4040
#![feature(fmt_internals)]
4141
#![feature(fused)]
42+
#![feature(generic_param_attrs)]
4243
#![feature(heap_api)]
4344
#![feature(inclusive_range)]
4445
#![feature(lang_items)]

src/libcollections/linked_list.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -726,8 +726,7 @@ impl<T> LinkedList<T> {
726726
}
727727

728728
#[stable(feature = "rust1", since = "1.0.0")]
729-
impl<T> Drop for LinkedList<T> {
730-
#[unsafe_destructor_blind_to_params]
729+
unsafe impl<#[may_dangle] T> Drop for LinkedList<T> {
731730
fn drop(&mut self) {
732731
while let Some(_) = self.pop_front_node() {}
733732
}

src/libcollections/vec.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,8 @@ impl<T> Vec<T> {
370370
/// * `capacity` needs to be the capacity that the pointer was allocated with.
371371
///
372372
/// Violating these may cause problems like corrupting the allocator's
373-
/// internal datastructures.
373+
/// internal datastructures. For example it is **not** safe
374+
/// to build a `Vec<u8>` from a pointer to a C `char` array and a `size_t`.
374375
///
375376
/// The ownership of `ptr` is effectively transferred to the
376377
/// `Vec<T>` which may then deallocate, reallocate or change the
@@ -1786,8 +1787,7 @@ impl<T: Ord> Ord for Vec<T> {
17861787
}
17871788

17881789
#[stable(feature = "rust1", since = "1.0.0")]
1789-
impl<T> Drop for Vec<T> {
1790-
#[unsafe_destructor_blind_to_params]
1790+
unsafe impl<#[may_dangle] T> Drop for Vec<T> {
17911791
fn drop(&mut self) {
17921792
unsafe {
17931793
// use drop for [T]
@@ -2056,8 +2056,7 @@ impl<T: Clone> Clone for IntoIter<T> {
20562056
}
20572057

20582058
#[stable(feature = "rust1", since = "1.0.0")]
2059-
impl<T> Drop for IntoIter<T> {
2060-
#[unsafe_destructor_blind_to_params]
2059+
unsafe impl<#[may_dangle] T> Drop for IntoIter<T> {
20612060
fn drop(&mut self) {
20622061
// destroy the remaining elements
20632062
for _x in self.by_ref() {}

src/libcollections/vec_deque.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ impl<T: Clone> Clone for VecDeque<T> {
6969
}
7070

7171
#[stable(feature = "rust1", since = "1.0.0")]
72-
impl<T> Drop for VecDeque<T> {
73-
#[unsafe_destructor_blind_to_params]
72+
unsafe impl<#[may_dangle] T> Drop for VecDeque<T> {
7473
fn drop(&mut self) {
7574
let (front, back) = self.as_mut_slices();
7675
unsafe {

src/libcompiler_builtins/build.rs

-6
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,12 @@ fn main() {
192192

193193
if !target.contains("ios") {
194194
sources.extend(&["absvti2.c",
195-
"addtf3.c",
196195
"addvti3.c",
197196
"ashlti3.c",
198197
"ashrti3.c",
199198
"clzti2.c",
200199
"cmpti2.c",
201200
"ctzti2.c",
202-
"divtf3.c",
203201
"divti3.c",
204202
"ffsti2.c",
205203
"fixdfti.c",
@@ -216,17 +214,13 @@ fn main() {
216214
"floatuntixf.c",
217215
"lshrti3.c",
218216
"modti3.c",
219-
"multf3.c",
220217
"multi3.c",
221218
"mulvti3.c",
222219
"negti2.c",
223220
"negvti2.c",
224221
"parityti2.c",
225222
"popcountti2.c",
226-
"powitf2.c",
227-
"subtf3.c",
228223
"subvti3.c",
229-
"trampoline_setup.c",
230224
"ucmpti2.c",
231225
"udivmodti4.c",
232226
"udivti3.c",

src/libcore/marker.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,26 @@ pub trait Sized {
100100
///
101101
/// All implementations of `Unsize` are provided automatically by the compiler.
102102
///
103+
/// `Unsize` is implemented for:
104+
///
105+
/// - `[T; N]` is `Unsize<[T]>`
106+
/// - `T` is `Unsize<Trait>` when `T: Trait`
107+
/// - `Foo<..., T, ...>` is `Unsize<Foo<..., U, ...>>` if:
108+
/// - `T: Unsize<U>`
109+
/// - Foo is a struct
110+
/// - Only the last field of `Foo` has a type involving `T`
111+
/// - `T` is not part of the type of any other fields
112+
/// - `Bar<T>: Unsize<Bar<U>>`, if the last field of `Foo` has type `Bar<T>`
113+
///
103114
/// `Unsize` is used along with [`ops::CoerceUnsized`][coerceunsized] to allow
104115
/// "user-defined" containers such as [`rc::Rc`][rc] to contain dynamically-sized
105-
/// types. See the [DST coercion RFC][RFC982] for more details.
116+
/// types. See the [DST coercion RFC][RFC982] and [the nomicon entry on coercion][nomicon-coerce]
117+
/// for more details.
106118
///
107119
/// [coerceunsized]: ../ops/trait.CoerceUnsized.html
108120
/// [rc]: ../../std/rc/struct.Rc.html
109121
/// [RFC982]: https://github.com/rust-lang/rfcs/blob/master/text/0982-dst-coercion.md
122+
110123
#[unstable(feature = "unsize", issue = "27732")]
111124
#[lang="unsize"]
112125
pub trait Unsize<T: ?Sized> {

src/libcore/ops.rs

+29
Original file line numberDiff line numberDiff line change
@@ -2710,6 +2710,35 @@ mod impls {
27102710

27112711
/// Trait that indicates that this is a pointer or a wrapper for one,
27122712
/// where unsizing can be performed on the pointee.
2713+
///
2714+
/// See the [DST coercion RfC][dst-coerce] and [the nomicon entry on coercion][nomicon-coerce]
2715+
/// for more details.
2716+
///
2717+
/// For builtin pointer types, pointers to `T` will coerce to pointers to `U` if `T: Unsize<U>`
2718+
/// by converting from a thin pointer to a fat pointer.
2719+
///
2720+
/// For custom types, the coercion here works by coercing `Foo<T>` to `Foo<U>`
2721+
/// provided an impl of `CoerceUnsized<Foo<U>> for Foo<T>` exists.
2722+
/// Such an impl can only be written if `Foo<T>` has only a single non-phantomdata
2723+
/// field involving `T`. If the type of that field is `Bar<T>`, an implementation
2724+
/// of `CoerceUnsized<Bar<U>> for Bar<T>` must exist. The coercion will work by
2725+
/// by coercing the `Bar<T>` field into `Bar<U>` and filling in the rest of the fields
2726+
/// from `Foo<T>` to create a `Foo<U>`. This will effectively drill down to a pointer
2727+
/// field and coerce that.
2728+
///
2729+
/// Generally, for smart pointers you will implement
2730+
/// `CoerceUnsized<Ptr<U>> for Ptr<T> where T: Unsize<U>, U: ?Sized`, with an
2731+
/// optional `?Sized` bound on `T` itself. For wrapper types that directly embed `T`
2732+
/// like `Cell<T>` and `RefCell<T>`, you
2733+
/// can directly implement `CoerceUnsized<Wrap<U>> for Wrap<T> where T: CoerceUnsized<U>`.
2734+
/// This will let coercions of types like `Cell<Box<T>>` work.
2735+
///
2736+
/// [`Unsize`][unsize] is used to mark types which can be coerced to DSTs if behind
2737+
/// pointers. It is implemented automatically by the compiler.
2738+
///
2739+
/// [dst-coerce]: https://github.com/rust-lang/rfcs/blob/master/text/0982-dst-coercion.md
2740+
/// [unsize]: ../marker/trait.Unsize.html
2741+
/// [nomicon-coerce]: ../../nomicon/coercions.html
27132742
#[unstable(feature = "coerce_unsized", issue = "27732")]
27142743
#[lang="coerce_unsized"]
27152744
pub trait CoerceUnsized<T> {

src/librustc/session/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,7 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
11751175
assumed.", "[KIND=]NAME"),
11761176
opt::multi_s("", "crate-type", "Comma separated list of types of crates
11771177
for the compiler to emit",
1178-
"[bin|lib|rlib|dylib|cdylib|staticlib]"),
1178+
"[bin|lib|rlib|dylib|cdylib|staticlib|proc-macro]"),
11791179
opt::opt_s("", "crate-name", "Specify the name of the crate being built",
11801180
"NAME"),
11811181
opt::multi_s("", "emit", "Comma separated list of types of output for \

src/libstd/collections/hash/table.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1061,8 +1061,7 @@ impl<K: Clone, V: Clone> Clone for RawTable<K, V> {
10611061
}
10621062
}
10631063

1064-
impl<K, V> Drop for RawTable<K, V> {
1065-
#[unsafe_destructor_blind_to_params]
1064+
unsafe impl<#[may_dangle] K, #[may_dangle] V> Drop for RawTable<K, V> {
10661065
fn drop(&mut self) {
10671066
if self.capacity == 0 {
10681067
return;

src/libstd/ffi/os_str.rs

+23
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,15 @@ impl OsStr {
259259
/// Yields a `&str` slice if the `OsStr` is valid Unicode.
260260
///
261261
/// This conversion may entail doing a check for UTF-8 validity.
262+
///
263+
/// # Examples
264+
///
265+
/// ```
266+
/// use std::ffi::OsStr;
267+
///
268+
/// let os_str = OsStr::new("foo");
269+
/// assert_eq!(os_str.to_str(), Some("foo"));
270+
/// ```
262271
#[stable(feature = "rust1", since = "1.0.0")]
263272
pub fn to_str(&self) -> Option<&str> {
264273
self.inner.to_str()
@@ -267,6 +276,20 @@ impl OsStr {
267276
/// Converts an `OsStr` to a `Cow<str>`.
268277
///
269278
/// Any non-Unicode sequences are replaced with U+FFFD REPLACEMENT CHARACTER.
279+
///
280+
/// # Examples
281+
///
282+
/// Calling `to_string_lossy` on an `OsStr` with valid unicode:
283+
///
284+
/// ```
285+
/// use std::ffi::OsStr;
286+
///
287+
/// let os_str = OsStr::new("foo");
288+
/// assert_eq!(os_str.to_string_lossy(), "foo");
289+
/// ```
290+
///
291+
/// Had `os_str` contained invalid unicode, the `to_string_lossy` call might
292+
/// have returned `"fo�"`.
270293
#[stable(feature = "rust1", since = "1.0.0")]
271294
pub fn to_string_lossy(&self) -> Cow<str> {
272295
self.inner.to_string_lossy()

src/libstd/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,14 @@
250250
#![feature(const_fn)]
251251
#![feature(core_float)]
252252
#![feature(core_intrinsics)]
253-
#![feature(dropck_parametricity)]
253+
#![feature(dropck_eyepatch)]
254254
#![feature(exact_size_is_empty)]
255255
#![feature(float_extras)]
256256
#![feature(float_from_str_radix)]
257257
#![feature(fn_traits)]
258258
#![feature(fnbox)]
259259
#![feature(fused)]
260+
#![feature(generic_param_attrs)]
260261
#![feature(hashmap_hasher)]
261262
#![feature(heap_api)]
262263
#![feature(inclusive_range)]

src/libstd/net/tcp.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub struct TcpStream(net_imp::TcpStream);
5252
/// // ...
5353
/// }
5454
///
55-
/// // accept connections and process them, spawning a new thread for each one
55+
/// // accept connections and process them serially
5656
/// for stream in listener.incoming() {
5757
/// match stream {
5858
/// Ok(stream) => {

0 commit comments

Comments
 (0)