Skip to content

Commit 704af2d

Browse files
committed
Auto merge of #52268 - Mark-Simulacrum:rollup, r=Mark-Simulacrum
Rollup of 14 pull requests Successful merges: - #51614 (Correct suggestion for println) - #51952 ( hygiene: Decouple transparencies from expansion IDs) - #52193 (step_by: leave time of item skip unspecified) - #52207 (improve error message shown for unsafe operations) - #52223 (Deny bare trait objects in in src/liballoc) - #52224 (Deny bare trait objects in in src/libsyntax) - #52239 (Remove sync::Once::call_once 'static bound) - #52247 (Deny bare trait objects in in src/librustc) - #52248 (Deny bare trait objects in in src/librustc_allocator) - #52252 (Deny bare trait objects in in src/librustc_codegen_llvm) - #52253 (Deny bare trait objects in in src/librustc_data_structures) - #52254 (Deny bare trait objects in in src/librustc_metadata) - #52261 (Deny bare trait objects in in src/libpanic_unwind) - #52265 (Deny bare trait objects in in src/librustc_codegen_utils) Failed merges: r? @ghost
2 parents d573fe1 + a0b288e commit 704af2d

File tree

97 files changed

+865
-480
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+865
-480
lines changed

src/liballoc/boxed.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ impl From<Box<str>> for Box<[u8]> {
446446
}
447447
}
448448

449-
impl Box<Any> {
449+
impl Box<dyn Any> {
450450
#[inline]
451451
#[stable(feature = "rust1", since = "1.0.0")]
452452
/// Attempt to downcast the box to a concrete type.
@@ -468,10 +468,10 @@ impl Box<Any> {
468468
/// print_if_string(Box::new(0i8));
469469
/// }
470470
/// ```
471-
pub fn downcast<T: Any>(self) -> Result<Box<T>, Box<Any>> {
471+
pub fn downcast<T: Any>(self) -> Result<Box<T>, Box<dyn Any>> {
472472
if self.is::<T>() {
473473
unsafe {
474-
let raw: *mut Any = Box::into_raw(self);
474+
let raw: *mut dyn Any = Box::into_raw(self);
475475
Ok(Box::from_raw(raw as *mut T))
476476
}
477477
} else {
@@ -480,7 +480,7 @@ impl Box<Any> {
480480
}
481481
}
482482

483-
impl Box<Any + Send> {
483+
impl Box<dyn Any + Send> {
484484
#[inline]
485485
#[stable(feature = "rust1", since = "1.0.0")]
486486
/// Attempt to downcast the box to a concrete type.
@@ -502,10 +502,10 @@ impl Box<Any + Send> {
502502
/// print_if_string(Box::new(0i8));
503503
/// }
504504
/// ```
505-
pub fn downcast<T: Any>(self) -> Result<Box<T>, Box<Any + Send>> {
506-
<Box<Any>>::downcast(self).map_err(|s| unsafe {
505+
pub fn downcast<T: Any>(self) -> Result<Box<T>, Box<dyn Any + Send>> {
506+
<Box<dyn Any>>::downcast(self).map_err(|s| unsafe {
507507
// reapply the Send marker
508-
Box::from_raw(Box::into_raw(s) as *mut (Any + Send))
508+
Box::from_raw(Box::into_raw(s) as *mut (dyn Any + Send))
509509
})
510510
}
511511
}
@@ -643,7 +643,7 @@ impl<A, F> FnBox<A> for F
643643

644644
#[unstable(feature = "fnbox",
645645
reason = "will be deprecated if and when `Box<FnOnce>` becomes usable", issue = "28796")]
646-
impl<'a, A, R> FnOnce<A> for Box<FnBox<A, Output = R> + 'a> {
646+
impl<'a, A, R> FnOnce<A> for Box<dyn FnBox<A, Output = R> + 'a> {
647647
type Output = R;
648648

649649
extern "rust-call" fn call_once(self, args: A) -> R {
@@ -653,7 +653,7 @@ impl<'a, A, R> FnOnce<A> for Box<FnBox<A, Output = R> + 'a> {
653653

654654
#[unstable(feature = "fnbox",
655655
reason = "will be deprecated if and when `Box<FnOnce>` becomes usable", issue = "28796")]
656-
impl<'a, A, R> FnOnce<A> for Box<FnBox<A, Output = R> + Send + 'a> {
656+
impl<'a, A, R> FnOnce<A> for Box<dyn FnBox<A, Output = R> + Send + 'a> {
657657
type Output = R;
658658

659659
extern "rust-call" fn call_once(self, args: A) -> R {

src/liballoc/boxed_test.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ struct Test;
3131

3232
#[test]
3333
fn any_move() {
34-
let a = Box::new(8) as Box<Any>;
35-
let b = Box::new(Test) as Box<Any>;
34+
let a = Box::new(8) as Box<dyn Any>;
35+
let b = Box::new(Test) as Box<dyn Any>;
3636

3737
match a.downcast::<i32>() {
3838
Ok(a) => {
@@ -47,26 +47,26 @@ fn any_move() {
4747
Err(..) => panic!(),
4848
}
4949

50-
let a = Box::new(8) as Box<Any>;
51-
let b = Box::new(Test) as Box<Any>;
50+
let a = Box::new(8) as Box<dyn Any>;
51+
let b = Box::new(Test) as Box<dyn Any>;
5252

5353
assert!(a.downcast::<Box<Test>>().is_err());
5454
assert!(b.downcast::<Box<i32>>().is_err());
5555
}
5656

5757
#[test]
5858
fn test_show() {
59-
let a = Box::new(8) as Box<Any>;
60-
let b = Box::new(Test) as Box<Any>;
59+
let a = Box::new(8) as Box<dyn Any>;
60+
let b = Box::new(Test) as Box<dyn Any>;
6161
let a_str = format!("{:?}", a);
6262
let b_str = format!("{:?}", b);
6363
assert_eq!(a_str, "Any");
6464
assert_eq!(b_str, "Any");
6565

6666
static EIGHT: usize = 8;
6767
static TEST: Test = Test;
68-
let a = &EIGHT as &Any;
69-
let b = &TEST as &Any;
68+
let a = &EIGHT as &dyn Any;
69+
let b = &TEST as &dyn Any;
7070
let s = format!("{:?}", a);
7171
assert_eq!(s, "Any");
7272
let s = format!("{:?}", b);
@@ -110,12 +110,12 @@ fn raw_trait() {
110110
}
111111
}
112112

113-
let x: Box<Foo> = Box::new(Bar(17));
113+
let x: Box<dyn Foo> = Box::new(Bar(17));
114114
let p = Box::into_raw(x);
115115
unsafe {
116116
assert_eq!(17, (*p).get());
117117
(*p).set(19);
118-
let y: Box<Foo> = Box::from_raw(p);
118+
let y: Box<dyn Foo> = Box::from_raw(p);
119119
assert_eq!(19, y.get());
120120
}
121121
}

src/liballoc/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
test(no_crate_inject, attr(allow(unused_variables), deny(warnings))))]
7373
#![no_std]
7474
#![needs_allocator]
75+
#![deny(bare_trait_objects)]
7576
#![deny(missing_debug_implementations)]
7677

7778
#![cfg_attr(test, allow(deprecated))] // rand

src/liballoc/rc.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ impl<T: Clone> Rc<T> {
618618
}
619619
}
620620

621-
impl Rc<Any> {
621+
impl Rc<dyn Any> {
622622
#[inline]
623623
#[stable(feature = "rc_downcast", since = "1.29.0")]
624624
/// Attempt to downcast the `Rc<Any>` to a concrete type.
@@ -641,7 +641,7 @@ impl Rc<Any> {
641641
/// print_if_string(Rc::new(0i8));
642642
/// }
643643
/// ```
644-
pub fn downcast<T: Any>(self) -> Result<Rc<T>, Rc<Any>> {
644+
pub fn downcast<T: Any>(self) -> Result<Rc<T>, Rc<dyn Any>> {
645645
if (*self).is::<T>() {
646646
let ptr = self.ptr.cast::<RcBox<T>>();
647647
forget(self);
@@ -1554,7 +1554,7 @@ mod tests {
15541554
assert_eq!(unsafe { &*ptr }, "foo");
15551555
assert_eq!(rc, rc2);
15561556

1557-
let rc: Rc<Display> = Rc::new(123);
1557+
let rc: Rc<dyn Display> = Rc::new(123);
15581558

15591559
let ptr = Rc::into_raw(rc.clone());
15601560
let rc2 = unsafe { Rc::from_raw(ptr) };
@@ -1755,8 +1755,8 @@ mod tests {
17551755
use std::fmt::Display;
17561756
use std::string::ToString;
17571757

1758-
let b: Box<Display> = box 123;
1759-
let r: Rc<Display> = Rc::from(b);
1758+
let b: Box<dyn Display> = box 123;
1759+
let r: Rc<dyn Display> = Rc::from(b);
17601760

17611761
assert_eq!(r.to_string(), "123");
17621762
}
@@ -1765,8 +1765,8 @@ mod tests {
17651765
fn test_from_box_trait_zero_sized() {
17661766
use std::fmt::Debug;
17671767

1768-
let b: Box<Debug> = box ();
1769-
let r: Rc<Debug> = Rc::from(b);
1768+
let b: Box<dyn Debug> = box ();
1769+
let r: Rc<dyn Debug> = Rc::from(b);
17701770

17711771
assert_eq!(format!("{:?}", r), "()");
17721772
}
@@ -1783,8 +1783,8 @@ mod tests {
17831783
fn test_downcast() {
17841784
use std::any::Any;
17851785

1786-
let r1: Rc<Any> = Rc::new(i32::max_value());
1787-
let r2: Rc<Any> = Rc::new("abc");
1786+
let r1: Rc<dyn Any> = Rc::new(i32::max_value());
1787+
let r2: Rc<dyn Any> = Rc::new("abc");
17881788

17891789
assert!(r1.clone().downcast::<u32>().is_err());
17901790

src/liballoc/sync.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -978,18 +978,18 @@ unsafe impl<#[may_dangle] T: ?Sized> Drop for Arc<T> {
978978
}
979979
}
980980

981-
impl Arc<Any + Send + Sync> {
981+
impl Arc<dyn Any + Send + Sync> {
982982
#[inline]
983983
#[stable(feature = "rc_downcast", since = "1.29.0")]
984-
/// Attempt to downcast the `Arc<Any + Send + Sync>` to a concrete type.
984+
/// Attempt to downcast the `Arc<dyn Any + Send + Sync>` to a concrete type.
985985
///
986986
/// # Examples
987987
///
988988
/// ```
989989
/// use std::any::Any;
990990
/// use std::sync::Arc;
991991
///
992-
/// fn print_if_string(value: Arc<Any + Send + Sync>) {
992+
/// fn print_if_string(value: Arc<dyn Any + Send + Sync>) {
993993
/// if let Ok(string) = value.downcast::<String>() {
994994
/// println!("String ({}): {}", string.len(), string);
995995
/// }
@@ -1574,7 +1574,7 @@ mod tests {
15741574
assert_eq!(unsafe { &*ptr }, "foo");
15751575
assert_eq!(arc, arc2);
15761576

1577-
let arc: Arc<Display> = Arc::new(123);
1577+
let arc: Arc<dyn Display> = Arc::new(123);
15781578

15791579
let ptr = Arc::into_raw(arc.clone());
15801580
let arc2 = unsafe { Arc::from_raw(ptr) };
@@ -1879,8 +1879,8 @@ mod tests {
18791879
use std::fmt::Display;
18801880
use std::string::ToString;
18811881

1882-
let b: Box<Display> = box 123;
1883-
let r: Arc<Display> = Arc::from(b);
1882+
let b: Box<dyn Display> = box 123;
1883+
let r: Arc<dyn Display> = Arc::from(b);
18841884

18851885
assert_eq!(r.to_string(), "123");
18861886
}
@@ -1889,8 +1889,8 @@ mod tests {
18891889
fn test_from_box_trait_zero_sized() {
18901890
use std::fmt::Debug;
18911891

1892-
let b: Box<Debug> = box ();
1893-
let r: Arc<Debug> = Arc::from(b);
1892+
let b: Box<dyn Debug> = box ();
1893+
let r: Arc<dyn Debug> = Arc::from(b);
18941894

18951895
assert_eq!(format!("{:?}", r), "()");
18961896
}
@@ -1907,8 +1907,8 @@ mod tests {
19071907
fn test_downcast() {
19081908
use std::any::Any;
19091909

1910-
let r1: Arc<Any + Send + Sync> = Arc::new(i32::max_value());
1911-
let r2: Arc<Any + Send + Sync> = Arc::new("abc");
1910+
let r1: Arc<dyn Any + Send + Sync> = Arc::new(i32::max_value());
1911+
let r2: Arc<dyn Any + Send + Sync> = Arc::new("abc");
19121912

19131913
assert!(r1.clone().downcast::<u32>().is_err());
19141914

src/libcore/iter/iterator.rs

+22-1
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,30 @@ pub trait Iterator {
271271
/// Creates an iterator starting at the same point, but stepping by
272272
/// the given amount at each iteration.
273273
///
274-
/// Note that it will always return the first element of the iterator,
274+
/// Note 1: The first element of the iterator will always be returned,
275275
/// regardless of the step given.
276276
///
277+
/// Note 2: The time at which ignored elements are pulled is not fixed.
278+
/// `StepBy` behaves like the sequence `next(), nth(step-1), nth(step-1), …`,
279+
/// but is also free to behave like the sequence
280+
/// `advance_n_and_return_first(step), advance_n_and_return_first(step), …`
281+
/// Which way is used may change for some iterators for performance reasons.
282+
/// The second way will advance the iterator earlier and may consume more items.
283+
///
284+
/// `advance_n_and_return_first` is the equivalent of:
285+
/// ```
286+
/// fn advance_n_and_return_first<I>(iter: &mut I, total_step: usize) -> Option<I::Item>
287+
/// where
288+
/// I: Iterator,
289+
/// {
290+
/// let next = iter.next();
291+
/// if total_step > 1 {
292+
/// iter.nth(total_step-2);
293+
/// }
294+
/// next
295+
/// }
296+
/// ```
297+
///
277298
/// # Panics
278299
///
279300
/// The method will panic if the given step is `0`.

src/libpanic_unwind/dwarf/eh.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ pub const DW_EH_PE_indirect: u8 = 0x80;
4848
pub struct EHContext<'a> {
4949
pub ip: usize, // Current instruction pointer
5050
pub func_start: usize, // Address of the current function
51-
pub get_text_start: &'a Fn() -> usize, // Get address of the code section
52-
pub get_data_start: &'a Fn() -> usize, // Get address of the data section
51+
pub get_text_start: &'a dyn Fn() -> usize, // Get address of the code section
52+
pub get_data_start: &'a dyn Fn() -> usize, // Get address of the data section
5353
}
5454

5555
pub enum EHAction {

src/libpanic_unwind/emcc.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,20 @@ pub fn payload() -> *mut u8 {
2929
ptr::null_mut()
3030
}
3131

32-
pub unsafe fn cleanup(ptr: *mut u8) -> Box<Any + Send> {
32+
pub unsafe fn cleanup(ptr: *mut u8) -> Box<dyn Any + Send> {
3333
assert!(!ptr.is_null());
3434
let ex = ptr::read(ptr as *mut _);
3535
__cxa_free_exception(ptr as *mut _);
3636
ex
3737
}
3838

39-
pub unsafe fn panic(data: Box<Any + Send>) -> u32 {
39+
pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
4040
let sz = mem::size_of_val(&data);
4141
let exception = __cxa_allocate_exception(sz);
4242
if exception == ptr::null_mut() {
4343
return uw::_URC_FATAL_PHASE1_ERROR as u32;
4444
}
45-
let exception = exception as *mut Box<Any + Send>;
45+
let exception = exception as *mut Box<dyn Any + Send>;
4646
ptr::write(exception, data);
4747
__cxa_throw(exception as *mut _, ptr::null_mut(), ptr::null_mut());
4848

src/libpanic_unwind/gcc.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ use dwarf::eh::{self, EHContext, EHAction};
6767
#[repr(C)]
6868
struct Exception {
6969
_uwe: uw::_Unwind_Exception,
70-
cause: Option<Box<Any + Send>>,
70+
cause: Option<Box<dyn Any + Send>>,
7171
}
7272

73-
pub unsafe fn panic(data: Box<Any + Send>) -> u32 {
73+
pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
7474
let exception = Box::new(Exception {
7575
_uwe: uw::_Unwind_Exception {
7676
exception_class: rust_exception_class(),
@@ -94,7 +94,7 @@ pub fn payload() -> *mut u8 {
9494
ptr::null_mut()
9595
}
9696

97-
pub unsafe fn cleanup(ptr: *mut u8) -> Box<Any + Send> {
97+
pub unsafe fn cleanup(ptr: *mut u8) -> Box<dyn Any + Send> {
9898
let my_ep = ptr as *mut Exception;
9999
let cause = (*my_ep).cause.take();
100100
uw::_Unwind_DeleteException(ptr as *mut _);

src/libpanic_unwind/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
//! More documentation about each implementation can be found in the respective
2323
//! module.
2424
25+
#![deny(bare_trait_objects)]
2526
#![no_std]
2627
#![unstable(feature = "panic_unwind", issue = "32837")]
2728
#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
@@ -117,6 +118,6 @@ pub unsafe extern "C" fn __rust_maybe_catch_panic(f: fn(*mut u8),
117118
#[no_mangle]
118119
#[unwind(allowed)]
119120
pub unsafe extern "C" fn __rust_start_panic(payload: usize) -> u32 {
120-
let payload = payload as *mut &mut BoxMeUp;
121+
let payload = payload as *mut &mut dyn BoxMeUp;
121122
imp::panic(Box::from_raw((*payload).box_me_up()))
122123
}

src/libpanic_unwind/seh.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
//! throwing. Note that throwing an exception into Rust is undefined behavior
4444
//! anyway, so this should be fine.
4545
//! * We've got some data to transmit across the unwinding boundary,
46-
//! specifically a `Box<Any + Send>`. Like with Dwarf exceptions
46+
//! specifically a `Box<dyn Any + Send>`. Like with Dwarf exceptions
4747
//! these two pointers are stored as a payload in the exception itself. On
4848
//! MSVC, however, there's no need for an extra heap allocation because the
4949
//! call stack is preserved while filter functions are being executed. This
@@ -243,7 +243,7 @@ static mut TYPE_DESCRIPTOR2: _TypeDescriptor = _TypeDescriptor {
243243
name: imp::NAME2,
244244
};
245245

246-
pub unsafe fn panic(data: Box<Any + Send>) -> u32 {
246+
pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
247247
use core::intrinsics::atomic_store;
248248

249249
// _CxxThrowException executes entirely on this stack frame, so there's no
@@ -297,7 +297,7 @@ pub fn payload() -> [u64; 2] {
297297
[0; 2]
298298
}
299299

300-
pub unsafe fn cleanup(payload: [u64; 2]) -> Box<Any + Send> {
300+
pub unsafe fn cleanup(payload: [u64; 2]) -> Box<dyn Any + Send> {
301301
mem::transmute(raw::TraitObject {
302302
data: payload[0] as *mut _,
303303
vtable: payload[1] as *mut _,

0 commit comments

Comments
 (0)